From 65e6d883d4e481941dcbd7065c1f785c79636bed Mon Sep 17 00:00:00 2001 From: choelzl Date: Tue, 3 May 2022 20:07:39 +0200 Subject: [PATCH] [m] Fixed & Cleanup & env.h --- env.h.default | 24 ++++++++++++++++++++++++ metesp.ino | 23 ++++++++++++++--------- src/display/display.cpp | 18 +++++++++++------- src/display/display.h | 1 + src/ntp/ntp.cpp | 8 ++++++++ src/touch/gt1151.cpp | 1 + 6 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 env.h.default diff --git a/env.h.default b/env.h.default new file mode 100644 index 0000000..25fc134 --- /dev/null +++ b/env.h.default @@ -0,0 +1,24 @@ +#ifndef TG_ENV_H +#define TG_ENV_H + +#define INFLUXDB_URL "https://influx.net" +#define INFLUXDB_TOKEN "LONG_TOKEN==" +#define INFLUXDB_ORG "ORG" +#define INFLUXDB_BUCKET "BUCKET" + + +#define NTP_URL "ch.pool.ntp.org" + +#define LOCATION_0 "Zurich,ch" +#define LOCATION_1 "Oslo,no" +#define LOCATION_2 "Tokyo,jp" +#define LOCATION_3 "Moscow,ru" +#define OPENWEATHER_API "API_KEY" + +#define WIFI_REGISTER_AP(wm) \ + do { \ + wifiMulti.addAP("SSID1", "PASS1"); \ + wifiMulti.addAP("SSID2", "PASS2"); \ + }while(0) + +#endif \ No newline at end of file diff --git a/metesp.ino b/metesp.ino index 7ecdece..a004460 100644 --- a/metesp.ino +++ b/metesp.ino @@ -150,11 +150,12 @@ void setup_TIMEDFUN() { } void setup_POWER() { - esp_sleep_enable_gpio_wakeup(); gpio_wakeup_enable(GPIO_NUM_15,GPIO_INTR_HIGH_LEVEL); - // esp_sleep_enable_ext0_wakeup(GPIO_NUM_15, 1); + esp_sleep_enable_gpio_wakeup(); esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); - esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO,ESP_PD_OPTION_ON); + + // esp_sleep_enable_ext0_wakeup(GPIO_NUM_15, 1); + // esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO,ESP_PD_OPTION_ON); } @@ -162,11 +163,11 @@ void setup_POWER() { void setup(){ Serial.begin(115200); I2C.begin(PIN_SDA, PIN_SCL); - I2C.setPins(PIN_SDA,PIN_SCL); setup_POWER(); Display::setup(); setup_WIFI(); + ntp->updateNTPtime(); setup_TOUCH(); setup_TIMER(); setup_TIMEDFUN(); @@ -208,14 +209,18 @@ void loop(){ delay(500); if(shutdownc >= 3){ + Display::clearTime(); EPD_2IN13_V2_Sleep(); Serial.println("Shuting down"); - strDateTime odt = (ntp->dt); - vTaskDelay(2000); - // touch->Reset(); + while(touch->dev.holding || touch->dev.pressing){ + touch->update(); + delay(100); + } + delay(500); touch->update(); - vTaskDelay(500); - esp_light_sleep_start(); + strDateTime odt = (ntp->dt); + delay(2000); + esp_light_sleep_start();//IRQ Raised for some reason Serial.println("Wakey Wakey"); wakeup(); tf->minuteTick(ntp->dt.minute - odt.minute); diff --git a/src/display/display.cpp b/src/display/display.cpp index c8c3687..b880b04 100644 --- a/src/display/display.cpp +++ b/src/display/display.cpp @@ -13,7 +13,7 @@ void DrawMain(bool v){ Paint_DrawIcon(89,36, ICON_LOGO, &FontIcon, BLACK, WHITE); Paint_DrawString_EN(29, 0, "Helcel", &Font45, WHITE, BLACK); if(v) - Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,"WESP-v0.1", &Font16, WHITE, BLACK); + Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - Font16.Height,"WESP-v0.1", &Font16, WHITE, BLACK); } void Display::setup(){ @@ -31,10 +31,14 @@ void Display::setup(){ EPD_2IN13_V2_DisplayPart(BlackImage); } +void Display::clearTime(){ + Paint_ClearWindows(170, EPD_2IN13_V2_WIDTH - Font24.Height+2, 170 + Font24.Width * 4.5, EPD_2IN13_V2_WIDTH, WHITE); +} + void Display::drawTime(strDateTime* dt){ - Paint_ClearWindows(170, EPD_2IN13_V2_WIDTH - Font24.Height+2, 170 + Font24.Width * 4.5, EPD_2IN13_V2_WIDTH, WHITE); + clearTime(); if (!dt->valid) return; - Paint_DrawTime(170, 98, dt, &Font24, WHITE, BLACK); + Paint_DrawTime(170, EPD_2IN13_V2_WIDTH - Font24.Height+2, dt, &Font24, WHITE, BLACK); EPD_2IN13_V2_DisplayPart(BlackImage); }; @@ -92,7 +96,7 @@ void WeatherDisplay::drawDisplay() { JsonObject weather_sys = cowm->weather["sys"]; if(!weather_0 || !weather_main || !weather_sys || !weather_wind) return; Paint_DrawIcon(0,8, getWeatherIcon(weather_0["id"]), &FontIcon, BLACK, WHITE); - Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,weather_0["main"], &Font16, WHITE, BLACK); + Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - Font16.Height,weather_0["main"], &Font16, WHITE, BLACK); Paint_DrawFltUnit(76,0,weather_main["temp"], "C", &Font24, BLACK, WHITE); Paint_DrawFltUnit(186,6,weather_main["feels_like"], "C", &Font12, BLACK, WHITE); Paint_DrawIntUnit(76,24,weather_main["pressure"], "hPa", &Font24, BLACK, WHITE); @@ -111,7 +115,7 @@ void TempDisplay::drawDisplay() { Paint_DrawFltUnit(76,24,sensor->pres, "hPa", &Font24, BLACK, WHITE); Paint_DrawFltUnit(76,48,sensor->hum, "%", &Font24, BLACK, WHITE); - Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,"Nominal", &Font16, WHITE, BLACK); + Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - Font16.Height,"Nominal", &Font16, WHITE, BLACK); } void AirDisplay::drawDisplay() { @@ -134,7 +138,7 @@ void AirDisplay::drawDisplay() { // particles_50um, ///< 5.0um Particle Count // particles_100um; ///< 10.0um Particle Count - Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,"Nominal", &Font16, WHITE, BLACK); + Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - Font16.Height,"Nominal", &Font16, WHITE, BLACK); } @@ -147,7 +151,7 @@ void LightDisplay::drawDisplay() { Paint_DrawFltUnit(76,24*2,sensor->light, "l", &Font24, BLACK, WHITE); Paint_DrawIntUnit(76,24*3,sensor->light_vis, "vl", &Font24, BLACK, WHITE); - Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,"Nominal", &Font16, WHITE, BLACK); + Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - Font16.Height,"Nominal", &Font16, WHITE, BLACK); } diff --git a/src/display/display.h b/src/display/display.h index b1d7b90..d9b7276 100644 --- a/src/display/display.h +++ b/src/display/display.h @@ -24,6 +24,7 @@ class DisplayWrapper { class Display { public: static void setup(); + static void clearTime(); static void drawTime(strDateTime* dt); static void refresh(); static void update(); diff --git a/src/ntp/ntp.cpp b/src/ntp/ntp.cpp index 406f2b8..6b741b3 100644 --- a/src/ntp/ntp.cpp +++ b/src/ntp/ntp.cpp @@ -1,5 +1,7 @@ #include "ntp.h" +#include + #define LEAP_YEAR(Y) ( ((1970+Y)>0) && !((1970+Y)%4) && ( ((1970+Y)%100) || !((1970+Y)%400) ) ) #define SEC_TO_MS 1000 @@ -167,6 +169,8 @@ unsigned long NTPtime::adjustTimeZone(unsigned long _timeStamp, float _timeZone, strDateTime NTPtime::getNTPtime(float _timeZone, boolean _DayLightSaving) { + + Serial.println("NTP: Updating Time"); int cb; strDateTime _dateTime; unsigned long _unixTime = 0; @@ -175,6 +179,8 @@ strDateTime NTPtime::getNTPtime(float _timeZone, boolean _DayLightSaving) { if (_sendPhase) { if (_sentTime && ((millis() - _sentTime) < _sendInterval)) { + + Serial.println("NTP: Too Fast"); return _dateTime; } @@ -221,6 +227,8 @@ strDateTime NTPtime::getNTPtime(float _timeZone, boolean _DayLightSaving) { } } + Serial.println("NTP: OK"); + return _dateTime; } diff --git a/src/touch/gt1151.cpp b/src/touch/gt1151.cpp index ead8275..cc97d3f 100644 --- a/src/touch/gt1151.cpp +++ b/src/touch/gt1151.cpp @@ -84,6 +84,7 @@ void GT1151::update() { uint8_t irq = gtIRQ; gtIRQ = 0; interrupts(); + // Serial.printf("IRQ: %d\n",irq); if (irq) onIRQ(); else dev.pressing = false; }