diff --git a/lib/face/faceToday.cpp b/lib/face/faceToday.cpp new file mode 100644 index 0000000..07fd021 --- /dev/null +++ b/lib/face/faceToday.cpp @@ -0,0 +1,115 @@ +#include "faceToday.h" +#include "settings.h" +#include "display.h" +#include "datetime.h" +#include "imageService.h" +#include "faceWeather.h" +#include "faceWeather/icons.h" + +#include +#include + +void addTodayBackgroundPicture(); +void addTodayDay(); +void addTodayWeather(); + +const char faceTodayPicture[] = "/faceToday.jpg"; +unsigned long faceTodayUpdate = 0; + +void setupFaceToday() +{ + // NOP +} + +void loopFaceToday() +{ + // update every 10 min + if ((millis() - faceTodayUpdate) >= 600000) + { + Serial.println(&now, "update today data @ %A, %B %d %Y %H:%M:%S"); + faceTodayUpdate = millis(); + imageServiceUpdateFile("640x384.jpg", faceTodayPicture); + } +} + +void showFaceToday() +{ + // init + GFXcanvas1 *canvas = displayGetCanvas(); + canvas->fillScreen(COLOR_BG); + canvas->setTextColor(COLOR_FG); + canvas->setTextSize(1); + + // add widgets + imageServiceRenderFile(faceTodayPicture, 0, 0, 0, 0, true); + addTodayDay(); + addTodayWeather(); + + // update display + displayFlush(); +} + +void addTodayDay() +{ + // init + GFXcanvas1 *canvas = displayGetCanvas(); + canvas->setFont(&FreeMono24pt7b); + canvas->setTextColor(COLOR_BG); + + // add tile + int16_t x1, y1; + uint16_t w, h; + int16_t time_base_y = 50; + int16_t time_base_x = 15; + canvas->getTextBounds("00", time_base_x, time_base_y, &x1, &y1, &w, &h); + // canvas->fillRect(0, 0, x1 + w + 25, time_base_y + (h *2) + 5, COLOR_FG); + canvas->fillRoundRect(-15, -15, x1 + w + 25 + 15, time_base_y + (h * 2) + 5 + 15, 15, COLOR_FG); + + // 1. row - day + canvas->setCursor(time_base_x, time_base_y); + canvas->print(now.tm_mday); + canvas->setCursor(canvas->getCursorX() - 10, canvas->getCursorY()); + canvas->print("."); + + // 2. row - month + char label[20]; + strftime(label, 20, "%b", &now); + canvas->setCursor(time_base_x, time_base_y + h + 10); + canvas->setFont(&FreeMono18pt7b); + canvas->println(label); +} + +void addTodayWeather() +{ + // init + GFXcanvas1 *canvas = displayGetCanvas(); + canvas->setTextColor(COLOR_BG); + + // set start point + int16_t x = displayGetWidth() - 150; + int16_t y = displayGetHeight() - 60; + + // add tile + canvas->fillRoundRect(x, y, 150 + 15, 60 + 15, 15, COLOR_FG); + + // current weather condition - icon + const unsigned char *icon = getIconById(weatherData.current_icon, 64); + if (icon) + { + canvas->drawBitmap(x + 15, y, icon, 64, 64, COLOR_FG, COLOR_BG); + } + + // current weather condition - temperature + canvas->setFont(&FreeMono24pt7b); + canvas->setTextSize(1); + + int16_t x1, y1; + uint16_t w, h; + int16_t textbox_x = x + 64 + 5; + int16_t textbox_y = y + 72; + canvas->getTextBounds("000", textbox_x, textbox_y, &x1, &y1, &w, &h); + Serial.printf("x:%d, y:%d", x1, y1); + + canvas->setCursor(x1, y1); + canvas->print(weatherData.current_temp); +} diff --git a/lib/face/faceToday.h b/lib/face/faceToday.h new file mode 100644 index 0000000..552e3c2 --- /dev/null +++ b/lib/face/faceToday.h @@ -0,0 +1,8 @@ +#ifndef FACE_TODAY_H +#define FACE_TODAY_H + +void setupFaceToday(); +void loopFaceToday(); +void showFaceToday(); + +#endif \ No newline at end of file