# Detect setup button press

**URL:** <https://community.particle.io/t/detect-setup-button-press/17819>\
**Category:** Firmware\
**Created:** [November 27, 2015, 11:28am UTC](https://community.particle.io/t/detect-setup-button-press/17819 "2015-11-27T11:28:07Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![MORA](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mora/32/8575_2.png) [@MORA](https://community.particle.io/u/MORA)\
**Post date:** [November 27, 2015, 11:28am UTC](https://community.particle.io/t/detect-setup-button-press/17819/1 "2015-11-27T11:28:07Z")

</div>

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 😕

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [November 27, 2015, 11:53am UTC](https://community.particle.io/t/detect-setup-button-press/17819/2 "2015-11-27T11:53:32Z")

</div>

This might be something for you  
[Photon Mode Button - User Access](https://community.particle.io/t/photon-mode-button-user-access/13471/4)  
[https://github.com/spark/firmware/pull/611](https://github.com/spark/firmware/pull/611)

---

<div class="post-metadata">

**Author:** ![MORA](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mora/32/8575_2.png) [@MORA](https://community.particle.io/u/MORA)\
**Post date:** [November 27, 2015, 12:12pm UTC](https://community.particle.io/t/detect-setup-button-press/17819/3 "2015-11-27T12:12:07Z")

</div>

Nice find, thanks 👍

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [November 28, 2015, 1:27am UTC](https://community.particle.io/t/detect-setup-button-press/17819/4 "2015-11-28T01:27:32Z")

</div>

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:

> [@Implications of customized system firmware - Photon](https://community.particle.io/t/implications-of-customized-system-firmware-photon/12948/12):
>
> The develop branch now contains a preliminary implementation of system events. Here’s a test app that programmatically enables listening mode, and turns it off after 3 seconds. If the user then presses the mode button to enter listening mode, it’s also exited after 3 seconds. #include "application.h" SYSTEM\_MODE(SEMI\_AUTOMATIC); void listen(system\_event\_t event, uint32\_t param, void\* pointer) { if (event==wifi\_listen\_update) { // exit listen mode after 3 seconds if (pa…

---

<div class="post-metadata">

**Author:** ![MORA](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mora/32/8575_2.png) [@MORA](https://community.particle.io/u/MORA)\
**Post date:** [November 28, 2015, 8:46am UTC](https://community.particle.io/t/detect-setup-button-press/17819/5 "2015-11-28T08:46:11Z")

</div>

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 🙂

```
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);
     }
 }
```

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [November 28, 2015, 11:11am UTC](https://community.particle.io/t/detect-setup-button-press/17819/6 "2015-11-28T11:11:03Z")

</div>

> [@MORA](#):
>
> Note that if you set brightness to 0 and then RGB.control(false), the brightness is not reset

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 🕶

But what do you mean here

> [@MORA](#):
>
> so I _ **cant** _ really reset the LED

What would you want to reset but can't?

---

<div class="post-metadata">

**Author:** ![MORA](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mora/32/8575_2.png) [@MORA](https://community.particle.io/u/MORA)\
**Post date:** [November 28, 2015, 12:07pm UTC](https://community.particle.io/t/detect-setup-button-press/17819/7 "2015-11-28T12:07:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [November 28, 2015, 12:25pm UTC](https://community.particle.io/t/detect-setup-button-press/17819/8 "2015-11-28T12:25:30Z")

</div>

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.

> <https://github.com/particle-iot/firmware/issues/279>

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

> <https://github.com/particle-iot/firmware/blob/v0.4.7/system/inc/system_event.h>

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [December 1, 2015, 5:24pm UTC](https://community.particle.io/t/detect-setup-button-press/17819/9 "2015-12-01T17:24:53Z")

</div>

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. 🙂 The docs will come in Q1 2016.

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [December 1, 2015, 5:31pm UTC](https://community.particle.io/t/detect-setup-button-press/17819/10 "2015-12-01T17:31:40Z")

</div>

> [@mdma](#):
>
> System events is a radical change from the normal arduino style of programming

It's about time!!! 😉
