@@ -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 += " \n SDK: " + String (ESP.getSdkVersion ());
667669 espInfo += " \n Sketch: " + 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 {
0 commit comments