PowerTGS440

simpleTFT Clock v1.3beta DEMO

Jun 20th, 2021
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 36.02 KB | None | 0 0
  1. // ------------------------------------------------------------------------------------------------------------------- //
  2. //                                                                                                                     //
  3. // Simple ESP8266 NodeMCU 1.3 SimpleTFT Clock by TOMASZ MAJCHER (TRANSLINE GROUP POAND)                                //
  4. //                                                                                                                     //
  5. // e-mail  : [email protected]                                                                               //
  6. // licence : DonationWare                                                                                              //
  7. // paypal  : @TomaszMajcher                                                                                            //
  8. // www     : https://esp32dev.blogspot.com/                                                                            //
  9. //                                                                                                                     //
  10. // ------------------------------------------------------------------------------------------------------------------- //
  11. //
  12. // bulild on v1.0 Base (13.06.2021) by Tomasz Majcher
  13. //
  14. /
  15. //
  16. // ------------------------------------------------------------------------------------------------------------------- //
  17. //
  18. // ILI9341 Driver (Pinout) Hardware SPI !!!
  19. //
  20. // VCC to         :   3.3V
  21. // GND to         :   GND
  22. // CS pin to      :   D1
  23. // Reset pin to   :   Reset
  24. // DC pin to      :   D4
  25. // SDI pin to     :   D7
  26. // SCK pin to     :   D5
  27. //
  28. //
  29. //
  30. // (20.06.2021) v1.3 beta  -  update : add TFT_ShowDate (show date on TFT display) from Task3 (one per min)
  31. // (20.06.2021) v1.2 beta  -  update : add TFT_ShowTime (show time on TFT display) from Task0 (one per sec)
  32. // (20.06.2021) v1.1 beta  -  update : add TFT (test, setup library -> ILI9341, pinout)
  33. // ------------------------------------------------------------------------------------------------------------------- //
  34. // --- I N C L U D E   L I B R A R Y --------------------------------------------------------------------------------- //
  35. // ------------------------------------------------------------------------------------------------------------------- //
  36.  
  37. extern "C" char* sbrk(int incr);
  38.  
  39. #include <ESP8266WiFi.h>                                         // biblioteka Wi-Fi
  40. #include <NTPClient.h>                                           // NTP klient (Time)
  41. #include <WiFiUdp.h>                                             // UDP dla NTP (Time)
  42. #include <TaskScheduler.h>                                       // scheluder
  43. #include <TimeLib.h>
  44. #include <Arduino.h>
  45.  
  46. // ------------------------------------------------------------------------------------------------------------------- //
  47. // --- L A N G U A G E   S E T U P ----------------------------------------------------------------------------------- //
  48. // ------------------------------------------------------------------------------------------------------------------- //
  49.  
  50. #define LANGUAGE 0                                            // 0 (Polish), 1 (English), 2 (Germany)
  51.                                                              
  52. #if LANGUAGE == 0                                                
  53.     #define POLISH 1
  54.     #define ENGLISH 0
  55.     #define GERMANY 0                                          
  56. #endif
  57.  
  58. #if LANGUAGE == 1                                                      
  59.     #define POLISH 0                                        
  60.     #define ENGLISH 1
  61.     #define GERMANY 0
  62. #endif
  63.  
  64. #if LANGUAGE == 2
  65.     #define POLISH 0
  66.     #define ENGLISH 0
  67.     #define GERMANY 1
  68. #endif      
  69.  
  70. // ------------------------------------------------------------------------------------------------------------------- //
  71. // --- M A C R O   D E F I N E --------------------------------------------------------------------------------------- //
  72. // ------------------------------------------------------------------------------------------------------------------- //
  73.  
  74. #define ARRAY_SIZE(a)   (sizeof(a) / sizeof((a)[0]))
  75.  
  76. // ------------------------------------------------------------------------------------------------------------------- //
  77. // --- N E T W O R K   S E T T I N G S ------------------------------------------------------------------------------- //
  78. // ------------------------------------------------------------------------------------------------------------------- //
  79.  
  80. const char *ssid     = "DIABLO";                                       // network wifi ssid  
  81. const char *password = "XXXXXXXXXXX";                                  // network wifi password
  82.  
  83. // ------------------------------------------------------------------------------------------------------------------- //
  84. // --- T F T --------------------------------------------------------------------------------------------------------- //
  85. // ------------------------------------------------------------------------------------------------------------------- //
  86.  
  87. //#include "Free_Fonts.h"       // not use in DEMO
  88. #include "SPI.h"
  89. #include "TFT_eSPI.h"
  90.  
  91. TFT_eSPI tft = TFT_eSPI();
  92.  
  93. // define color
  94.  
  95. #define TFT_LIGHTGRAY         tft.color565(163, 159, 158)
  96. #define TFT_SWEETBLUE         tft.color565(0, 128, 255)
  97.  
  98. // define day mode color
  99.  
  100. #define TFT_DAY_TEXT          TFT_BLACK
  101. #define TFT_DAY_BACKGROUND    TFT_LIGHTGRAY
  102.  
  103. // define night mode color
  104.  
  105. #define TFT_NIGHT_TEXT        TFT_LIGHTGRAY
  106. #define TFT_NIGHT_BACKGROUND  TFT_BLACK
  107.  
  108. // define cords
  109.  
  110. #define x_min 0
  111. #define y_min 0
  112. #define x_max 320
  113. #define y_max 240
  114. #define frame 5
  115.  
  116. // ------------------------------------------------------------------------------------------------------------------- //
  117. // --- S E R I A L   S E T T I N G S --------------------------------------------------------------------------------- //
  118. // ------------------------------------------------------------------------------------------------------------------- //
  119.  
  120. #define SERIAL true
  121. #define SerialSpeed 57600
  122.  
  123. // ------------------------------------------------------------------------------------------------------------------- //
  124. // --- P R O T O T Y P E --------------------------------------------------------------------------------------------- //
  125. // ------------------------------------------------------------------------------------------------------------------- //
  126.  
  127. void scheluderInit();                 // run from setup() - init scheluder
  128. void statWiFi();                      // show Wi-Fi Status
  129. void initWiFi();                      // init Wi-Fi connection
  130.  
  131. void TFT_Init();                      // init TFT (from setup)
  132. void TFT_ShowDate();                  // show Date on TFT
  133. void TFT_ShowTime();                  // show Time on TFT
  134.  
  135. // ------------------------------------------------------------------------------------------------------------------- //
  136. // --- P R O T O T Y P E --- C O R E T A S K ------------------------------------------------------------------------- //
  137. // ------------------------------------------------------------------------------------------------------------------- //
  138.  
  139. void Task0Callback();                 // function Task0 for ESP8266 Core
  140. void Task1Callback();                 // function Task1 for ESP8266 Core
  141. void Task2Callback();                 // function Task2 for ESP8266 Core
  142. void Task3Callback();                 // function Task3 for ESP8266 Core
  143. void Task4Callback();                 // function Task4 for ESP8266 Core
  144. void Task5Callback();                 // function Task4 for ESP8266 Core
  145. void Task6Callback();                 // function Task4 for ESP8266 Core
  146.  
  147. #define Second_01       1000          // 01 second timeout makro definition
  148. #define Second_05       5000          // 05 second timeout makro definition
  149. #define Second_10       10000         // 10 second timeout makro definition
  150. #define Second_30       30000         // 30 second timeout makro definition
  151. #define Second_60       60000         // 60 second timeout makro definition
  152. #define Minute_01       60000         // 01 minute timeout makro definition
  153. #define Minute_05      300000         // 05 minute timeout makro definition
  154. #define Minute_10      600000         // 10 minute timeout makro definition
  155. #define Minute_30     1800000         // 30 minute timeout makro definiction
  156. #define Minute_60     3600000         // 30 minute timeout makro definiction
  157.  
  158.  
  159. // ------------------------------------------------------------------------------------------------------------------- //
  160. // --- Z A D A N I A   S C H E L U D E R ' A ------------------------------------------------------------------------- //
  161. // ------------------------------------------------------------------------------------------------------------------- //
  162.                                                                                                    
  163. Task task_0( Second_01,  TASK_FOREVER, &Task0Callback);         // task_0 run at interval Second_01            
  164. Task task_1( Second_60,  TASK_FOREVER, &Task1Callback);         // task_1 run at interval Second_60            
  165. Task task_2( Second_10,  TASK_FOREVER, &Task2Callback);         // task_2 run at interval Second_10            
  166. Task task_3( Minute_01,  TASK_FOREVER, &Task3Callback);         // task_3 run at interval Minute_01  
  167. Task task_4( Minute_10,  TASK_FOREVER, &Task4Callback);         // task_4 run at interval Minute_10  
  168. Task task_5( Minute_30,  TASK_FOREVER, &Task5Callback);         // task_4 run at interval Minute_30  
  169. Task task_6( Minute_60,  TASK_FOREVER, &Task6Callback);         // task_4 run at interval Minute_60  
  170.                                                                                                    
  171. Scheduler runner;    
  172.  
  173. // ------------------------------------------------------------------------------------------------------------------- //
  174. //                                              *** WiFi Reconect ***                                                  //
  175. // ------------------------------------------------------------------------------------------------------------------- //
  176.  
  177. unsigned long previousMillis = 0;
  178. unsigned long interval = 30000;
  179.  
  180. // ------------------------------------------------------------------------------------------------------------------- //
  181. //                                              *** STRUKTURA Time ***                                                 //
  182. // ------------------------------------------------------------------------------------------------------------------- //
  183.  
  184. struct TIME_DATA
  185. {
  186.     int     Hour = 0;
  187.     int     Minute  = 0;
  188.     int     Second = 0;
  189.     String  FormatedData  = "NULL";
  190.     String  ShortData = "NULL";
  191.     String  LongData = "NULL";
  192.     String  TFT_Data = "NULL";
  193.     String  TFT_Time = "NULL";
  194.     int     DayOfTheWeek = 0;
  195.     int     DayOfTheMonth = 0;
  196.     int     Month = 0;
  197.     int     Year = 0;
  198. }
  199. Time;
  200.  
  201.  
  202. // ------------------------------------------------------------------------------------------------------------------- //
  203. //                                              *** STRUKTURA DZIEN ***                                                //
  204. // ------------------------------------------------------------------------------------------------------------------- //
  205.  
  206. #if POLISH
  207.     const char Day_0 [] = "Niedziela";
  208.     const char Day_1 [] = "Poniedzialek";
  209.     const char Day_2 [] = "Wtorek";
  210.     const char Day_3 [] = "Sroda";
  211.     const char Day_4 [] = "Czwartek";
  212.     const char Day_5 [] = "Piatek";
  213.     const char Day_6 [] = "Sobota";
  214. #endif
  215.  
  216. #if ENGLISH
  217.     const char Day_0 [] = "Sunday";
  218.     const char Day_1 [] = "Monday";
  219.     const char Day_2 [] = "Tuesday";
  220.     const char Day_3 [] = "Wednesday";
  221.     const char Day_4 [] = "Thursday";
  222.     const char Day_5 [] = "Friday";
  223.     const char Day_6 [] = "Saturday";
  224. #endif
  225.  
  226. #if GERMANY
  227.     const char Day_0 [] = "Sonntag";
  228.     const char Day_1 [] = "Montag";
  229.     const char Day_2 [] = "Dienstag";
  230.     const char Day_3 [] = "Mittwoch";
  231.     const char Day_4 [] = "Donnerstag";
  232.     const char Day_5 [] = "Freitag";
  233.     const char Day_6 [] = "Samstag";
  234. #endif
  235.  
  236. const char * const DAY[] = { Day_0, Day_1, Day_2, Day_3, Day_4, Day_5, Day_6 }; // dni tygodnia [0..6]
  237.  
  238. // ------------------------------------------------------------------------------------------------------------------- //
  239. //                                              *** STRUKTURA MONTH ***                                                //
  240. // ------------------------------------------------------------------------------------------------------------------- //
  241.  
  242. #if POLISH
  243.     const char MONTH_0  [] = "NULL";
  244.     const char MONTH_1  [] = "Styczen";
  245.     const char MONTH_2  [] = "Luty";
  246.     const char MONTH_3  [] = "Marzec";
  247.     const char MONTH_4  [] = "Kwiecien";
  248.     const char MONTH_5  [] = "Maj";
  249.     const char MONTH_6  [] = "Czerwiec";
  250.     const char MONTH_7  [] = "Lipiec";
  251.     const char MONTH_8  [] = "Sierpien";
  252.     const char MONTH_9  [] = "Wrzesien";
  253.     const char MONTH_10 [] = "Pazdziernik";
  254.     const char MONTH_11 [] = "Listopad";
  255.     const char MONTH_12 [] = "Grudzien";
  256. #endif
  257.  
  258. #if ENGLISH
  259.     const char MONTH_0  [] = "NULL";
  260.     const char MONTH_1  [] = "January";
  261.     const char MONTH_2  [] = "February";
  262.     const char MONTH_3  [] = "March";
  263.     const char MONTH_4  [] = "April";
  264.     const char MONTH_5  [] = "May";
  265.     const char MONTH_6  [] = "June";
  266.     const char MONTH_7  [] = "July";
  267.     const char MONTH_8  [] = "August";
  268.     const char MONTH_9  [] = "September";
  269.     const char MONTH_10 [] = "October";
  270.     const char MONTH_11 [] = "November";
  271.     const char MONTH_12 [] = "December";
  272. #endif
  273.  
  274. #if GERMANY
  275.     const char MONTH_0  [] = "NULL";
  276.     const char MONTH_1  [] = "Januar";
  277.     const char MONTH_2  [] = "Februar";
  278.     const char MONTH_3  [] = "März";
  279.     const char MONTH_4  [] = "April";
  280.     const char MONTH_5  [] = "Mai";
  281.     const char MONTH_6  [] = "Juni";
  282.     const char MONTH_7  [] = "Juli";
  283.     const char MONTH_8  [] = "August";
  284.     const char MONTH_9  [] = "September";
  285.     const char MONTH_10 [] = "Oktober";
  286.     const char MONTH_11 [] = "November";
  287.     const char MONTH_12 [] = "Dezember";
  288. #endif
  289.    
  290.     const char * const MONTH[] = { MONTH_0, MONTH_1, MONTH_2, MONTH_3, MONTH_4, MONTH_5, MONTH_6,
  291.                                    MONTH_7, MONTH_8, MONTH_9, MONTH_10, MONTH_11, MONTH_12 };
  292.  
  293. // ------------------------------------------------------------------------------------------------------------------- //
  294. // --- T O O L S   C L A S S ----------------------------------------------------------------------------------------- //
  295. // ------------------------------------------------------------------------------------------------------------------- //  
  296.  
  297. class TOOLS
  298. {
  299.     private:
  300.  
  301.     public:
  302.       void TypeWriter(const String & message, unsigned int wait, bool lf = true);
  303.       void FreeRam(bool lf = true);
  304.       void CpuInfo(bool lf = true);
  305.       void WiFiInfo(bool lf = true);
  306.       inline void BreakLine();
  307.       inline void PrintLine(byte lenght = 60);
  308. };
  309.  
  310. // ------------------------------------------------------------------------------------------------------------------- //  
  311.  
  312. void TOOLS :: TypeWriter(const String & message, unsigned int wait, bool lf)
  313. {
  314.     if(lf) Serial.printf("\n");   // if lf is true print next line
  315.    
  316.     for(const char c : message)
  317.     {
  318.         Serial.print(c);    
  319.         delay(wait);  
  320.     }  
  321. }
  322.  
  323. // ------------------------------------------------------------------------------------------------------------------- //
  324.  
  325. void TOOLS :: FreeRam(bool lf)
  326. {
  327.     if(lf) Serial.printf("\n");   // if lf is true print next line
  328.  
  329.     Serial.printf("[TOOLS] [Memory Free] \t\t: %u [kB]", ESP.getFreeHeap());      
  330. }
  331.  
  332. // ------------------------------------------------------------------------------------------------------------------- //
  333.  
  334. void TOOLS :: CpuInfo(bool lf)
  335. {
  336.     if(lf) Serial.printf("\n");   // if lf is true print next line
  337.  
  338.     Serial.printf("[TOOLS] [CPU frequency] \t: %u [MHz]",ESP.getCpuFreqMHz());      
  339. }
  340.  
  341. // ------------------------------------------------------------------------------------------------------------------- //
  342.  
  343. void TOOLS :: WiFiInfo(bool lf)
  344. {
  345.     if(lf) Serial.printf("\n");   // if lf is true print next line
  346.    
  347.     Serial.printf("[TOOLS] [IP adress] \t\t: %s", WiFi.localIP().toString().c_str());
  348. }
  349.  
  350. // ------------------------------------------------------------------------------------------------------------------- //
  351.  
  352. inline void TOOLS :: BreakLine()
  353. {
  354.     Serial.printf("\n");   // if lf is true print next line
  355. }
  356.  
  357. // ------------------------------------------------------------------------------------------------------------------- //
  358.  
  359. inline void TOOLS :: PrintLine(byte lenght)
  360. {
  361.     for(byte i = 0; i <= lenght; i++) Serial.print("-");
  362. }
  363.  
  364. // ------------------------------------------------------------------------------------------------------------------- //
  365. // --- O B J E C T   I N I T ----------------------------------------------------------------------------------------- //
  366. // ------------------------------------------------------------------------------------------------------------------- //  
  367.  
  368. WiFiUDP ntpUDP;                                                
  369. NTPClient timeClient(ntpUDP, "pool.ntp.org", 3600);  
  370. TOOLS tools;
  371.  
  372. // ------------------------------------------------------------------------------------------------------------------- //
  373. // --- Task0Callback() ----------------------------------------------------------------------------------------------- //
  374. // ------------------------------------------------------------------------------------------------------------------- //
  375.  
  376. void Task0Callback()
  377. {
  378.     String bufor = "NULL";
  379.  
  380.     static bool STEP = false;
  381.  
  382.     if (Time.Hour < 10)
  383.     {
  384.         bufor =  "0";
  385.         bufor += String(Time.Hour);
  386.     }
  387.     else
  388.     {
  389.         bufor = String(Time.Hour);
  390.     }
  391.  
  392.     if (STEP)                           // step 0 sec show :
  393.     {
  394.         bufor += ":";
  395.         STEP = false;
  396.     }
  397.     else                                // step 1 sec show _
  398.     {
  399.         bufor += " ";
  400.         STEP = true;
  401.     }
  402.  
  403.     if (Time.Minute < 10)
  404.     {
  405.         bufor +=  "0";
  406.         bufor += String(Time.Minute);
  407.     }
  408.     else
  409.     {
  410.         bufor += String(Time.Minute);
  411.     }
  412.  
  413.     Time.TFT_Time = bufor;                        // copy bufor to TFT_Time
  414.  
  415.     TFT_ShowTime();                               // show time on TFT
  416.  
  417. }
  418.  
  419. // ------------------------------------------------------------------------------------------------------------------- //
  420. // --- Task1Callback() ----------------------------------------------------------------------------------------------- //
  421. // ------------------------------------------------------------------------------------------------------------------- //
  422.  
  423. void Task1Callback()
  424. {
  425.     #if SERIAL
  426.        
  427.         String bufor;
  428.        
  429.         if (Time.Hour < 10)
  430.         {
  431.             bufor =  "0";
  432.             bufor += String(Time.Hour);
  433.         }
  434.         else
  435.         {
  436.             bufor = String(Time.Hour);
  437.         }
  438.  
  439.         bufor += ":";
  440.  
  441.         if (Time.Minute < 10)
  442.         {
  443.             bufor +=  "0";
  444.             bufor += String(Time.Minute);
  445.         }
  446.         else
  447.         {
  448.             bufor += String(Time.Minute);
  449.         }
  450.  
  451.         if (Time.Hour < 12) bufor += " AM";
  452.         else                bufor += " PM";
  453.        
  454.         Serial.printf("\n\n[ESP] [TASK1] [Time NTP] \t: %s", bufor.c_str());
  455.         Serial.printf("\n[ESP] [TASK1] [LongData]  \t: %s ", Time.LongData.c_str());
  456.         Serial.printf("\n[ESP] [TASK1] [ShortData] \t: %s ", Time.ShortData.c_str());
  457.        
  458.     #endif            
  459. }
  460.  
  461. // ------------------------------------------------------------------------------------------------------------------- //
  462. // --- Task2Callback() ----------------------------------------------------------------------------------------------- //
  463. // ------------------------------------------------------------------------------------------------------------------- //
  464.  
  465. void Task2Callback()
  466. {
  467.     timeClient.update();                                 // time update                                                        
  468.                                                                                    
  469.     Time.Hour    =  timeClient.getHours()+1;             // zapisz godzinę z serwera
  470.     Time.Minute  =  timeClient.getMinutes();             // zapisz minutę z serwera
  471.     Time.Second  =  timeClient.getSeconds();             // zapisz sekundę z serwera
  472. }
  473.  
  474. // ------------------------------------------------------------------------------------------------------------------- //
  475. // --- Task3Callback() ----------------------------------------------------------------------------------------------- //
  476. // ------------------------------------------------------------------------------------------------------------------- //
  477.  
  478. void Task3Callback()
  479. {
  480.     tools.BreakLine();                                   // breaking line
  481.     tools.FreeRam();                                     // show Free RAM
  482.     tools.CpuInfo();                                     // Show CPU
  483.     tools.WiFiInfo();                                    // Show WiFi Adress
  484.  
  485.     TFT_ShowDate();                                      // Show Date on TFT
  486. }
  487.  
  488. // ------------------------------------------------------------------------------------------------------------------- //
  489. // --- Task4Callback() ----------------------------------------------------------------------------------------------- //
  490. // ------------------------------------------------------------------------------------------------------------------- //
  491.  
  492. void Task4Callback()
  493. {
  494.    
  495. }
  496.  
  497. // ------------------------------------------------------------------------------------------------------------------- //
  498. // --- Task3Callback() ----------------------------------------------------------------------------------------------- //
  499. // ------------------------------------------------------------------------------------------------------------------- //
  500.  
  501. void Task5Callback()
  502. {
  503.    
  504. }
  505.  
  506. // ------------------------------------------------------------------------------------------------------------------- //
  507. // --- Task6Callback() ----------------------------------------------------------------------------------------------- //
  508. // ------------------------------------------------------------------------------------------------------------------- //
  509.  
  510. void Task6Callback()
  511. {
  512.     timeClient.update();                                                                              
  513.    
  514.     unsigned long epochTime = timeClient.getEpochTime();                                              
  515.     struct tm *ptm = gmtime ( (time_t *) &epochTime );                                          
  516.                                                                                                
  517.     Time.DayOfTheWeek      =   timeClient.getDay();                                          
  518.     Time.DayOfTheMonth     =   ptm->tm_mday;                                                
  519.     Time.Month             =   ptm->tm_mon+1;                                                
  520.     Time.Year              =   ptm->tm_year+1900;
  521.  
  522.     Time.FormatedData   =   String(DAY[Time.DayOfTheWeek])
  523.                         +   ", "
  524.                         +   String(Time.DayOfTheMonth)
  525.                         +   " "
  526.                         +   String(MONTH[Time.Month])
  527.                         +   " "
  528.                         +   String(Time.Year);    
  529.  
  530.     Time.ShortData      =   String(Time.DayOfTheMonth)
  531.                         +   " "
  532.                         +   String(MONTH[Time.Month])
  533.                         +   " "
  534.                         +   String(Time.Year);  
  535.  
  536.     Time.LongData       =   String(DAY[Time.DayOfTheWeek])
  537.                         +   " "
  538.                         +   String(Time.DayOfTheMonth)
  539.                         +   "/"
  540.                         +   String(Time.Month)
  541.                         +   "/"
  542.                         +   String(Time.Year);  
  543.  
  544.     String Buffor = "NULL";
  545.  
  546.     if(Time.DayOfTheMonth < 10)
  547.     {
  548.         Buffor = "0";
  549.         Buffor += Time.DayOfTheMonth;
  550.     }
  551.     else Buffor = Time.DayOfTheMonth;
  552.  
  553.     Buffor += "/";
  554.  
  555.     if(Time.Month < 10)
  556.     {
  557.         Buffor += "0";
  558.         Buffor += Time.Month;
  559.     }
  560.     else Buffor += Time.Month;
  561.    
  562.     Buffor += "/";
  563.     Buffor += Time.Year;    
  564.  
  565.     Time.TFT_Data = Buffor;
  566. }
  567.  
  568. // ------------------------------------------------------------------------------------------------------------------- //
  569. // --- stat Wi-Fi ---------------------------------------------------------------------------------------------------- //
  570. // ------------------------------------------------------------------------------------------------------------------- //
  571.  
  572. void statWiFi()
  573. {
  574.     switch (WiFi.status())
  575.     {
  576.         case WL_NO_SSID_AVAIL:
  577.                             #if SERIAL
  578.                                 #if ENGLISH
  579.                                     Serial.printf("\nConfigured SSID cannot be reached");
  580.                                 #endif
  581.                                 #if POLISH
  582.                                     Serial.printf("\nNie można osiągnąć skonfigurowanego identyfikatora SSID");
  583.                                 #endif
  584.                                 #if GERMANY
  585.                                     Serial.printf("\nKonfigurierte SSID ist nicht erreichbar");
  586.                                 #endif
  587.                             #endif        
  588.                             break;
  589.                            
  590.         case WL_CONNECTED:
  591.                             #if SERIAL
  592.                                 #if ENGLISH
  593.                                     Serial.printf("\nConnection successfully established");
  594.                                     Serial.printf("\nYour IP : %s", WiFi.localIP().toString().c_str());
  595.                                     Serial.printf("\nReceived Signal Strength Indication : %d", WiFi.RSSI());
  596.                                 #endif
  597.                                 #if POLISH
  598.                                     Serial.printf("\nPomyślnie nawiązano połączenie");
  599.                                     Serial.printf("\nTwój adres IP : %s", WiFi.localIP().toString().c_str());
  600.                                     Serial.printf("\nWskazanie siły odbieranego sygnału : %d", WiFi.RSSI());
  601.                                 #endif
  602.                                 #if GERMANY
  603.                                     Serial.printf("\nVerbindung erfolgreich hergestellt");
  604.                                     Serial.printf("\nDeine IP-Adresse : %s", WiFi.localIP().toString().c_str());
  605.                                     Serial.printf("\nAnzeige der empfangenen Signalstärke : %d", WiFi.RSSI());                                
  606.                                 #endif
  607.                             #endif
  608.                             break;
  609.                            
  610.         case WL_CONNECT_FAILED:
  611.                             #if SERIAL
  612.                                 #if ENGLISH
  613.                                     Serial.printf("\nConnection failed");
  614.                                 #endif
  615.                                 #if POLISH
  616.                                     Serial.printf("\nPołączenie nieudane");
  617.                                 #endif
  618.                                 #if GERMANY
  619.                                     Serial.printf("\nVerbindung fehlgeschlagen");
  620.                                 #endif
  621.                             #endif
  622.                             break;
  623.     }      
  624. }
  625.  
  626. // ------------------------------------------------------------------------------------------------------------------- //
  627. // --- init Wi-Fi ---------------------------------------------------------------------------------------------------- //
  628. // ------------------------------------------------------------------------------------------------------------------- //
  629.  
  630. void initWiFi()
  631. {
  632.     WiFi.mode(WIFI_STA);
  633.     WiFi.begin(ssid, password);
  634.  
  635.     #if SERIAL    
  636.         #if ENGLISH
  637.             Serial.printf("\nConnecting to WiFi ..");
  638.         #endif
  639.         #if POLISH
  640.             Serial.printf("\nŁącze z siecią WiFi ..");
  641.         #endif
  642.         #if GERMANY
  643.             Serial.printf("\nNetzwerkverbindung mit WLAN ..");
  644.         #endif
  645.     #endif
  646.    
  647.     while (WiFi.status() != WL_CONNECTED)
  648.     {
  649.         Serial.print('.');
  650.         delay(200);
  651.     }
  652.  
  653.     statWiFi();
  654.        
  655.     WiFi.setAutoReconnect(true);
  656.     WiFi.persistent(true);
  657. }
  658.  
  659. // ------------------------------------------------------------------------------------------------------------------- //
  660. // --- reconect Wi-Fi ------------------------------------------------------------------------------------------------ //
  661. // ------------------------------------------------------------------------------------------------------------------- //
  662.  
  663. void reconectWifi()
  664. {
  665.     unsigned long currentMillis = millis();
  666.    
  667.     if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >=interval))
  668.     {
  669.         #if SERIAL
  670.             #if ENGLISH
  671.                 Serial.println("Reconnecting to WiFi...");
  672.             #endif
  673.             #if POLISH
  674.                 Serial.println("Ponowne łączenie z Wi-Fi...");
  675.             #endif
  676.             #if GERMANY
  677.                 Serial.println("Erneut mit WLAN verbinden...");
  678.             #endif
  679.         #endif
  680.        
  681.         WiFi.disconnect();
  682.         WiFi.begin(ssid, password);
  683.        
  684.         statWiFi();
  685.        
  686.         previousMillis = currentMillis;
  687.   }
  688. }
  689.  
  690. // ------------------------------------------------------------------------------------------------------------------- //
  691. // --- schedulerInit ------------------------------------------------------------------------------------------------- //
  692. // ------------------------------------------------------------------------------------------------------------------- //
  693.  
  694. void scheluderInit()
  695. {
  696.     runner.init();                                       // inicjalizuj scheluder
  697.                                                                                  
  698.     runner.addTask(task_0);                              // dodaj zadanie do scheluder
  699.     task_0.enable();                                     // włącz zadanie do scheluder
  700.     runner.addTask(task_1);                              // dodaj zadanie do scheluder
  701.     task_1.enable();                                     // włącz zadanie do scheluder
  702.     runner.addTask(task_2);                              // dodaj zadanie do scheluder
  703.     task_2.enable();                                     // włącz zadanie do scheluder
  704.     runner.addTask(task_3);                              // dodaj zadanie do scheluder
  705.     task_3.enable();                                     // włącz zadanie do scheluder
  706.     runner.addTask(task_4);                              // dodaj zadanie do scheluder
  707.     task_4.enable();                                     // włącz zadanie do scheluder
  708.     runner.addTask(task_5);                              // dodaj zadanie do scheluder
  709.     task_5.enable();                                     // włącz zadanie do scheluder
  710.     runner.addTask(task_6);                              // dodaj zadanie do scheluder
  711.     task_6.enable();                                     // włącz zadanie do scheluder  
  712. }
  713.  
  714. // ------------------------------------------------------------------------------------------------------------------- //
  715. // --- S E T U P --- T F T --- I N I T ------------------------------------------------------------------------------- //
  716. // ------------------------------------------------------------------------------------------------------------------- //
  717.  
  718. void TFT_Init()
  719. {
  720.     tft.begin();
  721.     tft.setRotation(1);
  722.     TFT_DrawPanel();    
  723. }
  724.  
  725. // ------------------------------------------------------------------------------------------------------------------- //
  726. // --- S E T U P ----------------------------------------------------------------------------------------------------- //
  727. // ------------------------------------------------------------------------------------------------------------------- //
  728.  
  729. void setup()
  730. {
  731.     #if SERIAL
  732.         Serial.begin(SerialSpeed);
  733.     #endif
  734.  
  735.     delay(200);
  736.        
  737.     tools.TypeWriter("Project by Tomasz Majcher", 100, true);  
  738.     tools.TypeWriter("Tools version 0.01", 100);
  739.     tools.BreakLine();
  740.    
  741.     initWiFi();
  742.     TFT_Init();
  743.     scheluderInit();
  744.  
  745.     Task6Callback();
  746. }
  747.  
  748. // ------------------------------------------------------------------------------------------------------------------- //
  749. // --- L O O P ------------------------------------------------------------------------------------------------------- //
  750. // ------------------------------------------------------------------------------------------------------------------- //
  751.  
  752. void loop()
  753. {
  754.     runner.execute();     // scheluder init
  755.     reconectWifi();       // check Wi-Fi status
  756. }
  757.  
  758. // ------------------------------------------------------------------------------------------------------------------- //
  759. // --- D R A W   P A N E L   T F T ----------------------------------------------------------------------------------- //
  760. // ------------------------------------------------------------------------------------------------------------------- //
  761.  
  762. void TFT_DrawPanel()
  763. {
  764.     tft.fillScreen(TFT_LIGHTGRAY);                                                      // BACKGROUND COLOR (E-paper)
  765.  
  766.     tft.drawFastVLine(x_min+frame,    y_min+frame,    y_max-2*(frame),  TFT_BLACK);     // LEFT LINE
  767.     tft.drawFastVLine(x_min+frame+1,  y_min+frame+1,  y_max-2*(frame),  TFT_BLACK);     // LEFT LINE
  768.     tft.drawFastVLine(x_max-frame,    y_min+frame,    y_max-2*(frame),  TFT_BLACK);     // RIGHT LINE
  769.     tft.drawFastVLine(x_max-frame-1,  y_min+frame+1,  y_max-2*(frame),  TFT_BLACK);     // RIGHT LINE
  770.  
  771.     tft.drawFastHLine(x_min+frame,    y_min+frame,    x_max-2*(frame),  TFT_BLACK);     // UP LINE
  772.     tft.drawFastHLine(x_min+frame,    y_min+frame+1,  x_max-2*(frame),  TFT_BLACK);     // UP LINE
  773.     tft.drawFastHLine(x_min+frame,    y_max-frame,    x_max-2*(frame),  TFT_BLACK);     // DOWN LINE
  774.     tft.drawFastHLine(x_min+frame+1,  y_max-frame-1,  x_max-2*(frame),  TFT_BLACK);     // DOWN LINE
  775.  
  776.     tft.drawFastHLine(x_min+frame,    y_min+frame+60,    x_max-2*(frame),  TFT_BLACK);   // CLOCK LINE DOWN
  777.     tft.drawFastHLine(x_min+frame,    y_min+frame+61,    x_max-2*(frame),  TFT_BLACK);   // CLOCK LINE DOWN
  778.     tft.drawFastVLine(x_min+157,      y_min+frame+1,     60,  TFT_BLACK);                // CLOCK LINE RIGHT
  779.     tft.drawFastVLine(x_min+156,      y_min+frame+1,     60,  TFT_BLACK);                // CLOCK LINE RIGHT
  780. }
  781.  
  782. // ------------------------------------------------------------------------------------------------------------------- //
  783. // --- T F T   S H O W    D A T E -=---------------------------------------------------------------------------------- //
  784. // ------------------------------------------------------------------------------------------------------------------- //
  785.  
  786. void TFT_ShowDate()
  787. {
  788.     tft.setTextColor(TFT_BLACK, TFT_LIGHTGRAY);    
  789.     //tft.drawCentreString(DAY[Time.DayOfTheWeek], 240, 10, 4);    
  790.     tft.drawCentreString(Time.TFT_Data, 240, 25, 4);  
  791. }
  792.  
  793. // ------------------------------------------------------------------------------------------------------------------- //
  794. // --- T F T   S H O W    T I M E ------------------------------------------------------------------------------------ //
  795. // ------------------------------------------------------------------------------------------------------------------- //
  796.  
  797. void TFT_ShowTime()
  798. {
  799.     tft.setTextColor(TFT_BLACK, TFT_LIGHTGRAY);            
  800.     tft.drawString(Time.TFT_Time, 12, 12, 7);  
  801. }
  802.  
  803. // ------------------------------------------------------------------------------------------------------------------- //
Advertisement
Add Comment
Please, Sign In to add comment