E-switch UI Development / FSM

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.

I was thinking about how an alarm clock mode should work… how does this sound?

Let’s say the user sets an alarm to happen in 8 hours. After entering alarm clock mode, a few things happen:

  • The light blinks 8 times to indicate 8 hours until the alarm goes off.
  • Light shuts off.
  • 7.5 hours pass.
  • Light turns on at moon mode then slowly ramps up to ~150 lm. This takes 30 minutes.
  • The light blinks at 150 lm until someone shuts it off or the battery gets low. On for 1s, off for 1s, repeat.

To exit at any time, click once.
To go to the next blinky in the sequence, click twice.
To set the alarm time, click three times, wait until it buzzes, then click N times for N hours.

Neat!

  • Can the light be used while the alarm is counting down?
  • Can Good Night mode do its thing after setting the alarm?

I haven’t implemented it yet… just thinking about how it should work. It had occurred to me that it might be nice if the alarm clock mode also worked as a momentary low mode during the waiting period, but only if it doesn’t cost much space.

Or I guess it could do the good-night thing instead, but that adds some complications. I’ll keep it in mind though, in case a simple solution appears.

… actually, I already thought of a fairly simple way to do it — push goodnight mode, then make it pop itself at the end instead of turning off. This way it can be accessed from both off and from alarm clock mode. Hmm. But that also means it would inherit the parent mode’s event mappings for unhandled events. And it’d be less friendly in a mode group rotation. That’s problematic. I’ll have to give it more thought. The modes weren’t designed to be nested.

Mostly just looking for ideas at this point, for how people would use it. So this is good feedback.

Very cool that you are working with OKLuma. Was hoping that would happen.
Extremely cool gift of a DC2! That means you are a compensated consultant.

Unfortunately, the programming side of things are well outside my range of skills, I don’t have any decent input to offer.

Please do carry on, you are making our hobby more interesting and enjoyable

That sounds great. That’s something I’d probably use quite a bit.

Looking at the config for other modes, it seems like setting up multiple things is straightforward (in the UI, at least, I’m not sure how much complexity it adds to the code). Just configuring hours would work pretty well but you could add:

  • Delay granularity to tens of minutes, so 8 taps then 3 taps would be 8 hours and 30 minutes
  • Customisable brightness. 150lm is probably fine but it would be nice if this was flexible. It could be based on the mode memory but that could give unexpected results.
  • Customisable ramp duration.

I’m being a bit picky and know first hand that adding in more features and code into something isn’t always the best decision, so take these suggestions with a grain of salt.