You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
257 lines
7.0 KiB
257 lines
7.0 KiB
void readserial()
|
|
{
|
|
char c ;
|
|
int cur = 1;
|
|
int x1, y1;
|
|
bool ter = 0;
|
|
bool condition = true;
|
|
|
|
int cl1 = 0;
|
|
int save = 0;
|
|
x1 = 10;
|
|
y1 = 40;
|
|
myGLCD.fillScr(0, 0, 0);
|
|
// myGLCD.fillScr(BIRD_BG);
|
|
myGLCD.setColor(VGA_WHITE);
|
|
myGLCD.setBackColor(VGA_BLACK);
|
|
myGLCD.setFont(BigFont);
|
|
myGLCD.print("READ NTP SERVER", CENTER, 10);
|
|
while (Serial1.available())//очистка буфера
|
|
{
|
|
Serial1.read();
|
|
delay(2);
|
|
}
|
|
|
|
digitalWrite(14, LOW);
|
|
delay(1000);
|
|
digitalWrite(14, HIGH);//reset WIFI
|
|
myGLCD.print(" reset " , 300, 457);
|
|
delay(2000);
|
|
myGLCD.print(" connecting " , 280, 457);
|
|
myGLCD.setBackColor(0, 0, 0);
|
|
// delay(2000);
|
|
int r = 0;
|
|
int q = 0;
|
|
//***********************************************************************************************************
|
|
while (condition)
|
|
{
|
|
//*********** T O U C H ********************
|
|
if (myTouch.dataAvailable())
|
|
{ //myGLCD.fillScr(0, 0, 0);
|
|
myTouch.read();
|
|
xt = myTouch.getX();
|
|
yt = myTouch.getY();
|
|
// Serial.print("xt=");
|
|
// Serial.println(xt);
|
|
// Serial.print("yt=");
|
|
// Serial.println(yt);
|
|
myGLCD.drawPixel(xt, yt);
|
|
|
|
if ((yt >= 320) && (yt <= 360))
|
|
{ if ((xt >= 200) && (xt <= 350)) // Upper row
|
|
{ myGLCD.setColor(100, 255, 100);
|
|
myGLCD.drawRect(190, 320, 370, 360); //YES
|
|
myGLCD.setFont(BigFont);
|
|
myGLCD.print("YES" , 255, 335); //The time is set
|
|
save = 1;
|
|
|
|
}
|
|
if ((xt >= 450) && (xt <= 600)) // Upper row
|
|
{ myGLCD.setColor(255, 50, 0);
|
|
myGLCD.drawRect(430, 320, 610, 360); //NO
|
|
myGLCD.setFont(BigFont);
|
|
myGLCD.print("NO" , 500, 335); //time is not set
|
|
save = 2;
|
|
}
|
|
}
|
|
|
|
}
|
|
if (Serial1.available()) {
|
|
if (q == 0)
|
|
{
|
|
if (Serial1.find("hi"))
|
|
{
|
|
Serial1.print("7");//проверка подключения к точке доступа если ответ больше 0 то подключились
|
|
delay(1000);
|
|
// }
|
|
if (Serial1.find("IP"))
|
|
{
|
|
myGLCD.print("ip:" , 240, 457);
|
|
int ip1 = Serial1.parseInt();
|
|
int ip2 = Serial1.parseInt();
|
|
int ip3 = Serial1.parseInt();
|
|
int ip4 = Serial1.parseInt();
|
|
String data1 = String(ip1) + "." + String(ip2) + "." + String(ip3) + "." + String(ip4) + " ";
|
|
myGLCD.print(data1 , 280, 457);
|
|
Serial1.print("2");//проверка подключения к точке доступа если ответ больше 0 то подключились
|
|
delay(1000);
|
|
}
|
|
if (Serial1.find("2+"))
|
|
{ myGLCD.print(" read NTP " , 240, 457);
|
|
//delay(1000);
|
|
q = 2;
|
|
}
|
|
}
|
|
}
|
|
if (q == 2)
|
|
{ cl1 = 1;
|
|
|
|
// myGLCD.print(" end read NTP1 " , 280, 457);
|
|
|
|
// myGLCD.print(" end read NTP " , 280, 457);
|
|
myGLCD.setColor(155, 155, 155);
|
|
myGLCD.fillRect(160, 140, 660, 390); //тень
|
|
myGLCD.setColor(0, 0, 155);
|
|
myGLCD.fillRect(150, 130, 650, 380); //поле
|
|
myGLCD.setColor(VGA_WHITE);
|
|
myGLCD.drawRect(160, 140, 640, 370); //обводка
|
|
|
|
myGLCD.drawRect(190, 320, 370, 360); //YES
|
|
myGLCD.drawRect(430, 320, 610, 360); //NO
|
|
myGLCD.setBackColor(0, 0, 155); //фон цифр
|
|
myGLCD.print("YES" , 255, 335);
|
|
myGLCD.print("NO" , 500, 335);
|
|
myGLCD.print("Set NTP Time" , 300, 140);
|
|
|
|
h1 = Serial1.parseInt();
|
|
|
|
m1 = Serial1.parseInt();
|
|
|
|
s1 = Serial1.parseInt();
|
|
|
|
|
|
day1 = Serial1.parseInt();
|
|
|
|
month1 = Serial1.parseInt() * (-1);
|
|
|
|
year1 = Serial1.parseInt() * (-1);
|
|
if ( year1 == 1970)
|
|
{
|
|
q = 5;
|
|
}
|
|
else
|
|
{
|
|
q = 3;
|
|
|
|
String data = " " + String(day1) + "/" + String(month1) + "/" + String(year1) + " ";
|
|
myGLCD.print(data , 280, 457);
|
|
}
|
|
|
|
|
|
}
|
|
if (q == 5)
|
|
{ Serial1.print("2");
|
|
delay(2000);
|
|
// myGLCD.print(" end read NTP1 " , 280, 457);
|
|
if (Serial1.find("2+"))
|
|
{ myGLCD.print(" read NTP2 " , 280, 457);
|
|
delay(1000);
|
|
h1 = Serial1.parseInt();
|
|
|
|
m1 = Serial1.parseInt();
|
|
|
|
s1 = Serial1.parseInt();
|
|
|
|
|
|
day1 = Serial1.parseInt();
|
|
|
|
month1 = Serial1.parseInt() * (-1);
|
|
|
|
year1 = Serial1.parseInt() * (-1);
|
|
|
|
String data = String(day1) + "/" + String(month1) + "/" + String(year1) + " ";
|
|
myGLCD.print(data , 280, 457);
|
|
|
|
} else
|
|
{
|
|
q = 3;
|
|
|
|
String data = String(day1) + "/" + String(month1) + "/" + String(year1) + " ";
|
|
myGLCD.print(data , 280, 457);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cl1 == 1 )
|
|
{ if (myTimer.isReady())
|
|
{
|
|
myGLCD.setFont( SevenSegNumFont);
|
|
s1++;
|
|
if (s1 > 59) {
|
|
s1 = 0;
|
|
m1++;
|
|
if (m1 > 59) {
|
|
h1++;
|
|
m1 = 0;
|
|
if (h1 > 23)h1 = 0;
|
|
}
|
|
}
|
|
|
|
int clockCenterX = 270;
|
|
int clockCenterY = 237;
|
|
if (h1 < 10)
|
|
{
|
|
myGLCD.printNumI(0, clockCenterX, clockCenterY - 20);
|
|
myGLCD.printNumI(h1, clockCenterX + 32, clockCenterY - 20);
|
|
}
|
|
else
|
|
{
|
|
myGLCD.printNumI(h1, clockCenterX, clockCenterY - 20);
|
|
}
|
|
myGLCD.print(":", clockCenterX + 64, clockCenterY - 20);
|
|
if (m1 < 10)
|
|
{
|
|
myGLCD.printNumI(0, clockCenterX + 96, clockCenterY - 20);
|
|
myGLCD.printNumI(m1, clockCenterX + 128, clockCenterY - 20);
|
|
}
|
|
else
|
|
{
|
|
myGLCD.printNumI(m1, clockCenterX + 96, clockCenterY - 20);
|
|
}
|
|
myGLCD.print(":", clockCenterX + 160, clockCenterY - 20);
|
|
if (s1 < 10)
|
|
{
|
|
myGLCD.printNumI(0, clockCenterX + 96 * 2, clockCenterY - 20);
|
|
myGLCD.printNumI(s1, clockCenterX + 96 * 2 + 32, clockCenterY - 20);
|
|
}
|
|
else
|
|
{
|
|
myGLCD.printNumI(s1, clockCenterX + 96 * 2, clockCenterY - 20);
|
|
}
|
|
if (save == 2)
|
|
{ myGLCD.setFont(BigFont);
|
|
myGLCD.setColor(0, 0, 155);
|
|
myGLCD.fillRect(170, 280, 630, 368); //поле
|
|
myGLCD.setColor(255, 50, 0);
|
|
myGLCD.print("The time is not set" , 250, 310);
|
|
delay(5000);
|
|
loop();
|
|
}
|
|
if (save == 1)
|
|
{ myGLCD.setFont(BigFont);
|
|
// rtc.setTime(h1, m1,s1); // Set the time to 12:00:00 (24hr format)
|
|
// rtc.setDate(day1,month1,year1); // Set the date to January 1st, 2014
|
|
// dow=calcDOW(days1, mon1, years1);
|
|
// rtc.setDOW(dow);
|
|
myGLCD.setColor(0, 0, 155);
|
|
myGLCD.fillRect(170, 280, 630, 368); //поле
|
|
myGLCD.setColor(100, 255, 100);
|
|
myGLCD.print("The time is set" , 280, 310);
|
|
delay(5000);
|
|
loop();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
//*******************************************End While***************************************
|
|
|
|
}
|
|
|