Reboot on saved lora or bluetooth settings

This commit is contained in:
Ben Meadors 2022-08-18 12:32:50 -05:00
parent 475d405ee7
commit 09f5db5a91
9 changed files with 90 additions and 47 deletions

View File

@ -14,4 +14,5 @@ enum class Cmd {
STOP_BOOT_SCREEN, STOP_BOOT_SCREEN,
PRINT, PRINT,
START_SHUTDOWN_SCREEN, START_SHUTDOWN_SCREEN,
START_REBOOT_SCREEN,
}; };

View File

@ -317,6 +317,14 @@ static void drawFrameShutdown(OLEDDisplay *display, OLEDDisplayUiState *state, i
display->drawString(64 + x, 26 + y, "Shutting down..."); 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) static void drawFrameFirmware(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{ {
display->setTextAlignment(TEXT_ALIGN_CENTER); display->setTextAlignment(TEXT_ALIGN_CENTER);
@ -1042,6 +1050,9 @@ int32_t Screen::runOnce()
case Cmd::START_SHUTDOWN_SCREEN: case Cmd::START_SHUTDOWN_SCREEN:
handleShutdownScreen(); handleShutdownScreen();
break; break;
case Cmd::START_REBOOT_SCREEN:
handleShutdownScreen();
break;
default: default:
DEBUG_MSG("BUG: invalid cmd\n"); DEBUG_MSG("BUG: invalid cmd\n");
} }
@ -1234,6 +1245,18 @@ void Screen::handleShutdownScreen()
setFastFramerate(); 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() void Screen::handleStartFirmwareUpdateScreen()
{ {
DEBUG_MSG("showing firmware screen\n"); DEBUG_MSG("showing firmware screen\n");

View File

@ -167,6 +167,13 @@ class Screen : public concurrency::OSThread
enqueueCmd(cmd); enqueueCmd(cmd);
} }
void startRebootScreen()
{
ScreenCmd cmd;
cmd.cmd = Cmd::START_REBOOT_SCREEN;
enqueueCmd(cmd);
}
/// Stops showing the bluetooth PIN screen. /// Stops showing the bluetooth PIN screen.
void stopBluetoothPinScreen() { enqueueCmd(ScreenCmd{.cmd = Cmd::STOP_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 handlePrint(const char *text);
void handleStartFirmwareUpdateScreen(); void handleStartFirmwareUpdateScreen();
void handleShutdownScreen(); void handleShutdownScreen();
void handleRebootScreen();
/// Rebuilds our list of frames (screens) to default ones. /// Rebuilds our list of frames (screens) to default ones.
void setFrames(); void setFrames();

View File

@ -13,7 +13,7 @@ DeviceState versions used to be defined in the .proto file but really only this
#define here. #define here.
*/ */
#define DEVICESTATE_CUR_VER 15 #define DEVICESTATE_CUR_VER 16
#define DEVICESTATE_MIN_VER DEVICESTATE_CUR_VER #define DEVICESTATE_MIN_VER DEVICESTATE_CUR_VER
extern DeviceState devicestate; extern DeviceState devicestate;

View File

@ -116,13 +116,11 @@ bool PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength)
*/ */
size_t PhoneAPI::getFromRadio(uint8_t *buf) size_t PhoneAPI::getFromRadio(uint8_t *buf)
{ {
DEBUG_MSG("getFromRadio, state=%d\n", state);
if (!available()) { if (!available()) {
// DEBUG_MSG("PhoneAPI::getFromRadio, !available\n"); // DEBUG_MSG("PhoneAPI::getFromRadio, !available\n");
return 0; return 0;
} }
DEBUG_MSG("getFromRadio, state=%d\n", state);
// In case we send a FromRadio packet // In case we send a FromRadio packet
memset(&fromRadioScratch, 0, sizeof(fromRadioScratch)); memset(&fromRadioScratch, 0, sizeof(fromRadioScratch));
@ -278,7 +276,10 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf)
return 0; return 0;
} }
void PhoneAPI::handleDisconnect() {} void PhoneAPI::handleDisconnect()
{
DEBUG_MSG("PhoneAPI disconnect\n");
}
void PhoneAPI::releasePhonePacket() void PhoneAPI::releasePhonePacket()
{ {

View File

@ -59,7 +59,7 @@ class PhoneAPI
// Call this when the client drops the connection, resets the state to STATE_SEND_NOTHING // 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. // Unregisters our observer. A closed connection **can** be reopened by calling init again.
virtual void close(); virtual void close();
/** /**
* Handle a ToRadio protobuf * Handle a ToRadio protobuf
* @return true true if a packet was queued for sending (so that caller can yield) * @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; } bool isConnected() { return state != STATE_SEND_NOTHING; }
void setInitalState() { state = STATE_SEND_MY_INFO; }
/// emit a debugging log character, FIXME - implement /// emit a debugging log character, FIXME - implement
void debugOut(char c) { } void debugOut(char c) { }

View File

@ -170,45 +170,53 @@ void AdminModule::handleSetOwner(const User &o)
void AdminModule::handleSetConfig(const Config &c) void AdminModule::handleSetConfig(const Config &c)
{ {
bool requiresReboot = false;
switch (c.which_payloadVariant) { switch (c.which_payloadVariant) {
case Config_device_tag: case Config_device_tag:
DEBUG_MSG("Setting config: Device\n"); DEBUG_MSG("Setting config: Device\n");
config.has_device = true; config.has_device = true;
config.device = c.payloadVariant.device; config.device = c.payloadVariant.device;
break; break;
case Config_position_tag: case Config_position_tag:
DEBUG_MSG("Setting config: Position\n"); DEBUG_MSG("Setting config: Position\n");
config.has_position = true; config.has_position = true;
config.position = c.payloadVariant.position; config.position = c.payloadVariant.position;
break; break;
case Config_power_tag: case Config_power_tag:
DEBUG_MSG("Setting config: Power\n"); DEBUG_MSG("Setting config: Power\n");
config.has_power = true; config.has_power = true;
config.power = c.payloadVariant.power; config.power = c.payloadVariant.power;
break; break;
case Config_wifi_tag: case Config_wifi_tag:
DEBUG_MSG("Setting config: WiFi\n"); DEBUG_MSG("Setting config: WiFi\n");
config.has_wifi = true; config.has_wifi = true;
config.wifi = c.payloadVariant.wifi; config.wifi = c.payloadVariant.wifi;
break; break;
case Config_display_tag: case Config_display_tag:
DEBUG_MSG("Setting config: Display\n"); DEBUG_MSG("Setting config: Display\n");
config.has_display = true; config.has_display = true;
config.display = c.payloadVariant.display; config.display = c.payloadVariant.display;
break; break;
case Config_lora_tag: case Config_lora_tag:
DEBUG_MSG("Setting config: LoRa\n"); DEBUG_MSG("Setting config: LoRa\n");
config.has_lora = true; config.has_lora = true;
config.lora = c.payloadVariant.lora; config.lora = c.payloadVariant.lora;
break; requiresReboot = true;
case Config_bluetooth_tag: break;
DEBUG_MSG("Setting config: Bluetooth\n"); case Config_bluetooth_tag:
config.has_bluetooth = true; DEBUG_MSG("Setting config: Bluetooth\n");
config.bluetooth = c.payloadVariant.bluetooth; config.has_bluetooth = true;
break; 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) void AdminModule::handleSetModuleConfig(const ModuleConfig &c)

View File

@ -57,6 +57,7 @@ void onConnect(uint16_t conn_handle)
connection->getPeerName(central_name, sizeof(central_name)); connection->getPeerName(central_name, sizeof(central_name));
DEBUG_MSG("BLE Connected to %s\n", 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.stop();
Bluefruit.Advertising.clearData(); Bluefruit.Advertising.clearData();
Bluefruit.ScanResponse.clearData(); Bluefruit.ScanResponse.clearData();
config.bluetooth.mode = Config_BluetoothConfig_PairingMode_NoPin;
if (config.bluetooth.mode != Config_BluetoothConfig_PairingMode_NoPin) { if (config.bluetooth.mode != Config_BluetoothConfig_PairingMode_NoPin) {
configuredPasskey = config.bluetooth.mode == Config_BluetoothConfig_PairingMode_FixedPin ? 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); sprintf(specified, "%.3s%.3s", passkey, passkey+3);
static char configured[6]; static char configured[6];
sprintf(configured, "%i", configuredPasskey); sprintf(configured, "%i", configuredPasskey);
powerFSM.trigger(EVENT_BLUETOOTH_PAIR);
screen->startBluetoothPinScreen(configuredPasskey);
if (match_request) 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; bool accepted = false;
uint32_t start_time = millis(); uint32_t start_time = millis();
while(millis() < start_time + 30000) while(millis() < start_time + 30000)

View File

@ -8,6 +8,7 @@ void powerCommandsCheck()
{ {
if (rebootAtMsec && millis() > rebootAtMsec) { if (rebootAtMsec && millis() > rebootAtMsec) {
DEBUG_MSG("Rebooting\n"); DEBUG_MSG("Rebooting\n");
screen->startRebootScreen();
#if defined(ARCH_ESP32) #if defined(ARCH_ESP32)
ESP.restart(); ESP.restart();
#elif defined(ARCH_NRF52) #elif defined(ARCH_NRF52)