Rockbox

Tasklist

FS#11585 - New plugin: Resistor code calculator

Attached to Project: Rockbox
Opened by Calvin Walden (clone4crw) - Monday, 30 August 2010, 20:07 GMT
Last edited by Frank Gevaerts (fg) - Saturday, 02 October 2010, 14:12 GMT
Task Type Patches
Category Plugins
Status Closed
Assigned To No-one
Operating System Sansa e200
Severity Low
Priority Normal
Reported Version Daily build (which?)
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

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)
This task depends upon

Closed by  Frank Gevaerts (fg)
Saturday, 02 October 2010, 14:12 GMT
Reason for closing:  Accepted
Additional comments about closing:  Committed as r28191 (with minor changes)
Comment by Hayden Pearce (St.) - Monday, 30 August 2010, 23:10 GMT
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.]
Comment by Calvin Walden (clone4crw) - Monday, 30 August 2010, 23:54 GMT
Fixed the simulators, indentation, a few other things.
Comment by Calvin Walden (clone4crw) - Monday, 30 August 2010, 23:54 GMT
^^
Comment by Calvin Walden (clone4crw) - Tuesday, 31 August 2010, 02:33 GMT
Added better iPod Nano support here, switched to PluginLibActions, now checks for LCD type instead of keymaps.
Comment by Frank Gevaerts (fg) - Tuesday, 31 August 2010, 08:29 GMT
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.
Comment by Dominik Riebeling (bluebrother) - Tuesday, 31 August 2010, 20:57 GMT
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.
Comment by Calvin Walden (clone4crw) - Wednesday, 01 September 2010, 01:47 GMT
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.
Comment by Calvin Walden (clone4crw) - Friday, 03 September 2010, 23:26 GMT
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.
Comment by Frank Gevaerts (fg) - Monday, 06 September 2010, 18:43 GMT
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.
Comment by Calvin Walden (clone4crw) - Monday, 06 September 2010, 20:09 GMT
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.
Comment by Calvin Walden (clone4crw) - Monday, 06 September 2010, 20:13 GMT
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.
Comment by Calvin Walden (clone4crw) - Tuesday, 07 September 2010, 02:19 GMT
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.
Comment by Calvin Walden (clone4crw) - Tuesday, 07 September 2010, 03:33 GMT
Hmmm... Now the color_to_resistance() routine seems to be broken and causing segmentation faults.
Comment by Calvin Walden (clone4crw) - Wednesday, 08 September 2010, 00:38 GMT
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.
Comment by Calvin Walden (clone4crw) - Wednesday, 08 September 2010, 00:40 GMT
Sorry, forgot to attach the new diff.
Comment by Calvin Walden (clone4crw) - Saturday, 11 September 2010, 20:48 GMT
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.
Comment by Frank Gevaerts (fg) - Sunday, 26 September 2010, 15:46 GMT
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 132x80 and 128x128 respectively, so just adding a 128 pixel wide (or smaller) image would provide support for everything.
Comment by Calvin Walden (clone4crw) - Saturday, 02 October 2010, 00:36 GMT
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...