Skip to content

Commit 4d49144

Browse files
committed
1.2.0
- add charge command - fix notification state
1 parent 0d397ea commit 4d49144

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

ChronosESP32.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,16 @@ String ChronosESP32::getAddress()
181181
@brief set the battery level
182182
@param level
183183
battery level
184+
@param charging
185+
charging state
184186
*/
185-
void ChronosESP32::setBattery(uint8_t level)
187+
void ChronosESP32::setBattery(uint8_t level, bool charging)
186188
{
187-
if (batteryLevel != level)
189+
if (batteryLevel != level || isCharging != charging)
188190
{
189191
batteryChanged = true;
190192
batteryLevel = level;
193+
isCharging = charging;
191194
}
192195
}
193196

@@ -470,7 +473,7 @@ void ChronosESP32::sendInfo()
470473
*/
471474
void ChronosESP32::sendBattery()
472475
{
473-
uint8_t batCmd[] = {0xAB, 0x00, 0x05, 0xFF, 0x91, 0x80, 0x00, batteryLevel};
476+
uint8_t batCmd[] = {0xAB, 0x00, 0x05, 0xFF, 0x91, 0x80, isCharging ? 0x01 : 0x00, batteryLevel};
474477
pCharacteristicTX->setValue(batCmd, 8);
475478
pCharacteristicTX->notify();
476479
vTaskDelay(200);
@@ -670,6 +673,7 @@ void ChronosESP32::dataReceived()
670673
case 0x72:
671674
{
672675
int icon = incomingData.data[6];
676+
int state = incomingData.data[7];
673677

674678
String message = "";
675679
for (int i = 8; i < len; i++)
@@ -698,17 +702,19 @@ void ChronosESP32::dataReceived()
698702
}
699703
break;
700704
}
701-
702-
notificationIndex++;
703-
notifications[notificationIndex % NOTIF_SIZE].icon = icon;
704-
notifications[notificationIndex % NOTIF_SIZE].app = appName(icon);
705-
notifications[notificationIndex % NOTIF_SIZE].time = this->getTime("%H:%M");
706-
notifications[notificationIndex % NOTIF_SIZE].message = message;
707-
708-
if (notificationReceivedCallback != nullptr)
709-
{
710-
notificationReceivedCallback(notifications[notificationIndex % NOTIF_SIZE]);
705+
if (state == 0x02){
706+
notificationIndex++;
707+
notifications[notificationIndex % NOTIF_SIZE].icon = icon;
708+
notifications[notificationIndex % NOTIF_SIZE].app = appName(icon);
709+
notifications[notificationIndex % NOTIF_SIZE].time = this->getTime("%H:%M");
710+
notifications[notificationIndex % NOTIF_SIZE].message = message;
711+
712+
if (notificationReceivedCallback != nullptr)
713+
{
714+
notificationReceivedCallback(notifications[notificationIndex % NOTIF_SIZE]);
715+
}
711716
}
717+
712718
}
713719
break;
714720
case 0x73:

ChronosESP32.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ struct Alarm
9090
bool enabled;
9191
};
9292

93+
struct Setting
94+
{
95+
uint8_t hour;
96+
uint8_t minute;
97+
uint8_t repeat;
98+
bool enabled;
99+
};
100+
93101
enum Config
94102
{
95103
CF_TIME = 0, // time -
@@ -166,7 +174,7 @@ class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallback
166174
void set24Hour(bool mode);
167175
bool is24Hour();
168176
String getAddress();
169-
void setBattery(uint8_t level);
177+
void setBattery(uint8_t level, bool charging = false);
170178
bool isCameraReady();
171179

172180
// notifications
@@ -180,9 +188,16 @@ class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallback
180188
String getWeatherTime();
181189
Weather getWeatherAt(int index);
182190

191+
// settings
192+
// isQuietActive
193+
// isSleepActive
194+
183195
// alarms
184196
Alarm getAlarm(int index);
185197
void setAlarm(int index, Alarm alarm);
198+
// alarm active callback
199+
// isAlarmActive
200+
// getActiveAlarms
186201

187202
// control
188203
void sendCommand(uint8_t *command, size_t length);
@@ -208,6 +223,7 @@ class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallback
208223
String watchName = "Chronos ESP32";
209224
String address;
210225
uint8_t batteryLevel;
226+
bool isCharging;
211227
bool connected;
212228
bool batteryChanged;
213229
bool hour24;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bool isConnected();
3333
void set24Hour(bool mode);
3434
bool is24Hour();
3535
String getAddress();
36-
void setBattery(uint8_t level);
36+
void setBattery(uint8_t level, bool charging = false);
3737
bool isCameraReady();
3838
3939
// notifications

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ChronosESP32",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"keywords": "Arduino, ESP32, Time, BLE, Watch",
55
"description": "A library for ESP32 to interface with Chronos app over BLE",
66
"repository":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ChronosESP32
2-
version=1.1.0
2+
version=1.2.0
33
author=fbiego
44
maintainer=fbiego
55
sentence=Setup your ESP32 as a smartwatch and connect to Chronos app over BLE.

0 commit comments

Comments
 (0)