Skip to content

Commit 0d84ea2

Browse files
authored
Merge pull request #16 from fbiego/health
format code
2 parents b55a0e9 + 75668fa commit 0d84ea2

File tree

4 files changed

+53
-66
lines changed

4 files changed

+53
-66
lines changed

examples/health/health.ino

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
#include <ChronosESP32.h>
3434

35-
3635
ChronosESP32 watch("Chronos Health"); // set the bluetooth name
3736

3837
bool send_health = false; // flag to send health data
@@ -93,8 +92,6 @@ void setup()
9392

9493
watch.setBattery(80); // set the battery level, will be synced to the app
9594

96-
// watch.clearNotifications(); // clear the default notification (Chronos app install text)
97-
9895
watch.set24Hour(true); // the 24 hour mode will be overwritten when the command is received from the app
9996
}
10097

@@ -124,7 +121,6 @@ void loop()
124121
watch.sendStepsRecord(2345, 69, 14, watch.getDay(), watch.getMonth() + 1, watch.getYear(), 76, 96, 110, 70); // send steps records
125122
watch.sendStepsRecord(5654, 124, 15, watch.getDay(), watch.getMonth() + 1, watch.getYear(), 75, 97, 114, 76); // send steps records
126123

127-
128124
// heart rate records
129125
watch.sendHeartRateRecord(78, 30, 11, watch.getDay(), watch.getMonth() + 1, watch.getYear());
130126
watch.sendHeartRateRecord(82, 5, 12, watch.getDay(), watch.getMonth() + 1, watch.getYear());

examples/navigation/navigation.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ void configCallback(Config config, uint32_t a, uint32_t b)
6262
Serial.print("Navigation state: ");
6363
Serial.println(a ? "Active" : "Inactive");
6464
change = true;
65-
if (a){
65+
if (a)
66+
{
6667
Navigation nav = watch.getNavigation();
6768
Serial.println(nav.directions);
6869
Serial.println(nav.eta);
@@ -105,7 +106,7 @@ void loop()
105106

106107
// if (change){
107108
// change = false;
108-
109+
109110
// Navigation nav = watch.getNavigation();
110111
// if (nav.active){
111112
// Serial.println(nav.directions);
@@ -115,5 +116,4 @@ void loop()
115116
// Serial.println(nav.title);
116117
// }
117118
// }
118-
119119
}

src/ChronosESP32.cpp

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ ChronosESP32::ChronosESP32()
5151
_notifications[0].app = "Chronos";
5252
_notifications[0].message = "Download from Google Play to sync time and receive notifications";
5353

54-
_infoTimer.duration = 3 * 1000; // 3 seconds for info timer
55-
_findTimer.duration = 30 * 1000; // 30 seconds for find phone
54+
_infoTimer.duration = 3 * 1000; // 3 seconds for info timer
55+
_findTimer.duration = 30 * 1000; // 30 seconds for find phone
5656
}
5757

5858
/*!
@@ -180,7 +180,6 @@ void ChronosESP32::loop()
180180
sendESP();
181181
}
182182
}
183-
184183
}
185184

186185
/*!
@@ -751,11 +750,10 @@ void ChronosESP32::setNotifyBattery(bool state)
751750
void ChronosESP32::sendRealtimeSteps(uint32_t steps, uint32_t calories)
752751
{
753752
uint8_t stepsCmd[] = {
754-
0xAB, 0x00, 0x0E, 0xFF, 0x51, 0x08,
755-
(uint8_t)(steps >> 16), (uint8_t)(steps >> 8), (uint8_t)(steps),
753+
0xAB, 0x00, 0x0E, 0xFF, 0x51, 0x08,
754+
(uint8_t)(steps >> 16), (uint8_t)(steps >> 8), (uint8_t)(steps),
756755
(uint8_t)(calories >> 16), (uint8_t)(calories >> 8), (uint8_t)(calories),
757-
0x00, 0x00, 0x00, 0x00, 0x00
758-
};
756+
0x00, 0x00, 0x00, 0x00, 0x00};
759757
sendCommand(stepsCmd, 17);
760758
}
761759
/*!
@@ -768,8 +766,7 @@ void ChronosESP32::sendRealtimeHeartRate(uint8_t heartRate)
768766
{
769767
// AB 00 05 FF 31 0A 49 1B
770768
uint8_t heartCmd[] = {
771-
0xAB, 0x00, 0x05, 0xFF, 0x31, 0x0A, heartRate, 0x1B
772-
};
769+
0xAB, 0x00, 0x05, 0xFF, 0x31, 0x0A, heartRate, 0x1B};
773770
sendCommand(heartCmd, 8);
774771
}
775772

@@ -785,8 +782,7 @@ void ChronosESP32::sendRealtimeBloodPressure(uint8_t systolic, uint8_t diastolic
785782
{
786783
// AB 00 05 FF 31 22 71 4C
787784
uint8_t pressureCmd[] = {
788-
0xAB, 0x00, 0x05, 0xFF, 0x31, 0x22, systolic, diastolic
789-
};
785+
0xAB, 0x00, 0x05, 0xFF, 0x31, 0x22, systolic, diastolic};
790786
sendCommand(pressureCmd, 8);
791787
}
792788

@@ -800,8 +796,7 @@ void ChronosESP32::sendRealtimeBloodOxygen(uint8_t bloodOxygen)
800796
{
801797
// AB 00 05 FF 31 12 62 30
802798
uint8_t oxygenCmd[] = {
803-
0xAB, 0x00, 0x05, 0xFF, 0x31, 0x12, bloodOxygen, 0x30
804-
};
799+
0xAB, 0x00, 0x05, 0xFF, 0x31, 0x12, bloodOxygen, 0x30};
805800
sendCommand(oxygenCmd, 8);
806801
}
807802

@@ -821,8 +816,7 @@ void ChronosESP32::sendRealtimeHealthData(uint8_t heartRate, uint8_t bloodOxygen
821816
{
822817
// AB 00 07 FF 32 80 44 61 72 4B
823818
uint8_t healthCmd[] = {
824-
0xAB, 0x00, 0x07, 0xFF, 0x32, 0x80, heartRate, bloodOxygen, systolic, diastolic
825-
};
819+
0xAB, 0x00, 0x07, 0xFF, 0x32, 0x80, heartRate, bloodOxygen, systolic, diastolic};
826820
sendCommand(healthCmd, 10);
827821
}
828822

@@ -852,13 +846,12 @@ void ChronosESP32::sendRealtimeHealthData(uint8_t heartRate, uint8_t bloodOxygen
852846
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)
853847
{
854848
uint8_t stepsCmd[] = {
855-
0xAB, 0x00, 0x16, 0xFF, 0x51, 0x20,
856-
(uint8_t)(year - 2000), month, day, hour,
857-
(uint8_t)(steps >> 16), (uint8_t)(steps >> 8), (uint8_t)(steps),
849+
0xAB, 0x00, 0x16, 0xFF, 0x51, 0x20,
850+
(uint8_t)(year - 2000), month, day, hour,
851+
(uint8_t)(steps >> 16), (uint8_t)(steps >> 8), (uint8_t)(steps),
858852
(uint8_t)(calories >> 16), (uint8_t)(calories >> 8), (uint8_t)(calories),
859853
heartRate, bloodOxygen, systolic, diastolic,
860-
0x00, 0x00, 0x00, 0x00, 0x00
861-
};
854+
0x00, 0x00, 0x00, 0x00, 0x00};
862855
sendCommand(stepsCmd, 25);
863856
}
864857

@@ -880,10 +873,9 @@ void ChronosESP32::sendStepsRecord(uint32_t steps, uint32_t calories, uint8_t ho
880873
void ChronosESP32::sendHeartRateRecord(uint8_t heartRate, uint8_t minute, uint8_t hour, uint8_t day, uint8_t month, uint32_t year)
881874
{
882875
uint8_t heartCmd[] = {
883-
0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x11,
884-
(uint8_t)(year - 2000), month, day, hour, minute,
885-
heartRate, 0x00
886-
};
876+
0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x11,
877+
(uint8_t)(year - 2000), month, day, hour, minute,
878+
heartRate, 0x00};
887879
sendCommand(heartCmd, 13);
888880
}
889881

@@ -907,10 +899,9 @@ void ChronosESP32::sendHeartRateRecord(uint8_t heartRate, uint8_t minute, uint8_
907899
void ChronosESP32::sendBloodPressureRecord(uint8_t systolic, uint8_t diastolic, uint8_t minute, uint8_t hour, uint8_t day, uint8_t month, uint32_t year)
908900
{
909901
uint8_t pressureCmd[] = {
910-
0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x14,
911-
(uint8_t)(year - 2000), month, day, hour, minute,
912-
systolic, diastolic
913-
};
902+
0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x14,
903+
(uint8_t)(year - 2000), month, day, hour, minute,
904+
systolic, diastolic};
914905
sendCommand(pressureCmd, 13);
915906
}
916907

@@ -932,10 +923,9 @@ void ChronosESP32::sendBloodPressureRecord(uint8_t systolic, uint8_t diastolic,
932923
void ChronosESP32::sendBloodOxygenRecord(uint8_t bloodOxygen, uint8_t minute, uint8_t hour, uint8_t day, uint8_t month, uint32_t year)
933924
{
934925
uint8_t oxygenCmd[] = {
935-
0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x12,
936-
(uint8_t)(year - 2000), month, day, hour, minute,
937-
bloodOxygen, 0x00
938-
};
926+
0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x12,
927+
(uint8_t)(year - 2000), month, day, hour, minute,
928+
bloodOxygen, 0x00};
939929
sendCommand(oxygenCmd, 13);
940930
}
941931

@@ -959,10 +949,9 @@ void ChronosESP32::sendBloodOxygenRecord(uint8_t bloodOxygen, uint8_t minute, ui
959949
void ChronosESP32::sendSleepRecord(uint16_t sleepTime, SleepType type, uint8_t minute, uint8_t hour, uint8_t day, uint8_t month, uint32_t year)
960950
{
961951
uint8_t sleepCmd[] = {
962-
0xAB, 0x00, 0x0B, 0xFF, 0x52, 0x80,
963-
(uint8_t)(year - 2000), month, day, hour, minute,
964-
(uint8_t)(type), highByte(sleepTime), lowByte(sleepTime)
965-
};
952+
0xAB, 0x00, 0x0B, 0xFF, 0x52, 0x80,
953+
(uint8_t)(year - 2000), month, day, hour, minute,
954+
(uint8_t)(type), highByte(sleepTime), lowByte(sleepTime)};
966955
sendCommand(sleepCmd, 14);
967956
}
968957

@@ -984,10 +973,9 @@ void ChronosESP32::sendSleepRecord(uint16_t sleepTime, SleepType type, uint8_t m
984973
void ChronosESP32::sendTemperatureRecord(float temperature, uint8_t minute, uint8_t hour, uint8_t day, uint8_t month, uint32_t year)
985974
{
986975
uint8_t tempCmd[] = {
987-
0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x13,
988-
(uint8_t)(year - 2000), month, day, hour, minute,
989-
(uint8_t)(temperature), (uint8_t)((uint16_t)(temperature * 100.0) % 100)
990-
};
976+
0xAB, 0x00, 0x0A, 0xFF, 0x51, 0x13,
977+
(uint8_t)(year - 2000), month, day, hour, minute,
978+
(uint8_t)(temperature), (uint8_t)((uint16_t)(temperature * 100.0) % 100)};
991979
sendCommand(tempCmd, 13);
992980
}
993981

@@ -1315,18 +1303,22 @@ void ChronosESP32::onWrite(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo
13151303
}
13161304
}
13171305

1318-
void ChronosESP32::splitTitle(const String &input, String &title, String &message, int icon) {
1319-
int index = input.indexOf(':'); // Find the first occurrence of ':'
1320-
int newlineIndex = input.indexOf('\n'); // Find the first occurrence of '\n'
1306+
void ChronosESP32::splitTitle(const String &input, String &title, String &message, int icon)
1307+
{
1308+
int index = input.indexOf(':'); // Find the first occurrence of ':'
1309+
int newlineIndex = input.indexOf('\n'); // Find the first occurrence of '\n'
13211310

1322-
if (index != -1 && index < 30 && (newlineIndex == -1 || newlineIndex > index)) {
1323-
// Split only if ':' is before index 30 and there's no '\n' before it
1324-
title = input.substring(0, index);
1325-
message = input.substring(index + 1);
1326-
} else {
1327-
title = appName(icon); // No valid ':' before index 30, or '\n' appears before ':'
1328-
message = input; // Keep the full string in message
1329-
}
1311+
if (index != -1 && index < 30 && (newlineIndex == -1 || newlineIndex > index))
1312+
{
1313+
// Split only if ':' is before index 30 and there's no '\n' before it
1314+
title = input.substring(0, index);
1315+
message = input.substring(index + 1);
1316+
}
1317+
else
1318+
{
1319+
title = appName(icon); // No valid ':' before index 30, or '\n' appears before ':'
1320+
message = input; // Keep the full string in message
1321+
}
13301322
}
13311323

13321324
/*!
@@ -1390,7 +1382,7 @@ void ChronosESP32::dataReceived()
13901382
}
13911383
break;
13921384
}
1393-
1385+
13941386
break;
13951387
case 0x52:
13961388
switch (_incomingData.data[5])
@@ -1402,7 +1394,7 @@ void ChronosESP32::dataReceived()
14021394
}
14031395
break;
14041396
}
1405-
1397+
14061398
break;
14071399
case 0x53:
14081400
if (configurationReceivedCallback != nullptr)

src/ChronosESP32.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ enum Config
204204
enum HealthRequest
205205
{
206206
HR_STEPS_RECORDS = 0, // app is requesting step records
207-
HR_SLEEP_RECORDS, // app is requesting sleep records
207+
HR_SLEEP_RECORDS, // app is requesting sleep records
208208

209-
HR_HEART_RATE_MEASURE, // app has started heart rate measurement
210-
HR_BLOOD_OXYGEN_MEASURE, // app has started blood oxygen measurement
211-
HR_BLOOD_PRESSURE_MEASURE, // app has started blood pressure measurement
212-
HR_MEASURE_ALL, // app has started all health measurements
209+
HR_HEART_RATE_MEASURE, // app has started heart rate measurement
210+
HR_BLOOD_OXYGEN_MEASURE, // app has started blood oxygen measurement
211+
HR_BLOOD_PRESSURE_MEASURE, // app has started blood pressure measurement
212+
HR_MEASURE_ALL, // app has started all health measurements
213213
};
214214

215215
/*
@@ -353,7 +353,6 @@ class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallback
353353
void sendTemperatureRecord(float temperature, DateTime dateTime);
354354
void sendSleepRecord(uint16_t sleepTime, SleepType type, DateTime dateTime);
355355

356-
357356
// helper functions for ESP32Time
358357
int getHourC(); // return hour based on 24-hour variable (0-12 or 0-23)
359358
String getHourZ(); // return zero padded hour string based on 24-hour variable (00-12 or 00-23)

0 commit comments

Comments
 (0)