Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ void setQr(int index, String qr);
// alarms
Alarm getAlarm(int index);
void setAlarm(int index, Alarm alarm);
bool isAlarmActive(int index);
bool isAlarmActive(Alarm alarm);
bool isAnyAlarmActive();

// control
void sendCommand(uint8_t *command, size_t length);
Expand Down
23 changes: 21 additions & 2 deletions examples/watch/watch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include <ChronosESP32.h>

#define LED_PIN 2

ChronosESP32 watch;
// ChronosESP32 watch("Chronos Watch"); // set the bluetooth name
// ChronosESP32 watch("Chronos Watch", CS_360x360_130_CTF); // set the bluetooth name and screen configuration
Expand Down Expand Up @@ -329,6 +331,8 @@ void setup()
{
Serial.begin(115200);

pinMode(LED_PIN, OUTPUT);

// set the callbacks before calling begin funtion
watch.setConnectionCallback(connectionCallback);
watch.setNotificationCallback(notificationCallback);
Expand Down Expand Up @@ -364,7 +368,7 @@ void loop()

String time = watch.getHourC() + watch.getTime(":%M ") + watch.getAmPmC();
Serial.println(time);
delay(5000);
delay(500);

/*
// access available notifications
Expand All @@ -389,7 +393,7 @@ void loop()

/*
// read the alarms, 8 available
// the alarms are only stored as received from the app, there is no function to trigger it yet
// the alarms are only stored as received from the app
for (int j = 0; j < 8; j++){
Alarm a = watch.getAlarm(j);
Serial.print("Alarm: ");
Expand All @@ -401,8 +405,23 @@ void loop()
Serial.print("\tState: ");
Serial.println(a.enabled ? "Enabled": "Disabled");
}

// you need to save alarms after receiving them from the app and restore them during setup
// otherwise they will be lost when the esp32 is restarted
Alarm a1;
a1.hour = 7;
a1.minute = 30;
a1.repeat = 0b0111110; // repeat from Monday to Friday
a1.enabled = true;
watch.setAlarm(0, a1); // save alarm at index 0

watch.isAlarmActive(0); // check if alarm at index 0 is active
watch.isAlarmActive(watch.getAlarm(0)); // check if a specific alarm is active
watch.isAnyAlarmActive(); // check if any alarm is active
*/

digitalWrite(LED_PIN, watch.isAnyAlarmActive());

/* // access weather forecast details
int n = watch.getWeatherCount();
String updateTime = watch.getWeatherTime();
Expand Down
3 changes: 3 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ getQrAt KEYWORD2
setQr KEYWORD2
getAlarm KEYWORD2
setAlarm KEYWORD2
isAlarmActive KEYWORD2
isAlarmActive KEYWORD2
isAnyAlarmActive KEYWORD2
sendCommand KEYWORD2
musicControl KEYWORD2
setVolume KEYWORD2
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.8.1",
"version": "1.8.2",
"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.8.1
version=1.8.2
author=fbiego
maintainer=fbiego
sentence=Setup your ESP32 as a smartwatch and connect to Chronos app over BLE.
Expand Down
47 changes: 47 additions & 0 deletions src/ChronosESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,53 @@ void ChronosESP32::setAlarm(int index, Alarm alarm)
_alarms[index % ALARM_SIZE] = alarm;
}

/*!
@brief check whether the alarm at the index is active
@param index
position of the alarm to be checked
*/
bool ChronosESP32::isAlarmActive(int index)
{
return isAlarmActive(_alarms[index % ALARM_SIZE]);
}

/*!
@brief check whether the alarm is active
@param alarm
the alarm object to be checked
*/
bool ChronosESP32::isAlarmActive(Alarm alarm)
{
if (!alarm.enabled)
return false;

if (alarm.hour != this->getHour(true) || alarm.minute != this->getMinute())
return false;

if (alarm.repeat == 0x80 || alarm.repeat == 0x7F)
return true;

int day = this->getDayofWeek(); // 0=Sun, ... 6=Sat

if (day == 0) // Sunday → bit 6
return (alarm.repeat & (1 << 6)) != 0;
else // Mon–Sat → bits 0–5
return (alarm.repeat & (1 << (day - 1))) != 0;
}

/*!
@brief check whether any alarm is active
*/
bool ChronosESP32::isAnyAlarmActive()
{
for (int i = 0; i < ALARM_SIZE; i++)
{
if (isAlarmActive(_alarms[i]))
return true;
}
return false;
}

/*!
@brief send a command to the app
@param command
Expand Down
6 changes: 4 additions & 2 deletions src/ChronosESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#define CHRONOSESP_VERSION_MAJOR 1
#define CHRONOSESP_VERSION_MINOR 8
#define CHRONOSESP_VERSION_PATCH 1
#define CHRONOSESP_VERSION_PATCH 2

#define CHRONOSESP_VERSION F(CHRONOSESP_VERSION_MAJOR "." CHRONOSESP_VERSION_MINOR "." CHRONOSESP_VERSION_PATCH)

Expand Down Expand Up @@ -301,9 +301,11 @@ class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallback
// alarms
Alarm getAlarm(int index);
void setAlarm(int index, Alarm alarm);
bool isAlarmActive(int index);
bool isAlarmActive(Alarm alarm);
bool isAnyAlarmActive();
// TODO (alarms)
// alarm active callback
// isAlarmActive
// getActiveAlarms

// control
Expand Down