E-switch UI Development / FSM

Yes, abruptly ā€˜burning outā€™ is what I was thinking.

I meant itā€™d be neat to retain Candle modeā€™s adjustable flame brightness without interfering with the countdown.

Iā€™d be the envy of the camp with a diffused light hanging over my hammock burning Candle mode with a sleep timer. :smiley:

Great! Can we have a peek at what else is on your list? :partying_face:

Aw geez. I have so many listsā€¦ Um. Letā€™s see. At least part of it is visible. And at least some of whatā€™s visible is published. To see that part, check ā€˜anduril.txtā€™ in the repository, which was initially a todo list but is now mostly doneā€¦ Also, try ā€œegrep ā€˜TODO|FIXMEā€™ anduril.cā€ to see some other itemsā€¦

But I also have a variety of other lists which arenā€™t public. So many, in fact, that I wrote an aggregator system to merge the entire hierarchy together into a single flattened list with scores and priorities and recurring due dates and even a snooze button. Itā€™s called ā€œTKDOā€.

And then another aggregator to merge that together with some other systems and data sources, to boil it all down to a single number plus some randomized convenience hints about what sorts of productive things I could be doing right now. That one is called, um, something I canā€™t say here without violating profanity rules. Letā€™s call it a ā€œscrewometerā€ since the number shows, in percent, how ā€œscrewedā€ I am. It even graphs the status over time.

The graph is a relatively recent addition, so it hasnā€™t had time to populate much history, and Iā€™m still tweaking the factors and coefficients, but hereā€™s a sample of the past 24 hours:

Lower is better. If itā€™s dropping, that means Iā€™m getting stuff done. If itā€™s rising, that means Iā€™m probably either slacking or asleep or doing something it canā€™t automatically measure. Currently rising since Iā€™m chatting on BLF.

This may have all scrolled off by the time anyone sees this post (edit: nevermind, I linked to a frozen copy instead of a live version), but at the moment it shows me a graph starting at about 38, which then drops to about 20, then rises again to 34% or so. Then it starts dropping again but hasnā€™t gone far yet. This suggests that I got stuff done yesterday, tasks piled up while I was asleep, and now Iā€™m starting again. But todayā€™s peak is lower than yesterdayā€™s, which means Iā€™m doing something right.

If things go well, Iā€™m hoping to build a USB nixie-style clock I can use to display the current number and trendā€¦ but for now Iā€™ve got it displaying on an old 20x4 LCD, the same one I wrote LCDproc for back in the 90s. I donā€™t have a serial port any more though, so I kinda hacked together a couple of AVR reflashing cables plus some floating wires to give the display power and data. Still havenā€™t figured out exactly why itā€™s getting inverted and bitshifted data, but I can work around that (ā€œ1 + (254 - (byte << 1))ā€) until a proper usb-serial adapter shows up.

Is this enough of a peek? :smiley:

I just took a moment to contemplate the stacks and stacks of paperwork and books and techno-toys and Post-It notes and tools and electronic parts in this room.

Whenever something new arrives, it lands on top, then gradually settles to its natural depth within the geological strata as I pull more interesting things out from lower down and put them on top instead. Visitors can assess my priorities by noting that the books, parts and techno-toys are normally on top.

[performs an ironic bow, as from one engineer to another :slight_smile: ]

Ah cool, I didnā€™t realize this existedā€¦ I had started fooling with stock D4 firmware for fun. Iā€™ll have to try switching anduril as starting point.

Not super interesting or anyting, but I dunno I find UIs interesting so:

Presets: LOW/NORMAL/HIGH/TURBO

No auto-saved mode-memory but LOW/NORMAL/HIGH levels can all be explictly saved.

From off:
LongPress -> Turn on at LOW and rampā€¦
Click -> Turn on at NORMAL.
Click-Press -> Momentary TURBO while Press is held, then back to off.
Click-Click -> Turn on to HIGH.

From on:
Click -> Turn off.
LongPress -> Ramp up.
Click-Press -> Momentary TURBO while Press is held, then back previous level.
Click-Click -> Jump to HIGH unless in HIGH then jump to NORMAL.
Click-Click-Press -> Jump to LOW and ramp.
Click-Click-Click -> Save current level to active preset.

(Comparing master...RampingPresets Ā· bexamous/flashlight-firmware Ā· GitHub)

Iā€™m starting to sound like a broken record, but AndĆŗril is, by far, my favorite UI. :smiley:

Your UI looks good. I like the momentary turbo while on.

Be sure to also check out TKā€™s DarkHorse UI, a clone of the Zebralight UI.

Quite! :partying_face:

Please share photos of your Nixie project when you get to it!

That sounds familiarā€¦ and yes, thatā€™s pretty much what I was getting at. All the fiddly bits! :slight_smile:

The LCD Iā€™m using now has been buried for about 15 years, and I had to go down into a crawlspace storage area to find it. Although it wasnā€™t being used I couldnā€™t get rid of it because of its historyā€¦ got slashdotted, accidentally kept a company from going out of business, got a free trip to Canada, and somehow the project hasnā€™t died even after 20 years. And now itā€™s useful again.

I hope itā€™s not disappointing, but I might go with a nixie-style VFD instead of actual nixie tubes. That way, instead of 10 distinct digits and a dot, I get a 16-segment display and a dotā€¦ so it can display arbitrary text. Iā€™ve been talking a bit to someone who makes this thing, to see if it can be made to receive data over USB.

As suggested, DarkHorse seems closest to the UI described.

In general, FSM is probably going to be the easiest way to create a new e-switch UI. Itā€™s designed specifically to make it easy to go from a description to working code ā€” by structuring the code to resemble the description, and by hiding all the annoying fiddly bits under the hood. If you can describe the states and the event mappings between those states, as already done a few posts ago, you can probably turn it into a working UI.

Does the anduril have the low voltage shutdown? I noticed that it just ramps down at low voltage but doesnā€™t shut off.

Yes, it shuts down at low voltage. But not unless it has stepped down all the way and is still low. Here's the code for that:

void low_voltage() {
    ...
    // in normal or muggle mode, step down or turn off
    else if ((state == steady_state) || (state == muggle_state)) {
        if (actual_level > 1) {
            uint8_t lvl = (actual_level >> 1) + (actual_level >> 2);
            set_level(lvl);
        }
        else {
            set_state(off_state, 0);
        }
    }
    ...
}

But mine doesnā€™t turn off. It steps down at exactly 3v, and when I gradually set my power supply down to 2.4v it steps down to very low mode but doesnā€™t turn off.

Hello TK, good folks from this thread,

Could I ask someone willing to help out to compile momentary.c for me, I need .hex file to load to mcu.
For some reason it is harder than it looks, firs fail was: ā€œspaghetti-monster.h: No such file or directoryā€
then I find this header file, put it in the folder with my project, I hit rebuild AVRGCC1 and get 4 errors now,
several: expected ā€˜=ā€™, or ā€˜,ā€™,ā€˜;ā€™, ā€˜asmā€™ or ā€˜attributeā€™before ā€™int_fast8_tā€™ and
fsm-event.h: No such file or directory!
So now I download all those fsm-ā€¦ files and hit Rebuild AVRGCC1 one
more time and I get 23 errors and 7 warnings !!! :weary:
If I add one more .h file I will probably get 50 errorsā€¦ :frowning:
Why is this so hard :cry:

Thanks

I double-checked just now. Built and flashed the latest code, and it stepped down and turned off as expected.

How long did you let it run? It has a minimum amount of time between each step-down, and some of the lower levels may not appear to change because of duplicate entries in the ramp table.

Hunter, youā€™ll need to check out the entire branch and set up the build environment before compiling. The build options are shown in the bin/build-85.sh script, and it needs at least the ToyKeeper/* tree of the repository in order to compile.

I donā€™t know the exact steps for this in a GUI like Atmel Studio, because Iā€™ve never used one. In a terminal, though, the steps are:

  • bzr branch lp:~toykeeper/flashlight-firmware/fsm
  • cd fsm/ToyKeeper/spaghetti-monster/momentary
  • ā€¦/ā€¦/ā€¦/bin/build-85.sh momentary
  • ā€¦/ā€¦/ā€¦/bin/flash-85.sh momentary.hex

I ran it for about an hour at 2.4v and it stays at very low mode. My anduril is the latest version.

Hunter, it definitely looks like your build environment is missing some things. It canā€™t even find standard library components.

Unfortunately, I donā€™t know how to fix that, but perhaps there are answers in Hoopā€™s guide, Comfychairā€™s guide, or WarHawk-AVGā€™s guide?

Weird. It should activate in like 10 seconds. At least, mine didā€¦ and it was running at 2.6V.

If itā€™s low enough to trigger step-downs, it should also be able to trigger shutoff. I donā€™t have a ā€œlowā€ vs ā€œcriticalā€ distinction in the code.

Maybe itā€™s a different version of the code, but LVP has been working since near the beginning. Maybe thereā€™s a relevant hardware difference. IIRC a couple people mentioned the light bled a bit even while off, which would be hard to detect without measuring the mA during LVP. If itā€™s running at ~2 mA or higher, that probably means the MCU is still on and awake. But if itā€™s under 1 mA and light is still coming out, or if it never goes under ~3 mA, there may be a leak bypassing the MCU somehow.

@ToyKeeper

I have had NarsilM v1.2 on my Q8 for a long time, but now Iā€™ve flashed your new firmware anduril-q8.2018-01-24.hex
and noticed that the e-switch LED is illuminated when the lamp is turned off.

Iā€™ve been playing around like crazy with this new firmware testing ā€œeverythingā€ and after that the e-switch LED is no longer lit when the lamp is off.

I couldnā€™t figure out how to make the e-switch LED lit again while the lamp is off, so I had to re-flash the Q8 again with the same firmware anduril-q8.2018-01-24.hex and now the e-switch is illuminated again when the lamp is turned off.

My question is, how to toggle between e-switch LED behavior?

Many thanks for all your amazing work!

Isnā€™t AndĆŗril great? :heart_eyes:

ToyKeeper explained switch illumination settings a few pages back:

Nice!

Now youā€™ve got me wanting a double-sided dot matrix VFD from an IBM cash register mounted to my deskā€¦ :partying_face: