mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-17 18:42:10 +00:00
Erase NVS as part of factory reset & new triple click behavior.
This commit is contained in:
parent
6843ffe452
commit
6506d54859
@ -208,6 +208,7 @@ class ButtonThread : public OSThread
|
|||||||
userButton.attachClick(userButtonPressed);
|
userButton.attachClick(userButtonPressed);
|
||||||
userButton.attachDuringLongPress(userButtonPressedLong);
|
userButton.attachDuringLongPress(userButtonPressedLong);
|
||||||
userButton.attachDoubleClick(userButtonDoublePressed);
|
userButton.attachDoubleClick(userButtonDoublePressed);
|
||||||
|
userButton.attachMultiClick(userButtonMultiPressed);
|
||||||
userButton.attachLongPressStart(userButtonPressedLongStart);
|
userButton.attachLongPressStart(userButtonPressedLongStart);
|
||||||
userButton.attachLongPressStop(userButtonPressedLongStop);
|
userButton.attachLongPressStop(userButtonPressedLongStop);
|
||||||
wakeOnIrq(BUTTON_PIN, FALLING);
|
wakeOnIrq(BUTTON_PIN, FALLING);
|
||||||
@ -336,6 +337,14 @@ class ButtonThread : public OSThread
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void userButtonMultiPressed()
|
||||||
|
{
|
||||||
|
#ifndef NO_ESP32
|
||||||
|
clearNVS();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void userButtonPressedLongStart()
|
static void userButtonPressedLongStart()
|
||||||
{
|
{
|
||||||
DEBUG_MSG("Long press start!\n");
|
DEBUG_MSG("Long press start!\n");
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "mesh/http/WiFiAPClient.h"
|
#include "mesh/http/WiFiAPClient.h"
|
||||||
#include "plugins/esp32/StoreForwardPlugin.h"
|
#include "plugins/esp32/StoreForwardPlugin.h"
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
|
#include <nvs_flash.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NodeDB nodeDB;
|
NodeDB nodeDB;
|
||||||
@ -86,6 +87,7 @@ bool NodeDB::resetRadioConfig()
|
|||||||
if (radioConfig.preferences.factory_reset) {
|
if (radioConfig.preferences.factory_reset) {
|
||||||
DEBUG_MSG("Performing factory reset!\n");
|
DEBUG_MSG("Performing factory reset!\n");
|
||||||
installDefaultDeviceState();
|
installDefaultDeviceState();
|
||||||
|
nvs_flash_erase();
|
||||||
didFactoryReset = true;
|
didFactoryReset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#ifndef NO_ESP32
|
#ifndef NO_ESP32
|
||||||
#include "mesh/http/WiFiAPClient.h"
|
#include "mesh/http/WiFiAPClient.h"
|
||||||
|
#include <nvs_flash.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool pinShowing;
|
static bool pinShowing;
|
||||||
@ -484,7 +485,24 @@ void disablePin()
|
|||||||
doublepressed = millis();
|
doublepressed = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This should go somewhere else.
|
||||||
|
void clearNVS()
|
||||||
|
{
|
||||||
|
#ifndef NO_ESP32
|
||||||
|
|
||||||
|
// As soon as the LED flashing from double click is done, immediately do a tripple click to
|
||||||
|
// erase nvs memory.
|
||||||
|
if (doublepressed > (millis() - 2000)) {
|
||||||
|
DEBUG_MSG("Clearing NVS memory\n");
|
||||||
|
|
||||||
|
// This will erase ble pairings, ssl key and persistent preferences.
|
||||||
|
nvs_flash_erase();
|
||||||
|
|
||||||
|
DEBUG_MSG("Restarting...\n");
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// This routine is called multiple times, once each time we come back from sleep
|
// This routine is called multiple times, once each time we come back from sleep
|
||||||
void reinitBluetooth()
|
void reinitBluetooth()
|
||||||
@ -556,8 +574,7 @@ void setBluetoothEnable(bool on)
|
|||||||
|
|
||||||
bluetoothOn = on;
|
bluetoothOn = on;
|
||||||
if (on) {
|
if (on) {
|
||||||
if (! isWifiAvailable() )
|
if (!isWifiAvailable()) {
|
||||||
{
|
|
||||||
Serial.printf("Pre BT: %u heap size\n", ESP.getFreeHeap());
|
Serial.printf("Pre BT: %u heap size\n", ESP.getFreeHeap());
|
||||||
// ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
|
// ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
|
||||||
reinitBluetooth();
|
reinitBluetooth();
|
||||||
|
@ -15,6 +15,7 @@ void deinitBLE();
|
|||||||
void loopBLE();
|
void loopBLE();
|
||||||
void reinitBluetooth();
|
void reinitBluetooth();
|
||||||
void disablePin();
|
void disablePin();
|
||||||
|
void clearNVS();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper function that implements simple read and write handling for a uint32_t
|
* A helper function that implements simple read and write handling for a uint32_t
|
||||||
|
Loading…
Reference in New Issue
Block a user