diff --git a/examples/health/health.ino b/examples/health/health.ino index 2ffbe79..215d10a 100644 --- a/examples/health/health.ino +++ b/examples/health/health.ino @@ -32,7 +32,6 @@ #include - ChronosESP32 watch("Chronos Health"); // set the bluetooth name bool send_health = false; // flag to send health data @@ -93,8 +92,6 @@ void setup() watch.setBattery(80); // set the battery level, will be synced to the app - // watch.clearNotifications(); // clear the default notification (Chronos app install text) - watch.set24Hour(true); // the 24 hour mode will be overwritten when the command is received from the app } @@ -124,7 +121,6 @@ void loop() watch.sendStepsRecord(2345, 69, 14, watch.getDay(), watch.getMonth() + 1, watch.getYear(), 76, 96, 110, 70); // send steps records watch.sendStepsRecord(5654, 124, 15, watch.getDay(), watch.getMonth() + 1, watch.getYear(), 75, 97, 114, 76); // send steps records - // heart rate records watch.sendHeartRateRecord(78, 30, 11, watch.getDay(), watch.getMonth() + 1, watch.getYear()); watch.sendHeartRateRecord(82, 5, 12, watch.getDay(), watch.getMonth() + 1, watch.getYear()); diff --git a/examples/navigation/navigation.ino b/examples/navigation/navigation.ino index 25e0e30..6f5cad0 100644 --- a/examples/navigation/navigation.ino +++ b/examples/navigation/navigation.ino @@ -62,7 +62,8 @@ void configCallback(Config config, uint32_t a, uint32_t b) Serial.print("Navigation state: "); Serial.println(a ? "Active" : "Inactive"); change = true; - if (a){ + if (a) + { Navigation nav = watch.getNavigation(); Serial.println(nav.directions); Serial.println(nav.eta); @@ -105,7 +106,7 @@ void loop() // if (change){ // change = false; - + // Navigation nav = watch.getNavigation(); // if (nav.active){ // Serial.println(nav.directions); @@ -115,5 +116,4 @@ void loop() // Serial.println(nav.title); // } // } - } \ No newline at end of file diff --git a/src/ChronosESP32.cpp b/src/ChronosESP32.cpp index 43fd12b..b605476 100644 --- a/src/ChronosESP32.cpp +++ b/src/ChronosESP32.cpp @@ -51,8 +51,8 @@ ChronosESP32::ChronosESP32() _notifications[0].app = "Chronos"; _notifications[0].message = "Download from Google Play to sync time and receive notifications"; - _infoTimer.duration = 3 * 1000; // 3 seconds for info timer - _findTimer.duration = 30 * 1000; // 30 seconds for find phone + _infoTimer.duration = 3 * 1000; // 3 seconds for info timer + _findTimer.duration = 30 * 1000; // 30 seconds for find phone } /*! @@ -180,7 +180,6 @@ void ChronosESP32::loop() sendESP(); } } - } /*! @@ -751,11 +750,10 @@ void ChronosESP32::setNotifyBattery(bool state) void ChronosESP32::sendRealtimeSteps(uint32_t steps, uint32_t calories) { uint8_t stepsCmd[] = { - 0xAB, 0x00, 0x0E, 0xFF, 0x51, 0x08, - (uint8_t)(steps >> 16), (uint8_t)(steps >> 8), (uint8_t)(steps), + 0xAB, 0x00, 0x0E, 0xFF, 0x51, 0x08, + (uint8_t)(steps >> 16), (uint8_t)(steps >> 8), (uint8_t)(steps), (uint8_t)(calories >> 16), (uint8_t)(calories >> 8), (uint8_t)(calories), - 0x00, 0x00, 0x00, 0x00, 0x00 - }; + 0x00, 0x00, 0x00, 0x00, 0x00}; sendCommand(stepsCmd, 17); } /*! @@ -768,8 +766,7 @@ void ChronosESP32::sendRealtimeHeartRate(uint8_t heartRate) { // AB 00 05 FF 31 0A 49 1B uint8_t heartCmd[] = { - 0xAB, 0x00, 0x05, 0xFF, 0x31, 0x0A, heartRate, 0x1B - }; + 0xAB, 0x00, 0x05, 0xFF, 0x31, 0x0A, heartRate, 0x1B}; sendCommand(heartCmd, 8); } @@ -785,8 +782,7 @@ void ChronosESP32::sendRealtimeBloodPressure(uint8_t systolic, uint8_t diastolic { // AB 00 05 FF 31 22 71 4C uint8_t pressureCmd[] = { - 0xAB, 0x00, 0x05, 0xFF, 0x31, 0x22, systolic, diastolic - }; + 0xAB, 0x00, 0x05, 0xFF, 0x31, 0x22, systolic, diastolic}; sendCommand(pressureCmd, 8); } @@ -800,8 +796,7 @@ void ChronosESP32::sendRealtimeBloodOxygen(uint8_t bloodOxygen) { // AB 00 05 FF 31 12 62 30 uint8_t oxygenCmd[] = { - 0xAB, 0x00, 0x05, 0xFF, 0x31, 0x12, bloodOxygen, 0x30 - }; + 0xAB, 0x00, 0x05, 0xFF, 0x31, 0x12, bloodOxygen, 0x30}; sendCommand(oxygenCmd, 8); } @@ -821,8 +816,7 @@ void ChronosESP32::sendRealtimeHealthData(uint8_t heartRate, uint8_t bloodOxygen { // AB 00 07 FF 32 80 44 61 72 4B uint8_t healthCmd[] = { - 0xAB, 0x00, 0x07, 0xFF, 0x32, 0x80, heartRate, bloodOxygen, systolic, diastolic - }; + 0xAB, 0x00, 0x07, 0xFF, 0x32, 0x80, heartRate, bloodOxygen, systolic, diastolic}; sendCommand(healthCmd, 10); } @@ -852,13 +846,12 @@ void ChronosESP32::sendRealtimeHealthData(uint8_t heartRate, uint8_t bloodOxygen void ChronosESP32::sendStepsRecord(uint32_t steps, uint32_t calories, uint8_t hour, uint8_t day, uint8_t month, uint32_t year, uint8_t heartRate, uint8_t bloodOxygen, uint8_t systolic, uint8_t diastolic) { uint8_t stepsCmd[] = { - 0xAB, 0x00, 0x16, 0xFF, 0x51, 0x20, - (uint8_t)(year - 2000), month, day, hour, - (uint8_t)(steps >> 16), (uint8_t)(steps >> 8), (uint8_t)(steps), + 0xAB, 0x00, 0x16, 0xFF, 0x51, 0x20, + (uint8_t)(year - 2000), month, day, hour, + (uint8_t)(steps >> 16), (uint8_t)(steps >> 8), (uint8_t)(steps), (uint8_t)(calories >> 16), (uint8_t)(calories >> 8), (uint8_t)(calories), heartRate, bloodOxygen, systolic, diastolic, - 0x00, 0x00, 0x00, 0x00, 0x00 - }; + 0x00, 0x00, 0x00, 0x00, 0x00}; sendCommand(stepsCmd, 25); } @@ -880,10 +873,9 @@ void ChronosESP32::sendStepsRecord(uint32_t steps, uint32_t calories, uint8_t ho void ChronosESP32::sendHeartRateRecord(uint8_t heartRate, uint8_t minute, uint8_t hour, uint8_t day, uint8_t month, uint32_t year) { uint8_t heartCmd[] = { - 0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x11, - (uint8_t)(year - 2000), month, day, hour, minute, - heartRate, 0x00 - }; + 0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x11, + (uint8_t)(year - 2000), month, day, hour, minute, + heartRate, 0x00}; sendCommand(heartCmd, 13); } @@ -907,10 +899,9 @@ void ChronosESP32::sendHeartRateRecord(uint8_t heartRate, uint8_t minute, uint8_ void ChronosESP32::sendBloodPressureRecord(uint8_t systolic, uint8_t diastolic, uint8_t minute, uint8_t hour, uint8_t day, uint8_t month, uint32_t year) { uint8_t pressureCmd[] = { - 0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x14, - (uint8_t)(year - 2000), month, day, hour, minute, - systolic, diastolic - }; + 0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x14, + (uint8_t)(year - 2000), month, day, hour, minute, + systolic, diastolic}; sendCommand(pressureCmd, 13); } @@ -932,10 +923,9 @@ void ChronosESP32::sendBloodPressureRecord(uint8_t systolic, uint8_t diastolic, void ChronosESP32::sendBloodOxygenRecord(uint8_t bloodOxygen, uint8_t minute, uint8_t hour, uint8_t day, uint8_t month, uint32_t year) { uint8_t oxygenCmd[] = { - 0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x12, - (uint8_t)(year - 2000), month, day, hour, minute, - bloodOxygen, 0x00 - }; + 0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x12, + (uint8_t)(year - 2000), month, day, hour, minute, + bloodOxygen, 0x00}; sendCommand(oxygenCmd, 13); } @@ -959,10 +949,9 @@ void ChronosESP32::sendBloodOxygenRecord(uint8_t bloodOxygen, uint8_t minute, ui void ChronosESP32::sendSleepRecord(uint16_t sleepTime, SleepType type, uint8_t minute, uint8_t hour, uint8_t day, uint8_t month, uint32_t year) { uint8_t sleepCmd[] = { - 0xAB, 0x00, 0x0B, 0xFF, 0x52, 0x80, - (uint8_t)(year - 2000), month, day, hour, minute, - (uint8_t)(type), highByte(sleepTime), lowByte(sleepTime) - }; + 0xAB, 0x00, 0x0B, 0xFF, 0x52, 0x80, + (uint8_t)(year - 2000), month, day, hour, minute, + (uint8_t)(type), highByte(sleepTime), lowByte(sleepTime)}; sendCommand(sleepCmd, 14); } @@ -984,10 +973,9 @@ void ChronosESP32::sendSleepRecord(uint16_t sleepTime, SleepType type, uint8_t m void ChronosESP32::sendTemperatureRecord(float temperature, uint8_t minute, uint8_t hour, uint8_t day, uint8_t month, uint32_t year) { uint8_t tempCmd[] = { - 0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x13, - (uint8_t)(year - 2000), month, day, hour, minute, - (uint8_t)(temperature), (uint8_t)((uint16_t)(temperature * 100.0) % 100) - }; + 0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x13, + (uint8_t)(year - 2000), month, day, hour, minute, + (uint8_t)(temperature), (uint8_t)((uint16_t)(temperature * 100.0) % 100)}; sendCommand(tempCmd, 13); } @@ -1315,18 +1303,22 @@ void ChronosESP32::onWrite(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo } } -void ChronosESP32::splitTitle(const String &input, String &title, String &message, int icon) { - int index = input.indexOf(':'); // Find the first occurrence of ':' - int newlineIndex = input.indexOf('\n'); // Find the first occurrence of '\n' +void ChronosESP32::splitTitle(const String &input, String &title, String &message, int icon) +{ + int index = input.indexOf(':'); // Find the first occurrence of ':' + int newlineIndex = input.indexOf('\n'); // Find the first occurrence of '\n' - if (index != -1 && index < 30 && (newlineIndex == -1 || newlineIndex > index)) { - // Split only if ':' is before index 30 and there's no '\n' before it - title = input.substring(0, index); - message = input.substring(index + 1); - } else { - title = appName(icon); // No valid ':' before index 30, or '\n' appears before ':' - message = input; // Keep the full string in message - } + if (index != -1 && index < 30 && (newlineIndex == -1 || newlineIndex > index)) + { + // Split only if ':' is before index 30 and there's no '\n' before it + title = input.substring(0, index); + message = input.substring(index + 1); + } + else + { + title = appName(icon); // No valid ':' before index 30, or '\n' appears before ':' + message = input; // Keep the full string in message + } } /*! @@ -1390,7 +1382,7 @@ void ChronosESP32::dataReceived() } break; } - + break; case 0x52: switch (_incomingData.data[5]) @@ -1402,7 +1394,7 @@ void ChronosESP32::dataReceived() } break; } - + break; case 0x53: if (configurationReceivedCallback != nullptr) diff --git a/src/ChronosESP32.h b/src/ChronosESP32.h index f0821e0..c763c40 100644 --- a/src/ChronosESP32.h +++ b/src/ChronosESP32.h @@ -204,12 +204,12 @@ enum Config enum HealthRequest { HR_STEPS_RECORDS = 0, // app is requesting step records - HR_SLEEP_RECORDS, // app is requesting sleep records + HR_SLEEP_RECORDS, // app is requesting sleep records - HR_HEART_RATE_MEASURE, // app has started heart rate measurement - HR_BLOOD_OXYGEN_MEASURE, // app has started blood oxygen measurement - HR_BLOOD_PRESSURE_MEASURE, // app has started blood pressure measurement - HR_MEASURE_ALL, // app has started all health measurements + HR_HEART_RATE_MEASURE, // app has started heart rate measurement + HR_BLOOD_OXYGEN_MEASURE, // app has started blood oxygen measurement + HR_BLOOD_PRESSURE_MEASURE, // app has started blood pressure measurement + HR_MEASURE_ALL, // app has started all health measurements }; /* @@ -353,7 +353,6 @@ class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallback void sendTemperatureRecord(float temperature, DateTime dateTime); void sendSleepRecord(uint16_t sleepTime, SleepType type, DateTime dateTime); - // helper functions for ESP32Time int getHourC(); // return hour based on 24-hour variable (0-12 or 0-23) String getHourZ(); // return zero padded hour string based on 24-hour variable (00-12 or 00-23)