Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
- add volume control commands #1
- add ringer callback function
- remove setLogging()
- add screen configuration
- add high & low temperature for weather
- restructured internal data handling
  • Loading branch information
fbiego committed Oct 3, 2023
1 parent e3bb1a4 commit 0d397ea
Show file tree
Hide file tree
Showing 8 changed files with 503 additions and 267 deletions.
572 changes: 328 additions & 244 deletions ChronosESP32.cpp

Large diffs are not rendered by default.

80 changes: 71 additions & 9 deletions ChronosESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@
#define NOTIF_SIZE 10
#define WEATHER_SIZE 7
#define ALARM_SIZE 8
#define DATA_SIZE 512

#define MUSIC_PLAY 0x9D00
#define MUSIC_PAUSE 0x9D01
#define MUSIC_PREVIOUS 0x9D02
#define MUSIC_NEXT 0x9D03
#define MUSIC_TOGGLE 0x9900

#define VOLUME_UP 0x99A1
#define VOLUME_DOWN 0x99A2
#define VOLUME_MUTE 0x99A3

struct Notification
{
int icon;
Expand All @@ -60,15 +65,23 @@ struct Weather
int icon;
int day;
int temp;
int high;
int low;
};

struct ChronosESP32Timer
struct ChronosTimer
{
unsigned long time;
long duration = 5000;
bool active;
};

struct ChronosData
{
int length;
uint8_t data[DATA_SIZE];
};

struct Alarm
{
uint8_t hour;
Expand Down Expand Up @@ -98,15 +111,55 @@ enum Config
CF_CAMERA // camera config, (ready state)
};

/*
The screen configurations below is only used for identification on the Chronos app.
Under the watch tab, when you click on watch info you can see the detected screen configuration.
The primary purpose of this configuration is to aid in loading watchfaces on supported watches with the correct resolution.
ChronosESP32 library is implementing this for future development
*/
enum ChronosScreen
{
// Resolution(240x240), Size in inches(1.3), Type(0 - Round [C], 1 - Square [S], 2 - Rectangular [R])
CS_0x0_000_CFF = 0, // default no config
CS_240x240_130_STF = 1, // 240x240, 1.3 inches, Square, True, False
CS_240x240_130_STT = 2, // 240x240, 1.3 inches, Square, True, True
CS_80x160_096_RTF = 3, // 80x160, 0.96 inches, Rectangular, True, False
CS_80x160_096_RTT = 4, // 80x160, 0.96 inches, Rectangular, True, True
CS_135x240_114_RTF = 5, // 135x240, 1.14 inches, Rectangular, True, False
CS_135x240_114_RTT = 6, // 135x240, 1.14 inches, Rectangular, True, True
CS_240x240_128_CTF = 7, // 240x240, 1.28 inches, Round, True, False
CS_240x240_128_CTT = 8, // 240x240, 1.28 inches, Round, True, True
CS_240x288_157_RTF = 9, // 240x288, 1.57 inches, Rectangular, True, False
CS_240x288_157_RTT = 10, // 240x288, 1.57 inches, Rectangular, True, True
CS_240x283_172_RTF = 11, // 240x283, 1.72 inches, Rectangular, True, False
CS_240x283_172_RTT = 12, // 240x283, 1.72 inches, Rectangular, True, True
CS_360x360_130_CTF = 13, // 360x360, 1.3 inches, Round, True, False
CS_360x360_130_CTT = 14, // 360x360, 1.3 inches, Round, True, True
CS_320x380_177_RTF = 15, // 320x380, 1.77 inches, Rectangular, True, False
CS_320x380_177_RTT = 16, // 320x380, 1.77 inches, Rectangular, True, True
CS_320x385_175_RTF = 17, // 320x385, 1.75 inches, Rectangular, True, False
CS_320x385_175_RTT = 18, // 320x385, 1.75 inches, Rectangular, True, True
CS_320x360_160_RTF = 19, // 320x360, 1.6 inches, Rectangular, True, False
CS_320x360_160_RTT = 20, // 320x360, 1.6 inches, Rectangular, True, True
CS_240x296_191_RTF = 21, // 240x296, 1.91 inches, Rectangular, True, False
CS_240x296_191_RTT = 22, // 240x296, 1.91 inches, Rectangular, True, True
CS_412x412_145_CTF = 23, // 412x412, 1.45 inches, Round, True, False
CS_412x412_145_CTT = 24, // 412x412, 1.45 inches, Round, True, True
CS_410x494_200_RTF = 25, // 410x494, 2.0 inches, Rectangular, True, False
CS_410x494_200_RTT = 32, // 410x494, 2.0 inches, Rectangular, True, True
CS_466x466_143_CTF = 33, // 466x466, 1.43 inches, Round, True, False
CS_466x466_143_CTT = 34 // 466x466, 1.43 inches, Round, True, True
};


class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallbacks, public ESP32Time
{

public:
ChronosESP32();
ChronosESP32(String name); // set the BLE name
ChronosESP32(String name, ChronosScreen screen = CS_240x240_128_CTF); // set the BLE name
void begin(); // initializes BLE
void loop(); // handles routine functions
void setLogging(bool state); // to view raw data receive over BLE

// watch
bool isConnected();
Expand Down Expand Up @@ -134,6 +187,7 @@ class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallback
// control
void sendCommand(uint8_t *command, size_t length);
void musicControl(uint16_t command);
void setVolume(uint8_t level);
bool capturePhoto();
void findPhone(bool state);

Expand All @@ -145,24 +199,22 @@ class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallback
// callbacks
void setConnectionCallback(void (*callback)(bool));
void setNotificationCallback(void (*callback)(Notification));
void setRingerCallback(void (*callback)(String, bool));
void setConfigurationCallback(void (*callback)(Config, uint32_t, uint32_t));
void setDataCallback(void (*callback)(uint8_t *, int));
void setRawDataCallback(void (*callback)(uint8_t *, int));

private:
String watchName = "Chronos ESP32";
String address;
uint8_t batteryLevel;
bool connected;
bool batteryChanged;
bool logging;
bool hour24;
bool cameraReady;

bool receiving;

Notification notifications[NOTIF_SIZE];
int notificationIndex;
int msgLen = 0;

Weather weather[WEATHER_SIZE];
String weatherCity;
Expand All @@ -171,13 +223,20 @@ class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallback

Alarm alarms[ALARM_SIZE];

ChronosESP32Timer infoTimer;
ChronosESP32Timer findTimer;
ChronosTimer infoTimer;
ChronosTimer findTimer;
ChronosTimer ringerTimer;

ChronosData incomingData;

ChronosScreen screenConf = CS_240x240_128_CTF;

void (*connectionChangeCallback)(bool) = nullptr;
void (*notificationReceivedCallback)(Notification) = nullptr;
void (*ringerAlertCallback)(String, bool) = nullptr;
void (*configurationReceivedCallback)(Config, uint32_t, uint32_t) = nullptr;
void (*dataReceivedCallback)(uint8_t *, int) = nullptr;
void (*rawDataReceivedCallback)(uint8_t *, int) = nullptr;

void sendInfo();
void sendBattery();
Expand All @@ -190,6 +249,9 @@ class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallback

// from BLECharacteristicCallbacks
virtual void onWrite(BLECharacteristic *pCharacteristic);

void dataReceived();

};

#endif
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ Setup your ESP32 as a smartwatch and connect to Chronos app over BLE.
```
ChronosESP32();
ChronosESP32(String name); // set the BLE name
ChronosESP32(String name, ChronosScreen screen); // set the BLE name and screen configuration
void begin(); // initializes BLE
void loop(); // handles routine functions
void setLogging(bool state); // to view raw data receive over BLE
// watch
bool isConnected();
Expand Down Expand Up @@ -54,6 +54,7 @@ void setAlarm(int index, Alarm alarm);
// control
void sendCommand(uint8_t *command, size_t length);
void musicControl(uint16_t command);
void setVolume(uint8_t level);
bool capturePhoto();
void findPhone(bool state);
Expand All @@ -67,6 +68,7 @@ void setConnectionCallback(void (*callback)(bool));
void setNotificationCallback(void (*callback)(Notification));
void setConfigurationCallback(void (*callback)(Config, uint32_t, uint32_t));
void setDataCallback(void (*callback)(uint8_t *, int));
void setRawDataCallback(void (*callback)(uint8_t *, int));
```

## Dependencies
Expand Down
4 changes: 3 additions & 1 deletion examples/control/control.ino
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ void loop()
{
buttonPressed = false;
// music control,
watch.musicControl(MUSIC_TOGGLE); // MUSIC_PLAY, MUSIC_PAUSE, MUSIC_PREVIOUS, MUSIC_NEXT, MUSIC_TOGGLE
watch.musicControl(MUSIC_TOGGLE); // MUSIC_PLAY, MUSIC_PAUSE, MUSIC_PREVIOUS, MUSIC_NEXT, MUSIC_TOGGLE, VOLUME_UP, VOLUME_DOWN, VOLUME_MUTE
Serial.println("Sent music command");

// watch.setVolume(50); // set the music volume [0-100] (expreimental)

// find phone
// watch.findPhone(true); // true -> ring the phone, false -> stop the ringing, the ringing will also be stopped automatically after 10 seconds;
}
Expand Down
64 changes: 57 additions & 7 deletions examples/watch/watch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

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

void connectionCallback(bool state)
{
Expand All @@ -48,12 +49,25 @@ void notificationCallback(Notification notification)
Serial.println(notification.time);
Serial.print("From: ");
Serial.print(notification.app);
Serial.print("\t Icon->");
Serial.print("\tIcon: ");
Serial.println(notification.icon);
Serial.println(notification.message);
// see loop on how to access notifications
}

void ringerCallback(String caller, bool state)
{
if (state)
{
Serial.print("Ringer: Incoming call from ");
Serial.println(caller);
}
else
{
Serial.println("Ringer dismissed");
}
}

void configCallback(Config config, uint32_t a, uint32_t b)
{
switch (config)
Expand Down Expand Up @@ -197,11 +211,38 @@ void configCallback(Config config, uint32_t a, uint32_t b)
break;
case CF_WEATHER:
// weather is saved
Serial.print("Weather received: ");
Serial.println("Weather received");
if (a)
{
Serial.print("Forecast");
// see loop for weather details
// if a == 1, high & low temperature values might not yet be updated
if (a == 2)
{
int n = watch.getWeatherCount();
String updateTime = watch.getWeatherTime();
Serial.print("Weather Count: ");
Serial.print(n);
Serial.print("\tUpdated at: ");
Serial.println(updateTime);

for (int i = 0; i < n; i++)
{
// iterate through available notifications, index 0 is the latest received notification
Weather w = watch.getWeatherAt(i);
Serial.print("Day:"); // day of the week (0 - 6)
Serial.print(w.day);
Serial.print("\tIcon:");
Serial.print(w.icon);
Serial.print("\t");
Serial.print(w.temp);
Serial.print("°C");
Serial.print("\tHigh:");
Serial.print(w.high);
Serial.print("°C");
Serial.print("\tLow:");
Serial.print(w.low);
Serial.println("°C");
}
}
}
if (b)
{
Expand All @@ -228,9 +269,10 @@ void setup()
{
Serial.begin(115200);

watch.setLogging(false); // to view the raw received data over BLE (use the data callback instead)
// set the callbacks before calling begin funtion
watch.setConnectionCallback(connectionCallback);
watch.setNotificationCallback(notificationCallback);
watch.setRingerCallback(ringerCallback);
watch.setConfigurationCallback(configCallback);
watch.setDataCallback(dataCallback);

Expand All @@ -242,8 +284,10 @@ void setup()

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

// watch.clearNotifications();

watch.set24Hour(true); // the 24 hour mode will be overwritten when the command is received from the app
// this modifies the return of
// this modifies the return of the functions below
watch.getAmPmC(true); // 12 hour mode false->(am/pm), true->(AM/PM), if 24 hour mode returns empty string ("")
watch.getHourC(); // (0-12), (0-23)
watch.getHourZ(); // zero padded hour (00-12), (00-23)
Expand Down Expand Up @@ -313,7 +357,13 @@ void loop()
Serial.print(w.icon);
Serial.print("\t");
Serial.print(w.temp);
Serial.println("C");
Serial.print("°C");
Serial.print("\tHigh: ");
Serial.print(w.high);
Serial.print("°C");
Serial.print("\tLow: ");
Serial.print(w.low);
Serial.println("°C");
}
*/
}
42 changes: 39 additions & 3 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ getAlarm KEYWORD2
setAlarm KEYWORD2
setConnectionCallback KEYWORD2
setNotificationCallback KEYWORD2
setRingerCallback KEYWORD2
setConfigurationCallback KEYWORD2
setDataCallback KEYWORD2
setLogging KEYWORD2
setRawDataCallback KEYWORD2
setVolume KEYWORD2
setBattery KEYWORD2
set24Hour KEYWORD2
getAmPmC KEYWORD2
Expand All @@ -30,13 +32,18 @@ capturePhoto KEYWORD2
Notification LITERAL1
Alarm LITERAL1
Weather LITERAL1
ChronosESP32Timer LITERAL1
ChronosTimer LITERAL1
ChronosData LITERAL1
ChronosScreen LITERAL1

MUSIC_PLAY LITERAL1
MUSIC_PAUSE LITERAL1
MUSIC_PREVIOUS LITERAL1
MUSIC_NEXT LITERAL1
MUSIC_TOGGLE LITERAL1
VOLUME_UP LITERAL1
VOLUME_DOWN LITERAL1
VOLUME_MUTE LITERAL1

CF_TIME LITERAL1
CF_RTW LITERAL1
Expand All @@ -54,4 +61,33 @@ CF_SLEEP LITERAL1
CF_QUIET LITERAL1
CF_WATER LITERAL1
CF_WEATHER LITERAL1
CF_CAMERA LITERAL1
CF_CAMERA LITERAL1

CS_0x0_000_CFF LITERAL1
CS_240x240_130_STF LITERAL1
CS_240x240_130_STT LITERAL1
CS_80x160_096_RTF LITERAL1
CS_80x160_096_RTT LITERAL1
CS_135x240_114_RTF LITERAL1
CS_135x240_114_RTT LITERAL1
CS_240x240_128_CTF LITERAL1
CS_240x240_128_CTT LITERAL1
CS_240x288_157_RTF LITERAL1
CS_240x288_157_RTT LITERAL1
CS_240x283_172_RTF LITERAL1
CS_240x283_172_RTT LITERAL1
CS_360x360_130_CTT LITERAL1
CS_320x380_177_RTF LITERAL1
CS_320x380_177_RTT LITERAL1
CS_320x385_175_RTF LITERAL1
CS_320x385_175_RTT LITERAL1
CS_320x360_160_RTF LITERAL1
CS_320x360_160_RTT LITERAL1
CS_240x296_191_RTF LITERAL1
CS_240x296_191_RTT LITERAL1
CS_412x412_145_CTF LITERAL1
CS_412x412_145_CTT LITERAL1
CS_410x494_200_RTF LITERAL1
CS_410x494_200_RTT LITERAL1
CS_466x466_143_CTF LITERAL1
CS_466x466_143_CTT LITERAL1
Loading

0 comments on commit 0d397ea

Please sign in to comment.