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.
299 lines
7.8 KiB
299 lines
7.8 KiB
void intime()
|
|
{
|
|
char c7 ;
|
|
char c8 ;
|
|
int i = 0;
|
|
int h1, m1, s1, day1, month1, year1;
|
|
int cl1 = 0;
|
|
int save = 0;
|
|
int x, y;
|
|
int x1 = 170;
|
|
int y1 = 200;
|
|
//doo:
|
|
myGLCD.setColor(VGA_WHITE);
|
|
myGLCD.setBackColor(0, 172, 238);
|
|
myGLCD.setFont(BigFont);
|
|
|
|
|
|
while (Serial2.available()) { //очистка порта
|
|
|
|
c8 = Serial2.read();
|
|
//c7=Serial2.peek();
|
|
//Serial.print(String(c8));
|
|
delay(2);
|
|
|
|
}
|
|
|
|
digitalWrite(18, LOW);
|
|
delay(3000);
|
|
// Serial2.flush();
|
|
digitalWrite(18, HIGH);//reset WIFI
|
|
myGLCD.print(" NTP " , 280, 457);
|
|
|
|
delay(3000);
|
|
//myGLCD.print(" connecting " ,280, 457);
|
|
//delay(500);
|
|
//***************************
|
|
|
|
|
|
|
|
//****************************************************************************
|
|
i = 0;
|
|
while (Serial2.available()) {
|
|
if (Serial2.find("hi"))
|
|
{
|
|
myGLCD.print("WiFi connected" , 280, 457);
|
|
}
|
|
}
|
|
|
|
//**************************************
|
|
Serial2.print("7");//проверка подключения к точке доступа если ответ больше 0 то подключились
|
|
delay(1000);
|
|
myGLCD.print(" read server " , 280, 457);
|
|
//***************************
|
|
i = 0;
|
|
while (i < 600)
|
|
{
|
|
i++;
|
|
if (Serial2.available()) {
|
|
if (Serial2.find("IP"))
|
|
{ Serial2.read();
|
|
|
|
int ip1 = Serial2.parseInt();
|
|
|
|
int ip2 = Serial2.parseInt();
|
|
|
|
int ip3 = Serial2.parseInt();
|
|
|
|
int ip4 = Serial2.parseInt();
|
|
|
|
// Serial2.read();
|
|
String data1 = "IP:" + String(ip1) + "." + String(ip2) + "." + String(ip3) + "." + String(ip4) + " ";
|
|
// String data1;
|
|
// data1 += ip1;
|
|
// data1 += ".";
|
|
// data1 += ip2;
|
|
// data1 += ".";
|
|
// data1 += ip3;
|
|
// data1 += ".";
|
|
// data1 += ip4;
|
|
// data1 += " "
|
|
myGLCD.print(data1 , 240, 457);
|
|
}
|
|
Serial2.print("2");//проверка подключения к точке доступа если ответ больше 0 то подключились
|
|
delay(1000);
|
|
if (Serial2.find("2+"))
|
|
{ myGLCD.print(" read ntp " , 240, 457);
|
|
cl1 = 1;
|
|
i=601;
|
|
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 = Serial2.parseInt();
|
|
m1 = Serial2.parseInt();
|
|
s1 = Serial2.parseInt();
|
|
day1 = Serial2.parseInt();
|
|
month1 = Serial2.parseInt() * (-1);
|
|
year1 = Serial2.parseInt() * (-1);
|
|
//myGLCD.print(" end read NTP " , 280, 457);
|
|
if ( year1 == 1970)
|
|
{
|
|
Serial2.print("2");
|
|
delay(1000);
|
|
|
|
if (Serial2.find("2+"))
|
|
{
|
|
myGLCD.print(" read NTP2 " , 280, 457);
|
|
delay(1000);
|
|
h1 = Serial2.parseInt();
|
|
m1 = Serial2.parseInt();
|
|
s1 = Serial2.parseInt();
|
|
day1 = Serial2.parseInt();
|
|
month1 = Serial2.parseInt() * (-1);
|
|
year1 = Serial2.parseInt() * (-1);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
if (i > 0)delay (10);
|
|
}
|
|
|
|
//**************************************
|
|
if (cl1 == 1 )
|
|
{ myGLCD.setBackColor(0, 0, 155); //фон цифр
|
|
//***********************************************************************************************************
|
|
while (1)
|
|
{ t = rtc.getTime();
|
|
//*********** T O U C H ********************
|
|
if (myTouch.dataAvailable())
|
|
{ //myGLCD.fillScr(0, 0, 0);
|
|
myTouch.read();
|
|
x = myTouch.getX();
|
|
y = myTouch.getY();
|
|
// Serial.print("xt=");
|
|
// Serial.println(xt);
|
|
// Serial.print("yt=");
|
|
// Serial.println(yt);
|
|
myGLCD.drawPixel(x, y);
|
|
|
|
if ((y >= 320) && (y <= 360))
|
|
{ if ((x >= 200) && (x <= 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 ((x >= 450) && (x = 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 (t.sec != oldsec)
|
|
{ oldsec = t.sec;
|
|
myGLCD.setFont(BigFont);
|
|
String data = String(day1) + "/" + String(month1) + "/" + String(year1);
|
|
myGLCD.print(data , 330, 175);
|
|
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 = 220;
|
|
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(3000);
|
|
return;
|
|
}
|
|
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(day1, month1, year1);
|
|
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(3000);
|
|
return;
|
|
}
|
|
}
|
|
delay(500);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
//****************************************************************
|
|
void vrem()
|
|
{ //t19:05d29/0915/
|
|
// peredacha vremeni drugim ds1307
|
|
min1 = t.min;
|
|
hour1 = t.hour;
|
|
|
|
Serial.print("t");
|
|
|
|
|
|
|
|
if (hour1 > 9)
|
|
{
|
|
Serial.print(hour1);
|
|
}
|
|
else
|
|
{ Serial.print("0");
|
|
Serial.print(hour1);
|
|
}
|
|
Serial.print(":");
|
|
if (min1 > 9)
|
|
{
|
|
Serial.print(min1);
|
|
}
|
|
else
|
|
{ Serial.print("0");
|
|
Serial.print(min1);
|
|
}
|
|
Serial.print("d");
|
|
if (date > 9)
|
|
{ Serial.print(date);
|
|
}
|
|
else
|
|
{ Serial.print("0");
|
|
Serial.print(date);
|
|
}
|
|
Serial.print("/");
|
|
if (mon > 9)
|
|
{ Serial.print(mon);
|
|
}
|
|
else
|
|
{ Serial.print("0");
|
|
Serial.print(mon);
|
|
}
|
|
Serial.print(t.year - 2000);
|
|
Serial.print("/");
|
|
}
|
|
|
|
|