Flashlight Firmware Repository

Yes the shower must be slow, edited post above. Will test the card trick later but must first go out with the dog in the night and test a few new firmware features i just added. Multi group firmwares are pretty useful after all I must say. It’s amazing how much you can squeeze into 1024 bytes. :slight_smile:

Yes, in C arrays are passed as a pointer to the beginning of the array. If you want to know how big that chunk of memory is, you need to pass the size too.

Also, this means that the symbols for arrays and pointers can be used pretty much interchangeably. The syntax of “array[3]” is basically identical to “*(array + 3)”. Take the pointer, add three of whatever its size unit is, then get whatever is at that location in memory.

Lets just say that I found that out the hard way. Usually I just go by the “if it works don’t try to fix it” philosophy but when you only got 1024 bytes you must code as efficient as possible too.

It works but I’m not really sure I got it completely right though. The rest of the multi group code I got to work directly (didn’t think that would happen). Not sure it’s the most efficient way though but so far so good. Also, I can’t really see the point with battery monitoring (if you run out of juice just pop in another one :laughing:. I only kept the power down stuff and got rid of the low mode. Turbo timer I can see that it can be useful with high power DD drivers though so I also added that.

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?