wip - make ble come back after sleep
This commit is contained in:
+41
-18
@@ -44,11 +44,15 @@
|
||||
AXP20X_Class axp;
|
||||
bool pmu_irq = false;
|
||||
#endif
|
||||
bool isCharging = false;
|
||||
bool isUSBPowered = false;
|
||||
|
||||
bool ssd1306_found = false;
|
||||
bool axp192_found = false;
|
||||
// these flags are all in bss so they default false
|
||||
bool isCharging;
|
||||
bool isUSBPowered;
|
||||
|
||||
bool ssd1306_found;
|
||||
bool axp192_found;
|
||||
|
||||
bool bluetoothOn;
|
||||
|
||||
#define xstr(s) str(s)
|
||||
#define str(s) #s
|
||||
@@ -250,24 +254,43 @@ void setup()
|
||||
|
||||
service.init();
|
||||
|
||||
bool useBluetooth = true;
|
||||
if (useBluetooth)
|
||||
{
|
||||
DEBUG_MSG("Starting bluetooth\n");
|
||||
BLEServer *serve = initBLE(getDeviceName(), HW_VENDOR, str(APP_VERSION)); // FIXME, use a real name based on the macaddr
|
||||
createMeshBluetoothService(serve);
|
||||
|
||||
// Start advertising - this must be done _after_ creating all services
|
||||
serve->getAdvertising()->start();
|
||||
}
|
||||
|
||||
setBluetoothEnable(false);
|
||||
// setBluetoothEnable(false); we now don't start bluetooth until we enter the proper state
|
||||
setCPUFast(false); // 80MHz is fine for our slow peripherals
|
||||
|
||||
PowerFSM_setup();
|
||||
powerFSM.trigger(EVENT_BOOT); // transition to ON, FIXME, only do this for cold boots, not waking from SDS
|
||||
}
|
||||
|
||||
void initBluetooth()
|
||||
{
|
||||
DEBUG_MSG("Starting bluetooth\n");
|
||||
BLEServer *serve = initBLE(getDeviceName(), HW_VENDOR, str(APP_VERSION)); // FIXME, use a real name based on the macaddr
|
||||
createMeshBluetoothService(serve);
|
||||
|
||||
// Start advertising - this must be done _after_ creating all services
|
||||
serve->getAdvertising()->start();
|
||||
}
|
||||
|
||||
void setBluetoothEnable(bool on)
|
||||
{
|
||||
if (on != bluetoothOn)
|
||||
{
|
||||
DEBUG_MSG("Setting bluetooth enable=%d\n", on);
|
||||
|
||||
bluetoothOn = on;
|
||||
if (on)
|
||||
{
|
||||
initBluetooth();
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME - we are leaking like crazy
|
||||
BLEDevice::deinit(false);
|
||||
btPool.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ledBlinker()
|
||||
{
|
||||
static bool ledOn;
|
||||
@@ -337,7 +360,7 @@ void loop()
|
||||
static uint32_t minPressMs; // what tick should we call this press long enough
|
||||
static uint32_t lastPingMs;
|
||||
|
||||
if (!digitalRead(BUTTON_PIN))
|
||||
if (!digitalRead(BUTTON_PIN))
|
||||
{
|
||||
if (!wasPressed)
|
||||
{ // just started a new press
|
||||
@@ -371,7 +394,7 @@ void loop()
|
||||
// ESP.restart();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// No GPS lock yet, let the OS put the main CPU in low power mode for 100ms (or until another interrupt comes in)
|
||||
// i.e. don't just keep spinning in loop as fast as we can.
|
||||
|
||||
Reference in New Issue
Block a user