Rockbox

  • Status Closed
  • Percent Complete
    100%
  • Task Type Patches
  • Category Plugins
  • Assigned To No-one
  • Operating System Sansa e200
  • Severity Low
  • Priority Very Low
  • Reported Version Daily build (which?)
  • Due in Version Undecided
  • Due Date Undecided
  • Votes
  • Private
Attached to Project: Rockbox
Opened by clone4crw - 2010-08-30
Last edited by fg - 2010-10-02

FS#11585 - New plugin: Resistor code calculator

This is a calculator that will accept four band colors from menus, and graphically display a resistor corresponding to that, as well as the resistance in ohms. At the moment, its capability is limited to this.
It works on both the Sansa Fuze and e200, and will require someone else to help me port this to more players, because this plugin does NOT work in simulators.
I hope in the future to finish the second part, which is accepting a keyed-in value and outputting the corresponding colored bands.

More details are in the new resistor.c heading comments. (Should those be re/moved?)

The zip file contains 3 files: resistor.diff, and the two bmp images used (one for the two supported Sansas)

Closed by  fg
2010-10-02 14:12
Reason for closing:  Accepted
Additional comments about closing:   Warning: Undefined array key "typography" in /home/rockbox/flyspray/plugins/dokuwiki/inc/parserutils.php on line 371 Warning: Undefined array key "camelcase" in /home/rockbox/flyspray/plugins/dokuwiki/inc/parserutils.php on line 407

Committed as r28191 (with minor changes)

St. commented on 2010-08-30 23:10

I wanted to give this a go on my iPod Nanos so I cleaned up the resistor.176x220x16.bmp image.
“cleaned” == symmetry/colour correction in some places/smoothed some lines/general “prettying up”

[St.]

Fixed the simulators, indentation, a few other things.

Added better iPod Nano support here, switched to PluginLibActions, now checks for LCD type instead of keymaps.

Admin
fg commented on 2010-08-31 08:29

Things I’d say are real bugs:
- You should really look at LCD_WIDTH and LCD_HEIGHT to decide on screen layout.
- int a=1/10; stores 0 in a. You’ll want to handle fractional multipliers some other way. Unfortunately I think the obvious solution of using units of 1/100 ohm won’t work as is, because then the largest multiplier is 100,000,000, and is I read the code correctly the largest value you ever multiply this with is 99, so the largest “full” value would be 9,900,000,000 which doesn’t fit in an int anymore. You’ll need to do some thinking here.

Things I would personally change, but which aren’t bugs as such:
- I’d put the colour to value mapping in tables. The code right now looks very repetitive, and it can be shortened a lot by doing this.
- I’d change the variable and function names a bit, to “multiplier”, “tens”, …, as soon as you’re not dealing with real positioning any more. “first band” confuses me when you’re actually calculating the final value.
- Do you really need functions like color_to_resistance_menu()? If you just call do_*_band_menu() directly, it doesn’t make the code any harder to read, and it’s a lot shorter.
- Maybe change some of those defines to enums. That doesn’t change the generated code, but I think it looks nicer, and you can get compilers to warn you if you forget one in a switch statement.

Some nontechnical things:
- Won’t people who use this plugin know what a resistor is? Do you need to explain that in the help?
- Rockbox uses UK english for UI texts and manual, so “colour” and friends. For variable and function names in the code this doesn’t matter.

Please post diffs if you only change the code, not zip files. This makes it easier to review the code (simply because it removes one step required to read the diff). Putting the bitmaps into a separate zip file is another way that doesn’t require to unpack something just to look at the code too.

Frank:
> - int a=1/10; stores 0 in a. You’ll want to handle fractional multipliers some other way
Yes, I know, work needs to be done there.

- I’d put the colour to value mapping in tables. The code right now looks very repetitive, and it can be shortened a lot by doing this.
If you could help me with that, that’d be great.
- I’d change the variable and function names a bit, to “multiplier”, “tens”, …, as soon as
It makes a bit more sense to me personally… a bit more consistency across everything, if you will.
- Do you really need functions like color_to_resistance_menu()?
Was a way to isolate stupid early-on problems. I will consolidate that.
- Maybe change some of those defines to enums.
I am not exactly interested in doing that myself, but if you are, go at it.
- Won’t people who use this plugin know what a resistor is? Do you need to explain that in the help?
Just threw that in for the heck of it. Does it pose a problem?/ could a helpfile have a better use?
- Rockbox uses UK english for UI texts and manual, so “colour” and friends. For variable and function names in the code this doesn’t matter.
Sure, I can do that.

Dominik:
Ok, I’ll stop that.

Added: Support for monochrome targets: Sansa Clip and m200, more later
Fixed: changed “color” to “colour”, consolidated old color_to_resistance_menu()
Now broken: Fuze bitmap is all garbled. 99% sure it’s a stupid typo of mine somewhere.

Admin
fg commented on 2010-09-06 18:43

I’ve had a go at changing what I thought could be improved. I didn’t touch the help text or the menus (yet, I think the menus take too much code…), but I think I changed just about everything else

Feel free to pick the bits you like from this (or everything). As far as I can see, everything works the way it should. It compiles on non-colour targets and targets with smaller screens, but I haven’t tested those.

There’s one issue left (which it shares with *many* plugins): it ignores USB plugin events.

And here is pretty much the whole keyed-in resistance to color codes part completed.

Works with e200, Fuze (although the BMP’s still messed up), Clip, Nano, and m200. It requires all of the BMPs in the zip that will be in the next comment by me.

I’m guessing there’s still a bunch of issues regarding the new resistance to codes routines, but it seems to work with the common resistances (I mainly tested 470, 47, 1K, 10K, 100, a couple of others).

Frank: I still need to look at your changes, haven’t done that yet.

Here is the aforementioned zip file. The file resistor.112x64x1.bmp is never used by any of the targets (it was originally planned to be), but seems to be necessary to the compiler.

Frank, I am very impressed at how you well were able to turn my kludge of a plugin into some real nice-looking code. I made a few modifications to it, mostly removed some old, irrelevant comments of mine, and added the whole new resistance → colors routines. I think we’re almost there. I’ll look into fixing the USB event detection.

Hmmm… Now the color_to_resistance() routine seems to be broken and causing segmentation faults.

The segfaults were because I was using the 100822 build. Everything works in the 100906 build. I made a few more modifications, removed some more old stuff, and added a 3-line event handler for USB events in the main menu.

Sorry, forgot to attach the new diff.

Added: LED resistance calculator - determines the resistor needed for a LED based on the input voltage and current. Rounds the resistor to the nearest common one (350 Ohms > 390 Ohms) and calculates the necessary power rating.

Admin
fg commented on 2010-09-26 15:46

I haven’t tested this latest patch, but it mostly looks good.
One issue: int get_power_ten(float in_val). Don’t use float. On the one hand, the hardware doesn’t support it, so it’s *slow*, and on the other hand, the code that calls it passes an int anyway.

What’s also still missing is a patch for the manual, or at least one or two paragraphs of text to include if you don’t know LaTeX yourself. The in-plugin text is probably a good start.

Also, more (especially smaller) bitmaps would be nice. The smallest two colour screens we have are c200 and H10, with 132×80 and 128×128 respectively, so just adding a 128 pixel wide (or smaller) image would provide support for everything.

OK, sorry this took a week longer than I thought it would. I have added 5 more bitmaps, and an update and screenshots for the manual. The zip contains the new .diff, and the new images in their respective folders.

Loading...

Available keyboard shortcuts

Tasklist

Task Details

Task Editing