Flashlight Firmware Repository

Ok, itā€™s not exactly a bug but hereā€™s what I found. The _delay_loop function runs in software and doesnā€™t work reliably if you use a wdt. But I found out that _delay_ms runs on a hardware clock so I switched to that but it didnā€™t work anyway. So I was just about to throw in the towel when I realised that I donā€™t really need 1ms resolution so I tried with 5ms instead. And bloody he it worked. :slight_smile: So now I can set the strobe frequency in run time. I also saved a few bytes in the process as I could get rid of the uint16_t too.

Strobe seems super stable running with the delay_5ms function.

Added ramping too and still got a few bytes left to play with so if you got any ideas. But in another thread there is a guy that wants to set his own modes and this got me thinking if anyone has written a firmware that is completely empty and you have to program the modes yourself? That would be a bit cool actually. If you want ie 65, 32, 100, 42 you can have it that way.

Was going out with the dog in the night and wanted something to play with so I made an almost empty firmware, only took a few minutes. Only got one mode full blast by default and then you would have to program all other modes by yourself. I tested it right now in the night and itā€™s a bit tedious but you can have your own exact group as you wish. I set a limit on max six modes but can be increased easily if wanted.

This is very cool :slight_smile: can you program the turbo step down on the fly like dr jones guppydrv also?

How do you program it when its in the light? would it work with a twisty? or is it very many very quick clicks that would make it hard to do in a twisty?

And can you reset the modes whenever you want later?

Iā€™ve been a bit busy lately, but Iā€™d like to include all of the above as soon as I get time to add it to the collection. :slight_smile:

RTFM! :stuck_out_tongue: Iā€™m a flashlight noob and donā€™t know much about twistys. But you program the firmware with making 10-19 short presses and then you count flashes and switch off when you get the value you want. IE if you want 90 seconds turbo timer you make 11 short presses and then count 90 flashes and switch off. If this works with a twisty I donā€™t know.

Edit: And of course you can set all settings as many times as you want.

Iā€™m still updating my firmwares if I find anything broken or missing so maybe better just put a link or something. BTW, how do you rename links in your sig?

Very nice, sounds extremely useful.

A twisty is the colloquial term here for a flashlight that donā€™t have a button for on off, but you twist the body & head to turn off & on :slight_smile:

Often used on small AAA size & smaller lights, to be able to build them smaller & shorter than if they had a switch. The downside is more than a few modes is a hassle on them, because you canā€™t twist as fast as you can push a button, especially with one hand.
But for programming them when needed, it sounds manageable :slight_smile:

Does it have the basics like low volt protection shut off & step down & such features? Sorry if this is all spelled out in the manualā€¦ā€¦

Yeah I understand what a twisty is but I donā€™t got one myself. But thinking about it I do got an old mini-mag but I donā€™t count that one. :slight_smile: There is only low voltage shut off right now but thereā€™s plenty of space left so Iā€™ll add step down too. Just to copy and paste some code from one of my other firmwares anyway.

Iā€™m treating the code repo somewhat like a Linux distro. The projects there arenā€™t expected to be 100% complete, just mature enough to be usefulā€¦ and updates over time are totally fine. The idea is to get all the good stuff in one place as a convenient and curated collection.

HTML.

BLF allows a large subset of HTML in posts and in signatures, so you can do a regular <a href=ā€œhttp://fooā€>Foo!</a> to make a link.

Good, LVP is the most important bit anyway.

Bat check is another nice feature to have, also 2 pwm channels support. But that could get complicated.

Is you pwm fast for the lower pwm levels & phase for the max output mode, as is often recommended?

None of my firmwares support dual-pwm even though theyā€™re kinda prepared for it. As you say it will get a tad complicated as different people will have different opinions on how itā€™s going to be used. Just setting both outputs to the same value is easy though. And yes Iā€™m using phase for full output (mostly just doing as ToyKeeper says :laughing::

I havenā€™t thought of battery check, yet. Donā€™t think Iā€™m gonna bother with it but you should never say never. If I do it I think Iā€™m gonna hide it in 30 short presses or something like that. Will maybe have to throw out something else to make it fit though.

Hi TK, do you have any ramping firmware in your repository?

Yes. To get a list, browse to the index file, and search for ā€œrampā€:
http://bazaar.launchpad.net/~toykeeper/flashlight-firmware/trunk/view/head:/INDEX

Is there any firmware in the repository that has a good formula for smooth PWM brightness adjusting? The ones I have looked at all have a predefined arrays. Iā€™m looking to avoid that and would rather do it with coding. Increasing by the same amount just doesnā€™t work very well. So far I havenā€™t come up with one that smoothly and evenly goes from moon to 255.

Take a look at ToyKeeper/Ferrero_Rocher/Ramping_UI_Table.c and the ramp_calc.py tool. It calculates a small variety of visually-linear ramps with an arbitrary number of steps. I find that 64 steps works well for a 2-second ramp, though Ideally Iā€™d like more steps per second. I only used 64 because it was the most I could fit.

Calculating a smooth ramp on the device itself is difficult because it doesnā€™t do floating point math and doesnā€™t have much space. Itā€™s much much easier to use a table instead, even if itā€™s a large table.

In any case, the models Iā€™ve tried are logarithmic, quadratic, and cubic. I personally like logarithmic ramps because it gives me more resolution toward the lower levels, but cubic is technically more correct. Quadratic gives sort of a compromise between the two.

Additionally, the lowest levels can benefit from using PFM (pulse frequency modulation) in addition to PWM (pulse width modulation), because the lowest few PWM levels produce pretty large visual jumps in brightness. PFM can smooth out those lower levels, but it only works on single-channel drivers (no FET+1) and it can be very sensitive to battery voltage.

Iā€™ll check it out, thanks.

I have a ramping clicky, is there a ramping MOM anywhere? For an 8X ~ 12X Nanjg...

Yes, thatā€™s what the one a couple posts ago is ā€” a ramping UI for momentary switch lights like the SRK or Roche F6: ToyKeeper/Ferrero_Rocher/Ramping_UI_Table.c

For a nanjg-based driver, you might need to recalculate the ramp values. By default itā€™s calibrated for a FET driver or a 32x7135 driver, but regular nanjgs need a higher zero point. The ramp_calc.py tool can generate new values for you; just tell it the lowest PWM value which actually produces light and adjust the goal multiplierā€¦ it might take some trial and error to get it to produce the right number of steps though.

I'll check into it.

Thank you!