Skip to content

Commit

Permalink
Allow button to reset RX config (#1681)
Browse files Browse the repository at this point in the history
* 9x Long Button now resets config, works on STM32

* Clear SPIFFS as well when resetting
  • Loading branch information
CapnBry committed Jul 7, 2022
1 parent cf7b0b9 commit a69e639
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
36 changes: 28 additions & 8 deletions src/lib/BUTTON/devButton.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "targets.h"
#include "common.h"
#include "device.h"
#include "devButton.h"

#if defined(GPIO_PIN_BUTTON)
#include "common.h"
#include "logging.h"
#include "button.h"

Expand Down Expand Up @@ -43,18 +42,39 @@ static void cyclePower()
};
#endif

#if defined(TARGET_RX) && (defined(PLATFORM_ESP32) || defined(PLATFORM_ESP8266))
static void rxWebUpdateReboot()
#if defined(TARGET_RX)
#if defined(PLATFORM_ESP32)
#include <SPIFFS.h>
#elif defined(PLATFORM_ESP8266)
#include <FS.h>
#endif

static void buttonRxLong()
{
#if defined(PLATFORM_ESP32) || defined(PLATFORM_ESP8266)
// ESP/ESP32 goes to wifi mode in 5x longpress
if (button.getLongCount() > 4 && connectionState != wifiUpdate)
{
connectionState = wifiUpdate;
}
#endif

// All RX reset their config in 9x longpress and reboot
if (button.getLongCount() > 8)
{
config.SetDefaults(true);
#if defined(PLATFORM_ESP32) || defined(PLATFORM_ESP8266)
// Prevent WDT from rebooting too early if
// all this flash write is taking too long
yield();
// Remove options.json and hardware.json
SPIFFS.format();
ESP.restart();
#elif defined(PLATFORM_STM32)
HAL_NVIC_SystemReset();
#endif
}
};
}
#endif

static void initialize()
Expand All @@ -66,8 +86,8 @@ static void initialize()
button.OnShortPress = enterBindMode3Click;
button.OnLongPress = cyclePower;
#endif
#if defined(TARGET_RX) && (defined(PLATFORM_ESP32) || defined(PLATFORM_ESP8266))
button.OnLongPress = rxWebUpdateReboot;
#if defined(TARGET_RX)
button.OnLongPress = buttonRxLong;
#endif
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/lib/BUTTON/devButton.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#pragma once

#include "device.h"
#include "config.h"

#if defined(GPIO_PIN_BUTTON)
#if defined(TARGET_TX) || \
(defined(TARGET_RX) && (defined(PLATFORM_ESP32) || defined(PLATFORM_ESP8266)))
extern device_t Button_device;
#define HAS_BUTTON
#endif
extern device_t Button_device;
#define HAS_BUTTON
#endif

0 comments on commit a69e639

Please sign in to comment.