Flashlight Firmware Repository

One effective way to deal with array issues in C is to use the Pascal approachā€¦ make it one word bigger than necessary, and use the first item in the array to store its length. Another way is to make it one word longer and put a null at the end, but that means you canā€™t store any other nulls in it.

Or if itā€™s hardcoded at compile time, use ā€˜sizeof(myarray)ā€™ to get its length. But that only works for hardcoded arrays and only when the original symbol is referenced.

Yeah I managed to fix the problem with sizeof as my arrays are hardcoded compile time. But I did read up on the things you talk about too. Stackoverflow has tons of answers on just about any possible coding problem. :slight_smile: But now I ran into another problem, _delay_ms() only takes compile time constants as value! What da heck is up with that? I was thinking about making it possible to set strobe frequency at run time but now I donā€™t know if that is even possible to do with just a few bytes.

That's the nature of standard _delay_ms(). I replaced it with my own approximate delay function, which fixes that problem and also saves a couple of bytes. See TheStar.c in the repo.

Thanks man! Saved 4 bytes too. :slight_smile:

Edit: Your function seems a bit unstable, it doesnā€™t work properly.

Edit2: Could it be that it must have 16 bit integers as value because those seem to work properly? 8 bit doesnā€™t work?

Edit3: Forget what I wrote above, found a simple bug, will report back soon.

Iā€™m using nearly the same function in pretty much all my firmwares, so Iā€™d like to hear more about this bug.

Yes there seems to be a bug whan passing a uint8_t from eeprom as parameter. My strobe frequency is not stable to say the least. Any fix much welcome. :slight_smile:

Edit: Itā€™s this line: strobe_delay = eeprom_read_byte((const uint8_t *)(uint16_t)2);

Edit2: My strobe is on friggin shuffle mode!!!

Edit3: My 15hz strobe works ok for a few seconds and after that it freaks out. Slower faster and whatnot.

Edit4: Just a guess, when WDT kicks in after one second it mess things up for short delays.

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