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 HOUR=0;
|
||||||
|
|
||||||
unsigned long DAY=0;
|
unsigned long DAY=0;
|
||||||
unsigned long MONT=0;
|
unsigned long MONTH=0;
|
||||||
unsigned long YEAR=2026;
|
unsigned long YEAR=2026;
|
||||||
|
|
||||||
unsigned long preMil = 0;
|
unsigned long preMil = 0;
|
||||||
const long interval = 1000;
|
const long interval = 1000;
|
||||||
|
|
||||||
|
bool connected = false;
|
||||||
|
bool timeChanged = false;
|
||||||
|
|
||||||
Arduino_DataBus *bus = new Arduino_HWSPI(TFT_DC, -1);
|
Arduino_DataBus *bus = new Arduino_HWSPI(TFT_DC, -1);
|
||||||
Arduino_GFX *gfx = new Arduino_ST7789(bus, TFT_RST, 0, true, 240, 240, 0, 0);
|
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
|
//Time characteristic check
|
||||||
if (pCharacteristic->getUUID().equals(BLEUUID(CHAR_TIME_UUID))) {
|
if (pCharacteristic->getUUID().equals(BLEUUID(CHAR_TIME_UUID))) {
|
||||||
|
|
||||||
|
sscanf(value.c_str(), "%d %d %d", &HOUR, &MIN, &SEC);
|
||||||
|
|
||||||
Serial.print("Time Recived: ");
|
Serial.print("Time Recived: ");
|
||||||
Serial.println(value);
|
Serial.println(value);
|
||||||
}
|
}
|
||||||
if (pCharacteristic->getUUID().equals(BLEUUID(CHAR_DATE_UUID))) {
|
if (pCharacteristic->getUUID().equals(BLEUUID(CHAR_DATE_UUID))) {
|
||||||
|
|
||||||
|
sscanf(value.c_str(), "%d %d %d", &DAY, &MONTH, &YEAR);
|
||||||
|
|
||||||
Serial.print("Date Recived: ");
|
Serial.print("Date Recived: ");
|
||||||
Serial.println(value);
|
Serial.println(value);
|
||||||
}
|
}
|
||||||
@@ -55,11 +64,13 @@ class CharacteristicCallbacks: public BLECharacteristicCallbacks {
|
|||||||
class MyServerCallbacks: public BLEServerCallbacks {
|
class MyServerCallbacks: public BLEServerCallbacks {
|
||||||
void onConnect(BLEServer* pServer) {
|
void onConnect(BLEServer* pServer) {
|
||||||
Serial.println("Conecction with client");
|
Serial.println("Conecction with client");
|
||||||
BLEDevice::startAdvertising();
|
connected = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
void onDisconnect(BLEServer* pServer) {
|
void onDisconnect(BLEServer* pServer) {
|
||||||
Serial.println("Disconnection with client");
|
Serial.println("Disconnection with client");
|
||||||
|
connected = false;
|
||||||
|
BLEDevice::startAdvertising();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -73,35 +84,28 @@ void setup() {
|
|||||||
gfx->setTextColor(ST77XX_GREEN, ST77XX_BLACK);
|
gfx->setTextColor(ST77XX_GREEN, ST77XX_BLACK);
|
||||||
|
|
||||||
initDevice();
|
initDevice();
|
||||||
|
timeChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
drawText(10,10, 2, "{");
|
gfx->setTextSize(2);
|
||||||
drawText(30,30,2,"Time: {");
|
gfx->setCursor(20, 20);
|
||||||
|
if (connected){
|
||||||
|
gfx->print("Connected: true ");
|
||||||
|
}else {
|
||||||
|
gfx->print("Connected: flase");
|
||||||
|
}
|
||||||
|
|
||||||
gfx->setCursor(50, 50);
|
if (timeChanged) {
|
||||||
gfx->printf("Hour: %d%c\n", HOUR, ',');
|
gfx->setCursor(20, 50);
|
||||||
|
gfx->printf("Time: %02d:%02d:%02d\n", HOUR, MIN, SEC);
|
||||||
|
|
||||||
gfx->setCursor(50, 70);
|
gfx->setCursor(20, 80);
|
||||||
gfx->printf("Min: %d%c\n", MIN, ',');
|
gfx->printf("Date: %02d.%02d.%04d\n", DAY, MONTH, YEAR);
|
||||||
|
|
||||||
gfx->setCursor(50, 90);
|
timeChanged = false;
|
||||||
gfx->printf("Sec: %d%c\n", SEC);
|
}
|
||||||
|
|
||||||
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();
|
updateClock();
|
||||||
}
|
}
|
||||||
@@ -154,10 +158,11 @@ void updateClock(){
|
|||||||
if (curMil - preMil >= interval) {
|
if (curMil - preMil >= interval) {
|
||||||
preMil = curMil;
|
preMil = curMil;
|
||||||
SEC++;
|
SEC++;
|
||||||
|
timeChanged = true;
|
||||||
}
|
}
|
||||||
if (SEC >= 60) {SEC = 0; MIN++; }
|
if (SEC >= 60) {SEC = 0; MIN++; }
|
||||||
if (MIN >= 60) {MIN = 0; HOUR++;}
|
if (MIN >= 60) {MIN = 0; HOUR++; timeChanged = true;}
|
||||||
if (HOUR >= 24) {HOUR = 0; DAY++;}
|
if (HOUR >= 24) {HOUR = 0; DAY++; timeChanged = true;}
|
||||||
}
|
}
|
||||||
void drawText(int width, int hight,int size, const char* text) {
|
void drawText(int width, int hight,int size, const char* text) {
|
||||||
gfx->setCursor(width, hight);
|
gfx->setCursor(width, hight);
|
||||||
|
|||||||
Reference in new issue
Block a user