Flashlight Firmware Repository

1943 posts / 0 new
Last post
ToyKeeper
ToyKeeper's picture
Offline
Last seen: 54 min 34 sec ago
Joined: 01/12/2013 - 14:40
Posts: 8252
Location: (469219) 2016 HO3

guardior wrote:
Got a compiler warning when using a line from blf-a6 but managed to fix it with this:
eep = eeprom_read_byte((const uint8_t *)(uint16_t)eepos);

The compiler doesn’t fully understand the memory model on the attiny, or that the eeprom address space only has 64 slots, so it expects a 16-bit memory pointer and you’re passing it an 8-bit integer. This is totally fine, but the compiler is confused. You can turn off the warning by putting this somewhere in the code:

#pragma GCC diagnostic ignored “-Wint-to-pointer-cast”

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

My fix works without increasing size so if compiler is happy I’m happy already. Oh yeah forgot to say, as it turns out eeprom_read_block is just a wrapper for eeprom_read_byte so it’s basically the same thing.

Edit: Damn fast pwm is nice! No more friggin buzzing pwm modes. A big thanks to all who started this driver flasher thing. Smile

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

ToyKeeper wrote:
In sleep mode the PWM counter stops, but I haven’t specifically tested to see what that does when I don’t set it to zero first. I expect the emitter would stay on if it’s not turned off before entering sleep (which is a trick I use for the standby light on my Roche F6, but first I set it to a special non-PWM low mode).

Ok, I have investigated this now. If you enter sleep mode power down all pwm output is shut off. However, full output (255) is not shut off. I found a solution to that and if you make all your pins input (0 bits) all output is shut off. So to properly shut off as much power drain as possible you should first shut off WDT and ADC and then you set pins to input. After that you can enter power down mode. Too bad there is not a power off mode that takes care of everything already.
ToyKeeper
ToyKeeper's picture
Offline
Last seen: 54 min 34 sec ago
Joined: 01/12/2013 - 14:40
Posts: 8252
Location: (469219) 2016 HO3

guardior wrote:
If you enter sleep mode power down all pwm output is shut off. However, full output (255) is not shut off.

Sounds like it could also be a race condition… if the PWM wave is high, it stays on; if the PWM wave is low, it stays off? So if PWM is set to 128 it might have a 50% chance of shutting off?

Just a guess.

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

Frankly i don’t care. With that said, gaaah, I hate it when you’re right. But I guess that’s why you’re the sheriff in town. 8) Yes it seems to be a race. I only tested before with 10% and then it shut off a few times. But if you test 50% sometimes it shuts off and sometimes it goes to full output. It doesn’t matter though as you just set all pins to input and be done with it.

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

I’m pretty happy with my first driver so I wrote another one. I’m a c noob so I basically just make things up along the way. Smile And I managed to get just about everything to work except one thing, I couldn’t for my life get the right mode count of an array I pass as a parameter to a function. In the end I found out that it’s not possible and you have to pass the size as its own parameter. grrr. Anyway, it got run time group settings so it’s pretty cool. A seasoned c coder probably can save a few bytes here and there and squeeze a bit more modes into it so happy hacking.

https://github.com/xerxes2/flashlight-firmware/tree/master/sharkdrv

jhalb
jhalb's picture
Offline
Last seen: 1 year 8 months ago
Joined: 03/23/2015 - 21:24
Posts: 1350
Location: California

Thank you so much for this!!

I appreciate all your time and effort in enhancing our community as you have.Smile

Joat
Offline
Last seen: 1 week 11 hours ago
Joined: 06/13/2013 - 23:43
Posts: 521
Location: Minnesota

Toy Keeper, I’ve got your cypreus2 in my EagleEye XA-6 triple build, so far I’m liking it, the blinky modes are fun in the rain. Is there an easy way to make the first hidden mode High instead of Max Turbo? Hitting max turbo on this light is painful in daylight.

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 54 min 34 sec ago
Joined: 01/12/2013 - 14:40
Posts: 8252
Location: (469219) 2016 HO3

Joat, to change the hidden modes, just change the definition of HIDDENMODES so it says “100” or so instead of “TURBO”. You might also want to change the last “PHASE” to “FAST” on the next line. And if you want a short tap to go to max turbo instead of moon (off to moon, med top to high, short tap to either moon or max turbo), you should also change the ‘0’ on the HIDDENMODES_ALT line to the number of the mode you want next (probably SOLID_MODES-1).

So, it’s a little weird… but that’s because I wasn’t planning on putting any regular operation modes in the hidden loop.

Also, one reason max turbo is so easy to get to from off is because it serves as “impress mode”, for when muggles ask about a light. They don’t usually care that it has a nice moon mode, but they’re sure impressed by max turbo.

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

jhalb wrote:

Thank you so much for this!!

I appreciate all your time and effort in enhancing our community as you have.Smile


And thank you back. Smile I found this site when I was looking for pwm-less drivers to get away from the buzzing. I had zero knowledge about that you could write your own firmware with fast-pwm before. I’ve been seriously impressed with fast-pwm so far. All I can say to all of you is that if you don’t want to flash your driver yourself you should buy one from mtn that already got fast-pwm. I thought ToyKeeper was just talking bull when she said that fast-pwm is almost as good as no pwm but not even the SLOW shower trick seems to work with fast-pwm so I’m happy. Smile
ToyKeeper
ToyKeeper's picture
Offline
Last seen: 54 min 34 sec ago
Joined: 01/12/2013 - 14:40
Posts: 8252
Location: (469219) 2016 HO3

guardior wrote:
… not even the shower trick seems to work with fast-pwm so I’m happy. Smile

Speaking of shower tricks, a 24 Hz strobe with 0.3ms duty cycle is lots of fun with running water.

(also, showers are terrible at showing PWM unless it’s really slow… water droplets change shape as they fall so they generate their own light pulses even on constant-output lights… try waving a note card quickly through the beam instead)

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

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. Smile

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 54 min 34 sec ago
Joined: 01/12/2013 - 14:40
Posts: 8252
Location: (469219) 2016 HO3

guardior wrote:
I managed to get just about everything to work except one thing, I couldn’t for my life get the right mode count of an array I pass as a parameter to a function. In the end I found out that it’s not possible and you have to pass the size as its own parameter. grrr.

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.

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

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.

https://github.com/xerxes2/flashlight-firmware/blob/master/sharkdrv/shar...

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 :)). 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.

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 54 min 34 sec ago
Joined: 01/12/2013 - 14:40
Posts: 8252
Location: (469219) 2016 HO3

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.

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

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. 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.

_the_
_the_'s picture
Offline
Last seen: 1 week 19 hours ago
Joined: 07/08/2011 - 06:22
Posts: 3587
Location: Finland

guardior wrote:
But now I ran into another problem, _delay_ms() only takes compile time constants as value! What da heck is up with that?

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.

=the=

Disclaimer: Above post might contain referral links, but only to items that I myself have bought, tested & approved. Or items that, based on my experience, can be considered as good deals & worth sharing.

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

Thanks man! Saved 4 bytes too. 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.

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 54 min 34 sec ago
Joined: 01/12/2013 - 14:40
Posts: 8252
Location: (469219) 2016 HO3

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

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

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. 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.

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

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. 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.

https://github.com/xerxes2/flashlight-firmware/blob/master/sharkdrv/shar...

Strobe seems super stable running with the delay_5ms function.

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

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.

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

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.

https://github.com/xerxes2/flashlight-firmware/tree/master/geniedrv

cajampa
Offline
Last seen: 2 years 5 months ago
Joined: 08/01/2014 - 01:55
Posts: 1963
Location: Sweden

This is very cool 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?

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 54 min 34 sec ago
Joined: 01/12/2013 - 14:40
Posts: 8252
Location: (469219) 2016 HO3

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. Smile

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

cajampa wrote:
This is very cool 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?


RTFM! Silly 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.

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

ToyKeeper wrote:
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. Smile

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?
cajampa
Offline
Last seen: 2 years 5 months ago
Joined: 08/01/2014 - 01:55
Posts: 1963
Location: Sweden

guardior wrote:
RTFM! Silly 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.

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 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 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……

guardior
Offline
Last seen: 3 years 5 months ago
Joined: 04/06/2015 - 14:06
Posts: 129
Location: Sweden

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. 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.

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 54 min 34 sec ago
Joined: 01/12/2013 - 14:40
Posts: 8252
Location: (469219) 2016 HO3

guardior wrote:
I’m still updating my firmwares if I find anything broken or missing so maybe better just put a link or something.

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.

guardior wrote:
BTW, how do you rename links in your sig?

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.

Pages