E-switch UI Development / FSM

That sounds like a Far Side cartoon!
Iā€™m reminded of a early DX light I had that spelled out SOSOSOSOS.
If you really needed to signal someone you could just run your hand in front of the light and ā€œtapā€ it out yourself.
To save you extra effort remember that mountaineering distress signals are simply groups of 3. Can be 3 anything, just something that stands out.
The Batt Check would work with a slightly depleted battery if you covered it up for the decimal readings.

ā€œAll it says is SSSSSSS, must be someone messing aroundā€.

Awesome, thatā€™s pretty close to what we came up with too, which is a good sign. It seems several people have independently created very similar e-switch UIs with roughly the same basic operation. This tells me itā€™s probably a genuinely good solution, one of the tallest peaks in the problem space, since people keep creating similar designs.

I wonder why big-name commercial lights are usually so different than this obvious solution.

That sounds more complex that I was expecting. How about if it was done from moonlight (Iā€™m guessing thatā€™s under 20mA in most lights)? Would that make it pretty simple to implement? Overnight moonlight is often useful in these cases too.

Do you think a half-sleep mode would use much less than 5mA?

Iā€™ve actually got one of those mains powered ā€œsunrise clocksā€ that are supposed to emulate the sun rising to help you wake up in the morning. The technique works (fairly well, at least) but instead of a gradual ramp it jumps up about 10lm of 6500K every minute (to about 100lm). I can imagine something like the D4ā€™s ramp being much nicer. Having it in a flashlight would make it useful for camping and hotels too.

Really, I just want an excuse to buy the equipment needed to flash a driver :stuck_out_tongue:

Have you considered implementing PID algorithm for thermal control?

Copying and quoting from another thread, we have a perfect host for the above described light: The S42. I realize that the uC would need to be changed to an AT of some flavor, but perhaps by giving up in light charging we could gain enough real-estate to get the USB interface to function.

My S42 just sits on my desk at work, begging to be used, but the UI is just prohibitive.

Have you considered looking at the code? :stuck_out_tongue:

But joking aside, a wide range of things fall into the category of ā€œPID algorithmsā€ and it basically already uses one. It just has kind of a weird ā€œIā€ term implemented as a lowpass or latch on the ā€œDā€ term. And itā€™s heavy on the ā€œDā€ term in order to predict temperature in advance to compensate for lag in measurement.

Iā€™ve been meaning to try a version which uses an actual ā€œIā€ term of sorts as its primary output, to see if it behaves any better, but Iā€™ve been busy and the testing for thermal stuff always takes a long time.

Yes, a half-sleep mode should be well under 5mA. Hopefully well under 1mA, but I donā€™t recall offhand what the sleep mode power is with WDT enabled. The full standby mode is only like 0.02mA, which is nice, but it doesnā€™t wake up unless the button is pressed.

Using moon mode wouldnā€™t reduce power use. Idle mode with the MCU running is ~5mA, and moon mode is ~7mA. This means most of the power in moon mode is wasted just to keep the MCU running, not to make light. I wonder if thereā€™s a way to reduce that without sacrificing any functionalityā€¦ like maybe turn the ADC off most of the time, or run the MCU at a slower clock speed, or something.

I mean, if you wanted to combine the alarm clock with an all-night moonlight mode, thatā€™s do-able right now with no plumbing changes. But the high idle power has been bugging me anyway, so I should try to fix it. And a half-sleep mode is probably worth adding to the toolkit.

Itā€™s a good idea; I just need to add some extra plumbing to make it feasible without wasting lots of power. I have other plumbing to add too, like an option to use ā€œshort click, long click, or holdā€ instead of just ā€œclick, or holdā€. That one is mostly for the Russian crowd though, since I havenā€™t seen that type of UI anywhere else.

If you need any reasons to get firmware flashing equipment, there are plenty of reasons at the links in my signature. :smiley:

But what does the ā€œFā€ stand for?

Flashlight, of course.

Or whatever F word you feel like at the time.

Haha - that F* spaghetti monster.

But seriously cool stuff! Makes me want to pick up mcu coding.

How feasible is a Pi Zero flashlight? Other than a host to shove it in? The new ones even come with Bluetooth and wifi. All sorts of fun there.

One of my favourite E-switch UI is the Skilhunt H03.
From Off:
-one click: last used mode
-hold: lowest mode
-doubble click: highest mode
-hold more than x seconds: powers on moon then blinks and go to Lockout

In lockout mode : one click activete or deactivate the button lighting beacon flashing red led.

From ON:
-one click: go the next mode
-doubble click: change to other submode (every mode has two submodes and if you choose one the light will store it and you can adapt the mode spacing to your taste)
-hold: OFF

Some of the H03ā€™s UI looks pretty similar. Some of the differences are interesting, while others are things Iā€™ve been avoiding.

The clicks during lockout to change indicator LED behavior might be a good thing to keep in mind for later. I donā€™t have any lights with indicator LEDs and recent drivers, but as soon as I get a Q8 Iā€™ll be adding indicator LED support to the toolkit.

Another thing which might be worth adapting is the hold-for-moon thing during lockout. Not sure if the H03 does that, but my Baton lights do. It gives nice feedback and doesnā€™t cost much power. Basically, lockout mode becomes sort of a momentary moon mode with four clicks to exit.

I donā€™t really care for ā€œhold to toggle lockoutā€ though, since that kind of thing can happen pretty easily by accident. I implemented it once ~3 years ago (hold for moon and continue holding to enter lockout), because I was cloning the Olight Baton UI. But since then Iā€™ve gone for multiple clicks instead, to avoid lockout accidents.

On hot-running lights, people have expressed that ā€œhold to turn offā€ is probably not a good idea, especially if the button is near the emitters. That didnā€™t go over well in the S42 and E14 II.

Edit: I added momentary (ish) moon to lockout mode. Itā€™s not good for signalling, since it still needs to check for the 4-click exit action, but itā€™s still useful for quick tasks in the dark without exiting lockout.

I like your Ideas. Maybe for the hot light problem you can short click to turn off and hold to change modes like Sunwayman C22C. Or we are almost there at the ramping things which is better and no need for submodes.

A pi zero is pretty big and IIRC it uses significantly more power. It could be neat, but itā€™s total overkill for this purpose.

However, if things go well I might try making a pi zero-like driver for another projectā€¦ Iā€™ll need much more processing power than an attiny processor can handle, and probably more than an atmega, so something like a stripped down pi zero might be about right.

Thatā€™s only if prior projects go well though.

Yeah, for me I donā€™t really see a need to tell me I screwed the cap on. So many lights donā€™t have that, Iā€™m just not sure how many users find it that necessary to have 2 bright blinks to say you screwed it on. I would at least love the optional choice if people do need it. We all have different needs and I know it is difficult. I appreciate the work and consideration. :slight_smile:

+1
I really like the H03 UI. Itā€™s a very versatile UI (like the Zebralightā€¦which I think you have a sort-of-copy version, Toykeeper?).

I like NarsilM, but I have two issues, both in the Mode set Operation:

1) Mode Lock
Iā€™m not a fan of the light turning off when you click the switch after the light has locked in a specific mode. I just want to be able to make the light brighter immediately, not turn it off or make it dimmer first then brighter. If there was a ā€œMode Lock enable/disableā€ option, that would be great! I understand that changes the mode selection UI, but it would grant the user even more flexibility in use. I am constantly needing to change modes when using a light - itā€™s a necessity.

2) Long Hold (over 1.2s) for Strobe
I would LOVE to see this be a configurable option, allowing the user to choose between either Strobe or Max (of the selected mode set) when performing a Long Press.

I have read and re read and seen the topic went into details.
I canā€™t help but think I missed the core of the first three posts. A universal UI to be customized by all to their liking?
Diving into code is a huge step for me, with all the things I have too do a leap too much to ask and I am sure I am not the only one.
This FSM, could it be presented in such a way even newbies can set up a light, using some clever way of getting the desired modes in a light, by using say the LED as a receiving diode? FSM as a stand alone app?

+1 invitation remains open of course :slight_smile:

+1

One more thing, the Unnamed UI from the original post looks great! I love the option of ramping up/down at any time, not dependent on your last direction. Also, getting too/from max is great!

Yes, thereā€™s a clone called DarkHorse. Itā€™s almost identical to a ZebraLight. I doubt Iā€™ll end up actually using it on any of my lights, but itā€™s a nice example for reference.

Iā€™m not a big fan of those either; thatā€™s why I did the discrete / stair-step mode differently in my Narsil-like UI. It works exactly the same as smooth ramping, except itā€™s not smooth. Instead, it has however many steps you want, evenly spaced between your preferred lowest and highest levels. The same actions do the same things in either mode though, and switching between them is easy.

No, itā€™s not really intended for everyone to make their own UI. What it does, mostly, is it reduces the time to create a UI from ~50 hours down to ~5 hours. But to be a universal thing customizable by all, it would need to take that time down to like 5 minutesā€¦ and it doesnā€™t.

Iā€™ll probably add that as a compile-time option later, but itā€™s not there yet. I donā€™t have a FW3A yet or a compatible driver to use for development.

My quick light-sensing test used a tiny25, but itā€™s a power-switch light and FSM doesnā€™t work on tiny25. FSM adds like 1.8k of overhead, or a bit more with thermal regulation enabled, so itā€™s not tiny25-friendly at all. However, above that base size, it seems to make the resulting firmware smaller overall. Like, Iā€™ve got most of the Meteor M43 UI cloned and I still have almost half the ROM left. Thatā€™s a bit satisfying, since the Meteorā€™s firmware author insists that the only way to make the Meteorā€™s features fit (on the same MCU) is to use assembly code, because C is far too bloated for use on attiny MCUs. But the C version seems like itā€™ll be smaller.

Out of curiosity, I tested thermal regulation on a light with a H17F driver, a brand new Okluma copper DC2. Jeff sent me one to thank me for all the free code, and perhaps also because I think he might want an open-source version of it. And I graphed it against my D4-219c with FSM:

The H17F thermal ramp-down is as smooth as it can get (the occasional bump was because I was holding the light and I moved). It seems to step down at a maximum speed of two PWM levels per second on FET modes or one PWM level per second otherwise, one channel at a time, until the temperature is no longer out of spec. This makes it really smooth but also really slow. Eight minutes to reach stable state at the configured temperature limit.

My FSM-based D4 also steps down one PWM level at a time, but itā€™s much faster, up to 8 adjustments per second. It looks just as smooth in person, but it reaches its destination(s) sooner and then is a bit more jittery after reaching stable state. One minute to reach stable state in this test, and another minute for the aluminum bodyā€™s outer temperature to catch up.

The DC2ā€™s slow response seemed appropriate though, because it has a massive chunk of copper to sink heat into. It never got too hot to hold; the outside of the light stayed a pretty steady temperature.

Meanwhile, the higher-powered D4 has only a small chunk of aluminum, so it got painfully hot during the first minute even though it was stepping down so fast. It remained pretty hot during the second minute, but it did not continue to ramp down because the predictive algorithm figured out that there was no need since the temperature was already decreasing fast enough.

As a side note, I need to recharge the DC2ā€™s battery and measure its maximum output properly. Its vertical scale on this graph may be a bit off ā€” IIRC it was about 2300 or 2400 lm at the beginning but I need to double check.

Itā€™d be interesting to see how each light behaves with the drivers swapped. Thatā€™s not very feasible, but sometime soon I should at least be able to measure FSMā€™s behavior on a larger light, a SRK or Q8. If my guesses are right, it should still work fine with more thermal mass and should adjust output more slowly, because the extra thermal mass reduces the rate of change and that reduces the magnitude of response.

ā€¦

Itā€™s not shown in the graph, but afterward I held a block of ice against the DC2. The output ramped back up, but it was just as slow as when it ramped down. Even with the light literally ice-cold, it was still slow. The D4, however, when itā€™s that cold, increases the output rather quickly. Itā€™s not quite as fast as the initial ramp-down, but itā€™s still relatively quick.