E-switch UI Development / FSM

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:

Yes it is!

Now I can switch between the different modes.
Many thanks for your reply.

TK, why is DEFAULT_THERM_CEIL defined per-UI?
Shouldn’t it depend on hardware instead?

It could be defined per-hardware instead of per-UI. Hasn’t really come up before. It’s intended to be a value that the app/UI code can use to tweak behavior of the library.

Also, there isn’t really a per-host hardware definition concept. FSM’s hardware definitions are more about the driver type than about the host or emitters.

Mostly, there hasn’t been a need yet.

I tried compiling FSM.
It doesn’t have a makefile, weird. OK, I wrote one. But then it lacks system includes.
I see no mention of the compilation process in spaghetti-monster.txt.
TK, how should I compile it?

Nearly every project had the exact same Makefile, so I converted things to a build script per MCU type. Here’s what I do to build and flash it:

> cd ToyKeeper/spaghetti-monster/anduril
> ../../../bin/build-85.sh anduril
avr-gcc -Wall -g -Os -mmcu=attiny85 -c -std=gnu99 -DATTINY=85 -I.. -I../.. -I../../.. -o anduril.o -c anduril.c
avr-gcc -Wall -g -Os -mmcu=attiny85 -o anduril.elf anduril.o
avr-objcopy --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex anduril.elf anduril.hex
Program:    7372 bytes (90.0% Full)
Data:        288 bytes (56.2% Full)
> ../../../bin/flash-85.sh anduril.hex

Thanks, I managed to compile it now. Though these scripts use some avr-size extensions from Win-AVR, I had to remove -C and —mcu. And the following grep.