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

Commit

Permalink
Double check button press for reset on button reboot
Browse files Browse the repository at this point in the history
Squash
  • Loading branch information
ojousima committed Sep 6, 2019
1 parent b1a2066 commit d007f5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define APP_DEVICE_NAME APPLICATION_DEVICE_NAME /**< TODO: Refactoring **/
#define APP_DEVICE_NAME_LENGTH APPLICATION_DEVICE_NAME_LENGTH
#define APP_TX_POWER 4 /**< dBm **/
#define INIT_FWREV "2.5.6" /**< Github tag. Do not include specifiers such as "alpha" so you can accept ready binaries as they are **/
#define INIT_FWREV "2.5.7" /**< Github tag. Do not include specifiers such as "alpha" so you can accept ready binaries as they are **/
#define INIT_SWREV INIT_FWREV /**< FW and SW are same thing in this context **/

// milliseconds until main loop timer function is called. Other timers can bring
Expand Down
14 changes: 10 additions & 4 deletions ruuvi_examples/ruuvi_firmware/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static uint64_t debounce = 0; // Flag for avoiding double press
static uint16_t acceleration_events = 0; // Number of times accelerometer has triggered
static volatile uint16_t vbat = 0; // Update in interrupt after radio activity.
static uint64_t last_battery_measurement = 0; // Timestamp of VBat update.
static volatile bool pressed = false; // Debounce flag

// Possible modes of the app
#define RAWv1 0
Expand Down Expand Up @@ -223,8 +224,14 @@ static void store_mode(void* data, uint16_t length)
*/
static void reboot(void* p_context)
{
NRF_LOG_WARNING("Rebooting\r\n")
NVIC_SystemReset();
// Reboot if we've not registered a button press, OR
// if we have registered a button press and the button is still pressed (debounce)
if(!pressed || (pressed && !(nrf_gpio_pin_read(BUTTON_1))))
{
NRF_LOG_WARNING("Rebooting\r\n")
NVIC_SystemReset();
}
pressed = false;
}

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

1 comment on commit d007f5d

@DG12
Copy link
Contributor

@DG12 DG12 commented on d007f5d Sep 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always like to see some blinking (in case LOG_ENABLED 0 or not connected) and a LONG delay before reset to reduce looping just in case. (next update)
Can the button get stuck?

Please sign in to comment.