Skip to content

Commit efd91ca

Browse files
committed
v1.7.0
- add notification title - add forced chunked mode in sendCommand - fix #8 - minor patches
1 parent 091c8c0 commit efd91ca

File tree

7 files changed

+50
-13
lines changed

7 files changed

+50
-13
lines changed

Diff for: examples/navigation/navigation.ino

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void notificationCallback(Notification notification)
5050
Serial.print(notification.app);
5151
Serial.print("\tIcon: ");
5252
Serial.println(notification.icon);
53+
Serial.println(notification.title);
5354
Serial.println(notification.message);
5455
}
5556

Diff for: examples/watch/watch.ino

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ void notificationCallback(Notification notification)
5151
Serial.print(notification.app);
5252
Serial.print("\tIcon: ");
5353
Serial.println(notification.icon);
54+
Serial.println(notification.title);
5455
Serial.println(notification.message);
5556
// see loop on how to access notifications
5657
}

Diff for: keywords.txt

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ getForecastHour KEYWORD2
3535
getTouch KEYWORD2
3636
getQrAt KEYWORD2
3737
getNavigation KEYWORD2
38+
setChunkedTransfer KEYWORD2
39+
isSubscribed KEYWORD2
3840

3941
Notification LITERAL1
4042
Alarm LITERAL1

Diff for: library.json

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

Diff for: library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ChronosESP32
2-
version=1.6.0
2+
version=1.7.0
33
author=fbiego
44
maintainer=fbiego
55
sentence=Setup your ESP32 as a smartwatch and connect to Chronos app over BLE.

Diff for: src/ChronosESP32.cpp

+39-9
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void ChronosESP32::begin()
9898
BLEDevice::init(_watchName.c_str());
9999
BLEServer *pServer = BLEDevice::createServer();
100100
BLEDevice::setMTU(517);
101-
pServer->setCallbacks(this);
101+
pServer->setCallbacks(this, false);
102102

103103
BLEService *pService = pServer->createService(SERVICE_UUID);
104104
pCharacteristicTX = pService->createCharacteristic(CHARACTERISTIC_UUID_TX, NIMBLE_PROPERTY::NOTIFY);
@@ -435,16 +435,18 @@ void ChronosESP32::setAlarm(int index, Alarm alarm)
435435
command data
436436
@param length
437437
command length
438+
@param force_chunked
439+
override internal chunked
438440
*/
439-
void ChronosESP32::sendCommand(uint8_t *command, size_t length)
441+
void ChronosESP32::sendCommand(uint8_t *command, size_t length, bool force_chunked)
440442
{
441443
if (!_inited)
442444
{
443445
// begin not called. do nothing
444446
return;
445447
}
446448

447-
if (length <= 20 || !_chunked)
449+
if ((length <= 20 || !_chunked) && !force_chunked)
448450
{
449451
// Send the entire command if it fits in one packet
450452
pCharacteristicTX->setValue(command, length);
@@ -666,6 +668,11 @@ void ChronosESP32::sendESP()
666668
espInfo += "\nSDK: " + String(ESP.getSdkVersion());
667669
espInfo += "\nSketch: " + String((ESP.getSketchSize() / (1024.0)), 0) + "kB";
668670

671+
if (espInfo.length() > 505)
672+
{
673+
espInfo = espInfo.substring(0, 505);
674+
}
675+
669676
uint16_t len = espInfo.length();
670677
_outgoingData.data[0] = 0xAB;
671678
_outgoingData.data[1] = highByte(len + 3);
@@ -674,7 +681,7 @@ void ChronosESP32::sendESP()
674681
_outgoingData.data[4] = 0x92;
675682
_outgoingData.data[5] = 0x80;
676683
espInfo.toCharArray((char *)_outgoingData.data + 6, 506);
677-
sendCommand((uint8_t *)_outgoingData.data, 6 + len);
684+
sendCommand((uint8_t *)_outgoingData.data, 6 + len, true);
678685
}
679686

680687
/*!
@@ -962,6 +969,20 @@ void ChronosESP32::onWrite(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo
962969
}
963970
}
964971

972+
void ChronosESP32::splitTitle(const String &input, String &title, String &message, int icon) {
973+
int index = input.indexOf(':'); // Find the first occurrence of ':'
974+
int newlineIndex = input.indexOf('\n'); // Find the first occurrence of '\n'
975+
976+
if (index != -1 && index < 30 && (newlineIndex == -1 || newlineIndex > index)) {
977+
// Split only if ':' is before index 30 and there's no '\n' before it
978+
title = input.substring(0, index);
979+
message = input.substring(index + 1);
980+
} else {
981+
title = appName(icon); // No valid ':' before index 30, or '\n' appears before ':'
982+
message = input; // Keep the full string in message
983+
}
984+
}
985+
965986
/*!
966987
@brief dataReceived function, called after data packets have been assembled
967988
*/
@@ -1043,7 +1064,7 @@ void ChronosESP32::dataReceived()
10431064
_notifications[_notificationIndex % NOTIF_SIZE].icon = icon;
10441065
_notifications[_notificationIndex % NOTIF_SIZE].app = appName(icon);
10451066
_notifications[_notificationIndex % NOTIF_SIZE].time = this->getTime("%H:%M");
1046-
_notifications[_notificationIndex % NOTIF_SIZE].message = message;
1067+
splitTitle(message, _notifications[_notificationIndex % NOTIF_SIZE].title, _notifications[_notificationIndex % NOTIF_SIZE].message, icon);
10471068

10481069
if (notificationReceivedCallback != nullptr)
10491070
{
@@ -1361,17 +1382,26 @@ void ChronosESP32::dataReceived()
13611382
if (_incomingData.data[5] == 0x00)
13621383
{
13631384
_navigation.active = false;
1385+
_navigation.eta = "Navigation";
1386+
_navigation.title = "Chronos";
1387+
_navigation.duration = "Inactive";
1388+
_navigation.distance = "";
1389+
_navigation.directions = "Start navigation on Google maps";
1390+
_navigation.hasIcon = false;
1391+
_navigation.isNavigation = false;
1392+
_navigation.iconCRC = 0xFFFFFFFF;
13641393
}
13651394
else if (_incomingData.data[5] == 0xFF)
13661395
{
13671396
_navigation.active = true;
1368-
_navigation.title = "Disabled";
1369-
_navigation.duration = "";
1397+
_navigation.title = "Chronos";
1398+
_navigation.duration = "Disabled";
13701399
_navigation.distance = "";
1371-
_navigation.eta = "";
1372-
_navigation.directions = "Check app settings";
1400+
_navigation.eta = "Navigation";
1401+
_navigation.directions = "Check Chronos app settings";
13731402
_navigation.hasIcon = false;
13741403
_navigation.isNavigation = false;
1404+
_navigation.iconCRC = 0xFFFFFFFF;
13751405
}
13761406
else if (_incomingData.data[5] == 0x80)
13771407
{

Diff for: src/ChronosESP32.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <ESP32Time.h>
3939

4040
#define CHRONOSESP_VERSION_MAJOR 1
41-
#define CHRONOSESP_VERSION_MINOR 6
41+
#define CHRONOSESP_VERSION_MINOR 7
4242
#define CHRONOSESP_VERSION_PATCH 0
4343

4444
#define CHRONOSESP_VERSION F(CHRONOSESP_VERSION_MAJOR "." CHRONOSESP_VERSION_MINOR "." CHRONOSESP_VERSION_PATCH)
@@ -75,6 +75,7 @@ struct Notification
7575
int icon;
7676
String app;
7777
String time;
78+
String title;
7879
String message;
7980
};
8081

@@ -277,7 +278,7 @@ class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallback
277278
// getActiveAlarms
278279

279280
// control
280-
void sendCommand(uint8_t *command, size_t length);
281+
void sendCommand(uint8_t *command, size_t length, bool force_chunked = false);
281282
void musicControl(Control command);
282283
void setVolume(uint8_t level);
283284
bool capturePhoto();
@@ -379,6 +380,8 @@ class ChronosESP32 : public BLEServerCallbacks, public BLECharacteristicCallback
379380
void sendBattery();
380381
void sendESP();
381382

383+
void splitTitle(const String &input, String &title, String &message, int icon);
384+
382385
String appName(int id);
383386
String flashMode(FlashMode_t mode);
384387

0 commit comments

Comments
 (0)