Request: `hardware.wakereason()` but supporting multiple reasons

This is a proposal for a new Imp API method similar to hardware.wakereason()

The problem

Today I am wanting to do something in response to production devices being blinked up. The problem is, for most devices it will be their first time being blinked up in a long while, so they will also have to download a software update, and

If there is new Squirrel code available after restarting due to a BlinkUp, the wake reason will be overridden with WAKEREASON_NEW_SQUIRREL

so I can’t react to the BlinkUp. There is a similar clash between WAKEREASON_SW_RESTART or WAKEREASON_SW_RESET and WAKEREASON_NEW_SQUIRREL. The cause seems to me to be that only one wake reason can be reported, even when multiple apply.

The solution

What would solve my problem would be a new method that could report multiple wake reasons. For example, hardware.wakereasons() could return an integer/bit-array. Instead of

if (hardware.wakereason() == WAKEREASON_BLINKUP) {
    // ...
}

I could use

if (hardware.wakereasons() & WAKEREASONS_BLINKUP) {
    // ...
}

This would allow developers to more reliably react to events like BlinkUp or new Squirrel.

Also open to any tips I might be missing on existing ways to achieve this goal.

This has been in the backlog for a while and is slated to be in release 40 :slight_smile:

1 Like