Implement BLE OTA
This commit is contained in:
@@ -117,6 +117,9 @@ float cachedTempC = 25.0f;
|
||||
uint32_t loopStalls = 0; // loop iterations where dt > 20ms (behind schedule)
|
||||
bool pendingCal = false;
|
||||
bool pendingReset = false;
|
||||
#ifdef FEATURE_OTA
|
||||
bool pendingOTA = false;
|
||||
#endif
|
||||
|
||||
// Jerk-based shock detection - freeze cursor during tap impacts, doesn't work well yet!
|
||||
unsigned long shockFreezeUntil = 0;
|
||||
@@ -299,10 +302,28 @@ void loop() {
|
||||
char cmd = Serial.read();
|
||||
if (cmd == 'c') { Serial.println("[SERIAL] Calibrate"); pendingCal = true; }
|
||||
if (cmd == 'r') { Serial.println("[SERIAL] Reset"); pendingReset = true; }
|
||||
#ifdef FEATURE_OTA
|
||||
if (cmd == 'o') { Serial.println("[SERIAL] OTA DFU"); pendingOTA = true; }
|
||||
#endif
|
||||
}
|
||||
|
||||
if (pendingCal) { pendingCal = false; calibrateGyroBias(); prevAx = imu.readFloatAccelX(); prevAy = imu.readFloatAccelY(); prevAz = imu.readFloatAccelZ(); }
|
||||
if (pendingReset) { pendingReset = false; factoryReset(); }
|
||||
#ifdef FEATURE_OTA
|
||||
if (pendingOTA) {
|
||||
pendingOTA = false;
|
||||
Serial.println("[OTA] Disconnecting BLE and entering bootloader DFU mode...");
|
||||
Serial.flush();
|
||||
// Gracefully close the BLE connection first so the host can detect the
|
||||
// disconnect and be ready to see DfuTarg advertise after the reboot.
|
||||
if (Bluefruit.connected()) {
|
||||
Bluefruit.disconnect(0);
|
||||
delay(300);
|
||||
}
|
||||
delay(200);
|
||||
enterOTADfu(); // Adafruit nRF52 core: sets GPREGRET correctly and resets into bootloader OTA mode
|
||||
}
|
||||
#endif
|
||||
|
||||
// Heartbeat LED
|
||||
if (now - lastHeartbeat >= HEARTBEAT_MS) {
|
||||
|
||||
Reference in New Issue
Block a user