From bf640bec3cfcfaf3fa408abfca7132df8452b060 Mon Sep 17 00:00:00 2001 From: geeksville Date: Sun, 23 Feb 2020 11:46:58 -0800 Subject: [PATCH] WIP - more progress switching to dynamic alloc --- .../src/BluetoothSoftwareUpdate.cpp | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/BluetoothOTA/src/BluetoothSoftwareUpdate.cpp b/lib/BluetoothOTA/src/BluetoothSoftwareUpdate.cpp index 40ac092b8..98c00734e 100644 --- a/lib/BluetoothOTA/src/BluetoothSoftwareUpdate.cpp +++ b/lib/BluetoothOTA/src/BluetoothSoftwareUpdate.cpp @@ -56,8 +56,7 @@ public: } }; -static BLECharacteristic swUpdateResultCharacteristic("5e134862-7411-4424-ac4a-210937432c77", BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY); - +static BLECharacteristic *resultC; class CRC32Characteristic : public CallbackCharacteristic { @@ -96,24 +95,18 @@ public: } result = Update.getError(); } - swUpdateResultCharacteristic.setValue(&result, 1); - swUpdateResultCharacteristic.notify(); + assert(resultC); + resultC->setValue(&result, 1); + resultC->notify(); } }; - -static TotalSizeCharacteristic swUpdateTotalSizeCharacteristic; -static DataCharacteristic swUpdateDataCharacteristic; -static CRC32Characteristic swUpdateCRC32Characteristic; - - void bluetoothRebootCheck() { if (rebootAtMsec && millis() > rebootAtMsec) ESP.restart(); } - /* SoftwareUpdateService UUID cb0b9a0b-a84c-4c0d-bdbb-442e3144ee30 @@ -130,12 +123,14 @@ BLEService *createUpdateService(BLEServer *server) // Create the BLE Service BLEService *service = server->createService("cb0b9a0b-a84c-4c0d-bdbb-442e3144ee30"); - addWithDesc(service, &swUpdateTotalSizeCharacteristic, "total image size"); - addWithDesc(service, &swUpdateDataCharacteristic, "data"); - addWithDesc(service, &swUpdateCRC32Characteristic, "crc32"); - addWithDesc(service, &swUpdateResultCharacteristic, "result code"); + resultC = new (btPool) BLECharacteristic("5e134862-7411-4424-ac4a-210937432c77", BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY); - swUpdateResultCharacteristic.addDescriptor(new (btPool) BLE2902()); // Needed so clients can request notification + addWithDesc(service, new (btPool) TotalSizeCharacteristic, "total image size"); + addWithDesc(service, new (btPool) DataCharacteristic, "data"); + addWithDesc(service, new (btPool) CRC32Characteristic, "crc32"); + addWithDesc(service, resultC, "result code"); + + resultC->addDescriptor(new (btPool) BLE2902()); // Needed so clients can request notification return service; }