E-switch UI Development / FSM

TK:
An Idea for SMOOTH and DISCRETE
To switch between SMOOTH and DISCRETE you use 3 clicks.
I don’t know if you indicate the state to the user.

To show the user what he is using the main LED does this:
SMOOTH:
It dims from low to a brighter level and back down to low. Within one second or quicker. Like a single dragon breath from Manker Lamps.
DISCRETE:
It goes through three brightness​ steps within a second. Sth. like Low Mid High

wuuHOOuuu vs. TickTickTick

When you add a mogle mode you can use another 3 clicks and blink out eg. low high low high or another sequence.
So you can cycle through SMOOTH, DISCRETE and MOGLE MODE.

It blinks off and back on quickly to indicate that something happened… and if it’s going from smooth to discrete it’ll also jump to the nearest stair step. But otherwise it doesn’t attempt to indicate what happened.

Adding a detailed indication would require creating an asynchronous feedback system of some sort. It’s not terribly difficult, but it does expose the code to an entire new class of bugs. For example, Narsil does async feedback to indicate which power channel is being used, and if the user clicks during the feedback it can have side effects like turning the indicator LED off. It happens because there are multiple different logic threads fighting simultaneously for control over a shared resource.

Originally this was considered a bug because it wasn’t implemented on purpose, but Tom left it that way because he liked it. Not all interactions of this type are going to be beneficial though… and I’ve tried to avoid making it even possible. However, I think it should be reasonably safe, due to the way events and tasks are scheduled in FSM instead of running immediately. I haven’t tested, but I think the worst effects would be to delay things like state changes until the feedback animation has completed. Or possibly to interrupt the animation, depending on how it’s implemented.

I don’t think it’d be a good idea to include muggle mode in the cycle. Muggle mode is intended as a one-way trip, a state you can put a light in before handing it to someone who doesn’t know much about it, and they hopefully won’t be able to exit muggle mode by accident.

So the safest way to end mogle mode would be disconnect from power?

I think a battery disconnect can happen in a muggle hand. But a click, click, click, hold or some combination not happen offten.

In a few years we need lamps with a projector LED so we can project a UI diagramm on the ground.
:slight_smile:

I was thinking power cycle to exit muggle mode, because it’s consistent with how one must exit momentary mode, and it also works for lockout mode.

With a D4 flashed in the right way, it’s actually harder to power cycle than it might seem at first. I got standby power down to 0.35 uA (0.00035 mA), so I can take off the tailcap, walk away to have a conversation, come back, put the tailcap back on, and the light doesn’t know it was disconnected from power while it was asleep. So in practice a power cycle means “loosen tailcap, click button, tighten tailcap” or “loosen tailcap while light is coming out the front”.

What would it take to support the Schoki’s MP3431 driver ?

That depends… FSM can technically run on tiny25, but only just barely. It really needs tiny45 before it can do much at all, or tiny85 if you want something fancy like Anduril. And for that, things aren’t looking good:

Older e-switch code had a smaller base footprint but used more space for each feature. It could be approximated with something like “500 bytes base + 500 bytes per feature”. FSM has a bigger footprint but makes additions significantly smaller, like “3000 bytes base + 100 bytes per feature”. Or something along those lines, anyway.

I guess, to add support, what it would take is a bigger version of the driver with a bigger MCU, preferably SOIC8 (though reflashing pogo pads or holes would work too). It could be tiny85 or tiny1634 like Mike C uses, or tiny841, for the easiest options. For tiny1616/1617 things get more difficult, and for non-AVR options things also get more difficult.

Actually now the design uses a 4x4 MCU and ATTiny85 should fit.
I wonder about the OTSM discussion that I don’t understand… :blush:

Oh, if it has tiny85 now, then I just need a driver with flashing pads/vias or SOIC8, and I could add support for it fairly easily — some way to reflash without soldering. Not necessarily for production use; just for development purposes.

As for code… I don’t know what the pinouts are, but I’d need to add a driver layout definition and probably adjust the ramp tables. Maybe change a bit of init code. And it may also need new code to measure voltage. I seem to recall some discussion about that, and I don’t know if it was ever resolved. So battcheck and LVP might not work, depending on whether there’s a way to measure the battery voltage.

The OTSM stuff is irrelevant for FSM, and for e-switch lights in general.

FSM-based apps shouldn’t need any changes, or should need only very small changes. Mostly they should “just work” after the base library gets support for the new driver. Change one line per app to select a different driver type, and maybe update anything driver-specific it does (if there is anything).

Overall, porting should be relatively easy. That’s half the point of abstacting out the hardware layer and separating it from the UI code.

Glad to read that. :slight_smile:

I flashed my driver with anduril firmware and I really like it. I have some questions:

  1. Is there a way to turn off the thermal stepdown?
  2. Can you add brighter, dimmer option to the tactical strobe?

1. Disable USE_THERMAL_REGULATION at compile time. (should compile, but is untested)

2. Perhaps. It wouldn’t be difficult. Not sure if it’s a thing many people want though; usually tactical strobes only go at the maximum brightness. On small high-powered lights this risks overheating though, so it’d probably be a good idea to lower it for those or make it configurable.

On my Q8 with Andúril sometimes in the momentary tactical mode it leave the main led on after a few presses. I didn’t know the exact press combination but playing with it and somtimes it stays on. And once I got in ramping stuck in one level and no button presses helped just when I disconnected power.

I still need to tweak the debouncing and event detection a little more, to handle extra-noisy switches. It mostly works, but can run into some weirdness when the switch bounces for an unusually long time. It’s a bit difficult to test though, since I haven’t found any really-noisy switches to test with.

Maybe I can find a noisy switch somewhere in my drawers of parts.

A scope would help too, so I could measure this stuff instead of guessing. I usually do pretty well at programming blind, but it sure is helpful to have data to work with instead of just theories.

I installed Anduril on Q8 and on tactical mode I can get it stuck switched on with the switch released just like ZozzV6 mentioned earlier.

Also there is slight delay when switching the light off. Is it there because of ramp down UI (click, click&hold)? Is it waiting second click&hold? The delay is a bit too long for my liking.

I like lightning mode. Thank you ToyKeeper!

Now I am waiting impatiently for candle mode. Googling for “led candle flicker algorithm” shows up some interesting results.

The delay is because it’s waiting to see if you’re going to click again for a double/triple click. The timing of that can be changed by re-defining RELEASE_TIMEOUT. The default value is 24 frames.

The delay can also be eliminated entirely by mapping the “off” action to EV_click1_release instead of EV_click1_complete (a.k.a. EV_1click), but this will interfere with detecting double clicks. So you’d need to have a “turn emitters off” action on button release, followed by a “go to ‘off’ state” action after the timeout happens. This should be safe, but has the side effect of making it briefly blink off after the first click, even when “off” isn’t the action you were intending.

I’m not completely happy with candle mode yet, but here’s an example graph of its output:

Mostly, it seems a bit too spastic when used at low levels, and perhaps a bit too spastic overall. It’s like a candle in a breezy environment. Perhaps I should change it from free-running waves to fading waves triggered by random disturbances. Or maybe just decrease the amplitude on the mid-frequency oscillator. Or maybe make the mid oscillator fade and refresh at random. It’ll take some experimenting. It already does a random sample-and-hold modulation on the mid oscillator frequency, which helps, but it feels like it needs further adjustments.

In another thread, ‘stephenk’ mentioned that an adjustable strobe frequency is useful for light painting.

I suggested he look into Andúril, with its adjustable-frequency ‘Party Strobe’ and ‘Tactical Strobe’ modes.

He then mentioned that a momentary strobe would also be useful.

Could Andúril’s momentary mode also work with strobe modes? If not officially supported, could it be a compile-time option?

Momentary strobe? That’s not a thing I’ve considered.

I added it as a “TODO” note in the code, but I don’t have any plans to add it in upcoming production lights. I suspect that my rainbow saber thing may be more relevant for light painting anyway, since it’s specifically designed to make pretty patterns in the air while swinging a lighted sword. It does whatever patterns the user tells it to, and has a full color palette to work with. This includes a momentary “overdrive” function, which could potentially be configured in a manner similar to what he might want.

Hmm, I just tried it by turning the brightness down all the way on a police flasher mode, hoping that it’d become momentary-only so it only lights up in overdrive. However, the brightness mod is additive instead of subtractive, so it still flashes while idle — just not as bright. Overdrive works fine, but the non-overdrive isn’t dark like I had hoped. This could be fixed by making it subtractive, but I’m not sure if that’d be a good idea outside of this momentary thing.

I’m a bit late here, but I’d like to add my two cents. First of all, you’re 100% correct that it’s impossible to create, test, and host dozens of .hex files for every hardware configuration out there. However, I do think there is good demand for an alternative to NarsilM on TA drivers. Perhaps we could talk you in to creating one “master” triple-channel.c file, a la Bistro Tripledown? You’ve made it easy enough for all of us to utilize your /bin/ files for things like ramping table calculation, etc. I’m proficient enough in C and Python to write basic programs and edit your (very well-commented) code, but I have no clue where to start when it comes to adding a third power channel.