Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
- add charge command
- fix notification state
  • Loading branch information
fbiego committed Jan 5, 2024
1 parent 0d397ea commit 4d49144
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 17 deletions.
32 changes: 19 additions & 13 deletions ChronosESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,16 @@ String ChronosESP32::getAddress()
@brief set the battery level
@param level
battery level
@param charging
charging state
*/
void ChronosESP32::setBattery(uint8_t level)
void ChronosESP32::setBattery(uint8_t level, bool charging)
{
if (batteryLevel != level)
if (batteryLevel != level || isCharging != charging)
{
batteryChanged = true;
batteryLevel = level;
isCharging = charging;
}
}

Expand Down Expand Up @@ -470,7 +473,7 @@ void ChronosESP32::sendInfo()
*/
void ChronosESP32::sendBattery()
{
uint8_t batCmd[] = {0xAB, 0x00, 0x05, 0xFF, 0x91, 0x80, 0x00, batteryLevel};
uint8_t batCmd[] = {0xAB, 0x00, 0x05, 0xFF, 0x91, 0x80, isCharging ? 0x01 : 0x00, batteryLevel};
pCharacteristicTX->setValue(batCmd, 8);
pCharacteristicTX->notify();
vTaskDelay(200);
Expand Down Expand Up @@ -670,6 +673,7 @@ void ChronosESP32::dataReceived()
case 0x72:
{
int icon = incomingData.data[6];
int state = incomingData.data[7];

String message = "";
for (int i = 8; i < len; i++)
Expand Down Expand Up @@ -698,17 +702,19 @@ void ChronosESP32::dataReceived()
}
break;
}

notificationIndex++;
notifications[notificationIndex % NOTIF_SIZE].icon = icon;
notifications[notificationIndex % NOTIF_SIZE].app = appName(icon);
notifications[notificationIndex % NOTIF_SIZE].time = this->getTime("%H:%M");
notifications[notificationIndex % NOTIF_SIZE].message = message;

if (notificationReceivedCallback != nullptr)
{
notificationReceivedCallback(notifications[notificationIndex % NOTIF_SIZE]);
if (state == 0x02){
notificationIndex++;
notifications[notificationIndex % NOTIF_SIZE].icon = icon;
notifications[notificationIndex % NOTIF_SIZE].app = appName(icon);
notifications[notificationIndex % NOTIF_SIZE].time = this->getTime("%H:%M");
notifications[notificationIndex % NOTIF_SIZE].message = message;

if (notificationReceivedCallback != nullptr)
{
notificationReceivedCallback(notifications[notificationIndex % NOTIF_SIZE]);
}
}

}
break;
case 0x73:
Expand Down
18 changes: 17 additions & 1 deletion ChronosESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ struct Alarm
bool enabled;
};

struct Setting
{
uint8_t hour;
uint8_t minute;
uint8_t repeat;
bool enabled;
};

enum Config
{
CF_TIME = 0, // time -
Expand Down Expand Up @@ -166,7 +174,7 @@ class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallback
void set24Hour(bool mode);
bool is24Hour();
String getAddress();
void setBattery(uint8_t level);
void setBattery(uint8_t level, bool charging = false);
bool isCameraReady();

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

// settings
// isQuietActive
// isSleepActive

// alarms
Alarm getAlarm(int index);
void setAlarm(int index, Alarm alarm);
// alarm active callback
// isAlarmActive
// getActiveAlarms

// control
void sendCommand(uint8_t *command, size_t length);
Expand All @@ -208,6 +223,7 @@ class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallback
String watchName = "Chronos ESP32";
String address;
uint8_t batteryLevel;
bool isCharging;
bool connected;
bool batteryChanged;
bool hour24;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool isConnected();
void set24Hour(bool mode);
bool is24Hour();
String getAddress();
void setBattery(uint8_t level);
void setBattery(uint8_t level, bool charging = false);
bool isCameraReady();
// notifications
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ChronosESP32",
"version": "1.1.0",
"version": "1.2.0",
"keywords": "Arduino, ESP32, Time, BLE, Watch",
"description": "A library for ESP32 to interface with Chronos app over BLE",
"repository":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ChronosESP32
version=1.1.0
version=1.2.0
author=fbiego
maintainer=fbiego
sentence=Setup your ESP32 as a smartwatch and connect to Chronos app over BLE.
Expand Down

0 comments on commit 4d49144

Please sign in to comment.