@@ -98,7 +98,7 @@ void ChronosESP32::begin()
98
98
BLEDevice::init (_watchName.c_str ());
99
99
BLEServer *pServer = BLEDevice::createServer ();
100
100
BLEDevice::setMTU (517 );
101
- pServer->setCallbacks (this );
101
+ pServer->setCallbacks (this , false );
102
102
103
103
BLEService *pService = pServer->createService (SERVICE_UUID);
104
104
pCharacteristicTX = pService->createCharacteristic (CHARACTERISTIC_UUID_TX, NIMBLE_PROPERTY::NOTIFY);
@@ -435,16 +435,18 @@ void ChronosESP32::setAlarm(int index, Alarm alarm)
435
435
command data
436
436
@param length
437
437
command length
438
+ @param force_chunked
439
+ override internal chunked
438
440
*/
439
- void ChronosESP32::sendCommand (uint8_t *command, size_t length)
441
+ void ChronosESP32::sendCommand (uint8_t *command, size_t length, bool force_chunked )
440
442
{
441
443
if (!_inited)
442
444
{
443
445
// begin not called. do nothing
444
446
return ;
445
447
}
446
448
447
- if (length <= 20 || !_chunked)
449
+ if (( length <= 20 || !_chunked) && !force_chunked )
448
450
{
449
451
// Send the entire command if it fits in one packet
450
452
pCharacteristicTX->setValue (command, length);
@@ -666,6 +668,11 @@ void ChronosESP32::sendESP()
666
668
espInfo += " \n SDK: " + String (ESP.getSdkVersion ());
667
669
espInfo += " \n Sketch: " + String ((ESP.getSketchSize () / (1024.0 )), 0 ) + " kB" ;
668
670
671
+ if (espInfo.length () > 505 )
672
+ {
673
+ espInfo = espInfo.substring (0 , 505 );
674
+ }
675
+
669
676
uint16_t len = espInfo.length ();
670
677
_outgoingData.data [0 ] = 0xAB ;
671
678
_outgoingData.data [1 ] = highByte (len + 3 );
@@ -674,7 +681,7 @@ void ChronosESP32::sendESP()
674
681
_outgoingData.data [4 ] = 0x92 ;
675
682
_outgoingData.data [5 ] = 0x80 ;
676
683
espInfo.toCharArray ((char *)_outgoingData.data + 6 , 506 );
677
- sendCommand ((uint8_t *)_outgoingData.data , 6 + len);
684
+ sendCommand ((uint8_t *)_outgoingData.data , 6 + len, true );
678
685
}
679
686
680
687
/* !
@@ -962,6 +969,20 @@ void ChronosESP32::onWrite(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo
962
969
}
963
970
}
964
971
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
+
965
986
/* !
966
987
@brief dataReceived function, called after data packets have been assembled
967
988
*/
@@ -1043,7 +1064,7 @@ void ChronosESP32::dataReceived()
1043
1064
_notifications[_notificationIndex % NOTIF_SIZE].icon = icon;
1044
1065
_notifications[_notificationIndex % NOTIF_SIZE].app = appName (icon);
1045
1066
_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) ;
1047
1068
1048
1069
if (notificationReceivedCallback != nullptr )
1049
1070
{
@@ -1361,17 +1382,26 @@ void ChronosESP32::dataReceived()
1361
1382
if (_incomingData.data [5 ] == 0x00 )
1362
1383
{
1363
1384
_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 ;
1364
1393
}
1365
1394
else if (_incomingData.data [5 ] == 0xFF )
1366
1395
{
1367
1396
_navigation.active = true ;
1368
- _navigation.title = " Disabled " ;
1369
- _navigation.duration = " " ;
1397
+ _navigation.title = " Chronos " ;
1398
+ _navigation.duration = " Disabled " ;
1370
1399
_navigation.distance = " " ;
1371
- _navigation.eta = " " ;
1372
- _navigation.directions = " Check app settings" ;
1400
+ _navigation.eta = " Navigation " ;
1401
+ _navigation.directions = " Check Chronos app settings" ;
1373
1402
_navigation.hasIcon = false ;
1374
1403
_navigation.isNavigation = false ;
1404
+ _navigation.iconCRC = 0xFFFFFFFF ;
1375
1405
}
1376
1406
else if (_incomingData.data [5 ] == 0x80 )
1377
1407
{
0 commit comments