mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-06 13:44:46 +00:00
Reboot on saved lora or bluetooth settings
This commit is contained in:
parent
475d405ee7
commit
09f5db5a91
@ -14,4 +14,5 @@ enum class Cmd {
|
||||
STOP_BOOT_SCREEN,
|
||||
PRINT,
|
||||
START_SHUTDOWN_SCREEN,
|
||||
START_REBOOT_SCREEN,
|
||||
};
|
@ -317,6 +317,14 @@ static void drawFrameShutdown(OLEDDisplay *display, OLEDDisplayUiState *state, i
|
||||
display->drawString(64 + x, 26 + y, "Shutting down...");
|
||||
}
|
||||
|
||||
static void drawFrameReboot(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
||||
{
|
||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
|
||||
display->setFont(FONT_MEDIUM);
|
||||
display->drawString(64 + x, 26 + y, "Rebooting...");
|
||||
}
|
||||
|
||||
static void drawFrameFirmware(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
||||
{
|
||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
@ -1042,6 +1050,9 @@ int32_t Screen::runOnce()
|
||||
case Cmd::START_SHUTDOWN_SCREEN:
|
||||
handleShutdownScreen();
|
||||
break;
|
||||
case Cmd::START_REBOOT_SCREEN:
|
||||
handleShutdownScreen();
|
||||
break;
|
||||
default:
|
||||
DEBUG_MSG("BUG: invalid cmd\n");
|
||||
}
|
||||
@ -1234,6 +1245,18 @@ void Screen::handleShutdownScreen()
|
||||
setFastFramerate();
|
||||
}
|
||||
|
||||
void Screen::handleRebootScreen()
|
||||
{
|
||||
DEBUG_MSG("showing reboot screen\n");
|
||||
showingNormalScreen = false;
|
||||
|
||||
static FrameCallback rebootFrames[] = {drawFrameReboot};
|
||||
|
||||
ui.disableAllIndicators();
|
||||
ui.setFrames(rebootFrames, 1);
|
||||
setFastFramerate();
|
||||
}
|
||||
|
||||
void Screen::handleStartFirmwareUpdateScreen()
|
||||
{
|
||||
DEBUG_MSG("showing firmware screen\n");
|
||||
|
@ -167,6 +167,13 @@ class Screen : public concurrency::OSThread
|
||||
enqueueCmd(cmd);
|
||||
}
|
||||
|
||||
void startRebootScreen()
|
||||
{
|
||||
ScreenCmd cmd;
|
||||
cmd.cmd = Cmd::START_REBOOT_SCREEN;
|
||||
enqueueCmd(cmd);
|
||||
}
|
||||
|
||||
/// Stops showing the bluetooth PIN screen.
|
||||
void stopBluetoothPinScreen() { enqueueCmd(ScreenCmd{.cmd = Cmd::STOP_BLUETOOTH_PIN_SCREEN}); }
|
||||
|
||||
@ -280,6 +287,7 @@ class Screen : public concurrency::OSThread
|
||||
void handlePrint(const char *text);
|
||||
void handleStartFirmwareUpdateScreen();
|
||||
void handleShutdownScreen();
|
||||
void handleRebootScreen();
|
||||
/// Rebuilds our list of frames (screens) to default ones.
|
||||
void setFrames();
|
||||
|
||||
|
@ -13,7 +13,7 @@ DeviceState versions used to be defined in the .proto file but really only this
|
||||
#define here.
|
||||
*/
|
||||
|
||||
#define DEVICESTATE_CUR_VER 15
|
||||
#define DEVICESTATE_CUR_VER 16
|
||||
#define DEVICESTATE_MIN_VER DEVICESTATE_CUR_VER
|
||||
|
||||
extern DeviceState devicestate;
|
||||
|
@ -116,13 +116,11 @@ bool PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength)
|
||||
*/
|
||||
size_t PhoneAPI::getFromRadio(uint8_t *buf)
|
||||
{
|
||||
DEBUG_MSG("getFromRadio, state=%d\n", state);
|
||||
if (!available()) {
|
||||
// DEBUG_MSG("PhoneAPI::getFromRadio, !available\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEBUG_MSG("getFromRadio, state=%d\n", state);
|
||||
|
||||
// In case we send a FromRadio packet
|
||||
memset(&fromRadioScratch, 0, sizeof(fromRadioScratch));
|
||||
|
||||
@ -278,7 +276,10 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PhoneAPI::handleDisconnect() {}
|
||||
void PhoneAPI::handleDisconnect()
|
||||
{
|
||||
DEBUG_MSG("PhoneAPI disconnect\n");
|
||||
}
|
||||
|
||||
void PhoneAPI::releasePhonePacket()
|
||||
{
|
||||
|
@ -59,7 +59,7 @@ class PhoneAPI
|
||||
// Call this when the client drops the connection, resets the state to STATE_SEND_NOTHING
|
||||
// Unregisters our observer. A closed connection **can** be reopened by calling init again.
|
||||
virtual void close();
|
||||
|
||||
|
||||
/**
|
||||
* Handle a ToRadio protobuf
|
||||
* @return true true if a packet was queued for sending (so that caller can yield)
|
||||
@ -81,6 +81,8 @@ class PhoneAPI
|
||||
|
||||
bool isConnected() { return state != STATE_SEND_NOTHING; }
|
||||
|
||||
void setInitalState() { state = STATE_SEND_MY_INFO; }
|
||||
|
||||
/// emit a debugging log character, FIXME - implement
|
||||
void debugOut(char c) { }
|
||||
|
||||
|
@ -170,45 +170,53 @@ void AdminModule::handleSetOwner(const User &o)
|
||||
|
||||
void AdminModule::handleSetConfig(const Config &c)
|
||||
{
|
||||
bool requiresReboot = false;
|
||||
switch (c.which_payloadVariant) {
|
||||
case Config_device_tag:
|
||||
DEBUG_MSG("Setting config: Device\n");
|
||||
config.has_device = true;
|
||||
config.device = c.payloadVariant.device;
|
||||
break;
|
||||
case Config_position_tag:
|
||||
DEBUG_MSG("Setting config: Position\n");
|
||||
config.has_position = true;
|
||||
config.position = c.payloadVariant.position;
|
||||
break;
|
||||
case Config_power_tag:
|
||||
DEBUG_MSG("Setting config: Power\n");
|
||||
config.has_power = true;
|
||||
config.power = c.payloadVariant.power;
|
||||
break;
|
||||
case Config_wifi_tag:
|
||||
DEBUG_MSG("Setting config: WiFi\n");
|
||||
config.has_wifi = true;
|
||||
config.wifi = c.payloadVariant.wifi;
|
||||
break;
|
||||
case Config_display_tag:
|
||||
DEBUG_MSG("Setting config: Display\n");
|
||||
config.has_display = true;
|
||||
config.display = c.payloadVariant.display;
|
||||
break;
|
||||
case Config_lora_tag:
|
||||
DEBUG_MSG("Setting config: LoRa\n");
|
||||
config.has_lora = true;
|
||||
config.lora = c.payloadVariant.lora;
|
||||
break;
|
||||
case Config_bluetooth_tag:
|
||||
DEBUG_MSG("Setting config: Bluetooth\n");
|
||||
config.has_bluetooth = true;
|
||||
config.bluetooth = c.payloadVariant.bluetooth;
|
||||
break;
|
||||
case Config_device_tag:
|
||||
DEBUG_MSG("Setting config: Device\n");
|
||||
config.has_device = true;
|
||||
config.device = c.payloadVariant.device;
|
||||
break;
|
||||
case Config_position_tag:
|
||||
DEBUG_MSG("Setting config: Position\n");
|
||||
config.has_position = true;
|
||||
config.position = c.payloadVariant.position;
|
||||
break;
|
||||
case Config_power_tag:
|
||||
DEBUG_MSG("Setting config: Power\n");
|
||||
config.has_power = true;
|
||||
config.power = c.payloadVariant.power;
|
||||
break;
|
||||
case Config_wifi_tag:
|
||||
DEBUG_MSG("Setting config: WiFi\n");
|
||||
config.has_wifi = true;
|
||||
config.wifi = c.payloadVariant.wifi;
|
||||
break;
|
||||
case Config_display_tag:
|
||||
DEBUG_MSG("Setting config: Display\n");
|
||||
config.has_display = true;
|
||||
config.display = c.payloadVariant.display;
|
||||
break;
|
||||
case Config_lora_tag:
|
||||
DEBUG_MSG("Setting config: LoRa\n");
|
||||
config.has_lora = true;
|
||||
config.lora = c.payloadVariant.lora;
|
||||
requiresReboot = true;
|
||||
break;
|
||||
case Config_bluetooth_tag:
|
||||
DEBUG_MSG("Setting config: Bluetooth\n");
|
||||
config.has_bluetooth = true;
|
||||
config.bluetooth = c.payloadVariant.bluetooth;
|
||||
requiresReboot = true;
|
||||
break;
|
||||
}
|
||||
|
||||
service.reloadConfig();
|
||||
bool didSave = service.reloadConfig();
|
||||
|
||||
// Reboot 5 seconds after a config that requires rebooting is set
|
||||
if (didSave && requiresReboot) {
|
||||
rebootAtMsec = millis() + 5 * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
void AdminModule::handleSetModuleConfig(const ModuleConfig &c)
|
||||
|
@ -57,6 +57,7 @@ void onConnect(uint16_t conn_handle)
|
||||
connection->getPeerName(central_name, sizeof(central_name));
|
||||
|
||||
DEBUG_MSG("BLE Connected to %s\n", central_name);
|
||||
bluetoothPhoneAPI->setInitalState();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,7 +222,6 @@ void NRF52Bluetooth::setup()
|
||||
Bluefruit.Advertising.stop();
|
||||
Bluefruit.Advertising.clearData();
|
||||
Bluefruit.ScanResponse.clearData();
|
||||
config.bluetooth.mode = Config_BluetoothConfig_PairingMode_NoPin;
|
||||
|
||||
if (config.bluetooth.mode != Config_BluetoothConfig_PairingMode_NoPin) {
|
||||
configuredPasskey = config.bluetooth.mode == Config_BluetoothConfig_PairingMode_FixedPin ?
|
||||
@ -308,12 +308,11 @@ bool NRF52Bluetooth::onPairingPasskey(uint16_t conn_handle, uint8_t const passke
|
||||
sprintf(specified, "%.3s%.3s", passkey, passkey+3);
|
||||
static char configured[6];
|
||||
sprintf(configured, "%i", configuredPasskey);
|
||||
|
||||
powerFSM.trigger(EVENT_BLUETOOTH_PAIR);
|
||||
screen->startBluetoothPinScreen(configuredPasskey);
|
||||
|
||||
if (match_request)
|
||||
{
|
||||
DEBUG_MSG("*** Enter passkey %d on the peer side ***\n", passkey);
|
||||
powerFSM.trigger(EVENT_BLUETOOTH_PAIR);
|
||||
screen->startBluetoothPinScreen(configuredPasskey);
|
||||
bool accepted = false;
|
||||
uint32_t start_time = millis();
|
||||
while(millis() < start_time + 30000)
|
||||
|
@ -8,6 +8,7 @@ void powerCommandsCheck()
|
||||
{
|
||||
if (rebootAtMsec && millis() > rebootAtMsec) {
|
||||
DEBUG_MSG("Rebooting\n");
|
||||
screen->startRebootScreen();
|
||||
#if defined(ARCH_ESP32)
|
||||
ESP.restart();
|
||||
#elif defined(ARCH_NRF52)
|
||||
|
Loading…
Reference in New Issue
Block a user