E-switch UI Development / FSM

I forget; do you have firmware flashing tools? If not, it might be a good idea to get some. I think you would probably enjoy being able to tweak behavior exactly how you like it. At minimum, it would give you access to change compile-time options, but you could probably make deeper changes too.

Itā€™s not something I recommend for everyone, but I think youā€™re probably serious enough about lights to get some benefit from it.

They are on the way.

:smiley:

I went for a two hour hike last night with a friend and five flashlights running AndĆŗril. Two Q8s, Emisar D1, Emisar D4, and EagleEye X6R.

My friend was very impressed with the Q8 and got the hang of ramping very quickly. It was fun to keep handing him lights to try without needing to explain a different UI with each one.

I set the ramp ceilings to turbo-1 for all but the D4, which I set to turbo-55. He ramped the D4 to the ceiling and said, ā€œWow!ā€ I told him to double-click and he about fell over. :laughing:

Is there a way to set AndĆŗrilā€™s ramp ceiling to turbo, or is turbo-1 the max value? Would this be a compile-only option? What if the ramp value was set to ā€˜turbo-(N-1)ā€™ instead of ā€˜turbo-Nā€™ when using ramp config? Must ramp ceiling and turbo remain non-equal?

BTW, dual-switch support seems to work great. I really like the ā€˜hold e-switch and click tailswitchā€™ to override memory.

I find this AndĆŗril more and more interesting. I need to build a triple or quad X6R and try it in that. Or in my Q8 if it ever reach me from china. Ordered it in the first 100 and Iā€™m just waiting and waiting patient.

It already does ā€œturbo - (N-1)ā€ā€¦ or, more specifically, ā€œ151 - Nā€. I should probably update the UI diagram to make that more clear.

To check whether the ceiling is set to turbo or if itā€™s lower, double-click from off, then double-click again. If it goes up, they werenā€™t equal. :slight_smile:

Got it! I was worried about missing out on that one last ramp level. :smiley:

BTW, your UI diagrams are works of art in their own right.

I need to stop adding thingsā€¦ I have no idea how to fit them into the diagram! :slight_smile:

Specifically, muggle mode. Itā€™ll probably need a whole new section, but thereā€™s no space left on the page.

Iā€™m thinking 6 clicks from off to enter muggle mode, or 6 clicks from ramp to enter muggle config mode. Settings include floor and ceiling levels only. Will probably default to floor=15/150 (~7 lm) and ceiling=100/150 (25% power). Ish. Not sure if Iā€™ll try to fit a 4-bar battcheck mode into it or if itā€™ll be limited to just ramping.

This sounds great! No turbo for muggles, right?

I vote to omit battery check, or make it a compile-time option. I can already hear my button-mashing friendsā€¦ ā€œWHYā€™S IT BLINKING?!ā€ :person_facepalming:

Speaking of muggles, it seems the first thing they do when I hand them a new light is unscrew the tailcap to look at the battery. Iā€™ll have to let them get that over with before I enable muggle mode. :smiley:

I know this, I have the same problem with Tom and the NarsilM cheat sheet. :slight_smile:

TK, Iā€™d like to shorten (nearly eliminate) the delay before ramping when holding the switch from off. I want ramping to start almost immediately.

I poked around in several of the .c and .h files but couldnā€™t determine where I should make changes.

Could you point me to the code I would need to modify to accomplish this? Thanks!

Ramping starts after 48 frames by default. The first 24 frames allow for a regular click to happen (instead of holding to ramp). The next 24 frames are the window for long-press-for-moon. After that, ramping starts.

Look for EV_click1_hold in off_state, and remove the part about ā€œif (arg >= HOLD_TIMEOUT)ā€. This should make ramping start about 24 frames sooner. However, it will also eliminate the ability to long-press from off to go to moon.

You could also try reducing the value of HOLD_TIMEOUT or the value of RELEASE_TIMEOUT to speed up the entire interface, but itā€™ll mean less time to do each click.

Or you could even make it start ramping before it hits HOLD_TIMEOUT, but that will also eliminate the ability to do any clicks of any type from off, unless youā€™re clever and do some much bigger changes.

If I recall correctly, the way Narsil does it is somewhat different:

  • Frames 1-18: Light is off, release for regular click.
  • Frames 19-41: Light is at moon mode, release for moon.
  • Frames 42+: Ramping.

At least, if Iā€™m reading the code correctly.

In Anduril the sequence is:

  • Frames 1-24: Light is at floor level, release for regular click.
  • Frames 25-48: Light is at floor level, release for floor/moon.
  • Frames 49+: Ramping.

Eliminating the pause at step 2 is easy. Eliminating or reducing the pause at step 1 is not so easy.

Iā€™ll try this. Thanks!

I use low modes frequently, but I might be willing to lose a shortcut to moon to get a slightly shorter delay in ramping up from off.

You could also just give it a smaller value, like 6 to allow a 6-frame window to stop at moon before ramping.

And to make the timing easier, you could make it not turn the light on until that window starts. Slower feedback from off, but it gives a timing hint for the shortcut. Tradeoffsā€¦

I tried a few different values for HOLD_TIMEOUT in fsm_events.h on two Q8s. Here are my findings:

  • 6: canā€™t reliably power off with single click
  • 10: still some misfires with power off
  • 12: works great, can still shortcut to moon

12 it is! Ramping feels much snappier from off.

Thanks again for the help, TK!

It runs at 62 frames per second, or 0.016 ms per frame. So a value of 12 is just barely under 1/5th of a second.

People have had difficulty with a window of 18 frames on the Q8, and Iā€™ve found that 31 frames feels too long, so I used a default of 24.

Zebralights, IIRC, use a window of 0.5s or 31 frames:

  • Frames 1-31: Light is at low, release to go to high.
  • Frames 32-62: Light is at low, release to stay at low.
  • Frames 63-93: Light is at med, release to stay at med.

Anyway, I just wrapped the definitions of HOLD_TIMEOUT and RELEASE_TIMEOUT to make them definable from the UI code instead of having to dive into headers. So, after this update is pushed, just stick an extra line in the main UI file and itā€™ll override the toolkitā€™s defaults.

The HOLD one is how many frames it takes to go from a ā€œpressā€ to a ā€œholdā€, or how long a single click can be. The RELEASE one is how many frames it waits after a click to see if another click will happen. To cause a full click event to be sent to the UI code, what happens isā€¦

  • User presses button. ā€œEV_click1_pressā€ event gets sent to the UI code.
  • Anywhere from 1 to HOLD_TIMEOUT frames happens. Letā€™s say 12 frames.
  • User releases button. ā€œEV_click1_releaseā€ event gets sent to the UI code.
  • Light waits RELEASE_TIMEOUT frames, and nothing happens. Now weā€™re at frame 36.
  • ā€œEV_1clickā€ event gets sent to the UI code, indicating that it was only a single click and itā€™s too late for a double click to happen.

The events arenā€™t quite immediate thoughā€¦ they go into a queue and get sent/processed later when the MCU is in an idle loop. In normal circumstances, this only delays things by a few microsecondsā€¦ enough for the current interrupt (WDT, PCINT, ADC) to finish. Iā€™ve generally been very careful to avoid anything time-consuming during interrupts, because those need to be serviced quickly and then go back to the regular code flow as soon as possible. The queue offloads the time-consuming parts to a safer part of the code.

Iā€™m kind of just rambling now though, twiddling my thumbs while waiting for DHL to show up with new lights.

:+1:

Thank you for the detailed explanation.

With HOLD_TIMEOUT set to 12, I was having an issue where a hold while on would do nothing. Iā€™ve changed the value to 15.

And please make the battery insertion double blink at moonight.

Yeahā€¦it bothers me too. As well as voltage / temperature indication.

Hang on there a minute. On a bright sunny day blinking out temperature or voltage might be rather hard to see if done at moonlight levels. At the risk of adding ANOTHER configuration, it might be nice to be able to select the intensity of these blinks.