ota updates

This commit is contained in:
Dan Priece
2026-05-28 13:59:56 -04:00
parent 2c5f532717
commit 51dbd5e5b0
5 changed files with 105 additions and 105 deletions
+18 -28
View File
@@ -1,6 +1,10 @@
#include "ChronoBLE.h"
#include <NimBLEDevice.h>
// Flag to signal that a new reading is ready to be processed
volatile bool newReadingAvailable = false;
volatile int lastReadFPS = 0;
static NimBLEClient* _pClient = nullptr;
static ChronoBLE::ConnectionState currentState;
static const NimBLEAdvertisedDevice* advDevice = nullptr;
@@ -61,39 +65,25 @@ class ScanCallbacks : public NimBLEScanCallbacks {
//notification callback
void notifyCB(NimBLERemoteCharacteristic* pRemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify) {
uint16_t speed;
char sbuffer[256];
std::string str = (isNotify == true) ? "Notification" : "Indication";
str += " from ";
str += pRemoteCharacteristic->getClient()->getPeerAddress().toString();
str += ": Service = " + pRemoteCharacteristic->getRemoteService()->getUUID().toString();
str += ", Characteristic = " + pRemoteCharacteristic->getUUID().toString();
str += ", Value = " + std::string((char*)pData, length);
// Serial.printf("%s\n", str.c_str());
// Serial.printf("%d\n",pData);
//if(length>0){
speed = ((char*)pData)[0];
// Extract speed from data - only what's needed, avoid String allocations
if (length >= 2) {
speed = pData[0];
speed <<= 8;
speed |= ((char*)pData)[1];
speed |= pData[1];
if (speed>0){
float energy;
float fspeed = speed;
/* Draw the speed string */
//if(units == UNITS_IMPERIAL) {
fspeed *= 0.0475111859;
//sprintf (sbuffer, "%d FPS", int(fspeed));
Serial.printf("%d FPS\n", int(fspeed));
//} else {
//fspeed *= 0.014481409;
//sprintf (sbuffer, "%d M/S", int(fspeed));
//}
//}
if (speedCallback!= nullptr){
speedCallback(fspeed);
if (speed > 0) {
// Convert to FPS
float fspeed = speed * 0.0475111859;
// Store the reading for later processing in main loop
// This avoids heap fragmentation and display updates in interrupt context
lastReadFPS = (int)fspeed;
newReadingAvailable = true;
Serial.printf("%d FPS\n", (int)fspeed);
}
}
}