You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

154 lines
3.8 KiB

//
// Created by julia on 12.06.21.
//
#include "Watchy_Julia.h"
bool DARK = SIMPLE_DARKMODE;
#define BG (DARK ? GxEPD_BLACK : GxEPD_WHITE)
#define FG (DARK ? GxEPD_WHITE : GxEPD_BLACK)
#if NTP_ENABLE
RTC_DATA_ATTR int NTPSyncCounter = NTP_SYNC_INTERVAL;
#endif
WatchyJulia::WatchyJulia() = default;
void WatchyJulia::drawWatchFace() {
preDraw();
#if ADAPTIVE_DARKMODE
setAdaptiveDarkmode();
#endif
display.fillScreen(BG);
display.setTextColor(FG);
drawStatusBar();
drawTime();
drawDate();
postDraw();
}
void WatchyJulia::drawTime() {
display.setFont(&DSEG7_Classic_Bold_53);
display.setCursor(5, 96);
if(currentTime.Hour < 10){
display.print("0");
}
display.print(currentTime.Hour);
display.print(":");
if(currentTime.Minute < 10){
display.print("0");
}
display.println(currentTime.Minute);
}
void WatchyJulia::drawDate() {
display.setFont(&FreeSans18pt7b);
display.setCursor(10, 124);
String dayOfWeek = dayStr(currentTime.Wday);
display.print(currentTime.Year + YEAR_OFFSET);
display.print("-");
if (currentTime.Month < 10) {
display.print("0");
}
display.print(currentTime.Month);
display.print("-");
if (currentTime.Day < 10) {
display.print("0");
}
display.print(currentTime.Day);
display.setFont(&FreeSans12pt7b);
display.setCursor(10, 146);
display.print(dayOfWeek);
}
int16_t statusbarYOffset(int16_t height) {
return (STATUSBAR_HEIGHT - height) / 2;
}
void WatchyJulia::drawStatusBar() {
display.fillRect(0, STATUSBAR_HEIGHT, 200, 5, FG);
drawBattery(0, false);
uint8_t offset = 200;
if (BLE_CONFIGURED) {
offset -= drawSBIcon(bluetooth, offset, true);
}
if (WIFI_CONFIGURED) {
offset -= drawSBIcon(wifi, offset, true);
}
// if (UNREAD_NOTIFS) {
if (true) { // debug purposes
offset -= drawSBIcon(bell, offset, true);
}
}
int16_t WatchyJulia::drawBattery(int16_t x, bool reverseSpace) {
if (reverseSpace) {
x -= (battery.width + STATUSBAR_SPACE);
} else {
x += STATUSBAR_SPACE;
}
int16_t y = statusbarYOffset(battery.height);
int8_t batteryLevel = 0;
float vBat = getBatteryVoltage();
if (vBat > BATTERY_THRESHOLD_3) {
batteryLevel = 3;
} else if (vBat > BATTERY_THRESHOLD_2) {
batteryLevel = 2;
} else if (vBat > BATTERY_THRESHOLD_1) {
batteryLevel = 1;
}
display.drawBitmap(x, y, battery.data, battery.width, battery.height, FG);
int16_t segX = x + 3;
int16_t segY = y + 5 + 3 * (BATTERY_SEGMENT_HEIGHT + BATTERY_SEGMENT_GAP);
for (int8_t i = 0; i < batteryLevel; i++, segY -= (BATTERY_SEGMENT_HEIGHT + BATTERY_SEGMENT_GAP)) {
display.fillRect(segX, segY, BATTERY_SEGMENT_WIDTH, BATTERY_SEGMENT_HEIGHT, FG);
}
return 2 * STATUSBAR_SPACE + battery.width;
}
int16_t WatchyJulia::drawSBIcon(const icon &i, int16_t x, bool reverseSpace) {
if (reverseSpace) {
x -= (i.width + STATUSBAR_SPACE);
} else {
x += STATUSBAR_SPACE;
}
display.drawBitmap(x, statusbarYOffset(i.height),
i.data, i.width, i.height, FG);
return 2 * STATUSBAR_SPACE + i.width;
}
void WatchyJulia::setAdaptiveDarkmode() {
DARK = (6 >= currentTime.Hour && 21 <= currentTime.Hour);
}
void WatchyJulia::preDraw() {
connectWiFi();
#if NTP_ENABLE
if (NTPSyncCounter >= NTP_SYNC_INTERVAL) {
if (WIFI_CONFIGURED) {
configTzTime(TIME_ZONE, NTP_SERVER);
struct tm timeinfo;
getLocalTime(&timeinfo);
time_t t = mktime(&timeinfo);
RTC.set(t);
NTPSyncCounter = 0;
}
} else {
NTPSyncCounter++;
}
#endif
}
void WatchyJulia::postDraw() {
}