Detect setup button press

Is it possible to detect when the setup button is pressed in firmware ?
Or is there an alternative way to let the photon take back RGB led control when entering listening mode for example ?

If you disable the LED in user code and enter listening mode by holding setup button, theres no visual feedback to the user that it happened :confused:

This might be something for you
Photon Mode Button - User Access
https://github.com/spark/firmware/pull/611

1 Like

Nice find, thanks :+1:

1 Like

Give this a try as well. We have System.on(event, event_handler) for catching system events like when the setup button is pressed. I haven’t found any documentation though besides this example:

I ended up using this, it seems that you get a call with non-zero duration when entering listening mode, even though the user didnt release the button yet, so I cant really reset the LED, but its an acceptable side effect IMO, once the device is reset the LED is back to its old self.

Note that if you set brightness to 0 and then RGB.control(false), the brightness is not reset, took me a few minutes to figure out that was why the example code was not working :slight_smile:

System.on(button_status, button_handler);
void button_handler(system_event_t event, uint32_t duration, void* )
 {
     if (!duration) { // just pressed
         RGB.brightness(100);
         RGB.control(false);
     }
 }
1 Like

Yup, that’s intended behaviour to grant control over the max brightness of the standard status feedback.
People complained that they couldn’t sleep next to a device but wanted to keep the standard behaviour :sunglasses:

But what do you mean here

What would you want to reset but can’t?

Well actually I can reset the LED, if I just check the duration against the needed duration to enter listening mode.

The “issue” is that you get a button event when the device enters listening mode, even though the user didnt release the key, so a simple else in the method would trigger on that too.

Another way to ensure that you only catch the correct state is to check for if (WiFi.istening()) in connection with duration, or instead of going for the button press, you could go for the (also still) undocumented System.on() events that @BDub has provided an “indirect” link to.

I’m not up to date with the current syntax tho’.

To get an idea about the possible events/parameters you could have a look in the open source repo

System events is a radical change from the normal arduino style of programming, so we want to be sure the documentation includes enough examples and guidance for them to be useful and comprehensible. :slight_smile: The docs will come in Q1 2016.

2 Likes

It’s about time!!! :wink: