time sync from mobilephone. Edited main screen
This commit is contained in:
1 parent
8b6875d819
commit
f6da5b649f
1 file changed
+31
-26
@@ -14,12 +14,15 @@ unsigned long MIN=0;
|
||||
unsigned long HOUR=0;
|
||||
|
||||
unsigned long DAY=0;
|
||||
unsigned long MONT=0;
|
||||
unsigned long MONTH=0;
|
||||
unsigned long YEAR=2026;
|
||||
|
||||
unsigned long preMil = 0;
|
||||
const long interval = 1000;
|
||||
|
||||
bool connected = false;
|
||||
bool timeChanged = false;
|
||||
|
||||
Arduino_DataBus *bus = new Arduino_HWSPI(TFT_DC, -1);
|
||||
Arduino_GFX *gfx = new Arduino_ST7789(bus, TFT_RST, 0, true, 240, 240, 0, 0);
|
||||
|
||||
@@ -39,10 +42,16 @@ class CharacteristicCallbacks: public BLECharacteristicCallbacks {
|
||||
|
||||
//Time characteristic check
|
||||
if (pCharacteristic->getUUID().equals(BLEUUID(CHAR_TIME_UUID))) {
|
||||
|
||||
sscanf(value.c_str(), "%d %d %d", &HOUR, &MIN, &SEC);
|
||||
|
||||
Serial.print("Time Recived: ");
|
||||
Serial.println(value);
|
||||
}
|
||||
if (pCharacteristic->getUUID().equals(BLEUUID(CHAR_DATE_UUID))) {
|
||||
|
||||
sscanf(value.c_str(), "%d %d %d", &DAY, &MONTH, &YEAR);
|
||||
|
||||
Serial.print("Date Recived: ");
|
||||
Serial.println(value);
|
||||
}
|
||||
@@ -55,11 +64,13 @@ class CharacteristicCallbacks: public BLECharacteristicCallbacks {
|
||||
class MyServerCallbacks: public BLEServerCallbacks {
|
||||
void onConnect(BLEServer* pServer) {
|
||||
Serial.println("Conecction with client");
|
||||
BLEDevice::startAdvertising();
|
||||
connected = true;
|
||||
};
|
||||
|
||||
void onDisconnect(BLEServer* pServer) {
|
||||
Serial.println("Disconnection with client");
|
||||
connected = false;
|
||||
BLEDevice::startAdvertising();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,35 +84,28 @@ void setup() {
|
||||
gfx->setTextColor(ST77XX_GREEN, ST77XX_BLACK);
|
||||
|
||||
initDevice();
|
||||
timeChanged = true;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
drawText(10,10, 2, "{");
|
||||
drawText(30,30,2,"Time: {");
|
||||
gfx->setTextSize(2);
|
||||
gfx->setCursor(20, 20);
|
||||
if (connected){
|
||||
gfx->print("Connected: true ");
|
||||
}else {
|
||||
gfx->print("Connected: flase");
|
||||
}
|
||||
|
||||
gfx->setCursor(50, 50);
|
||||
gfx->printf("Hour: %d%c\n", HOUR, ',');
|
||||
if (timeChanged) {
|
||||
gfx->setCursor(20, 50);
|
||||
gfx->printf("Time: %02d:%02d:%02d\n", HOUR, MIN, SEC);
|
||||
|
||||
gfx->setCursor(50, 70);
|
||||
gfx->printf("Min: %d%c\n", MIN, ',');
|
||||
gfx->setCursor(20, 80);
|
||||
gfx->printf("Date: %02d.%02d.%04d\n", DAY, MONTH, YEAR);
|
||||
|
||||
gfx->setCursor(50, 90);
|
||||
gfx->printf("Sec: %d%c\n", SEC);
|
||||
timeChanged = false;
|
||||
}
|
||||
|
||||
drawText(30,110,2,"},");
|
||||
|
||||
drawText(30,130,2,"Date: {");
|
||||
|
||||
gfx->setCursor(50, 150);
|
||||
gfx->printf("Day: %d%c\n", DAY, ',');
|
||||
|
||||
gfx->setCursor(50, 170);
|
||||
gfx->printf("Mont: %d%c\n", MONT, ',');
|
||||
|
||||
gfx->setCursor(50, 190);
|
||||
gfx->printf("Year: %d%c\n", YEAR);
|
||||
|
||||
drawText(10,210,2,"}");
|
||||
|
||||
updateClock();
|
||||
}
|
||||
@@ -154,10 +158,11 @@ void updateClock(){
|
||||
if (curMil - preMil >= interval) {
|
||||
preMil = curMil;
|
||||
SEC++;
|
||||
timeChanged = true;
|
||||
}
|
||||
if (SEC >= 60) {SEC = 0; MIN++; }
|
||||
if (MIN >= 60) {MIN = 0; HOUR++;}
|
||||
if (HOUR >= 24) {HOUR = 0; DAY++;}
|
||||
if (MIN >= 60) {MIN = 0; HOUR++; timeChanged = true;}
|
||||
if (HOUR >= 24) {HOUR = 0; DAY++; timeChanged = true;}
|
||||
}
|
||||
void drawText(int width, int hight,int size, const char* text) {
|
||||
gfx->setCursor(width, hight);
|
||||
|
||||
Reference in new issue
Block a user