@@ -43,6 +43,8 @@ ChronosESP32::ChronosESP32()
4343{
4444 connected = false ;
4545 cameraReady = false ;
46+ batteryChanged = true ;
47+ qrLinks[0 ] = " https://chronos.ke/" ;
4648}
4749
4850/* !
@@ -64,6 +66,7 @@ void ChronosESP32::begin()
6466{
6567 BLEDevice::init (watchName.c_str ());
6668 BLEServer *pServer = BLEDevice::createServer ();
69+ BLEDevice::setMTU (517 );
6770 pServer->setCallbacks (this );
6871
6972 BLEService *pService = pServer->createService (SERVICE_UUID);
@@ -269,6 +272,16 @@ Weather ChronosESP32::getWeatherAt(int index)
269272 return weather[index % WEATHER_SIZE];
270273}
271274
275+ /* !
276+ @brief return the weatherforecast for the hour
277+ @param hour
278+ position of the weather to be returned
279+ */
280+ HourlyForecast ChronosESP32::getForecastHour (int hour)
281+ {
282+ return hourlyForecast[hour % FORECAST_SIZE];
283+ }
284+
272285/* !
273286 @brief get the alarm at the index
274287 @param index
@@ -398,6 +411,25 @@ String ChronosESP32::getAmPmC(bool caps)
398411 return " " ;
399412}
400413
414+
415+ /* !
416+ @brief get remote touch data
417+ */
418+ RemoteTouch ChronosESP32::getTouch ()
419+ {
420+ return touch;
421+ }
422+
423+ /* !
424+ @brief get the qr link at the index
425+ @param index
426+ position of the qr link to be returned
427+ */
428+ String ChronosESP32::getQrAt (int index)
429+ {
430+ return qrLinks[index % QR_SIZE];
431+ }
432+
401433/* !
402434 @brief set the connection callback
403435*/
@@ -451,7 +483,7 @@ void ChronosESP32::setRawDataCallback(void (*callback)(uint8_t *, int))
451483*/
452484void ChronosESP32::sendInfo ()
453485{
454- uint8_t infoCmd[] = {0xab , 0x00 , 0x11 , 0xff , 0x92 , 0xc0 , 0x01 , 0x00 , 0x00 , 0xfb , 0x1e , 0x40 , 0xc0 , 0x0e , 0x32 , 0x28 , 0x00 , 0xe2 , screenConf, 0x80 };
486+ uint8_t infoCmd[] = {0xab , 0x00 , 0x11 , 0xff , 0x92 , 0xc0 , LIB_VER_MAJOR, (LIB_VER_MINOR * 10 + LIB_VER_PATCH) , 0x00 , 0xfb , 0x1e , 0x40 , 0xc0 , 0x0e , 0x32 , 0x28 , 0x00 , 0xe2 , screenConf, 0x80 };
455487 sendCommand (infoCmd, 20 );
456488}
457489
@@ -590,6 +622,7 @@ void ChronosESP32::onDisconnect(BLEServer *pServer)
590622 connected = false ;
591623 cameraReady = false ;
592624 BLEDevice::startAdvertising ();
625+ touch.state = false ; // release touch
593626 if (connectionChangeCallback != nullptr )
594627 {
595628 connectionChangeCallback (false );
@@ -927,6 +960,40 @@ void ChronosESP32::dataReceived()
927960 configurationReceivedCallback (CF_FONT, color, select);
928961 }
929962 break ;
963+ case 0xA8 :
964+ if (incomingData.data [3 ] == 0xFE )
965+ {
966+ // end of qr data
967+ int size = incomingData.data [5 ]; // number of links received
968+ if (configurationReceivedCallback != nullptr )
969+ {
970+ configurationReceivedCallback (CF_QR, 1 , size);
971+ }
972+ }
973+ if (incomingData.data [3 ] == 0xFF )
974+ {
975+ // receiving qr data
976+ int index = incomingData.data [5 ]; // index of the curent link
977+ qrLinks[index] = " " ; // clear existing
978+ for (int i = 6 ; i < len; i++)
979+ {
980+ qrLinks[index] += (char )incomingData.data [i];
981+ }
982+ if (configurationReceivedCallback != nullptr )
983+ {
984+ configurationReceivedCallback (CF_QR, 0 , index);
985+ }
986+
987+ }
988+ break ;
989+ case 0xBF :
990+ if (incomingData.data [3 ] == 0xFE )
991+ {
992+ touch.state = incomingData.data [5 ] == 1 ;
993+ touch.x = uint32_t (incomingData.data [6 ] << 8 ) | uint32_t (incomingData.data [7 ]);
994+ touch.y = uint32_t (incomingData.data [8 ] << 8 ) | uint32_t (incomingData.data [9 ]);
995+ }
996+ break ;
930997 case 0xCA :
931998 if (incomingData.data [3 ] == 0xFE )
932999 {
@@ -942,22 +1009,66 @@ void ChronosESP32::dataReceived()
9421009 }
9431010 }
9441011 break ;
1012+ case 0xEE :
1013+ if (incomingData.data [3 ] == 0xFE )
1014+ {
1015+ // nvIc
1016+ }
1017+ break ;
1018+ case 0xEF :
1019+ if (incomingData.data [3 ] == 0xFE )
1020+ {
1021+ // nvData
1022+ }
1023+ break ;
9451024 }
9461025 }
9471026 else if (incomingData.data [0 ] == 0xEA )
9481027 {
949- if (incomingData.data [4 ] == 0x7E && incomingData. data [ 5 ] == 0x01 )
1028+ if (incomingData.data [4 ] == 0x7E )
9501029 {
951- String city = " " ;
952- for (int c = 7 ; c < len; c++)
1030+ switch (incomingData.data [5 ])
9531031 {
954- city += (char )incomingData.data [c];
1032+ case 0x01 :
1033+ {
1034+ String city = " " ;
1035+ for (int c = 7 ; c < len; c++)
1036+ {
1037+ city += (char )incomingData.data [c];
1038+ }
1039+ weatherCity = city;
1040+ if (configurationReceivedCallback != nullptr )
1041+ {
1042+ configurationReceivedCallback (CF_WEATHER, 0 , 1 );
1043+ }
9551044 }
956- weatherCity = city ;
957- if (configurationReceivedCallback != nullptr )
1045+ break ;
1046+ case 0x02 :
9581047 {
959- configurationReceivedCallback (CF_WEATHER, 0 , 1 );
1048+ int size = incomingData.data [6 ];
1049+ int hour = incomingData.data [7 ];
1050+ for (int z = 0 ; z < size; z++)
1051+ {
1052+ if (hour + z >= FORECAST_SIZE)
1053+ {
1054+ break ;
1055+ }
1056+ int icon = incomingData.data [8 + (6 * z)] >> 4 ;
1057+ int sign = (incomingData.data [8 + (6 * z)] & 1 ) ? -1 : 1 ;
1058+ int temp = ((int )incomingData.data [9 + (6 * z)]) * sign;
1059+
1060+ hourlyForecast[hour + z].day = this ->getDayofYear ();
1061+ hourlyForecast[hour + z].hour = hour + z;
1062+ hourlyForecast[hour + z].wind = (incomingData.data [10 + (6 * z)] * 256 ) + incomingData.data [11 + (6 * z)];
1063+ hourlyForecast[hour + z].humidity = incomingData.data [12 + (6 * z)];
1064+ hourlyForecast[hour + z].uv = incomingData.data [13 + (6 * z)];
1065+ hourlyForecast[hour + z].icon = icon;
1066+ hourlyForecast[hour + z].temp = temp;
1067+ }
1068+ }
1069+ break ;
9601070 }
9611071 }
9621072 }
963- }
1073+ }
1074+
0 commit comments