Skip to content
This repository was archived by the owner on Sep 23, 2021. It is now read-only.

Commit d007f5d

Browse files
committed
Double check button press for reset on button reboot
Squash
1 parent b1a2066 commit d007f5d

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

ruuvi_examples/ruuvi_firmware/bluetooth_application_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define APP_DEVICE_NAME APPLICATION_DEVICE_NAME /**< TODO: Refactoring **/
66
#define APP_DEVICE_NAME_LENGTH APPLICATION_DEVICE_NAME_LENGTH
77
#define APP_TX_POWER 4 /**< dBm **/
8-
#define INIT_FWREV "2.5.6" /**< Github tag. Do not include specifiers such as "alpha" so you can accept ready binaries as they are **/
8+
#define INIT_FWREV "2.5.7" /**< Github tag. Do not include specifiers such as "alpha" so you can accept ready binaries as they are **/
99
#define INIT_SWREV INIT_FWREV /**< FW and SW are same thing in this context **/
1010

1111
// milliseconds until main loop timer function is called. Other timers can bring

ruuvi_examples/ruuvi_firmware/main.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ static uint64_t debounce = 0; // Flag for avoiding double press
110110
static uint16_t acceleration_events = 0; // Number of times accelerometer has triggered
111111
static volatile uint16_t vbat = 0; // Update in interrupt after radio activity.
112112
static uint64_t last_battery_measurement = 0; // Timestamp of VBat update.
113+
static volatile bool pressed = false; // Debounce flag
113114

114115
// Possible modes of the app
115116
#define RAWv1 0
@@ -223,8 +224,14 @@ static void store_mode(void* data, uint16_t length)
223224
*/
224225
static void reboot(void* p_context)
225226
{
226-
NRF_LOG_WARNING("Rebooting\r\n")
227-
NVIC_SystemReset();
227+
// Reboot if we've not registered a button press, OR
228+
// if we have registered a button press and the button is still pressed (debounce)
229+
if(!pressed || (pressed && !(nrf_gpio_pin_read(BUTTON_1))))
230+
{
231+
NRF_LOG_WARNING("Rebooting\r\n")
232+
NVIC_SystemReset();
233+
}
234+
pressed = false;
228235
}
229236

230237
/**@brief Function for handling button events.
@@ -237,8 +244,7 @@ static void reboot(void* p_context)
237244
*/
238245
ret_code_t button_press_handler(const ruuvi_standard_message_t message)
239246
{
240-
// Avoid double presses
241-
static bool pressed = false;
247+
// Debounce
242248
if(false == message.payload[1] && ((millis() - debounce) > DEBOUNCE_THRESHOLD) && !pressed)
243249
{
244250
NRF_LOG_INFO("Button pressed\r\n");

0 commit comments

Comments
 (0)