Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //****************************************************************************************************************************
- //
- // ESP8266 Wiktoria Home Monitoring System v1.0.8
- //
- // by Tomasz Majcher
- // mail : [email protected]
- //
- //
- //*****************************************************************************************************************************/
- #define FS_NO_GLOBALS
- #include <FS.h>
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- WiFi Setup ---------------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- #include <ESP8266WiFi.h> // Library for WiFi Network (biblioteka do obsługi sieci WiFi)
- #include <WiFiUdp.h> // Library for NTP Server (biblioteka do obsługi serwera NTP)
- char ssid[] = "xxxxxx"; // your network SSID (nazwa twojej sieci WiFi)
- char pass[] = "xxxxxxxxxxx"; // your network password (hasło dostępu do sieci WiFi)
- WiFiUDP ntpUDP;
- unsigned long previousMillis = 0; // for WiFiReconect
- unsigned long interval = 30000; // for WiFiReconect
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- NTP server ---------------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- #define NTP_DBG_PORT Serial // where Debug NTP ---> Serial
- #define _NTP_LOGLEVEL_ 0 // 0 = no NTP debug
- #include <NTPClient_Generic.h> // Library for NTP Server
- char timeServer[] = "pl.pool.ntp.org"; // Time Server (Europe/Poland)
- #define TIME_ZONE_OFFSET_HRS (2) // Time Zone (Europe/Warsaw)
- #define NTP_UPDATE_INTERVAL_MS 60000L // Ntp Update (60 seconds)
- NTPClient timeClient(ntpUDP, timeServer, (3600 * TIME_ZONE_OFFSET_HRS), NTP_UPDATE_INTERVAL_MS);
- bool FtimeUpdate = false;
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- B L Y N K ----------------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- #include <BlynkSimpleEsp8266.h>
- #define VPIN_BUTTON_1 V1
- #define VPIN_BUTTON_2 V2
- #define VPIN_BUTTON_3 V3
- #define VPIN_BUTTON_4 V4
- #define VPIN_BUTTON_5 V5
- #define VPIN_BUTTON_6 V6
- #define VPIN_BUTTON_7 V7
- #define VPIN_BUTTON_8 V8
- #define AUTH "xxx-qYWwXdG6Kq-btpnM-95DPmU" // You should get Auth Token in the Blynk App.
- BlynkTimer timer;
- int toggleState_1 = 1; //Define integer to remember the toggle state for relay 1
- int toggleState_2 = 1; //Define integer to remember the toggle state for relay 2
- int toggleState_3 = 1; //Define integer to remember the toggle state for relay 3
- int toggleState_4 = 1; //Define integer to remember the toggle state for relay 4
- int toggleState_5 = 1; //Define integer to remember the toggle state for relay 5
- int toggleState_6 = 1; //Define integer to remember the toggle state for relay 6
- int toggleState_7 = 1; //Define integer to remember the toggle state for relay 7
- int toggleState_8 = 1; //Define integer to remember the toggle state for relay 8
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- E X P A N D E R ---------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- #include <pcf8574_esp.h>
- #include <Wire.h>
- /*
- Wire.h already defines "Wire" which the PCF8574-class would use by default,
- but for the sakes of an example let's define our own instance of it and use that instead!
- Also, since I2C is emulated on the ESP8266 let's redefine what pins to use as SDA and SCL
- and instead swap them around!
- DO NOT FORGET TO WIRE ACCORDINGLY, SDA GOES TO GPIO5, SCL TO GPIO4 (ON NODEMCU GPIO5 IS D1 AND GPIO4 IS D2)
- */
- TwoWire rWire; // wire SCL D2 (GPIO4), SCA D1 (GPIO5)
- PCF857x expander(0x20, &rWire); // expander on 0x20
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- R E L A Y S -------------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- #define RELAY0 0 // reserved (to manage from 1 to 8)
- #define RELAY1 0 // RELAY 1 on pin 0 (EXPANDER)
- #define RELAY2 1 // RELAY 2 on pin 1 (EXPANDER)
- #define RELAY3 2 // RELAY 3 on pin 2 (EXPANDER)
- #define RELAY4 3 // RELAY 4 on pin 3 (EXPANDER)
- #define RELAY5 4 // RELAY 5 on pin 4 (EXPANDER)
- #define RELAY6 5 // RELAY 6 on pin 5 (EXPANDER)
- #define RELAY7 6 // RELAY 7 on pin 6 (EXPANDER)
- #define RELAY8 7 // RELAY 8 on pin 7 (EXPANDER)
- #define RelayMin 1 // define first RELAY (to debug)
- #define RelayMax 8 // define last RELAY (to debug)
- const byte RELAY[9] = { RELAY0, RELAY1, RELAY2, RELAY3, RELAY4, RELAY5, RELAY6, RELAY7, RELAY8 };
- /*
- How to use ?
- RelayOn(0); turn on all relay (set to LOW)
- RelayOff(0); turn off all relay (set to HIGH)
- RelayOn(1); turn on relay nr. 1 (set to LOW)
- RelayOn(3); turn on relay nr. 3 (set to LOW)
- RelayOff(3); turn off relay nr. 1 (set to HIGH)
- RelayOff(1); turn off relay nr. 3 (set to HIGH)
- */
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- T F T ------------------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- // PINS TFT -> NodeMCU ESP8266
- // SDI pin to : D7
- // SCK pin to : D5
- // CS pin to : D3
- // DC pin to : D4
- // RST pin to : RST
- // ------------------------------------------------------------------------------------------------------------------- //
- #include "SPI.h"
- #include "TFT_eSPI.h"
- TFT_eSPI tft = TFT_eSPI();
- #define x_min 0
- #define y_min 0
- #define x_max 320
- #define y_max 240
- #define frame 5
- #define clock_font 6
- #define clock_color_day TFT_LIGHTGREY
- #define clock_color_night TFT_DARKGREY
- int clock_color = clock_color_night;
- #include "bulb.h" // zarowki
- bool F_display_clock = true; // flaga -> pokaz zegar
- bool F_display_temp = false; // flaga -> pokaz pogodę i temperaturę
- bool F_display_moon = false; // flaga -> pokaż fazę księżyca i godziny wschodu i zachodu
- bool F_display_sun = false; // flaga -> pokaz słońce i godziny wschodu i zachodu
- bool F_refresh_all = false; // flaga -> odswiez zegar po powrocie do trybu: display_clock
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- J P E G D E C O D E R---------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- #include <JPEGDecoder.h>
- // --- digits size 112 ----------------------------------------------------------------------------------------------- //
- const char digit0 [] = "/digits/n0_112.jpg";
- const char digit1 [] = "/digits/n1_112.jpg";
- const char digit2 [] = "/digits/n2_112.jpg";
- const char digit3 [] = "/digits/n3_112.jpg";
- const char digit4 [] = "/digits/n4_112.jpg";
- const char digit5 [] = "/digits/n5_112.jpg";
- const char digit6 [] = "/digits/n6_112.jpg";
- const char digit7 [] = "/digits/n7_112.jpg";
- const char digit8 [] = "/digits/n8_112.jpg";
- const char digit9 [] = "/digits/n9_112.jpg";
- const char * const digit112[] = {digit0, digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8, digit9};
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- R T C --- D S 1 3 0 2 ----------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- #include <virtuabotixRTC.h>
- virtuabotixRTC myRTC(D0, D6, D8); // stwórz obiekt myRTC i zdefiniuj PIN myRTC (clock, data, RST)
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- T A S K ------------------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- #include <TaskScheduler.h> // scheluder
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- JSON PARSER---------------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- #define ARDUINOJSON_DECODE_UNICODE 1
- #include <ArduinoJson.h>
- #include <ESP8266HTTPClient.h>
- #include <WiFiClient.h>
- WiFiClient client;
- String PogodaToken = "xxxxx"; // token serwera pogodowego http://api.weatherapi.com
- String PogodaMiasto = "Lubin";
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- GLOBAL --- DLA TFT -------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- // wystąpiły problemy przy wyświetlaniu napisów z tablicy CHAR na razie utworzone zostają w takim razie pomocnicze //
- // zmienne typu STRING do przechowywania : faza księżyca, czas wschodu księżyca, czas zachodu księżyca //
- // czas wschodu słońca, czas zachodu słońca //
- // ------------------------------------------------------------------------------------------------------------------- //
- #include "notes.h"
- // 437305 (41) / 43116 (52)
- String moon_phase;
- String moonrise;
- String moonset;
- String sunrise;
- String sunset;
- String super_msg = "ESP8266 Wiki Center";
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- P R O T O T Y P Y --------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void Task0Callback(); // funkcja dla task_0
- void Task1Callback(); // funkcja dla task_1
- void Task2Callback(); // funkcja dla task_2
- void Task3Callback(); // funkcja dla task_3
- void Task4Callback(); // funkcja dla task_4
- void Task5Callback(); // funkcja dla task_5
- void Task6Callback(); // funckja dla task_6
- void SerialInit();
- void DrawLine(byte l, char s);
- void WiFiInit() ;
- void WiFiStat();
- void WiFiReconect();
- void myRTC_Update();
- int NTPInit();
- void Show_NTP();
- void MyClock_Update();
- void TaskInit();
- void TFTInit();
- void ExpanderInit();
- void Bulb(byte nr, byte state);
- void RelayOff(byte nr);
- void RelayOn(byte nr);
- BLYNK_WRITE(VPIN_BUTTON_1);
- BLYNK_WRITE(VPIN_BUTTON_2);
- BLYNK_WRITE(VPIN_BUTTON_3);
- BLYNK_WRITE(VPIN_BUTTON_4);
- BLYNK_WRITE(VPIN_BUTTON_5);
- BLYNK_WRITE(VPIN_BUTTON_6);
- BLYNK_WRITE(VPIN_BUTTON_7);
- BLYNK_WRITE(VPIN_BUTTON_8);
- void WeatherUpdate();
- void AstronomyUpdate();
- void AirUpdate();
- void TFT_WeatherDisplay();
- void TFT_MoonDisplay();
- void TFT_WeatherIconShow();
- void drawJpeg(const char *filename, int xpos, int ypos); // Otwiera plik obrazu i uruchamia dekoder JPEG
- void jpegRender(int xpos, int ypos); // Dekoduj i renderuj obraz JPEG na ekranie TFT
- void jpegInfo(); // Wydrukuj informacje odkodowane z obrazu JPEG
- void createArray(const char *filename); // Otwórz plik JPEG i wyślij go do portu szeregowego w formacie zgodnym z tablicą C
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- Z A D A N I A S C H E L U D E R ' A ------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- Task task_0( 360000, TASK_FOREVER, &Task0Callback); // task_0 - co 1 godzinę
- Task task_1( 60000, TASK_FOREVER, &Task1Callback); // task_1 - co 1 minutę
- Task task_2( 1000, TASK_FOREVER, &Task2Callback); // task_2 - co 1 sekundę
- Task task_3( 90000, TASK_FOREVER, &Task3Callback); // task_3 - co 90 sekund
- Task task_4( 360000, TASK_FOREVER, &Task4Callback); // task_4 - co 10 minut
- Task task_5( 7200000, TASK_FOREVER, &Task5Callback); // task_5 - co 120 minut
- Task task_6( 8400000, TASK_FOREVER, &Task5Callback); // task_5 - co 140 minut
- Scheduler runner;
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- L A N G U A G E S E T U P ----------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- #define LANGUAGE 1 // 0 (Polish), 1 (English)
- #if LANGUAGE == 0 // if POLISH Language
- #define POLISH 1
- #define ENGLISH 0
- #endif
- #if LANGUAGE == 1 // if ENGLISH Language
- #define POLISH 0
- #define ENGLISH 1
- #endif
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- S E R I A L S E T U P --------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- #define SERIAL true
- #define SerialSpeed 57600
- void _p(boolean nl, const char *format, va_list args )
- {
- char buf[128]; // resulting string limited to 128 chars
- vsnprintf(buf, sizeof(buf), format, args);
- #if SERIAL
- Serial.print(buf);
- #endif
- }
- void _p(boolean nl,const __FlashStringHelper *format, va_list args )
- {
- char buf[128]; // resulting string limited to 128 chars
- #ifdef __AVR__
- vsnprintf_P(buf, sizeof(buf), (const char *)format, args); // progmem dla AVR
- #else
- vsnprintf(buf, sizeof(buf), (const char *)format, args); // progmem dla pozostałych modułóœ
- #endif
- #if SERIAL
- Serial.print(buf);
- #endif
- }
- void PRINT(const char *format, ... )
- {
- va_list args;
- va_start (args, format );
- _p(1,format,args);
- va_end(args);
- }
- void PRINT(const __FlashStringHelper *format, ... )
- {
- va_list args;
- va_start(args, format );
- _p(1,format,args);
- va_end(args);
- }
- void p(const char *format, ... )
- {
- va_list args;
- va_start(args, format );
- _p(0,format,args);
- va_end(args);
- }
- void p(const __FlashStringHelper *format, ... )
- {
- va_list args;
- va_start(args, format );
- _p(0,format,args);
- va_end(args);
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // *** STRUKTURA DNI TYGODNIA / STRUCT DAY OF WEEK *** //
- // ------------------------------------------------------------------------------------------------------------------- //
- const char PL_Day_0 [] PROGMEM = "Fake";
- const char PL_Day_1 [] PROGMEM = "Niedziela";
- const char PL_Day_2 [] PROGMEM = "Poniedzialek";
- const char PL_Day_3 [] PROGMEM = "Wtorek";
- const char PL_Day_4 [] PROGMEM = "Sroda";
- const char PL_Day_5 [] PROGMEM = "Czwartek";
- const char PL_Day_6 [] PROGMEM = "Piatek";
- const char PL_Day_7 [] PROGMEM = "Sobota";
- const char EN_Day_0 [] PROGMEM = "Fake";
- const char EN_Day_1 [] PROGMEM = "Sunday";
- const char EN_Day_2 [] PROGMEM = "Monday";
- const char EN_Day_3 [] PROGMEM = "Tuesday";
- const char EN_Day_4 [] PROGMEM = "Wednesday";
- const char EN_Day_5 [] PROGMEM = "Thursday";
- const char EN_Day_6 [] PROGMEM = "Friday";
- const char EN_Day_7 [] PROGMEM = "Saturday";
- const char * const PL_DAY[] PROGMEM = { PL_Day_0, PL_Day_1, PL_Day_2, PL_Day_3, PL_Day_4, PL_Day_5, PL_Day_6, PL_Day_7 }; // in POLISH
- const char * const EN_DAY[] PROGMEM = { EN_Day_0, EN_Day_1, EN_Day_2, EN_Day_3, EN_Day_4, EN_Day_5, EN_Day_6, EN_Day_7 }; // in ENGLISH
- // ------------------------------------------------------------------------------------------------------------------- //
- // *** STRUKTURA MIESIĄCE / STRUCT MONTH *** //
- // ------------------------------------------------------------------------------------------------------------------- //
- const char PL_MONTH_00 [] PROGMEM = "Fake";
- const char PL_MONTH_01 [] PROGMEM = "Styczen";
- const char PL_MONTH_02 [] PROGMEM = "Luty";
- const char PL_MONTH_03 [] PROGMEM = "Marzec";
- const char PL_MONTH_04 [] PROGMEM = "Kwiecien";
- const char PL_MONTH_05 [] PROGMEM = "Maj";
- const char PL_MONTH_06 [] PROGMEM = "Czerwiec";
- const char PL_MONTH_07 [] PROGMEM = "Lipiec";
- const char PL_MONTH_08 [] PROGMEM = "Sierpien";
- const char PL_MONTH_09 [] PROGMEM = "Wrzesien";
- const char PL_MONTH_10 [] PROGMEM = "Pazdziernik";
- const char PL_MONTH_11 [] PROGMEM = "Listopad";
- const char PL_MONTH_12 [] PROGMEM = "Grudzien";
- const char EN_MONTH_00 [] PROGMEM = "Fake";
- const char EN_MONTH_01 [] PROGMEM = "January";
- const char EN_MONTH_02 [] PROGMEM = "February";
- const char EN_MONTH_03 [] PROGMEM = "March";
- const char EN_MONTH_04 [] PROGMEM = "April";
- const char EN_MONTH_05 [] PROGMEM = "May";
- const char EN_MONTH_06 [] PROGMEM = "June";
- const char EN_MONTH_07 [] PROGMEM = "July";
- const char EN_MONTH_08 [] PROGMEM = "August";
- const char EN_MONTH_09 [] PROGMEM = "September";
- const char EN_MONTH_10 [] PROGMEM = "October";
- const char EN_MONTH_11 [] PROGMEM = "November";
- const char EN_MONTH_12 [] PROGMEM = "December";
- const char * const PL_MONTH[] PROGMEM = { PL_MONTH_00,
- PL_MONTH_01, PL_MONTH_02, PL_MONTH_03,
- PL_MONTH_04, PL_MONTH_05, PL_MONTH_06,
- PL_MONTH_07, PL_MONTH_08, PL_MONTH_09,
- PL_MONTH_10, PL_MONTH_11, PL_MONTH_12
- };
- const char * const EN_MONTH[] PROGMEM = { EN_MONTH_00,
- EN_MONTH_01, EN_MONTH_02, EN_MONTH_03,
- EN_MONTH_04, EN_MONTH_05, EN_MONTH_06,
- EN_MONTH_07, EN_MONTH_08, EN_MONTH_09,
- EN_MONTH_10, EN_MONTH_11, EN_MONTH_12
- };
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- M Y N T P S T R U C T --------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- struct TIMEDATA
- {
- // *** L O C T I M E & D A T A *** ///
- int iLOCYear;
- int iLOCMonth;
- int iLOCWeekDay; // Day of week (need re-build library by Tomasz Majcher)
- int iLOCDay;
- int iLOCHours;
- int iLOCMinutes;
- int iLOCSeconds;
- char cHour[3];
- char cMinutes[3];
- char cSeconds[3];
- // *** E X T R A S T R I N G *** ///
- String sPL_DayOfWeek; // Day of week (need re-build library by Tomasz Majcher)
- String sEN_DayOfWeek; // Day of week (need re-build library by Tomasz Majcher)
- String sPL_Month;
- String sEN_Month;
- }
- MyClock;
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- W E A T H E R ------------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- struct Weather
- {
- char city[30]; // ok - miasto
- char country[30]; // ok - kraj
- char tz_id[30]; // ok - kontynent/stolica
- double lat = 0; // ok - szerokość geograficzna
- double lon = 0; // ok - długość geograficzna
- int localtime_epoch = 0; // ok - czas lokalny - format epoch (1629046610)
- char localtime[30]; // ok - czas lokalny - format string (2021-08-15 18:56)
- char last_updated[30]; // ok - czas ostatniej aktualizacji - format string (2021-08-15 18:45)
- double temp_c = 0; // ok - temperatura w st.C
- double feelslike_c = 0; // ok - temperatura odczuwalna w st.C
- double temp_f = 0; // ok - temperatura w st.F
- double feelslike_f = 0; // ok - temperatura odczuwalna w st.F
- char condition_en[50]; // ok - kondycja pogody np. Sunny, Cloud, etc
- char condition_pl[50]; // ok - kondycja pogody np. Słonecznie, Pochmurnie, etc
- char icon[100]; // ok - adres grafiki //cdn.weatherapi.com/weather/64x64/day/113.png
- int code = 0; // ok - kod czegoś, 1000
- double wind_mph = 0; // ok - prędkość wiatru w milach/h
- double wind_kph = 0; // ok - prędkość wiatru w km/h
- int wind_degree = 0; // ok - kierunek wiatru w stopniach
- char wind_dir[10]; // ok - kierunek wiatru np. NNE
- int pressure_mb = 0; // ok - cisnienie atmosferyczne
- double pressure_in = 0; // ok - huj wie co to !!!
- double precip_mm = 0; // ok - opady [mm]
- double precip_in = 0; // ok - huj wie co to !!!
- int humidity = 0; // ok - wilgotnosc powietrza
- int cloud = 0; // zachmurzenie
- double vis_km = 0; // widzialność w km
- double vis_miles = 0; // widzialność w milach
- double uv = 0; // index UV
- double gust_mph = 0; // * porywy wiatru w milach
- double gust_kph = 0; // * porywy wiatru w kilometrach
- };
- struct Weather *ptrWeather; // wskaźnik do struktury Weather
- bool F_ptrWeather = false; // flaga dla wskaźnika alokacji pamięci dla strukury
- bool F_WeatherUpdate = false;
- // ------------------------------------------------------------------------------------------------------------ //
- // --- S T R U C T A S T R O N O M Y --- //
- // ------------------------------------------------------------------------------------------------------------ //
- struct Astronomy
- {
- char city[30]; // ok - miasto
- char country[30]; // ok - kraj
- char tz_id[30]; // ok - kontynent/stolica
- double lat = 0; // ok - szerokość geograficzna
- double lon = 0; // ok - długość geograficzna
- int localtime_epoch = 0; // ok - czas lokalny - format epoch (1629046610)
- char localtime[30]; // ok - czas lokalny - format string (2021-08-15 18:56)
- char sunrise[20]; // wschód słońca
- char sunset[20]; // zachód słońca
- char moonrise[20]; // wschód księżyca
- char moonset[20]; // zachód księżyca
- char moon_phase[30]; // faza księżyca
- int moon_illumination = 0; // iluminacja
- };
- // ------------------------------------------------------------------------------------------------------------ //
- struct Astronomy *ptrAstronomy; // wskaźnik do struktury Weather
- bool F_ptrAstronomy = false; // flaga (false jesli struktura Astronomy nie została utworzona)
- bool F_AstronomyUpdate = false;
- // ------------------------------------------------------------------------------------------------------------ //
- // --- S T R U C T A I R --- //
- // ------------------------------------------------------------------------------------------------------------ //
- struct Air
- {
- double co = 0; // Carbon Monoxide (μg/m3) - Tlenek węgla (μg / m3)
- double o3 = 0; // Ozone (μg/m3) - Ozon (μg / m3)
- double no2 = 0; // Nitrogen dioxide (μg/m3) - Dwutlenek azotu (μg / m3)
- double so2 = 0; // Sulphur dioxide (μg/m3) - Dwutlenek siarki (μg / m3)
- double pm25 = 0; // PM2.5 (μg/m3) - aerozole atmosferyczne o średnicy nie większej niż 2,5 μm
- double pm10 = 0; // PM10 (μg/m3) - mieszanina zawieszonych w powietrzu cząsteczek o średnicy nie większej niż 10 μm
- int defra = 0; // Air Quality Index - index jakości powietrza
- int epa = 0; // Air Quality Index - index jakosci powietrza (standard EPA)
- char description[50]; // Air Quality descriptin - opis jakości powietrza (standard EPA)
- };
- // ------------------------------------------------------------------------------------------------------------ //
- struct Air *ptrAir; // wskaźnik do struktury Air
- bool F_ptrAir = false; // flaga (false jesli struktura Air nie została utworzona)
- bool F_AirUpdate = false; // flaga błędu
- // ------------------------------------------------------------------------------------------------------------ //
- void SuperMsgCreate()
- {
- super_msg = GetSuperMsg(myRTC.month, myRTC.dayofmonth);
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- S E R I A L I N I T ---------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void SerialInit()
- {
- #if SERIAL
- Serial.begin(SerialSpeed); // init Serial and set speed
- while (!Serial); // wait if not ready
- PRINT(F("\n\n")); // next line please
- #endif
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- D R A W L I N E --------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void DrawLine(byte l, char s)
- {
- #if SERIAL
- PRINT(F("\n"));
- for (byte i=0; i<l; i++) Serial.print(s);
- #endif
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- W i F i I N I T --------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void WiFiInit()
- {
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, pass);
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [WiFI] Connecting to WiFi .."));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [WiFI] Łącze z siecią WiFi .."));
- #endif
- #endif
- // --------------------------------------------------------------------------------------- //
- // --- TFT MONITOR ----------------------------------------------------------------------- //
- // --------------------------------------------------------------------------------------- //
- tft.fillScreen(TFT_BLACK);
- drawJpeg("/wifi.jpeg", 40, 5);
- tft.setTextSize(1);
- tft.setTextColor(TFT_DARKGREY);
- #if ENGLISH
- tft.drawString("Connecting to WiFi",50,10,4);
- #endif
- #if POLISH
- tft.drawString("Lacze z siecia WiFi",50,10,4);
- #endif
- // --------------------------------------------------------------------------------------- //
- // --- Connect to WIFI ------------------------------------------------------------------- //
- // --------------------------------------------------------------------------------------- //
- int x = 0;
- int colorWIFI = TFT_LIGHTGREY;
- while (WiFi.status() != WL_CONNECTED)
- {
- tft.fillRect(20+x,230,7,7,colorWIFI);
- if (x < 280)
- {
- x = x + 20;
- }
- else
- {
- x = 0;
- if (colorWIFI == 54938) colorWIFI = TFT_DARKGREY;
- else
- if (colorWIFI == 31727) colorWIFI = TFT_LIGHTGREY;
- }
- delay(10);
- }
- WiFiStat();
- WiFi.setAutoReconnect(true);
- WiFi.persistent(true);
- tft.fillScreen(TFT_BLACK);
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- WiFiStat ------------------------------------------------------------------------------------------------------ //
- // ------------------------------------------------------------------------------------------------------------------- //
- void WiFiStat()
- {
- switch (WiFi.status())
- {
- case WL_NO_SSID_AVAIL:
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [WiFI] Configured SSID cannot be reached"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [WiFI] Nie można osiągnąć skonfigurowanego identyfikatora SSID"));
- #endif
- #endif
- break;
- case WL_CONNECTED:
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [WiFI] Connection successfully established"));
- PRINT(F("\n[ESP] [WiFI] Your IP : %s"), WiFi.localIP().toString().c_str());
- PRINT(F("\n[ESP] [WiFI] Received Signal Strength Indication : %d"), WiFi.RSSI());
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [WiFI] Pomyślnie nawiązano połączenie"));
- PRINT(F("\n[ESP] [WiFI] Twój adres IP : %s"), WiFi.localIP().toString().c_str());
- PRINT(F("\n[ESP] [WiFI] Wskazanie siły odbieranego sygnału : %d"), WiFi.RSSI());
- #endif
- #endif
- break;
- case WL_CONNECT_FAILED:
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [WiFI] Connection failed"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [WiFI] Połączenie nieudane"));
- #endif
- #endif
- break;
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- reconect Wi-Fi ------------------------------------------------------------------------------------------------ //
- // ------------------------------------------------------------------------------------------------------------------- //
- void WiFiReconect()
- {
- unsigned long currentMillis = millis();
- if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >=interval)) // if no WiFi connect now
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [WiFI] Reconnecting to WiFi..."));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [WiFI] Ponowne łączenie z Wi-Fi..."));
- #endif
- #endif
- WiFi.disconnect();
- WiFi.begin(ssid, pass);
- WiFiStat(); // show WiFi Status
- previousMillis = currentMillis;
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- R T C U P A T E------------------------------------------------------------------------------------------------ //
- // ------------------------------------------------------------------------------------------------------------------- //
- void myRTC_Update()
- {
- if ( WiFi.status() == WL_CONNECTED ) // if WiFi is OK
- {
- timeClient.update();
- myRTC.setDS1302Time(timeClient.getSeconds(), timeClient.getMinutes(), timeClient.getHours(), timeClient.getWeek(), timeClient.getDay(), timeClient.getMonth(), timeClient.getYear());
- myRTC.updateTime();
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n\n[ESP] [RTC] RTC module updated "));
- #endif
- #if POLISH
- PRINT(F("\n\n[ESP] [RTC] czas został zaktualizowany i zsynchronizowany "));
- #endif
- #endif
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // ---N T P I N I T ------------------------------------------------------------------------------------------------ //
- // ------------------------------------------------------------------------------------------------------------------- //
- int NTPInit()
- {
- timeClient.update();
- if (timeClient.updated())
- {
- #if SERIAL
- DrawLine(60,'*');
- #if ENGLISH
- PRINT(F("\n[ESP] [NTP] Time Update :-)"));
- PRINT(F("\n[ESP] [NTP] Using NTP Server : %s"), timeClient.getPoolServerName().c_str());
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [NTP] Czas został zaktualizowany :-)"));
- PRINT(F("\n[ESP] [NTP] Używasz Serwera NTP : %s"), timeClient.getPoolServerName().c_str());
- #endif
- #endif
- return 1; // return 1 if time is update
- }
- else
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [NTP] Time in not Update !!!"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [NTP] Czas nie został zaktualizowany !!!"));
- #endif
- #endif
- return 0; // return 0 if time is not update
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- S H O W N T P ----------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void Show_NTP()
- {
- myRTC.updateTime();
- #if SERIAL
- DrawLine(60,'*');
- #if POLISH
- //Serial.printf("\n[ESP] [TIME] UTC Czas : %s", timeClient.getFormattedUTCTime().c_str());
- //Serial.printf("\n[ESP] [TIME] UTC Data : %d/%d/%d", timeClient.getUTCDay(),timeClient.getUTCMonth(),timeClient.getUTCYear());
- //Serial.printf("\n[ESP] [TIME] LOC Czas : %s", timeClient.getFormattedTime().c_str());
- //Serial.printf("\n[ESP] [TIME] LOC Data : %d/%d/%d", timeClient.getDay(),timeClient.getMonth(),timeClient.getYear());
- //Serial.printf("\n[ESP] [TIME] EXT Data : %s %d %s %d", MyClock.sPL_DayOfWeek.c_str(), timeClient.getDay(), MyClock.sPL_Month, timeClient.getYear());
- //Serial.printf("\n[ESP] [TIME] RTC Czas : %d:%d:%d", myRTC.hours, myRTC.minutes, myRTC.seconds);
- //Serial.printf("\n[ESP] [TIME] RTC Data : %d/%d/%d", myRTC.dayofmonth, myRTC.month, myRTC.year);
- PRINT(F("\n[ESP] [TIME] RTC Czas : %d:%d:%d"), myRTC.hours, myRTC.minutes, myRTC.seconds);
- PRINT(F("\n[ESP] [TIME] RTC Data : %d/%d/%d"), myRTC.dayofmonth, myRTC.month, myRTC.year);
- // Szkic używa 464633 bajtów (44%) pamięci programu. Maksimum to 1044464 bajtów.
- // Zmienne globalne używają 42860 bajtów (52%) pamięci dynamicznej, pozostawiając 39060 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
- // bez makra F dla printf
- // Szkic używa 464749 bajtów (44%) pamięci programu. Maksimum to 1044464 bajtów.
- // Zmienne globalne używają 42784 bajtów (52%) pamięci dynamicznej, pozostawiając 39136 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
- // z makrem F dla printf
- #endif
- #if ENGLISH
- //Serial.printf("\n[ESP] [TIME] UTC Time : %s", timeClient.getFormattedUTCTime().c_str());
- //Serial.printf("\n[ESP] [TIME] UTC Data : %d/%d/%d", timeClient.getUTCDay(),timeClient.getUTCMonth(),timeClient.getUTCYear());
- //Serial.printf("\n[ESP] [TIME] LOC Time : %s", timeClient.getFormattedTime().c_str());
- //Serial.printf("\n[ESP] [TIME] LOC Data : %d/%d/%d", timeClient.getDay(),timeClient.getMonth(),timeClient.getYear());
- //Serial.printf("\n[ESP] [TIME] EXT Data : %s %d %s %d", MyClock.sEN_DayOfWeek, timeClient.getDay(), MyClock.sEN_Month, timeClient.getYear());
- PRINT(F("\n[ESP] [TIME] RTC Time : %d:%d:%d"), myRTC.hours, myRTC.minutes, myRTC.seconds);
- PRINT(F("\n[ESP] [TIME] RTC Data : %d/%d/%d"), myRTC.dayofmonth, myRTC.month, myRTC.year);
- #endif
- #endif
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- U P D A T E M Y N T P S T R U C T U R E ------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void MyClock_Update()
- {
- // *** L O C T I M E & D A T A *** ///
- myRTC.updateTime();
- MyClock.iLOCYear = myRTC.year;
- MyClock.iLOCMonth = myRTC.month;
- MyClock.iLOCWeekDay = myRTC.dayofweek;
- MyClock.iLOCDay = myRTC.dayofmonth;
- MyClock.iLOCHours = myRTC.hours;
- MyClock.iLOCMinutes = myRTC.minutes;
- MyClock.iLOCSeconds = myRTC.seconds;
- // *** E X T R A C H A R *** ///
- if( MyClock.iLOCHours < 10 )
- {
- strcpy (MyClock.cHour, "0"); // 0H:MM:SS
- strcat (MyClock.cHour, String(MyClock.iLOCHours).c_str()); // 01:MM:SS
- }
- else
- if( MyClock.iLOCHours > 9 )
- {
- strcpy (MyClock.cHour, String(MyClock.iLOCHours).c_str()); // 01:MM:SS
- }
- if( MyClock.iLOCMinutes < 10 )
- {
- strcpy (MyClock.cMinutes, "0"); // HH:0M:SS
- strcat (MyClock.cMinutes, String(MyClock.iLOCMinutes).c_str()); // 01:M0:SS
- }
- else
- if( MyClock.iLOCMinutes > 9 )
- {
- strcpy (MyClock.cMinutes, String(MyClock.iLOCMinutes).c_str()); // HH:10:SS
- }
- if( MyClock.iLOCSeconds < 10 )
- {
- strcpy (MyClock.cSeconds, "0"); // HH:MM:0S
- strcat (MyClock.cSeconds, String(MyClock.iLOCSeconds).c_str()); // HH:MH:S0
- }
- else
- if( MyClock.iLOCSeconds > 9 )
- {
- strcpy (MyClock.cSeconds, String(MyClock.iLOCSeconds).c_str()); // HH:MM:10
- }
- // *** E X T R A S T R I N G *** ///
- // Zmienne globalne używają 43680 bajtów (53%) pamięci dynamicznej, pozostawiając 38240 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
- // bez PROGMEM
- char buf[30];
- strcpy_P(buf, (char*) pgm_read_dword(&(PL_MONTH[MyClock.iLOCMonth])));
- MyClock.sPL_Month = String(buf);
- strcpy_P(buf, (char*) pgm_read_dword(&(EN_MONTH[MyClock.iLOCMonth])));
- MyClock.sEN_Month = String(buf);
- // Zmienne globalne używają 43388 bajtów (52%) pamięci dynamicznej, pozostawiając 38532 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
- // z PROGMEM
- // Szkic używa 464601 bajtów (44%) pamięci programu. Maksimum to 1044464 bajtów.
- // Zmienne globalne używają 43388 bajtów (52%) pamięci dynamicznej, pozostawiając 38532 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
- // bez PROGMEM
- strcpy_P(buf, (char*) pgm_read_dword(&(PL_DAY[MyClock.iLOCWeekDay])));
- MyClock.sPL_DayOfWeek = String(buf);
- strcpy_P(buf, (char*) pgm_read_dword(&(EN_DAY[MyClock.iLOCWeekDay])));
- MyClock.sEN_DayOfWeek = String(buf);
- // Szkic używa 464649 bajtów (44%) pamięci programu. Maksimum to 1044464 bajtów.
- // Zmienne globalne używają 43196 bajtów (52%) pamięci dynamicznej, pozostawiając 38724 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
- // z PROGMEM
- //MyClock.sPL_DayOfWeek = PL_DAY[MyClock.iLOCWeekDay]; // day of week (dzień tygodnia) POLISH (need Re-Build Library NTP by Tomasz Majcher)
- //MyClock.sPL_DayOfWeek = EN_DAY[MyClock.iLOCWeekDay]; // day of week (dzień tygodnia) ENGLISH(need Re-Build Library NTP by Tomasz Majcher)
- //MyClock.sPL_Month = PL_MONTH[MyClock.iLOCMonth]; // month (miesiąc) in POLISH
- //MyClock.sEN_Month = EN_MONTH[MyClock.iLOCMonth]; // month (miesiąć) in ENGLISH
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- T A S K S E T U P ------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void TaskInit()
- {
- runner.init(); // inicjalizuj scheluder
- runner.addTask(task_0); // dodaj zadanie do scheluder
- task_0.enable(); // włącz zadanie do scheluder
- // Szkic używa 464649 bajtów (44%) pamięci programu. Maksimum to 1044464 bajtów.
- // Zmienne globalne używają 43196 bajtów (52%) pamięci dynamicznej, pozostawiając 38724 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
- // bez makra F
- // Szkic używa 464649 bajtów (44%) pamięci programu. Maksimum to 1044464 bajtów.
- // Zmienne globalne używają 42860 bajtów (52%) pamięci dynamicznej, pozostawiając 39060 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
- // z makrem F
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [TASK] Init Task0 - status OK"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [TASK] Init Task0 - wszystko w porządku"));
- #endif
- #endif
- runner.addTask(task_1); // dodaj zadanie do scheluder
- task_1.enable();
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [TASK] Init Task1 - status OK"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [TASK] Init Task1 - wszystko w porządku"));
- #endif
- #endif
- runner.addTask(task_2); // dodaj zadanie do scheluder
- task_2.enable();
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [TASK] Init Task2 - status OK"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [TASK] Init Task2 - wszystko w porządku"));
- #endif
- #endif
- runner.addTask(task_3); // dodaj zadanie do scheluder
- task_3.enable(); // włącz zadanie do scheluder
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [TASK] Init Task3 - status OK"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [TASK] Init Task3 - wszystko w porządku"));
- #endif
- #endif
- runner.addTask(task_4); // dodaj zadanie do scheluder
- task_4.enable(); // włącz zadanie do scheluder
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [TASK] Init Task4 - status OK"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [TASK] Init Task4 - wszystko w porządku"));
- #endif
- #endif
- runner.addTask(task_5); // dodaj zadanie do scheluder
- task_5.enable(); // włącz zadanie do scheluder
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [TASK] Init Task5 - status OK"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [TASK] Init Task5 - wszystko w porządku"));
- #endif
- #endif
- runner.addTask(task_6); // dodaj zadanie do scheluder
- task_6.enable(); // włącz zadanie do scheluder
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [TASK] Init Task6 - status OK"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [TASK] Init Task6 - wszystko w porządku"));
- #endif
- #endif
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- T A S K C A L L B A C K ------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void Task0Callback() // run with interval 60 minutes
- {
- if (!FtimeUpdate)
- {
- myRTC_Update();
- myRTC.updateTime();
- MyClock_Update();
- FtimeUpdate = true;
- }
- if (WiFi.status() == WL_CONNECTED) // jeśli połączenie WiFi jest aktywne
- {
- WeatherUpdate(); // aktualizuj pogodę
- AstronomyUpdate(); // aktualizuj astronomię
- AirUpdate(); // aktualizuj jakość powietrza
- SuperMsgCreate(); // stwoj super_msg
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- T A S K C A L L B A C K ------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void Task1Callback() // run with interval 60 seconds
- {
- MyClock_Update();
- #if SERIAL
- PRINT(F("\n\n[ESP] [TASK1] Inside Task1Callback() "));
- DrawLine(60,'*');
- PRINT(F("\n[ESP] [TASK1] [Memory Free] : %u [kB]"), ESP.getFreeHeap());
- PRINT(F("\n[ESP] [TASK1] [CPU frequency] : %u [MHz]"),ESP.getCpuFreqMHz());
- PRINT(F("\n[ESP] [TASK1] [WiFi IP] : ")); Serial.print(WiFi.localIP() );
- PRINT(F("\n[ESP] [TASK1] RTC Time : %d:%d:%d"), myRTC.hours, myRTC.minutes, myRTC.seconds);
- PRINT(F("\n[ESP] [TASK1] RTC Time : %s:%s:%s"), MyClock.cHour, MyClock.cMinutes, MyClock.cSeconds);
- #if ENGLISH
- PRINT(F("\n[ESP] [TASK1] Nameday : %s"), GetNameday(myRTC.month, myRTC.dayofmonth).c_str());
- PRINT(F("\n[ESP] [TASK1] Event of the day : %s"), GetEvent(myRTC.month, myRTC.dayofmonth).c_str());
- PRINT(F("\n[ESP] [TASK1] RTC Data : %s %d/%d/%d"), MyClock.sEN_DayOfWeek, myRTC.dayofmonth, myRTC.month, myRTC.year);
- PRINT(F("\n[ESP] [TASK1] RTC Data : %s %d %s %d"), MyClock.sEN_DayOfWeek, myRTC.dayofmonth, MyClock.sEN_Month, myRTC.year);
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [TASK1] Imieniny obchodzą : %s"), GetNameday(myRTC.month, myRTC.dayofmonth).c_str());
- PRINT(F("\n[ESP] [TASK1] Wydarzenie dnia : %s"), GetEvent(myRTC.month, myRTC.dayofmonth).c_str());
- PRINT(F("\n[ESP] [TASK1] RTC Data : %s %d/%d/%d"), MyClock.sPL_DayOfWeek, myRTC.dayofmonth, myRTC.month, myRTC.year);
- PRINT(F("\n[ESP] [TASK1] RTC Data : %s %d %s %d"), MyClock.sPL_DayOfWeek, myRTC.dayofmonth, MyClock.sPL_Month, myRTC.year);
- #endif
- #endif
- switch (myRTC.minutes)
- {
- case 2 : {
- if(F_display_clock)
- {
- F_display_clock = false;
- F_display_temp = true;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- break;
- }
- case 3 : {
- if(!F_display_clock)
- {
- F_display_clock = true;
- F_display_temp = false;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- }
- case 5 : {
- if (F_display_clock)
- {
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(super_msg, 160,217,1); // wyświetl super msg
- }
- break;
- }
- case 7 : {
- if (F_display_clock)
- {
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString("Free Memory : " + String(ESP.getFreeHeap()), 160,217,1); // wyświetl sformatowaną datę pod zegarem na TFT
- }
- break;
- }
- case 8 : {
- if(F_display_clock)
- {
- F_display_clock = false;
- F_display_temp = true;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- break;
- }
- case 9 : {
- if(!F_display_clock)
- {
- F_display_clock = true;
- F_display_temp = false;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- }
- case 10 : {
- if (F_display_clock)
- {
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(super_msg, 160,217,1); // wyświetl super msg
- }
- break;
- }
- case 12 : {
- if (F_display_clock)
- {
- #if ENGLISH
- String bufor = "Temperature " + String(ptrWeather->temp_c) + " st.C";
- #endif
- #if POLISH
- String bufor = "Temperatura " + String(ptrWeather->temp_c) + " st.C";
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl temperarurę
- }
- break;
- }
- case 15 : {
- if (F_display_clock)
- {
- #if ENGLISH
- String bufor = "Humidity " + String(ptrWeather->humidity) + " %";
- #endif
- #if POLISH
- String bufor = "Wilgotnosc " + String(ptrWeather->humidity) + " %";
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl wilgotność
- }
- break;
- }
- case 17 : {
- if(F_display_clock)
- {
- F_display_clock = false;
- F_display_temp = true;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- break;
- }
- case 18 : {
- if(!F_display_clock)
- {
- F_display_clock = true;
- F_display_temp = false;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- }
- case 19 : {
- if (F_display_clock)
- {
- #if ENGLISH
- String bufor = "Pressure " + String(ptrWeather->pressure_mb ) + " mPA";
- #endif
- #if POLISH
- String bufor = "Ciśnienie " + String(ptrWeather->pressure_mb ) + " mPA";
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl cisnienie atmosferyczne
- }
- break;
- }
- case 21 : {
- if (F_display_clock)
- {
- #if ENGLISH
- String bufor = "Wind " + String(ptrWeather->wind_kph) + " km/h";
- #endif
- #if POLISH
- String bufor = "Wiatr " + String(ptrWeather->wind_kph) + " km/h";
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl prędkość wiatru
- }
- break;
- }
- case 23 : {
- if (F_display_clock)
- {
- #if ENGLISH
- String bufor = "Rainfall " + String(ptrWeather->precip_mm) + " mm";
- #endif
- #if POLISH
- String bufor = "Opady " + String(ptrWeather->precip_mm) + " mm";
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl opady atmosferyczne
- }
- break;
- }
- case 25 : {
- if (F_display_clock)
- {
- #if ENGLISH
- String bufor = "Cloudy " + String(ptrWeather->cloud) + " %";
- #endif
- #if POLISH
- String bufor = "Zachmurzenie " + String(ptrWeather->cloud) + " %";
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl zachmurzenie w %
- }
- break;
- }
- case 26 : {
- if (F_display_clock)
- {
- String bufor;
- #if ENGLISH
- bufor = "Visibility " + String(ptrWeather->vis_km) + " km";
- #endif
- #if POLISH
- bufor = "Widzialnosc " + String(ptrWeather->vis_km) + " km";
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl widzialność w km
- }
- break;
- }
- case 27 : {
- if(F_display_clock)
- {
- F_display_clock = false;
- F_display_temp = true;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- break;
- }
- case 28 : {
- if(!F_display_clock)
- {
- F_display_clock = true;
- F_display_temp = false;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- }
- case 29 : {
- if (F_display_clock)
- {
- #if ENGLISH
- String bufor = "Sunrise" + String(ptrAstronomy->sunrise);
- #endif
- #if POLISH
- String bufor = "Wschod slonca " + String(ptrAstronomy->sunrise);
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl godzinę wschodu słońca
- }
- break;
- }
- case 30 : {
- if(F_display_clock)
- {
- F_display_clock = false;
- F_display_temp = true;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- break;
- }
- case 31 : {
- if(!F_display_clock)
- {
- F_display_clock = true;
- F_display_temp = false;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- if (F_display_clock)
- {
- #if ENGLISH
- String bufor = "Sunset " + String(ptrAstronomy->sunset);
- #endif
- #if POLISH
- String bufor = "Zachod slonca " + String(ptrAstronomy->sunset);
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl godzinę zachodu słońca
- }
- break;
- }
- case 32 : {
- if (F_display_clock)
- {
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(super_msg, 160,217,1); // wyświetl super msg
- }
- break;
- }
- case 33 : {
- if(F_display_clock)
- {
- F_display_clock = false;
- F_display_temp = true;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- break;
- }
- case 34 : {
- if(!F_display_clock)
- {
- F_display_clock = true;
- F_display_temp = false;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- if (F_display_clock)
- {
- #if ENGLISH
- String bufor = "Sunset " + String(ptrAstronomy->sunset);
- #endif
- #if POLISH
- String bufor = "Zachod slonca " + String(ptrAstronomy->sunset);
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl godzinę zachodu słońca
- }
- break;
- }
- case 35 : {
- if (F_display_clock)
- {
- #if ENGLISH
- String bufor = "Moonrise " + String(ptrAstronomy->moonrise);
- #endif
- #if POLISH
- String bufor = "Wschod ksiezyca " + String(ptrAstronomy->moonrise);
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl godzinę wschodu księżyca
- }
- break;
- }
- case 36 : {
- if (F_display_clock)
- {
- #if ENGLISH
- String bufor = "Moonset " + String(ptrAstronomy->moonset);
- #endif
- #if POLISH
- String bufor = "Zachod ksiezyca " + String(ptrAstronomy->moonset);
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl godzinę zachodu księżyca
- }
- break;
- }
- case 37 : {
- if(F_display_clock)
- {
- F_display_clock = false;
- F_display_temp = true;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- break;
- }
- case 38 : {
- if(!F_display_clock)
- {
- F_display_clock = true;
- F_display_temp = false;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- if (F_display_clock)
- {
- #if ENGLISH
- String bufor = "Sunset " + String(ptrAstronomy->sunset);
- #endif
- #if POLISH
- String bufor = "Zachod slonca " + String(ptrAstronomy->sunset);
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl godzinę zachodu słońca
- }
- break;
- }
- case 43 : {
- if(F_display_clock)
- {
- F_display_clock = false;
- F_display_temp = true;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- break;
- }
- case 44 : {
- if(!F_display_clock)
- {
- F_display_clock = true;
- F_display_temp = false;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- if (F_display_clock)
- {
- #if ENGLISH
- String bufor = "Sunset " + String(ptrAstronomy->sunset);
- #endif
- #if POLISH
- String bufor = "Zachod slonca " + String(ptrAstronomy->sunset);
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl godzinę zachodu słońca
- }
- break;
- }
- case 45 : {
- if (F_display_clock)
- {
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString("Free Memory : " + String(ESP.getFreeHeap()), 160,217,1);
- }
- break;
- }
- case 54 : {
- if(F_display_clock)
- {
- F_display_clock = false;
- F_display_temp = true;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- break;
- }
- case 55 : {
- if(!F_display_clock)
- {
- F_display_clock = true;
- F_display_temp = false;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- break;
- }
- case 58 : {
- if (F_display_clock)
- {
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(super_msg, 160,217,1); // wyświetl super msg
- }
- break;
- }
- default : {
- if(!F_display_clock)
- {
- F_display_clock = true;
- F_display_temp = false;
- F_display_moon = false;
- F_display_sun = false;
- F_refresh_all = true; // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
- tft.fillRect(1,60,319,180,TFT_BLACK);
- }
- break;
- }
- }
- if (F_display_temp && F_ptrWeather) TFT_WeatherDisplay();
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- T A S K C A L L B A C K ------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void Task2Callback() // run with interval 1 seconds
- {
- static byte staticHour = 0;
- static byte staticMinutes = 0;
- byte x_pos_hour = 10;
- byte y_pos_hour = 100;
- byte x_pos_min = 180;
- byte y_pos_min = 100;
- myRTC.updateTime();
- // -------------------------------------------- DISPLAY CLOCK ---------------------------------------- //
- if (F_display_clock) // jesli flaga jest true
- {
- tft.setTextColor(clock_color); // ustaw kolor znaków na ciemno szary
- tft.setTextSize(1); // ustaw wielkosc znakow na 2
- if (F_refresh_all)
- {
- staticHour = -1;
- staticMinutes = -1;
- F_refresh_all = false;
- }
- if ((staticHour != myRTC.hours) ) // jesli zmienila sie godzina wyswietl nowa
- {
- // ---------------------------------------------------------------------- //
- // check clock color mode --- use only for TFT FONT --------------------- //
- // ---------------------------------------------------------------------- //
- if ( myRTC.hours > 6 && myRTC.hours < 20 ) clock_color = clock_color_day;
- else clock_color = clock_color_night;
- // ---------------------------------------------------------------------- //
- staticHour = myRTC.hours; // zapisz nowa godzine
- drawJpeg(digit112[myRTC.hours/10], 10, 80); // wyświetla dziesiątki godziny
- drawJpeg(digit112[myRTC.hours%10], 74, 80); // wyświetla jedności godziny
- }
- if (staticMinutes != myRTC.minutes) // jesli zmienila sie minuta wyswietl nowa
- {
- staticMinutes = myRTC.minutes; // zapisz nowa minute
- drawJpeg(digit112[myRTC.minutes/10], 180, 80);
- drawJpeg(digit112[myRTC.minutes%10], 244, 80);
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- String bufor;
- #if POLISH
- bufor = MyClock.sPL_DayOfWeek + " " + String(myRTC.dayofmonth) + "-" + String(myRTC.month) + "-" + String(myRTC.year);
- #endif
- #if ENGLISH
- bufor = MyClock.sEN_DayOfWeek + " " + String(myRTC.dayofmonth) + "-" + String(myRTC.month) + "-" + String(myRTC.year);
- #endif
- tft.drawCentreString(bufor, 160,217,1); // wyświetl sformatowaną datę pod zegarem na TFT
- }
- // --------------------------- display : (second) ------------------------------------------------- //
- if(myRTC.seconds%2) // jesli sekunda modulo daje 0
- {
- tft.fillCircle(160, 115, 7, TFT_WHITE);
- tft.fillCircle(160, 150, 7, TFT_WHITE);
- }
- else // jesli sekunda modula daje 1
- {
- tft.fillCircle(160, 115, 7, TFT_BLACK);
- tft.fillCircle(160, 150, 7, TFT_BLACK);
- }
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- T A S K C A L L B A C K ------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void Task3Callback() // run with interval 90 seconds
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n\n[ESP] [TASK3] Inside -> Task3Callback() "));
- #endif
- #if POLISH
- PRINT(F("\n\n[ESP] [TASK3] Wykonuje -> Task3Callback() "));
- #endif
- #endif
- if (WiFi.status() == WL_CONNECTED) // jeśli połączenie WiFi jest aktywne
- {
- if ( !F_WeatherUpdate ) WeatherUpdate(); // i pogoda nie została jeszcze zaktualizowana
- if ( !F_AstronomyUpdate ) AstronomyUpdate(); // i pogoda nie została jeszcze zaktualizowana
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- T A S K C A L L B A C K ------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void Task4Callback() // run with interval 15 minut
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n\n[ESP] [TASK3] Inside -> Task4Callback() "));
- #endif
- #if POLISH
- PRINT(F("\n\n[ESP] [TASK3] Wykonuje -> Task4Callback() "));
- #endif
- #endif
- if (WiFi.status() == WL_CONNECTED) // jeśli połączenie WiFi jest aktywne
- {
- WeatherUpdate(); // i pogoda nie została jeszcze zaktualizowana
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- T A S K C A L L B A C K ------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void Task5Callback() // run with interval 120 minut
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n\n[ESP] [TASK3] Inside -> Task5Callback() "));
- #endif
- #if POLISH
- PRINT(F("\n\n[ESP] [TASK3] Wykonuje -> Task5Callback() "));
- #endif
- #endif
- if (WiFi.status() == WL_CONNECTED) // jeśli połączenie WiFi jest aktywne
- {
- AstronomyUpdate(); // i pogoda nie została jeszcze zaktualizowana
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- T A S K C A L L B A C K ------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void Task6Callback() // run with interval 140 minut
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n\n[ESP] [TASK3] Inside -> Task6Callback() "));
- #endif
- #if POLISH
- PRINT(F("\n\n[ESP] [TASK3] Wykonuje -> Task6Callback() "));
- #endif
- #endif
- if (WiFi.status() == WL_CONNECTED) // jeśli połączenie WiFi jest aktywne
- {
- AirUpdate(); // i astronomia nie została jeszcze zaktualizowana
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- S E T U P --- T F T --- I N I T ------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void TFTInit()
- {
- tft.begin();
- tft.setRotation(1);
- tft.fillScreen(TFT_BLACK);
- tft.setSwapBytes(true);
- drawJpeg("/wiki.jpg", 0, 0);
- delay(5000);
- tft.fillScreen(TFT_BLACK);
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- E X P A N D E R I N I T ------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void ExpanderInit()
- {
- rWire.begin(5, 4);
- rWire.setClock(100000L);
- expander.begin();
- RelayOff(0); // all Relay OFF (send 0)
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- M A I N S E T U P ------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void setup()
- {
- SerialInit(); // check and init serial monitor
- // Init TFT Display
- if (!SPIFFS.begin())
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [SETUP] SPIFFS initialisation failed!"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [SETUP] błąd inicjalizacji SPIFFS !"));
- #endif
- #endif
- while (1) yield();
- }
- else
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [SETUP] SPIFFS initialisation done."));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [SETUP] SPIFFS zainicjowano pomyślnie."));
- #endif
- #endif
- }
- listFiles(); // Lists the files so you can see what is in the SPIFFS
- TFTInit();
- WiFiInit(); // start WiFi Connection
- WiFiStat(); // show WiFi Status
- WiFiReconect(); // check WiFi Connection and conect if loss !!!
- timeClient.begin(); // start timeClient
- DrawLine(60,'*'); // Draw 60x separator *
- if ( WiFi.status() == WL_CONNECTED ) // if WiFi is OK
- {
- while(!NTPInit()); // init NTP server
- myRTC_Update(); // update RTC module
- MyClock_Update(); // copy Time & Data to structure MyClock
- Show_NTP(); // show NTP time & data
- }
- ExpanderInit(); // ExpanderInit
- TaskInit(); // Init Task Scheluder
- for(byte i = 1; i <= 8; i ++) Bulb(i, 0); // wyłącz wszystkie żarówki
- timer.setInterval(3000L, checkBlynkStatus); // check if Blynk server is connected every 3 seconds
- Blynk.config(AUTH);
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- M A I N L O O P --------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void loop()
- {
- runner.execute(); // scheluder
- Blynk.run(); // Blynk
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- //
- //
- // *** T F T f u n c t i o n s ***
- //
- //
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- T F T B U L B O N / O F F --------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void Bulb(byte nr, byte state)
- {
- switch(nr)
- {
- case 1 : {
- if (!state) tft.pushImage(5, 10, bulb_off_Width, bulb_off_Height, bulb_off);
- else tft.pushImage(5, 10, bulb_off_Width, bulb_off_Height, bulb_on);
- break;
- }
- case 2 : {
- if (!state) tft.pushImage(45, 10, bulb_off_Width, bulb_off_Height, bulb_off);
- else tft.pushImage(45, 10, bulb_off_Width, bulb_off_Height, bulb_on);
- break;
- }
- case 3 : {
- if (!state) tft.pushImage(85, 10, bulb_off_Width, bulb_off_Height, bulb_off);
- else tft.pushImage(85, 10, bulb_off_Width, bulb_off_Height, bulb_on);
- break;
- }
- case 4 : {
- if (!state) tft.pushImage(125, 10, bulb_off_Width, bulb_off_Height, bulb_off);
- else tft.pushImage(125, 10, bulb_off_Width, bulb_off_Height, bulb_on);
- break;
- }
- case 5 : {
- if (!state) tft.pushImage(165, 10, bulb_off_Width, bulb_off_Height, bulb_off);
- else tft.pushImage(165, 10, bulb_off_Width, bulb_off_Height, bulb_on);
- break;
- }
- case 6 : {
- if (!state) tft.pushImage(205, 10, bulb_off_Width, bulb_off_Height, bulb_off);
- else tft.pushImage(205, 10, bulb_off_Width, bulb_off_Height, bulb_on);
- break;
- }
- case 7 : {
- if (!state) tft.pushImage(245, 10, bulb_off_Width, bulb_off_Height, bulb_off);
- else tft.pushImage(245, 10, bulb_off_Width, bulb_off_Height, bulb_on);
- break;
- }
- case 8 : {
- if (!state) tft.pushImage(285, 10, bulb_off_Width, bulb_off_Height, bulb_off);
- else tft.pushImage(285, 10, bulb_off_Width, bulb_off_Height, bulb_on);
- break;
- }
- }
- if ( F_display_clock )
- {
- tft.fillRect(1,210,319,30,TFT_BLACK); // wyczyść pole msg
- tft.drawRect(1,210,319,30,TFT_WHITE); // narysuj pole msg
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- String bufor = "Relay no. " + String (nr) + " turn "; // przygotuj bufor do wyswietlenia
- if (state) bufor += "ON"; // jesli przekaznik wlaczony
- else bufor += "OFF"; // jesli przekaznik wylaczony
- tft.drawCentreString(bufor, 160,217,1); // wyświetl sformatowaną datę pod zegarem na TFT
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- //
- //
- // *** R E L A Y S ***
- //
- //
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- Relay to OFF -------------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void RelayOff(byte nr)
- {
- if (!nr) // if nr = 0 all relay set to OFF (RelayMin, RelayMax)
- {
- for (byte i = RelayMin; i <= RelayMax; i++) expander.write(RELAY[i], HIGH);
- #if SERIAL
- DrawLine(60,'-'); // draw line
- #if POLISH
- PRINT(F("\n[ESP] [RELAY] Wyłączono wszystkie przekaźniki"));
- #endif
- #if ENGLISH
- PRINT(F("\n[ESP] [RELAY] Turn off all relay"));
- #endif
- #endif
- }
- else
- {
- if ( nr >= RelayMin && nr <= RelayMax ) // only value (1-8)
- {
- if ( !expander.read(RELAY[nr]) ) // if Relay is ON
- {
- expander.write(RELAY[nr], HIGH); // turn off Relay
- Bulb(nr, 0);
- #if SERIAL
- DrawLine(60,'-'); // draw line
- #if POLISH
- PRINT(F("\n[ESP] [RELAY] Wyłączono przekaźnik nr. %d"), nr);
- #endif
- #if ENGLISH
- PRINT(F("\n[ESP] [RELAY] Turn off relay no. %d"), nr);
- #endif
- #endif
- }
- else // relay is off, re-off
- {
- #if SERIAL
- DrawLine(60,'-');
- #if POLISH
- PRINT(F("\n[ESP] [RELAY] Wykryto próbę ponownego wyłączenia przekaźnika nr. %d"), nr);
- #endif
- #if ENGLISH
- PRINT(F("\n[ESP] [RELAY] An attempt to re-engage the relay has been detected no. %d"), nr);
- #endif
- #endif
- }
- }
- else // ERROR !!! Relay does not exist (jeśli taki przekaźnik nie istnieje)
- {
- #if SERIAL
- DrawLine(60,'-');
- #if POLISH
- PRINT(F("\n[ESP] [RELAY] Nie ma takiego przekaźnika, nr. %d"), nr);
- #endif
- #if ENGLISH
- PRINT(F("\n[ESP] [RELAY] There is no such relay, no. %d"), nr);
- #endif
- #endif
- }
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- Relay to OFF -------------------------------------------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void RelayOn(byte nr)
- {
- if (!nr) // if nr = 0 all relay set to ON (RelayMin, RelayMax)
- {
- for (byte i = RelayMin; i <= RelayMax; i++) expander.write(RELAY[i], LOW);
- #if SERIAL
- DrawLine(60,'-'); // draw line
- #if POLISH
- PRINT(F("\n[ESP] [RELAY] Włączono wszystkie przekaźniki"));
- #endif
- #if ENGLISH
- PRINT(F("\n[ESP] [RELAY] Turn on all relay"));
- #endif
- #endif
- }
- else
- {
- if ( nr >= RelayMin && nr <= RelayMax ) // only value (1-8)
- {
- if ( expander.read(RELAY[nr]) ) // if Relay is OFF
- {
- expander.write(RELAY[nr], LOW); // turn on Relay
- Bulb(nr, 1);
- #if SERIAL
- DrawLine(60,'-'); // draw line
- #if POLISH
- PRINT(F("\n[ESP] [RELAY] Włączono przekaźnik nr. %d"), nr);
- #endif
- #if ENGLISH
- PRINT(F("\n[ESP] [RELAY] Turn on relay no. %d"), nr);
- #endif
- #endif
- }
- else // relay is on, re-on
- {
- #if SERIAL
- DrawLine(60,'-');
- #if POLISH
- PRINT(F("\n[ESP] [RELAY] Wykryto próbę ponownego włączenia przekaźnika nr. %d"), nr);
- #endif
- #if ENGLISH
- PRINT(F("\n[ESP] [RELAY] An attempt to re-engage the relay has been detected no. %d"), nr);
- #endif
- #endif
- }
- }
- else
- {
- #if SERIAL
- DrawLine(60,'-'); // draw line
- #if POLISH
- PRINT(F("\n[ESP] [RELAY] Nie ma takiego przekaźnika, nr. %d"), nr);
- #endif
- #if ENGLISH
- PRINT(F("\n[ESP] [RELAY] There is no such relay, no. %d"), nr);
- #endif
- #endif
- }
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- //
- //
- // B L Y N K S E C T I O N
- //
- //
- // ------------------------------------------------------------------------------------------------------------------- //
- // BLYNK_CONNECTED
- // ------------------------------------------------------------------------------------------------------------------- //
- BLYNK_CONNECTED()
- {
- Blynk.syncVirtual(VPIN_BUTTON_1);
- Blynk.syncVirtual(VPIN_BUTTON_2);
- Blynk.syncVirtual(VPIN_BUTTON_3);
- Blynk.syncVirtual(VPIN_BUTTON_4);
- Blynk.syncVirtual(VPIN_BUTTON_5);
- Blynk.syncVirtual(VPIN_BUTTON_6);
- Blynk.syncVirtual(VPIN_BUTTON_7);
- Blynk.syncVirtual(VPIN_BUTTON_8);
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // BLYNK BUTTON 1
- // ------------------------------------------------------------------------------------------------------------------- //
- BLYNK_WRITE(VPIN_BUTTON_1)
- {
- toggleState_1 = param.asInt();
- if(toggleState_1)
- {
- RelayOn(1);
- }
- else
- {
- RelayOff(1);
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // BLYNK BUTTON 2
- // ------------------------------------------------------------------------------------------------------------------- //
- BLYNK_WRITE(VPIN_BUTTON_2)
- {
- toggleState_2 = param.asInt();
- if(toggleState_2)
- {
- RelayOn(2);
- }
- else
- {
- RelayOff(2);
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // BLYNK BUTTON 3
- // ------------------------------------------------------------------------------------------------------------------- //
- BLYNK_WRITE(VPIN_BUTTON_3)
- {
- toggleState_3 = param.asInt();
- if(toggleState_3)
- {
- RelayOn(3);
- }
- else
- {
- RelayOff(3);
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // BLYNK BUTTON 4
- // ------------------------------------------------------------------------------------------------------------------- //
- BLYNK_WRITE(VPIN_BUTTON_4)
- {
- toggleState_4 = param.asInt();
- if(toggleState_4)
- {
- RelayOn(4);
- }
- else
- {
- RelayOff(4);
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // BLYNK BUTTON 5
- // ------------------------------------------------------------------------------------------------------------------- //
- BLYNK_WRITE(VPIN_BUTTON_5)
- {
- toggleState_5 = param.asInt();
- if(toggleState_5)
- {
- RelayOn(5);
- }
- else
- {
- RelayOff(5);
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // BLYNK BUTTON 6
- // ------------------------------------------------------------------------------------------------------------------- //
- BLYNK_WRITE(VPIN_BUTTON_6)
- {
- toggleState_6 = param.asInt();
- if(toggleState_6)
- {
- RelayOn(6);
- }
- else
- {
- RelayOff(6);
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // BLYNK BUTTON 7
- // ------------------------------------------------------------------------------------------------------------------- //
- BLYNK_WRITE(VPIN_BUTTON_7)
- {
- toggleState_7 = param.asInt();
- if(toggleState_7)
- {
- RelayOn(7);
- }
- else
- {
- RelayOff(7);
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // BLYNK BUTTON 8
- // ------------------------------------------------------------------------------------------------------------------- //
- BLYNK_WRITE(VPIN_BUTTON_8)
- {
- toggleState_8 = param.asInt();
- if(toggleState_8)
- {
- RelayOn(8);
- }
- else
- {
- RelayOff(8);
- }
- }
- void checkBlynkStatus()
- {
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- W E A T H E R A L L O C A T E M E M O R Y ------------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void ptrWeatherMalloc()
- {
- if (!F_ptrWeather)
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
- PRINT(F("\n[ESP] [Weather Malloc] i try allocate memory in RAM for struct -> Weather"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
- PRINT(F("\n[ESP] [Weather Malloc] próba alokacji pamięci RAM dla struktury -> Weather"));
- #endif
- #endif
- ptrWeather = ( struct Weather * ) malloc ( sizeof (struct Weather) );
- F_ptrWeather = true;
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
- PRINT(F("\n[ESP] [Weather Malloc] allocate memory in RAM for struct Weather sucefull\n"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
- PRINT(F("\n[ESP] [Weather Malloc] alokakacji pamięci RAM dla struktury - Weather UDANA\n"));
- #endif
- #endif
- }
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- W E A T H E R C O N D I T I O N T F T D I S P L A Y --------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void TFT_WeatherDisplay()
- {
- // ------------------------------------------------------------------------------------ //
- // --- DRAW TEMPERATURE DIGIS --------------------------------------------------------- //
- // ------------------------------------------------------------------------------------ //
- TFT_WeatherIconShow();
- drawJpeg(digit112[abs(int(ptrWeather -> temp_c)) / 10], 165,80); // Xx digit
- drawJpeg(digit112[abs(int(ptrWeather -> temp_c)) % 10], 230,80); // xX digit
- tft.fillCircle(300,90, 7, TFT_WHITE); // st.C
- if (ptrWeather -> temp_c < 0) tft.fillRect(130,135,20,5,TFT_WHITE);// minus symbol
- #if ENGLISH
- String bufor = String(ptrWeather -> condition_en);
- #endif
- #if POLISH
- String bufor = String(ptrWeather -> condition_pl);
- #endif
- tft.fillRect(1,210,319,30,TFT_BLACK);
- tft.drawRect(1,210,319,30,TFT_WHITE);
- tft.setTextSize(2); // ustaw rozmiar fontów
- tft.setTextColor(TFT_LIGHTGREY); // ustaw kolor fontów
- tft.drawCentreString(bufor, 160,217,1); // wyświetl godzinę zachodu księżyca
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // --- W E A T H E R D E L E T E F R O M M E M O R Y ------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------------- //
- void ptrWeatherFree()
- {
- if (F_ptrWeather)
- {
- free(ptrWeather);
- F_ptrWeather = false;
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [Weather Malloc] delete [ptrWeather] from RAM memory ..."));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [Weather Malloc] usunięto [ptrWeather] z pamięci RAM ..."));
- #endif
- #endif
- }
- else
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [Weather] cannot be deleted [ptrWeather] does not exist !!! "));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [Weather] nie można usunąć [ptrWeather] nie isnieje w pamięci RAM ..."));
- #endif
- #endif
- }
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // --- WEATHER UPDATE --- CREATE BUFFOR in RAM --- COPY DATA to STRUCT WEATHER in RAM --- by TRANSLINE ------- //
- // ------------------------------------------------------------------------------------------------------------ //
- // --- DUAL LANGUAGE --- POLISH & ENGLISH --- SET IN MACRO in MAIN PROJECT --- TRANSLATE in GOOGLE --- :-) --- //
- // ------------------------------------------------------------------------------------------------------------ //
- void WeatherUpdate()
- {
- if (!F_ptrWeather) ptrWeatherMalloc(); // jesli pamięć nie utworzona stwórz ją w PSRAM
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[[ESP] Weather Update] Try Downloading JSON File from https://api.weatherapi.com/"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [Weather Update] Próbuję pobrać plik JSON z https://api.weatherapi.com/"));
- #endif
- #endif
- #if ENGLISH
- String path = "http://api.weatherapi.com/v1/current.json?key=" + PogodaToken + "&q=" + PogodaMiasto + "&lang=en";
- #endif
- #if POLISH
- String path = "http://api.weatherapi.com/v1/current.json?key=" + PogodaToken + "&q=" + PogodaMiasto + "&lang=pl";
- #endif
- HTTPClient http;
- http.useHTTP10(true);
- http.begin(client, path);
- http.GET();
- DynamicJsonDocument doc(2000);
- DeserializationError error = deserializeJson(doc, http.getStream());
- if(error)
- {
- F_WeatherUpdate = false; // aktualizacja nie powiodła się
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[Weather Update] DeserializeJson() failed: "));
- Serial.println(error.c_str());
- #endif
- #if POLISH
- PRINT(F("\n[Weather Update] DeserializeJson() error: "));
- Serial.println(error.c_str());
- #endif
- #endif
- }
- else
- {
- F_WeatherUpdate = true;
- }
- http.end();
- if(F_WeatherUpdate)
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [Weather Update] JsonDocument Usage Memory : %s bytes"), String(doc.memoryUsage()));
- PRINT(F("\n[ESP] [Weather Update] [FREE RAM] : %d kB\n"), ESP.getFreeHeap());
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [Weather Update] JsonDocument zaalokował pamięć : %s bajtów"), String(doc.memoryUsage()));
- PRINT(F("\n[ESP] [Weather Update] [FREE RAM] : %d kB\n"), ESP.getFreeHeap());
- #endif
- #endif
- // --- update struct WEATHER in PSRAM !!! -------------------------------------------------- //
- strcpy(ptrWeather->city, doc["location"]["name"].as<String>().c_str()); // nazwę miasta
- strcpy(ptrWeather->country, doc["location"]["country"].as<String>().c_str()); // nazwę kraju
- ptrWeather->lat = doc["location"]["lat"].as<double>(); // szer.geograficzną
- ptrWeather->lon = doc["location"]["lon"].as<double>(); // dł.geograficzną
- strcpy(ptrWeather->tz_id, doc["location"]["tz_id"].as<String>().c_str()); // kontynent/stolica
- ptrWeather->localtime_epoch = doc["location"]["localtime_epoch"]; // czas EPOCH
- strcpy(ptrWeather->localtime, doc["location"]["localtime"].as<String>().c_str()); // czas lokalny
- strcpy(ptrWeather->last_updated, doc["current"]["last_updated"].as<String>().c_str()); // ost. aktualizacja
- ptrWeather->temp_c = doc["current"]["temp_c"].as<double>(); // temp Celcius
- ptrWeather->feelslike_c = doc["current"]["feelslike_c"].as<double>(); // temp odczuwalna C
- ptrWeather->temp_f = doc["current"]["temp_f"].as<double>(); // temp Faranhaid
- ptrWeather->feelslike_f = doc["current"]["feelslike_f"].as<double>(); // temp odczuwalna Faranhaid
- strcpy(ptrWeather->condition_en, doc["current"]["condition"]["text"].as<String>().c_str()); // opis pogody ENGLISH
- strcpy(ptrWeather->condition_pl, doc["current"]["condition"]["text"].as<String>().c_str()); // opis pogody POLISH *** do zrobienia ***
- strcpy(ptrWeather->icon, doc["current"]["condition"]["icon"].as<String>().c_str()); // adres ikony pogody
- ptrWeather->code = doc["current"]["condition"]["code"]; // kod pogody
- ptrWeather->wind_kph = doc["current"]["wind_kph"].as<double>(); // prędkość wiatru w km/h
- ptrWeather->gust_kph = doc["current"]["gust_kph"].as<double>(); // porywy wiatru w km/h
- ptrWeather->wind_mph = doc["current"]["wind_mph"].as<double>(); // prędkość wiatru w milach/h
- ptrWeather->gust_mph = doc["current"]["gust_mph"].as<double>(); // porywy wiatru w milach/h
- ptrWeather->wind_degree = doc["current"]["wind_degree"]; // kierunek wiatru (stopnie) int
- strcpy(ptrWeather->wind_dir, doc["current"]["wind_dir"].as<String>().c_str()); // kierunke wiatru (dir)
- ptrWeather->pressure_mb = doc["current"]["pressure_mb"]; // cisnienie atmosferyczne
- ptrWeather->pressure_in = doc["current"]["pressure_in"].as<double>(); // huj wie co to !!!
- ptrWeather->precip_mm = doc["current"]["precip_mm"].as<double>(); // opady w mm
- ptrWeather->precip_in = doc["current"]["precip_in"].as<double>(); // huj wie co to !!!
- ptrWeather->humidity = doc["current"]["humidity"]; // wilgotność powietrza
- ptrWeather->cloud = doc["current"]["cloud"]; // zachmurzenie %
- ptrWeather->vis_km = doc["current"]["vis_km"].as<double>(); // widzialnosc km
- ptrWeather->vis_miles = doc["current"]["vis_miles"].as<double>(); // widzialnosc mile
- ptrWeather->uv = doc["current"]["uv"].as<double>(); // index UV
- // --- update struct WEATHER in PSRAM !!! -------------------------------------------------- //
- #if SERIAL
- if(F_WeatherUpdate) WeatherShow(); // pokaż jeśli SERIAl jest TRUE
- #endif
- }
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // --- WEATHER SHOW FROM BUFFOR in RAM --- //
- // ------------------------------------------------------------------------------------------------------------ //
- // --- DUAL LANGUAGE --- POLISH & ENGLISH --- SET IN MACRO in MAIN PROJECT --- TRANSLATE in GOOGLE --- :-) --- //
- // ------------------------------------------------------------------------------------------------------------ //
- void WeatherShow()
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[API] [Weather] City : %s"), ptrWeather->city);
- PRINT(F("\n[API] [Weather] Country : %s"), ptrWeather->country);
- PRINT(F("\n[API] [Weather] TZ ID : %s"), ptrWeather->tz_id);
- PRINT(F("\n[API] [Weather] Latitude : %0.2f"), ptrWeather->lat);
- PRINT(F("\n[API] [Weather] Longitude : %0.2f"), ptrWeather->lon);
- PRINT(F("\n[API] [Weather] Epoch Time : %d"), ptrWeather->localtime_epoch);
- PRINT(F("\n[API] [Weather] Localtime : %s"), ptrWeather->localtime);
- PRINT(F("\n[API] [Weather] Last Updade : %s"), ptrWeather->last_updated);
- PRINT(F("\n[API] [Weather] Temp C : %0.2f"), ptrWeather->temp_c);
- PRINT(F("\n[API] [Weather] Temp feel C : %0.2f"), ptrWeather->feelslike_c);
- PRINT(F("\n[API] [Weather] Temp F : %0.2f"), ptrWeather->temp_f);
- PRINT(F("\n[API] [Weather] Temp feel F : %0.2f"), ptrWeather->feelslike_f);
- PRINT(F("\n[API] [Weather] Condition EN : %s"), ptrWeather->condition_en);
- PRINT(F("\n[API] [Weather] Condition PL : %s"), ptrWeather->condition_pl);
- PRINT(F("\n[API] [Weather] icon : %s"), ptrWeather->icon);
- PRINT(F("\n[API] [Weather] icon code : %d"), ptrWeather->code);
- PRINT(F("\n[API] [Weather] Wind speed kph : %0.2f"), ptrWeather->wind_kph);
- PRINT(F("\n[API] [Weather] Wind gust kph : %0.2f"), ptrWeather->gust_kph);
- PRINT(F("\n[API] [Weather] Wind speed mph : %0.2f"), ptrWeather->wind_mph);
- PRINT(F("\n[API] [Weather] Wind gust mph : %0.2f"), ptrWeather->gust_mph);
- PRINT(F("\n[API] [Weather] Wind degree : %d"), ptrWeather->wind_degree);
- PRINT(F("\n[API] [Weather] Wind dir : %s"), ptrWeather->wind_dir);
- PRINT(F("\n[API] [Weather] Pressure mb : %d"), ptrWeather->pressure_mb);
- PRINT(F("\n[API] [Weather] Pressure in : %0.2f"), ptrWeather->pressure_in);
- PRINT(F("\n[API] [Weather] Precip mm : %0.2f"), ptrWeather->precip_mm);
- PRINT(F("\n[API] [Weather] Precip in : %0.2f"), ptrWeather->precip_in);
- PRINT(F("\n[API] [Weather] Humidity : %d"), ptrWeather->humidity);
- PRINT(F("\n[API] [Weather] Cloud : %d"), ptrWeather->cloud);
- PRINT(F("\n[API] [Weather] Vis km : %0.2f"), ptrWeather->vis_km);
- PRINT(F("\n[API] [Weather] Vis miles : %0.2f"), ptrWeather->vis_miles);
- PRINT(F("\n"));
- #endif
- #if POLISH
- PRINT(F("\n[API] [Weather] City : %s"), ptrWeather->city);
- PRINT(F("\n[API] [Weather] Country : %s"), ptrWeather->country);
- PRINT(F("\n[API] [Weather] TZ ID : %s"), ptrWeather->tz_id);
- PRINT(F("\n[API] [Weather] Latitude : %0.2f"), ptrWeather->lat);
- PRINT(F("\n[API] [Weather] Longitude : %0.2f"), ptrWeather->lon);
- PRINT(F("\n[API] [Weather] Epoch Time : %d"), ptrWeather->localtime_epoch);
- PRINT(F("\n[API] [Weather] Localtime : %s"), ptrWeather->localtime);
- PRINT(F("\n[API] [Weather] Last Updade : %s"), ptrWeather->last_updated);
- PRINT(F("\n[API] [Weather] Temp C : %0.2f"), ptrWeather->temp_c);
- PRINT(F("\n[API] [Weather] Temp feel C : %0.2f"), ptrWeather->feelslike_c);
- PRINT(F("\n[API] [Weather] Temp F : %0.2f"), ptrWeather->temp_f);
- PRINT(F("\n[API] [Weather] Temp feel F : %0.2f"), ptrWeather->feelslike_f);
- PRINT(F("\n[API] [Weather] Condition EN : %s"), ptrWeather->condition_en);
- PRINT(F("\n[API] [Weather] Condition PL : %s"), ptrWeather->condition_pl);
- PRINT(F("\n[API] [Weather] icon : %s"), ptrWeather->icon);
- PRINT(F("\n[API] [Weather] icon code : %d"), ptrWeather->code);
- PRINT(F("\n[API] [Weather] Wind speed kph : %0.2f"), ptrWeather->wind_kph);
- PRINT(F("\n[API] [Weather] Wind gust kph : %0.2f"), ptrWeather->gust_kph);
- PRINT(F("\n[API] [Weather] Wind speed mph : %0.2f"), ptrWeather->wind_mph);
- PRINT(F("\n[API] [Weather] Wind gust mph : %0.2f"), ptrWeather->gust_mph);
- PRINT(F("\n[API] [Weather] Wind degree : %d"), ptrWeather->wind_degree);
- PRINT(F("\n[API] [Weather] Wind dir : %s"), ptrWeather->wind_dir);
- PRINT(F("\n[API] [Weather] Pressure mb : %d"), ptrWeather->pressure_mb);
- PRINT(F("\n[API] [Weather] Pressure in : %0.2f"), ptrWeather->pressure_in);
- PRINT(F("\n[API] [Weather] Precip mm : %0.2f"), ptrWeather->precip_mm);
- PRINT(F("\n[API] [Weather] Precip in : %0.2f"), ptrWeather->precip_in);
- PRINT(F("\n[API] [Weather] Humidity : %d"), ptrWeather->humidity);
- PRINT(F("\n[API] [Weather] Cloud : %d"), ptrWeather->cloud);
- PRINT(F("\n[API] [Weather] Vis km : %0.2f"), ptrWeather->vis_km);
- PRINT(F("\n[API] [Weather] Vis miles : %0.2f"), ptrWeather->vis_miles);
- PRINT(F("\n"));
- #endif
- #endif
- }
- // ------------------------------------------------------------------------------------------------------------ //
- void ptrAstronomyMalloc()
- {
- if (!F_ptrAstronomy)
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
- PRINT(F("\n[ESP] [Weather Malloc] i try allocate memory in RAM for struct -> Astronomy"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
- PRINT(F("\n[ESP] [Weather Malloc] próba alokacji pamięci RAM dla struktury -> Astronomy"));
- #endif
- #endif
- ptrAstronomy = ( struct Astronomy * ) malloc ( sizeof (struct Astronomy) );
- F_ptrAstronomy = true;
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
- PRINT(F("\n[ESP] [Weather Malloc] allocate memory in RAM for struct Astronomy sucefull\n"));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
- PRINT(F("\n[ESP] [Weather Malloc] alokakacji pamięci RAM dla struktury -> Astronomy UDANA\n"));
- #endif
- #endif
- }
- }
- // ------------------------------------------------------------------------------------------------------------ //
- void ptrAstronomyFree()
- {
- if (F_ptrAstronomy)
- {
- free(ptrAstronomy);
- F_ptrAstronomy = false;
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [Astronomy Malloc] delete [ptrAstronomy] from RAM memory ..."));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [Astronomy Malloc] usunięto [ptrAstronomy] z pamięci RAM ..."));
- #endif
- #endif
- }
- else
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [Astronomy] cannot be deleted [ptrAstronomy] does not exist !!! "));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [Astronomy] nie można usunąć [ptrAstronomy] nie isnieje w pamięci RAM ..."));
- #endif
- #endif
- }
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // Display weather icon (sun/night) - load file *.jpg from SPIFF memory --------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- // Wyświetla ikonę pogody (dzień/noc) - plik *.jpg ładowany z pamięci SPIFF ----------------------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- void TFT_WeatherIconShow()
- {
- byte pos_x = 1; // współrzędna ekranu -> x
- byte pos_y = 60; // współrzędna ekranu -> y
- switch(ptrWeather->code)
- {
- case 1000 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s00.jpg", pos_x, pos_y); // clear sun
- }
- else
- {
- drawJpeg("/weather/150m00.jpg", pos_x, pos_y); // clear moon
- }
- break;
- }
- case 1003 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s01.jpg", pos_x, pos_y); // Partly cloudy sun (Test OK) rozmiar 150x150
- }
- else
- {
- drawJpeg("/weather/150m01.jpg", pos_x, pos_y); // Partly cloudy moon (Test OK) rozmiar 150x150
- }
- break;
- }
- case 1006 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s02.jpg", pos_x, pos_y); // cloudy sun (Test OK) rozmiar 150x150
- }
- else
- {
- drawJpeg("/weather/150m02.jpg", pos_x, pos_y); // cloudy moon (Test OK) rozmiar 150x150
- }
- break;
- }
- case 1009 : {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150ovc.jpg", pos_x, pos_y); // overcast (Tesk OK) rozmiar 150x150
- }
- else
- {
- drawJpeg("/weather/150ovc.jpg", pos_x, pos_y); // overcast (Tesk OK) rozmiar 150x150
- }
- break;
- }
- case 1030 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s10.jpg", pos_x, pos_y); // mist (day) mgła dzień
- }
- else
- {
- drawJpeg("/weather/150m10.jpg", pos_x, pos_y); // mist (night) mgła noc
- }
- break;
- }
- case 1063 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s10.jpg", pos_x, pos_y); // Patchy rain possible
- }
- else
- {
- drawJpeg("/weather/150m10.jpg", pos_x, pos_y); // Patchy rain possible
- }
- break;
- }
- case 1066 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150dps.jpg", pos_x, pos_y); // Patchy snow possible (day) 150x150
- }
- else
- {
- drawJpeg("/weather/150mps.jpg", pos_x, pos_y); // Patchy snow possible (night) 150x150
- }
- break;
- }
- case 1069 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150dps.jpg", pos_x, pos_y); // Patchy sleet possible (day) 150x150
- }
- else
- {
- drawJpeg("/weather/150mps.jpg", pos_x, pos_y); // Patchy sleet possible (night) 150x150
- }
- break;
- }
- case 1072 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150dmm.jpg", pos_x, pos_y); // Patchy freezing drizzle possible (day) 150x150
- }
- else
- {
- drawJpeg("/weather/150nmm.jpg", pos_x, pos_y); // Patchy freezing drizzle possible (night) 150x150
- }
- break;
- }
- case 1087 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150sth.jpg", pos_x, pos_y); // thunder possible 150x150
- }
- else
- {
- drawJpeg("/weather/150mth.jpg", pos_x, pos_y); // thunder possible 150x150
- }
- break;
- }
- case 1114 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150dmm.jpg", pos_x, pos_y); // // Blowing snow 150x150
- }
- else
- {
- drawJpeg("/weather/150nmm.jpg", pos_x, pos_y); // // Blowing snow 150x150
- }
- break;
- }
- case 1117 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150zss.jpg", pos_x, pos_y); // blizzard 150x150
- }
- else
- {
- drawJpeg("/weather/150zss.jpg", pos_x, pos_y); // blizzard 150x150
- }
- break;
- }
- case 1135 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s10.jpg", pos_x, pos_y); // mist (day) mgła dzień 150x150
- }
- else
- {
- drawJpeg("/weather/150m10.jpg", pos_x, pos_y); // mist (night) mgła noc 150x150
- }
- break;
- }
- case 1147 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s10.jpg.jpg", pos_x, pos_y); // mist (day) mgła dzień 150x150
- }
- else
- {
- drawJpeg("/weather/150m10.jpg", pos_x, pos_y); // mist (night) mgła noc 150x150
- }
- break;
- }
- case 1150 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s04.jpg.jpg", pos_x, pos_y); // Patchy light drizzle 150x150
- }
- else
- {
- drawJpeg("/weather/150m04.jpg", pos_x, pos_y); // Patchy light drizzle 150x150
- }
- break;
- }
- case 1153 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s04.jpg.jpg", pos_x, pos_y); // light drizzle 150x150
- }
- else
- {
- drawJpeg("/weather/150m04.jpg", pos_x, pos_y); // light drizzle 150x150
- }
- break;
- }
- case 1168 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150dmm.jpg", pos_x, pos_y); // freezing drizzle possible (day) 150x150
- }
- else
- {
- drawJpeg("/weather/150nmm.jpg", pos_x, pos_y); // freezing drizzle possible (night) 150x150
- }
- break;
- }
- case 1171 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150mm.jpg", pos_x, pos_y); // Heavy freezing drizzle (day) 150x150
- }
- else
- {
- drawJpeg("/weather/150mm.jpg", pos_x, pos_y); // Heavy freezing drizzle (night) 150x150
- }
- break;
- }
- case 1180 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s04.jpg", pos_x, pos_y); // patchy rain at times
- }
- else
- {
- drawJpeg("/weather/150m04.jpg", pos_x, pos_y); // patchy rain at times
- }
- break;
- }
- case 1183 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s04.jpg", pos_x, pos_y); // light rain at times
- }
- else
- {
- drawJpeg("/weather/150m04.jpg", pos_x, pos_y); // light rain at times
- }
- break;
- }
- case 1186 : // Moderate rain at times
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s04.jpg", pos_x, pos_y); // Moderate rain at times
- }
- else
- {
- drawJpeg("/weather/150m04.jpg", pos_x, pos_y); // Moderate rain at times
- }
- break;
- }
- case 1189 : // Moderate rain
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s05.jpg", pos_x, pos_y); // Moderate rain
- }
- else
- {
- drawJpeg("/weather/150m05.jpg", pos_x, pos_y); // Moderate rain
- }
- break;
- }
- case 1192 : // Heavy rain at times
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s06.jpg", pos_x, pos_y); // Heavy rain at times
- }
- else
- {
- drawJpeg("/weather/150m06.jpg", pos_x, pos_y); // Heavy rain at times
- }
- break;
- }
- case 1195 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s06.jpg", pos_x, pos_y); // Heavy rain
- }
- else
- {
- drawJpeg("/weather/150m06.jpg", pos_x, pos_y); // Heavy rain
- }
- break;
- }
- case 1198 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s04.jpg", pos_x, pos_y); // light rain at times
- }
- else
- {
- drawJpeg("/weather/150m04.jpg", pos_x, pos_y); // light rain at times
- }
- break;
- }
- case 1201 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s07.jpg", pos_x, pos_y); // Moderate or heavy freezing rain
- }
- else
- {
- drawJpeg("/weather/150m07.jpg", pos_x, pos_y); // Moderate or heavy freezing rain
- }
- break;
- }
- case 1204 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s07.jpg", pos_x, pos_y); // Light sleet
- }
- else
- {
- drawJpeg("/weather/150m07.jpg", pos_x, pos_y); // Light sleet
- }
- break;
- }
- case 1207 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s07.jpg", pos_x, pos_y); // Moderate or heavy sleet
- }
- else
- {
- drawJpeg("/weather/150m07.jpg", pos_x, pos_y); // Moderate or heavy sleet
- }
- break;
- }
- case 1210 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150ss.jpg", pos_x, pos_y); // moderate snow
- }
- else
- {
- drawJpeg("/weather/150ms.jpg", pos_x, pos_y); // moderate snow
- }
- break;
- }
- case 1213 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150ss.jpg", pos_x, pos_y); // light snow
- }
- else
- {
- drawJpeg("/weather/150ms.jpg", pos_x, pos_y); // light snow
- }
- break;
- }
- case 1216 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150ss.jpg", pos_x, pos_y); // Patchy moderate snow
- }
- else
- {
- drawJpeg("/weather/150ms.jpg", pos_x, pos_y); // Patchy moderate snow
- }
- break;
- }
- case 1219 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150ss.jpg", pos_x, pos_y); // Moderate snow
- }
- else
- {
- drawJpeg("/weather/150ms.jpg", pos_x, pos_y); // Moderate snow
- }
- break;
- }
- case 1222 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150snow.jpg", pos_x, pos_y); // Patchy heavy snow
- }
- else
- {
- drawJpeg("/weather/150snow.jpg", pos_x, pos_y); // Patchy heavy snow
- }
- break;
- }
- case 1225 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150snow.jpg", pos_x, pos_y); // heavy snow
- }
- else
- {
- drawJpeg("/weather/150snow.jpg", pos_x, pos_y); // heavy snow
- }
- break;
- }
- case 1237 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150snow.jpg", pos_x, pos_y); // Ice pellets
- }
- else
- {
- drawJpeg("/weather/150snow.jpg", pos_x, pos_y); // Ice pellets
- }
- break;
- }
- case 1240 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s04.jpg", pos_x, pos_y); // light rain shower
- }
- else
- {
- drawJpeg("/weather/150m04.jpg", pos_x, pos_y); // light rain shower
- }
- break;
- }
- case 1243 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s06.jpg", pos_x, pos_y); // "Moderate or heavy rain shower"
- }
- else
- {
- drawJpeg("/weather/150m06.jpg", pos_x, pos_y); // "Moderate or heavy rain shower"
- }
- break;
- }
- case 1246 : // Torrential rain shower
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150s06.jpg", pos_x, pos_y); // Torrential rain shower
- }
- else
- {
- drawJpeg("/weather/150m06.jpg", pos_x, pos_y); // Torrential rain shower
- }
- break;
- }
- case 1249 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150ss.jpg", pos_x, pos_y); // Light sleet showers
- }
- else
- {
- drawJpeg("/weather/150ms.jpg", pos_x, pos_y); // Light sleet showers
- }
- break;
- }
- case 1252 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150ss.jpg", pos_x, pos_y); // Moderate or heavy sleet showers
- }
- else
- {
- drawJpeg("/weather/150ms.jpg", pos_x, pos_y); // Moderate or heavy sleet showers
- }
- break;
- }
- case 1255 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150ss.jpg", pos_x, pos_y); // Light snow showers
- }
- else
- {
- drawJpeg("/weather/150ms.jpg", pos_x, pos_y); // Light snow showers
- }
- break;
- }
- case 1258 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150ss.jpg", pos_x, pos_y); // Moderate or heavy snow showers
- }
- else
- {
- drawJpeg("/weather/150ms.jpg", pos_x, pos_y); // Moderate or heavy snow showers
- }
- break;
- }
- case 1261 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150ss.jpg", pos_x, pos_y); // Light showers of ice pellets
- }
- else
- {
- drawJpeg("/weather/150ms.jpg", pos_x, pos_y); // Light showers of ice pellets
- }
- break;
- }
- case 1264 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150ss.jpg", pos_x, pos_y); // Moderate or heavy showers of ice pellets
- }
- else
- {
- drawJpeg("/weather/150ms.jpg", pos_x, pos_y); // Moderate or heavy showers of ice pellets
- }
- break;
- }
- case 1273 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150dprt.jpg", pos_x, pos_y); // Patchy light rain with thunder
- }
- else
- {
- drawJpeg("/weather/1150nprt.jpg", pos_x, pos_y); // Patchy light rain with thunder
- }
- break;
- }
- case 1276 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150srt01.jpg", pos_x, pos_y); // rain and thunder
- }
- else
- {
- drawJpeg("/weather/150mrt01.jpg", pos_x, pos_y); // rain and thunder
- }
- break;
- }
- case 1279 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150srt01.jpg", pos_x, pos_y); // Patchy light snow with thunder
- }
- else
- {
- drawJpeg("/weather/150mrt01.jpg", pos_x, pos_y); // Patchy light snow with thunder
- }
- break;
- }
- case 1282 :
- {
- if (myRTC.hours > 7 && myRTC.hours < 20)
- {
- drawJpeg("/weather/150srt01.jpg", pos_x, pos_y); // Moderate or heavy snow with thunder
- }
- else
- {
- drawJpeg("/weather/150mrt01.jpg", pos_x, pos_y); // Moderate or heavy snow with thunder
- }
- break;
- }
- }
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // --- ASTRONOMY SHOW FROM BUFFOR in RAM --- //
- // ------------------------------------------------------------------------------------------------------------ //
- // --- DUAL LANGUAGE --- POLISH & ENGLISH --- SET IN MACRO in MAIN PROJECT --- TRANSLATE in GOOGLE --- :-) --- //
- // ------------------------------------------------------------------------------------------------------------ //
- void AstronomyShow()
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[API] [Astronomy] City : %s"), ptrAstronomy->city);
- PRINT(F("\n[API] [Astronomy] Country : %s"), ptrAstronomy->country);
- PRINT(F("\n[API] [Astronomy] TZ ID : %s"), ptrAstronomy->tz_id);
- PRINT(F("\n[API] [Astronomy] Latitude : %0.2f"), ptrAstronomy->lat);
- PRINT(F("\n[API] [Astronomy] Longitude : %0.2f"), ptrAstronomy->lon);
- PRINT(F("\n[API] [Astronomy] Epoch Time : %d"), ptrAstronomy->localtime_epoch);
- PRINT(F("\n[API] [Astronomy] Localtime : %s"), ptrAstronomy->localtime);
- PRINT(F("\n[API] [Astronomy] Sunrise : %s"), ptrAstronomy->sunrise);
- PRINT(F("\n[API] [Astronomy] Sunset : %s"), ptrAstronomy->sunset);
- PRINT(F("\n[API] [Astronomy] Moonrise : %s"), ptrAstronomy->moonrise);
- PRINT(F("\n[API] [Astronomy] Moonset : %s"), ptrAstronomy->moonset);
- PRINT(F("\n[API] [Astronomy] Moon Phase : %s"), ptrAstronomy->moon_phase);
- PRINT(F("\n[API] [Astronomy] Illumination : %d"), ptrAstronomy->moon_illumination);
- PRINT(F("\n"));
- #endif
- #if POLISH
- PRINT(F("\n[API] [Astronomy] City : %s"), ptrAstronomy->city);
- PRINT(F("\n[API] [Astronomy] Country : %s"), ptrAstronomy->country);
- PRINT(F("\n[API] [Astronomy] TZ ID : %s"), ptrAstronomy->tz_id);
- PRINT(F("\n[API] [Astronomy] Latitude : %0.2f"), ptrAstronomy->lat);
- PRINT(F("\n[API] [Astronomy] Longitude : %0.2f"), ptrAstronomy->lon);
- PRINT(F("\n[API] [Astronomy] Epoch Time : %d"), ptrAstronomy->localtime_epoch);
- PRINT(F("\n[API] [Astronomy] Localtime : %s"), ptrAstronomy->localtime);
- PRINT(F("\n[API] [Astronomy] Sunrise : %s"), ptrAstronomy->sunrise);
- PRINT(F("\n[API] [Astronomy] Sunset : %s"), ptrAstronomy->sunset);
- PRINT(F("\n[API] [Astronomy] Moonrise : %s"), ptrAstronomy->moonrise);
- PRINT(F("\n[API] [Astronomy] Moonset : %s"), ptrAstronomy->moonset);
- PRINT(F("\n[API] [Astronomy] Moon Phase : %s"), ptrAstronomy->moon_phase);
- PRINT(F("\n[API] [Astronomy] Illumination : %d"), ptrAstronomy->moon_illumination);
- PRINT(F("\n"));
- #endif
- #endif
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // --- ASTRONOMY UPDATE --- CREATE BUFFOR in RAM --- COPY DATA to STRUCT in RAM --- by TRANSLINE ------- //
- // ------------------------------------------------------------------------------------------------------------ //
- // --- DUAL LANGUAGE --- POLISH & ENGLISH --- SET IN MACRO in MAIN PROJECT --- TRANSLATE in GOOGLE --- :-) --- //
- // ------------------------------------------------------------------------------------------------------------ //
- void AstronomyUpdate()
- {
- if (!F_ptrAstronomy) ptrAstronomyMalloc(); // jesli pamięć nie utworzona stwórz ją w PSRAM
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[Astronomy Update] Try Downloading JSON File from https://api.weatherapi.com/"));
- #endif
- #if POLISH
- PRINT(F("\n[Astronomy Update] Próbuję pobrać plik JSON z https://api.weatherapi.com/"));
- #endif
- #endif
- #if ENGLISH
- String path = "http://api.weatherapi.com/v1/astronomy.json?key=" + PogodaToken + "&q=" + PogodaMiasto;
- #endif
- #if POLISH
- String path = "http://api.weatherapi.com/v1/astronomy.json?key=" + PogodaToken + "&q=" + PogodaMiasto;
- #endif
- HTTPClient http;
- http.useHTTP10(true);
- http.begin(client, path);
- http.GET();
- DynamicJsonDocument doc(1024);
- DeserializationError error = deserializeJson(doc, http.getStream());
- if(error)
- {
- F_AstronomyUpdate = false; // aktualizacja nie powiodła się
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[Astronomy Update] DeserializeJson() failed: "));
- Serial.println(error.c_str());
- #endif
- #if POLISH
- PRINT(F("\n[Astronomy Update] DeserializeJson() error: "));
- Serial.println(error.c_str());
- #endif
- #endif
- }
- else
- {
- F_AstronomyUpdate = true; // aktualizacja w porządku !!!
- }
- http.end();
- if(F_AstronomyUpdate)
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [Astronomy Update] JsonDocument Usage Memory : %s bytes"), String(doc.memoryUsage()));
- PRINT(F("\n[ESP] [Astronomy Update] [FREE RAM] : %d kB\n"), ESP.getFreeHeap());
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [Astronomy Update] JsonDocument zaalokował pamięć : %s bajtów"), String(doc.memoryUsage()));
- PRINT(F("\n[ESP] [Astronomy Update] [FREE RAM] : %d kB\n"), ESP.getFreeHeap());
- #endif
- #endif
- // --- update struct ASTRONOMY in PSRAM !!! -------------------------------------------------- //
- strcpy(ptrAstronomy->sunrise, doc["astronomy"]["astro"]["sunrise"].as<String>().c_str());
- strcpy(ptrAstronomy->sunset, doc["astronomy"]["astro"]["sunset"].as<String>().c_str());
- sunrise = doc["astronomy"]["astro"]["sunrise"].as<String>();
- sunset = doc["astronomy"]["astro"]["sunset"].as<String>();
- strcpy(ptrAstronomy->moonrise, doc["astronomy"]["astro"]["moonrise"].as<String>().c_str());
- moonrise = doc["astronomy"]["astro"]["moonrise"].as<String>();
- moonset = doc["astronomy"]["astro"]["moonset"].as<String>();
- strcpy(ptrAstronomy->moonset, doc["astronomy"]["astro"]["moonset"].as<String>().c_str());
- strcpy(ptrAstronomy->moon_phase, doc["astronomy"]["astro"]["moon_phase"].as<String>().c_str());
- moon_phase = doc["astronomy"]["astro"]["moon_phase"].as<String>();
- ptrAstronomy->moon_illumination = doc["astronomy"]["astro"]["moon_illumination"];
- strcpy(ptrAstronomy->city, doc["location"]["name"].as<String>().c_str()); // nazwę miasta
- strcpy(ptrAstronomy->country, doc["location"]["country"].as<String>().c_str()); // nazwę kraju
- strcpy(ptrAstronomy->tz_id, doc["location"]["tz_id"].as<String>().c_str()); // kontynent/stolica
- ptrAstronomy->lat = doc["location"]["lat"].as<double>(); // szer.geograficzną
- ptrAstronomy->lon = doc["location"]["lon"].as<double>(); // dł.geograficzną
- strcpy(ptrAstronomy->localtime, doc["location"]["localtime"].as<String>().c_str()); // czas lokalny
- // --- update struct ASTRONOMY in PSRAM !!! -------------------------------------------------- //
- #if SERIAL
- if (F_AstronomyUpdate) AstronomyShow(); // pokaż jeśli SERIAl jest TRUE
- #endif
- }
- }
- // ------------------------------------------------------------------------------------------------------------ //
- void ptrAirMalloc()
- {
- if (!F_ptrAir)
- {
- #if SERIAL
- PRINT(F("\n[ESP] [Air Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
- PRINT(F("\n[ESP] [Air Malloc] i try allocate memory in RAM for struct Air"));
- #endif
- ptrAir = ( struct Air * ) malloc ( sizeof (struct Air) );
- F_ptrAstronomy = true;
- #if SERIAL
- PRINT(F("\n[ESP] [Air Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
- PRINT(F("\n[ESP] [Air Malloc] allocate memory in RAM for struct Air sucefull\n"));
- #endif
- }
- }
- // ------------------------------------------------------------------------------------------------------------ //
- void ptrAirFree()
- {
- if (F_ptrAir)
- {
- free(ptrAir);
- F_ptrAir = false;
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [Air Malloc] delete [ptrAir] from RAM memory ..."));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [Air Malloc] usunięto [ptrAir] z pamięci RAM ..."));
- #endif
- #endif
- }
- else
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [Air] cannot be deleted [ptrAir] does not exist !!! "));
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [Air] nie można usunąć [ptrAir] nie isnieje w pamięci RAM ..."));
- #endif
- #endif
- }
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // --- Air SHOW FROM BUFFOR in PSRAM --- //
- // ------------------------------------------------------------------------------------------------------------ //
- // --- DUAL LANGUAGE --- POLISH & ENGLISH --- SET IN MACRO in MAIN PROJECT --- TRANSLATE in GOOGLE --- :-) --- //
- // ------------------------------------------------------------------------------------------------------------ //
- void AirShow()
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[API] [Air Quality] CO : %2.3f [μg/ m3]"), ptrAir->co);
- PRINT(F("\n[API] [Air Quality] NO2 : %2.3f [μg/ m3]"), ptrAir->no2);
- PRINT(F("\n[API] [Air Quality] Ozon : %2.3f [μg/m3]"), ptrAir->o3);
- PRINT(F("\n[API] [Air Quality] PM2.5 : %2.3f [μm]"), ptrAir->pm25);
- PRINT(F("\n[API] [Air Quality] PM10 : %2.3f [μm]"), ptrAir->pm10);
- PRINT(F("\n[API] [Air Quality] Index DEFRA : %d DEFRA"), ptrAir->defra);
- PRINT(F("\n[API] [Air Quality] Index EPA : %d EPA"), ptrAir->epa);
- PRINT(F("\n[API] [Air Quality] Desciption : %s "), ptrAir->description);
- PRINT(F("\n"));
- #endif
- #if POLISH
- PRINT(F("\n[API] [Jakość Powietrza] Tlenek węgla \t\t: %2.3f [μg/ m3]"), ptrAir->co);
- PRINT(F("\n[API] [Jakość Powietrza] Dwutlenek azotu \t: %2.3f [μg/ m3]"), ptrAir->no2);
- PRINT(F("\n[API] [Jakość Powietrza] Ozon \t\t\t: %2.3f [μg/m3]"), ptrAir->o3);
- PRINT(F("\n[API] [Jakość Powietrza] Pyły i aerozole PM2.5 \t: %2.3f [μm]"), ptrAir->pm25);
- PRINT(F("\n[API] [Jakość Powietrza] Pyły i aerozole PM10 \t: %2.3f [μm]"), ptrAir->pm10);
- PRINT(F("\n[API] [Jakość Powietrza] Index jakości \t\t: %d DEFRA"), ptrAir->defra);
- PRINT(F("\n[API] [Jakość Powietrza] Index jakości \t\t: %d EPA"), ptrAir->epa);
- PRINT(F("\n[API] [Jakość Powietrza] Jakość powietrza \t: %s "), ptrAir->description);
- PRINT(F("\n"));
- #endif
- #endif
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // --- Air UPDATE --- CREATE BUFFOR in PSRAM --- COPY DATA to STRUCT Air in PSRAM --- by TRANSLINE ----------- //
- // ------------------------------------------------------------------------------------------------------------ //
- // --- DUAL LANGUAGE --- POLISH & ENGLISH --- SET IN MACRO in MAIN PROJECT --- TRANSLATE in GOOGLE --- :-) --- //
- // ------------------------------------------------------------------------------------------------------------ //
- void AirUpdate()
- {
- if (!F_ptrAir) ptrAirMalloc(); // jesli pamięć nie utworzona stwórz ją w PSRAM
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[Air Update] Try Downloading JSON File from https://api.weatherapi.com/"));
- #endif
- #if POLISH
- PRINT(F("\n[Air Update] Próbuję pobrać plik JSON z https://api.weatherapi.com/"));
- #endif
- #endif
- #if ENGLISH
- String path = "http://api.weatherapi.com/v1/current.json?key=" + PogodaToken + "&q=" + PogodaMiasto + "&aqi=yes";
- #endif
- #if POLISH
- String path = "http://api.weatherapi.com/v1/current.json?key=" + PogodaToken + "&q=" + PogodaMiasto + "&aqi=yes";
- #endif
- HTTPClient http;
- http.useHTTP10(true);
- http.begin(client, path);
- http.GET();
- DynamicJsonDocument doc(2048);
- DeserializationError error = deserializeJson(doc, http.getStream());
- if(error)
- {
- F_AirUpdate = false; // aktualizacja nie powiodła się
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[Air Update] DeserializeJson() failed: "));
- Serial.println(error.c_str());
- #endif
- #if POLISH
- PRINT(F("\n[Air Update] DeserializeJson() error: "));
- Serial.println(error.c_str());
- #endif
- #endif
- }
- else
- {
- F_AirUpdate = true;
- }
- http.end();
- if(F_AirUpdate)
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[ESP] [Air Update] JsonDocument Usage Memory : %s bytes"), String(doc.memoryUsage()));
- PRINT(F("\n[ESP] [Air Update] [FREE RAM] : %d kB\n"), ESP.getFreeHeap());
- #endif
- #if POLISH
- PRINT(F("\n[ESP] [Air Update] JsonDocument zaalokował pamięć : %s bajtów"), String(doc.memoryUsage()));
- PRINT(F("\n[ESP] [Air Update] [FREE RAM] : %d kB\n"), ESP.getFreeHeap());
- #endif
- #endif
- // --- update struct Air in PSRAM !!! -------------------------------------------------- //
- ptrAir->co = doc["current"]["air_quality"]["co"].as<double>();
- ptrAir->o3 = doc["current"]["air_quality"]["o3"].as<double>();
- ptrAir->no2 = doc["current"]["air_quality"]["no2"].as<double>();
- ptrAir->so2 = doc["current"]["air_quality"]["so2"].as<double>();
- ptrAir->pm25 = doc["current"]["air_quality"]["pm2_5"].as<double>();
- ptrAir->pm10 = doc["current"]["air_quality"]["pm10"].as<double>();
- ptrAir->defra = doc["current"]["air_quality"]["gb-defra-index"];
- ptrAir->epa = doc["current"]["air_quality"]["us-epa-index"];
- switch (ptrAir->epa)
- {
- #if POLISH
- case 1: strcpy(ptrAir->description, "dobra"); break;
- case 2: strcpy(ptrAir->description, "umiarkowana"); break;
- case 3: strcpy(ptrAir->description, "niezdrowa dla alergików"); break;
- case 4: strcpy(ptrAir->description, "niezdrowa"); break;
- case 5: strcpy(ptrAir->description, "bardzo niezdrowa"); break;
- case 6: strcpy(ptrAir->description, "niebezpieczna"); break;
- default : strcpy(ptrAir->description, "błąd parsowania"); break;
- #endif
- #if ENGLISH
- case 1: strcpy(ptrAir->description, "good"); break;
- case 2: strcpy(ptrAir->description, "moderate"); break;
- case 3: strcpy(ptrAir->description, "unhealthy for allergy sufferers"); break;
- case 4: strcpy(ptrAir->description, "unhealthy"); break;
- case 5: strcpy(ptrAir->description, "very unhealthy"); break;
- case 6: strcpy(ptrAir->description, "dangerous"); break;
- default : strcpy(ptrAir->description, "parsing error"); break;
- #endif
- }
- // --- update struct Air in PSRAM !!! -------------------------------------------------- //
- #if SERIAL
- if (F_AirUpdate) AirShow(); // pokaż jeśli SERIAl jest TRUE
- #endif
- }
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // --- W E A T H E R E N D S E C T I O N ------------------------------------------------------------------ //
- // ------------------------------------------------------------------------------------------------------------ //
- //
- //
- //
- //
- //
- // ------------------------------------------------------------------------------------------------------------ //
- // --- Opens the image file and prime the Jpeg decoder -------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- // --- Otwiera plik obrazu i uruchamia dekoder JPEG ----------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- void listFiles(void)
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n\n====================================================================="));
- PRINT(F("SPIFFS files found:"));
- PRINT(F("\n File name Size"));
- PRINT(F("\n\n=====================================================================\n"));
- #endif
- #if POLISH
- PRINT(F("\n\n====================================================================="));
- PRINT(F("SPIFFS odnalezione pliki:"));
- PRINT(F("\n Nazwa pliku Rozmiar"));
- PRINT(F("\n\n=====================================================================\n"));
- #endif
- #endif
- fs::Dir dir = SPIFFS.openDir("/"); // Root directory
- String line = "=====================================================================";
- while (dir.next())
- {
- String fileName = dir.fileName();
- Serial.print(fileName);
- int spaces = 25 - fileName.length(); // Tabulate nicely
- while (spaces--) PRINT(F(" "));
- fs::File f = dir.openFile("r");
- Serial.print(f.size());
- #if SERIAL
- #if ENGLISH
- PRINT(F(" bytes"));
- #endif
- #if POLISH
- PRINT(F(" bajtów"));
- #endif
- #endif
- Serial.println();
- }
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // --- replace minimum in JPEGDecoder !!! error in compilation ------------------------------------------------ //
- // ------------------------------------------------------------------------------------------------------------ //
- #define minimum(a,b) (((a) < (b)) ? (a) : (b))
- // ------------------------------------------------------------------------------------------------------------ //
- // --- Opens the image file and prime the Jpeg decoder -------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- // --- Otwiera plik obrazu i uruchamia dekoder JPEG ----------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- void drawJpeg(const char *filename, int xpos, int ypos)
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n\n====================================================================="));
- PRINT(F("\n[JPEG DECODER] [INFO] Drawing file: %s"), filename);
- #endif
- #if POLISH
- PRINT(F("\n\n====================================================================="));
- PRINT(F("\nJPEG DECODER] [INFO] Wyświetlam plik: %s"), filename);
- #endif
- #endif
- fs::File jpegFile = SPIFFS.open( filename, "r");
- if ( !jpegFile )
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[JPEG DECODER] [ERROR] File: %s not found!"), filename);
- #endif
- #if POLISH
- PRINT(F("\n[JPEG DECODER] [ERROR] Plik: %s nie znaleziony!"), filename);
- #endif
- #endif
- return;
- }
- // ------------------------------------------------------------------------------------------------------------------- //
- // Use one of the three following methods to initialise the decoder: //
- // boolean decoded = JpegDec.decodeFsFile(jpegFile); // Pass a SPIFFS file handle to the decoder, //
- // boolean decoded = JpegDec.decodeSdFile(jpegFile); // or pass the SD file handle to the decoder, //
- // boolean decoded = JpegDec.decodeFsFile(filename); // pass the filename (leading / distinguishes SPIFFS files) //
- // ------------------------------------------------------------------------------------------------------------------- //
- boolean decoded = JpegDec.decodeFsFile(filename); // pass the filename (leading / distinguishes SPIFFS files)
- if (decoded)
- {
- //jpegInfo(); // print information about the image to the serial port
- jpegRender(xpos, ypos); // render the image onto the screen at given coordinates
- }
- else
- {
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n[JPEG DECODER] [ERROR] : Jpeg file format not supported!"));
- #endif
- #if POLISH
- PRINT(F("\n[JPEG DECODER] [ERROR] : Format pliku JPEG nie jest obsługiwany!"));
- #endif
- #endif
- }
- #if SERIAL
- Serial.printf("\n====================================================================="); // end line JPEG DECODER
- #endif
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // --- Decode and render the Jpeg image onto the TFT screen --------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- // --- Dekoduj i renderuj obraz JPEG na ekranie TFT ----------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- void jpegRender(int xpos, int ypos)
- {
- // ---------------------------------------------------------- //
- // retrieve infomration about the image //
- // ---------------------------------------------------------- //
- // pobrać informacje o obrazie //
- // ---------------------------------------------------------- //
- uint16_t *pImg;
- uint16_t mcu_w = JpegDec.MCUWidth;
- uint16_t mcu_h = JpegDec.MCUHeight;
- uint32_t max_x = JpegDec.width;
- uint32_t max_y = JpegDec.height;
- // --------------------------------------------------------------------------------------------- //
- // Jpeg images are draw as a set of image block (tiles) called Minimum Coding Units (MCUs) //
- // Typically these MCUs are 16x16 pixel blocks //
- // Determine the width and height of the right and bottom edge image blocks //
- // --------------------------------------------------------------------------------------------- //
- // Obrazy JPEG są rysowane jako zestaw bloków obrazu (kafelków) zwanych (MCU) //
- // zazwyczaj te MCU są blokami 16x16 pikseli //
- // Określ szerokość i wysokość bloków obrazu prawej i dolnej krawędzi //
- // --------------------------------------------------------------------------------------------- //
- uint32_t min_w = minimum(mcu_w, max_x % mcu_w);
- uint32_t min_h = minimum(mcu_h, max_y % mcu_h);
- // --------------------------------------------------------------------------------------------- //
- // save the current image block size //
- // --------------------------------------------------------------------------------------------- //
- // zapisz aktualny rozmiar bloku obrazu //
- // --------------------------------------------------------------------------------------------- //
- uint32_t win_w = mcu_w;
- uint32_t win_h = mcu_h;
- // --------------------------------------------------------------------------------------------- //
- // record the current time so we can measure how long it takes to draw an image //
- // --------------------------------------------------------------------------------------------- //
- // rejestruj aktualny czas, abyśmy mogli zmierzyć, ile czasu zajmuje narysowanie obrazu //
- // --------------------------------------------------------------------------------------------- //
- uint32_t drawTime = millis();
- // --------------------------------------------------------------------------------------------- //
- // save the coordinate of the right and bottom edges to assist image cropping //
- // to the screen size //
- // --------------------------------------------------------------------------------------------- //
- // zapisz współrzędne prawej i dolnej krawędzi, aby ułatwić przycinanie obrazu //
- // do rozmiaru ekranu //
- // --------------------------------------------------------------------------------------------- //
- max_x += xpos;
- max_y += ypos;
- // read each MCU block until there are no more
- #ifdef USE_SPI_BUFFER
- while ( JpegDec.readSwappedBytes()) {
- #else
- while ( JpegDec.read()) {
- #endif
- pImg = JpegDec.pImage;
- int mcu_x = JpegDec.MCUx * mcu_w + xpos;
- int mcu_y = JpegDec.MCUy * mcu_h + ypos;
- if ( mcu_y < tft.height() )
- {
- if (mcu_x + mcu_w <= max_x) win_w = mcu_w;
- else win_w = min_w;
- if (mcu_y + mcu_h <= max_y) win_h = mcu_h;
- else win_h = min_h;
- if (win_w != mcu_w)
- {
- for (int h = 1; h < win_h; h++)
- {
- memcpy(pImg + h * win_w, pImg + h * mcu_w, win_w << 1);
- }
- }
- tft.pushImage(mcu_x, mcu_y, win_w, win_h, pImg);
- }
- else
- {
- JpegDec.abort();
- }
- } // else makro
- drawTime = millis() - drawTime; // Calculate the time it took
- #if SERIAL
- #if ENGLISH
- PRINT(F("\n====================================================================="));
- PRINT(F("\n[JPEG DECODER] [INFO] Total render time was : %d ms"), drawTime);
- #endif
- #if POLISH
- PRINT(F("\n====================================================================="));
- PRINT(F("\n[JPEG DECODER] [INFO] Całkowity czas renderowania wynosił : %d ms"), drawTime);
- #endif
- #endif
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // --- Print information decoded from the Jpeg image ---------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- // --- Wydrukuj informacje odkodowane z obrazu JPEG ----------------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- void jpegInfo()
- {
- #if SERIAL
- PRINT(F("\n====================================================================="));
- PRINT(F("\n[JPEG DECODER] [JPEG image info]"));
- PRINT(F("\n====================================================================="));
- PRINT(F("\nWidth : %d"),JpegDec.width);
- PRINT(F("\nHeight : %d"),JpegDec.height);
- PRINT(F("\nComponents : %d"),JpegDec.comps);
- PRINT(F("\nMCU / row : %d"),JpegDec.MCUSPerRow);
- PRINT(F("\nMCU / col : %d"),JpegDec.MCUSPerCol);
- PRINT(F("\nScan type : %d"),JpegDec.scanType);
- PRINT(F("\nMCU width : %d"),JpegDec.MCUWidth);
- PRINT(F("\nMCU height : %d"),JpegDec.MCUHeight);
- #endif
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // --- Open a Jpeg file and send it to the Serial port in a C array compatible format ------------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- // --- Otwórz plik JPEG i wyślij go do portu szeregowego w formacie zgodnym z tablicą C ----------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- void createArray(const char *filename)
- {
- #if SERIAL
- Serial.printf("\n=====================================================================");
- Serial.printf("\n[JPEG DECODER] [JPEG ARRAY ENCODER] jpeg to array ");
- Serial.printf("\n=====================================================================");
- fs::File jpgFile = SPIFFS.open( filename, "r"); // File handle reference for SPIFFS
- // File jpgFile = SD.open( filename, FILE_READ); // or, file handle reference for SD library
- if ( !jpgFile )
- {
- Serial.print("ERROR: File \""); Serial.print(filename); Serial.println ("\" not found!");
- return;
- }
- uint8_t data;
- byte line_len = 0;
- while (*filename != '.') Serial.print(*filename++);
- Serial.println("[] PROGMEM = {"); // PROGMEM added for AVR processors, it is ignored by Due
- while ( jpgFile.available())
- {
- data = jpgFile.read();
- line_len++;
- if ( line_len >= 32) line_len = 0;
- }
- Serial.println("};\r\n");
- jpgFile.close();
- #endif
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // --- GET NAMEDAY --- POBIERZ kto obchodzi dziś imieniny ----------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- String GetNameday(byte m, byte d)
- {
- char buf[100];
- switch(m)
- {
- case 1 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_STYCZEN[d]))); break;
- case 2 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_LUTY[d]))); break;
- case 3 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_MARZEC[d]))); break;
- case 4 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_KWIECIEN[d]))); break;
- case 5 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_MAJ[d]))); break;
- case 6 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_CZERWIEC[d]))); break;
- case 7 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_LIPIEC[d]))); break;
- case 8 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_SIERPIEN[d]))); break;
- case 9 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_WRZESIEN[d]))); break;
- case 10 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_PAZDZIERNIK[d]))); break;
- case 11 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_LISTOPAD[d]))); break;
- case 12 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_GRUDZIEN[d]))); break;
- default : strcpy(buf, "ERROR"); break;
- }
- return(String(buf));
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // --- GET Event --- POBIERZ jakie dziś święto / wydarzenie --------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- String GetEvent(byte m, byte d)
- {
- char buf[150];
- switch(m)
- {
- case 1 : strcpy_P(buf, (char*) pgm_read_dword(&(STYCZEN[d]))); break;
- case 2 : strcpy_P(buf, (char*) pgm_read_dword(&(LUTY[d]))); break;
- case 3 : strcpy_P(buf, (char*) pgm_read_dword(&(MARZEC[d]))); break;
- case 4 : strcpy_P(buf, (char*) pgm_read_dword(&(KWIECIEN[d]))); break;
- case 5 : strcpy_P(buf, (char*) pgm_read_dword(&(MAJ[d]))); break;
- case 6 : strcpy_P(buf, (char*) pgm_read_dword(&(CZERWIEC[d]))); break;
- case 7 : strcpy_P(buf, (char*) pgm_read_dword(&(LIPIEC[d]))); break;
- case 8 : strcpy_P(buf, (char*) pgm_read_dword(&(SIERPIEN[d]))); break;
- case 9 : strcpy_P(buf, (char*) pgm_read_dword(&(WRZESIEN[d]))); break;
- case 10 : strcpy_P(buf, (char*) pgm_read_dword(&(PAZDZIERNIK[d]))); break;
- case 11 : strcpy_P(buf, (char*) pgm_read_dword(&(LISTOPAD[d]))); break;
- case 12 : strcpy_P(buf, (char*) pgm_read_dword(&(GRUDZIEN[d]))); break;
- default : strcpy(buf,"ERROR"); break;
- }
- return(String(buf));
- }
- // ------------------------------------------------------------------------------------------------------------ //
- // --- GET Event --- POBIERZ jakie dziś święto / wydarzenie --------------------------------------------------- //
- // ------------------------------------------------------------------------------------------------------------ //
- String GetSuperMsg(byte m, byte d)
- {
- String bufor = "ESP8266 Wiki Center";
- if (m==1)
- {
- switch (d)
- {
- case 1 : bufor = "Happy New Year"; break;
- default : bufor = "Sweet Home"; break;
- }
- }
- else
- if (m==2)
- {
- switch (d)
- {
- default : bufor = "Sweet Home"; break;
- }
- }
- else
- if (m==3)
- {
- switch (d)
- {
- default : bufor = "Sweet Home"; break;
- }
- }
- else
- if (m==4)
- {
- switch (d)
- {
- default : bufor = "Sweet Home"; break;
- }
- }
- else
- if (m==5)
- {
- switch (d)
- {
- case 16 : bufor = "Tomek's birthday"; break;
- default : bufor = "Sweet Home"; break;
- }
- }
- else
- if (m==6)
- {
- switch (d)
- {
- default : bufor = "Sweet Home"; break;
- }
- }
- else
- if (m==7)
- {
- switch (d)
- {
- default : bufor = "Sweet Home"; break;
- }
- }
- else
- if (m==8)
- {
- switch (d)
- {
- default : bufor = "Sweet Home"; break;
- }
- }
- else
- if (m==9)
- {
- switch (d)
- {
- case 1 : bufor = "Festival of Knowledge"; break;
- case 3 : bufor = "Viking 2 on Mars"; break;
- case 14 : bufor = "Gravitational Waves"; break;
- case 15 : bufor = "Albatros is flying"; break;
- case 16 : bufor = "PZL M-20 Mewa flying"; break;
- case 17 : bufor = "Soyuz T-14 launch"; break;
- default : bufor = "ESP8266 Wiki Center"; break;
- }
- }
- else
- if (m==10)
- {
- switch (d)
- {
- case 7 : bufor = "Marcin's birthday"; break;
- default : bufor = "Sweet Home"; break;
- }
- }
- else
- if (m==11)
- {
- switch (d)
- {
- case 3 : bufor = "Sylwia's birthday"; break;
- default : bufor = "Sweet Home"; break;
- }
- }
- else
- if (m==12)
- {
- switch (d)
- {
- default : bufor = "Sweet Home"; break;
- }
- }
- return bufor;
- }
- //---- END----------------//
Add Comment
Please, Sign In to add comment