E-switch UI Development / FSM

Hmm… timed candle mode might be interesting. It wouldn’t be easy to make it dim over time, since it fluctuates across a fairly wide range and the low end doesn’t have sufficient resolution, but it could still stop more abruptly after a while.

The main difficulty there is just whether to spend the extra bytes or not.

Perhaps I could refactor some code to make all config-type modes use a single function and thus be smaller overall. This would free up space and reduce the cost of making modes configurable. Probably not today, but I’ll put it on the list…

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: