INFOBoard/lib/image/image.cpp

93 lines
2.8 KiB
C++

#ifndef __IMAGE__
#include <image.h>
#endif
#include <font.h>
#include <utils.h>
// Overlays
int overlaysCount = 1;
OverlayCallback overlays[] = { timeOverlay };
void timeOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
String time("");
if( localIP == "Unconnected" or localIP == "10.1.1.1" ) {
unsigned long mscount = millis();
unsigned long sec = mscount / 1000;
unsigned long mse = mscount / 100 - sec * 10;
time = (String)sec + "." + (String)mse;
} else {
time = ntpTime();
}
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->drawString(64, 54, time);
}
// frames
int frameCount = 3;
FrameCallback frames[] = { oledWebFrame, oledBilibiliFrame, oledOsFrame };
void oledTitle(OLEDDisplay *display, String s, int16_t x, int16_t y) {
// Title
display->setFont(Roboto_Mono_13);
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->drawString(64+x, 0+y, s);
display->setFont(Roboto_Mono_10);
}
void oledWebFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
// Title
oledTitle(display, "Fox Home", x, y);
// Items
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->drawString(0+x, 16+y, "Today");
display->drawString(0+x, 30+y, "Last Week");
display->drawString(0+x, 44+y, "Last Month");
// Values
display->setTextAlignment(TEXT_ALIGN_RIGHT);
display->drawString(120+x, 16+y, (String)dayView);
display->drawString(120+x, 30+y, (String)weekView);
display->drawString(120+x, 44+y, (String)monthView);
}
void oledMQTTFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
}
void oledBilibiliFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
// Title
oledTitle(display, "BiliBili", x, y);
// Items
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->drawString(0+x, 16+y, "Follower");
display->drawString(0+x, 30+y, "View");
display->drawString(0+x, 44+y, "Likes");
// Values
display->setTextAlignment(TEXT_ALIGN_RIGHT);
display->drawString(120+x, 16+y, (String)follower);
display->drawString(120+x, 30+y, (String)view);
display->drawString(120+x, 44+y, (String)likes);
}
void oledOsFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
// Title
oledTitle(display, "INFO BOARD", x, y);
display->setTextAlignment(TEXT_ALIGN_LEFT);
// Version
display->drawFastImage(0+x, 16+y, 16, 16, Board_Icon);
display->drawString(24+x, 18+y, boardVersion);
// WiFi
if( localIP == "Unconnected")
display->drawFastImage(0+x, 34+y, 16, 16, Wifi_Unconnected_Icon);
else
display->drawFastImage(0+x, 34+y, 16, 16, Wifi_Connected_Icon);
display->drawString(24+x, 36+y, localIP);
}