Oled full working
parent
1ab8d23320
commit
4763a5f008
File diff suppressed because it is too large
Load Diff
|
|
@ -16,7 +16,6 @@ void OledDisplay::preSetup() {
|
|||
this->oledDisplay->display();
|
||||
}
|
||||
|
||||
|
||||
void OledDisplay::postSetup() {
|
||||
static OledDisplay* obj = this;
|
||||
this->frames[0] = [](OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { obj->drawScreen1(display, state, x, y); };
|
||||
|
|
@ -43,6 +42,7 @@ void OledDisplay::postSetup() {
|
|||
}
|
||||
|
||||
void OledDisplay::handleUpdate() {
|
||||
this->checkDisplay();
|
||||
this->ui->update();
|
||||
}
|
||||
|
||||
|
|
@ -103,32 +103,252 @@ void OledDisplay::showWebserverSplashScreen(bool isEnabled) {
|
|||
|
||||
|
||||
|
||||
void OledDisplay::checkDisplay() {
|
||||
BasePrinterClient *printerClient = this->globalDataController->getPrinterClient();
|
||||
|
||||
if (!this->displayOn && this->globalDataController->getDisplayClock()) {
|
||||
this->enableDisplay(true);
|
||||
}
|
||||
if (this->displayOn && !printerClient->isPrinting() && !this->globalDataController->getDisplayClock()) {
|
||||
// Put Display to sleep
|
||||
this->oledDisplay->clear();
|
||||
this->oledDisplay->display();
|
||||
this->oledDisplay->setFont(ArialMT_Plain_16);
|
||||
this->oledDisplay->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
this->oledDisplay->setContrast(255); // default is 255
|
||||
this->oledDisplay->drawString(64, 5, "Printer Offline\nSleep Mode...");
|
||||
this->oledDisplay->display();
|
||||
delay(5000);
|
||||
this->enableDisplay(false);
|
||||
this->debugController->printLn("Printer is offline going down to sleep...");
|
||||
return;
|
||||
} else if (!this->displayOn && !this->globalDataController->getDisplayClock()) {
|
||||
if (printerClient->isOperational()) {
|
||||
// Wake the Screen up
|
||||
this->enableDisplay(true);
|
||||
this->oledDisplay->clear();
|
||||
this->oledDisplay->display();
|
||||
this->oledDisplay->setFont(ArialMT_Plain_16);
|
||||
this->oledDisplay->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
this->oledDisplay->setContrast(255); // default is 255
|
||||
this->oledDisplay->drawString(64, 5, "Printer Online\nWake up...");
|
||||
this->oledDisplay->display();
|
||||
this->debugController->printLn("Printer is online waking up...");
|
||||
delay(5000);
|
||||
return;
|
||||
}
|
||||
} else if (this->globalDataController->getDisplayClock()) {
|
||||
if ((!printerClient->isPrinting() || printerClient->isPSUoff()) && !this->isClockOn) {
|
||||
this->debugController->printLn("Clock Mode is turned on.");
|
||||
if (!DISPLAYWEATHER) {
|
||||
this->ui->disableAutoTransition();
|
||||
this->ui->setFrames(clockFrame, 1);
|
||||
} else {
|
||||
this->ui->enableAutoTransition();
|
||||
this->ui->setFrames(clockFrame, 2);
|
||||
}
|
||||
this->ui->setOverlays(clockOverlay, 1);
|
||||
this->isClockOn = true;
|
||||
} else if (printerClient->isPrinting() && !printerClient->isPSUoff() && this->isClockOn) {
|
||||
this->debugController->printLn("Printer Monitor is active.");
|
||||
this->ui->setFrames(frames, 3);
|
||||
this->ui->setOverlays(overlays, 1);
|
||||
this->ui->enableAutoTransition();
|
||||
isClockOn = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OledDisplay::enableDisplay(boolean enable) {
|
||||
this->displayOn = enable;
|
||||
TimeClient * timeClient = this->globalDataController->getTimeClient();
|
||||
if (enable) {
|
||||
if (timeClient->getMinutesFromLast(this->displayOffEpoch) >= this->globalDataController->getClockResyncMinutes()) {
|
||||
// The display has been off longer than the minutes between refresh -- need to get fresh data
|
||||
timeClient->resetLastEpoch();
|
||||
this->displayOffEpoch = 0; // reset
|
||||
}
|
||||
this->oledDisplay->displayOn();
|
||||
this->debugController->printLn(
|
||||
"Display was turned ON: " + timeClient->getFormattedTime()
|
||||
);
|
||||
} else {
|
||||
this->oledDisplay->displayOff();
|
||||
this->debugController->printLn(
|
||||
"Display was turned OFF: " + timeClient->getFormattedTime()
|
||||
);
|
||||
this->displayOffEpoch = timeClient->getLastEpoch();
|
||||
}
|
||||
}
|
||||
|
||||
void OledDisplay::drawScreen1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
|
||||
BasePrinterClient *printerClient = this->globalDataController->getPrinterClient();
|
||||
|
||||
String bed = printerClient->getValueRounded(printerClient->getTempBedActual());
|
||||
String tool = printerClient->getValueRounded(printerClient->getTempToolActual());
|
||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display->setFont(ArialMT_Plain_16);
|
||||
if (bed != "0") {
|
||||
display->drawString(29 + x, 0 + y, "Tool");
|
||||
display->drawString(89 + x, 0 + y, "Bed");
|
||||
} else {
|
||||
display->drawString(64 + x, 0 + y, "Tool Temp");
|
||||
}
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->setFont(ArialMT_Plain_24);
|
||||
if (bed != "0") {
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->drawString(12 + x, 14 + y, tool + "°");
|
||||
display->drawString(74 + x, 14 + y, bed + "°");
|
||||
} else {
|
||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display->drawString(64 + x, 14 + y, tool + "°");
|
||||
}
|
||||
}
|
||||
|
||||
void OledDisplay::drawScreen2(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
|
||||
BasePrinterClient *printerClient = this->globalDataController->getPrinterClient();
|
||||
|
||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display->setFont(ArialMT_Plain_16);
|
||||
|
||||
display->drawString(64 + x, 0 + y, "Time Remaining");
|
||||
//display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->setFont(ArialMT_Plain_24);
|
||||
int val = printerClient->getProgressPrintTimeLeft().toInt();
|
||||
int hours = this->globalDataController->numberOfHours(val);
|
||||
int minutes = this->globalDataController->numberOfMinutes(val);
|
||||
int seconds = this->globalDataController->numberOfSeconds(val);
|
||||
|
||||
String time = this->globalDataController->zeroPad(hours) + ":" +
|
||||
this->globalDataController->zeroPad(minutes) + ":" +
|
||||
this->globalDataController->zeroPad(seconds);
|
||||
display->drawString(64 + x, 14 + y, time);
|
||||
}
|
||||
|
||||
void OledDisplay::drawScreen3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
|
||||
BasePrinterClient *printerClient = this->globalDataController->getPrinterClient();
|
||||
|
||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display->setFont(ArialMT_Plain_16);
|
||||
|
||||
display->drawString(64 + x, 0 + y, "Printing Time");
|
||||
//display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->setFont(ArialMT_Plain_24);
|
||||
int val = printerClient->getProgressPrintTime().toInt();
|
||||
int hours = this->globalDataController->numberOfHours(val);
|
||||
int minutes = this->globalDataController->numberOfMinutes(val);
|
||||
int seconds = this->globalDataController->numberOfSeconds(val);
|
||||
|
||||
String time = this->globalDataController->zeroPad(hours) + ":" +
|
||||
this->globalDataController->zeroPad(minutes) + ":" +
|
||||
this->globalDataController->zeroPad(seconds);
|
||||
display->drawString(64 + x, 14 + y, time);
|
||||
}
|
||||
|
||||
void OledDisplay::drawClock(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
|
||||
TimeClient * timeClient = this->globalDataController->getTimeClient();
|
||||
BasePrinterClient *printerClient = this->globalDataController->getPrinterClient();
|
||||
|
||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
|
||||
String displayTime = timeClient->getAmPmHours() + ":" + timeClient->getMinutes() + ":" + timeClient->getSeconds();
|
||||
if (this->globalDataController->getClockIs24h()) {
|
||||
displayTime = timeClient->getHours() + ":" + timeClient->getMinutes() + ":" + timeClient->getSeconds();
|
||||
}
|
||||
String displayName = this->globalDataController->getPrinterHostName();
|
||||
if (printerClient->getPrinterType() == "Repetier") {
|
||||
displayName = printerClient->getPrinterName();
|
||||
}
|
||||
display->setFont(ArialMT_Plain_16);
|
||||
display->drawString(64 + x, 0 + y, displayName);
|
||||
display->setFont(ArialMT_Plain_24);
|
||||
display->drawString(64 + x, 17 + y, displayTime);
|
||||
}
|
||||
|
||||
void OledDisplay::drawWeather(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
|
||||
OpenWeatherMapClient *weatherClient = this->globalDataController->getWeatherClient();
|
||||
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->setFont(ArialMT_Plain_24);
|
||||
display->drawString(0 + x, 0 + y, weatherClient->getTempRounded(0) + weatherClient->getTempSymbol());
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->setFont(ArialMT_Plain_24);
|
||||
|
||||
display->setFont(ArialMT_Plain_16);
|
||||
display->drawString(0 + x, 24 + y, weatherClient->getCondition(0));
|
||||
display->setFont((const uint8_t*)Meteocons_Plain_42);
|
||||
display->drawString(86 + x, 0 + y, weatherClient->getWeatherIcon(0));
|
||||
}
|
||||
|
||||
void OledDisplay::drawHeaderOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
|
||||
TimeClient * timeClient = this->globalDataController->getTimeClient();
|
||||
BasePrinterClient *printerClient = this->globalDataController->getPrinterClient();
|
||||
|
||||
display->setColor(WHITE);
|
||||
display->setFont(ArialMT_Plain_16);
|
||||
String displayTime = timeClient->getAmPmHours() + ":" + timeClient->getMinutes();
|
||||
if (this->globalDataController->getClockIs24h()) {
|
||||
displayTime = timeClient->getHours() + ":" + timeClient->getMinutes();
|
||||
}
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->drawString(0, 48, displayTime);
|
||||
|
||||
if (!this->globalDataController->getClockIs24h()) {
|
||||
String ampm = timeClient->getAmPm();
|
||||
display->setFont(ArialMT_Plain_10);
|
||||
display->drawString(39, 54, ampm);
|
||||
}
|
||||
|
||||
display->setFont(ArialMT_Plain_16);
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
String percent = String(printerClient->getProgressCompletion()) + "%";
|
||||
display->drawString(64, 48, percent);
|
||||
|
||||
// Draw indicator to show next update
|
||||
int updatePos = (printerClient->getProgressCompletion().toFloat() / float(100)) * 128;
|
||||
display->drawRect(0, 41, 128, 6);
|
||||
display->drawHorizontalLine(0, 42, updatePos);
|
||||
display->drawHorizontalLine(0, 43, updatePos);
|
||||
display->drawHorizontalLine(0, 44, updatePos);
|
||||
display->drawHorizontalLine(0, 45, updatePos);
|
||||
|
||||
this->drawRssi(display);
|
||||
}
|
||||
|
||||
void OledDisplay::drawClockHeaderOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
|
||||
TimeClient * timeClient = this->globalDataController->getTimeClient();
|
||||
BasePrinterClient *printerClient = this->globalDataController->getPrinterClient();
|
||||
|
||||
display->setColor(WHITE);
|
||||
display->setFont(ArialMT_Plain_16);
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
int printerStateDrawXPos = 0;
|
||||
if (!this->globalDataController->getClockIs24h()) {
|
||||
display->drawString(0, 48, timeClient->getAmPm());
|
||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
printerStateDrawXPos = 64;
|
||||
}
|
||||
if (printerClient->isPSUoff()) {
|
||||
display->drawString(printerStateDrawXPos, 47, "psu off");
|
||||
} else if (printerClient->getState() == "Operational") {
|
||||
display->drawString(printerStateDrawXPos, 47, "online");
|
||||
} else {
|
||||
display->drawString(printerStateDrawXPos, 47, "offline");
|
||||
}
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->drawRect(0, 43, 128, 2);
|
||||
|
||||
this->drawRssi(display);
|
||||
}
|
||||
|
||||
void OledDisplay::drawRssi(OLEDDisplay *display) {
|
||||
int8_t quality = this->globalDataController->getWifiQuality();
|
||||
for (int8_t i = 0; i < 4; i++) {
|
||||
for (int8_t j = 0; j < 3 * (i + 2); j++) {
|
||||
if (quality > i * 25 || j == 0) {
|
||||
display->setPixel(114 + 4 * i, 63 - j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
#include "../Global/GlobalDataController.h"
|
||||
#include <OLEDDisplayUi.h>
|
||||
#include <OLEDDisplay.h>
|
||||
#include "../../include/WeatherStationFonts.h"
|
||||
|
||||
class OledDisplay {
|
||||
private:
|
||||
|
|
@ -11,6 +12,8 @@ private:
|
|||
DebugController *debugController;
|
||||
OLEDDisplay *oledDisplay;
|
||||
OLEDDisplayUi *ui;
|
||||
boolean displayOn = true;
|
||||
long displayOffEpoch = 0;
|
||||
|
||||
FrameCallback frames[3];
|
||||
FrameCallback clockFrame[2];
|
||||
|
|
@ -29,7 +32,8 @@ public:
|
|||
|
||||
|
||||
|
||||
|
||||
void checkDisplay();
|
||||
void enableDisplay(boolean enable);
|
||||
void drawScreen1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
|
||||
void drawScreen2(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
|
||||
void drawScreen3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
|
||||
|
|
@ -37,4 +41,5 @@ public:
|
|||
void drawWeather(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
|
||||
void drawHeaderOverlay(OLEDDisplay *display, OLEDDisplayUiState* state);
|
||||
void drawClockHeaderOverlay(OLEDDisplay *display, OLEDDisplayUiState* state);
|
||||
void drawRssi(OLEDDisplay *display);
|
||||
};
|
||||
|
|
@ -7,7 +7,7 @@ TimeClient::TimeClient(float utcOffset, DebugController * debugController) {
|
|||
|
||||
bool TimeClient::handleSync(int snycDelayMinutes) {
|
||||
//Get Time Update
|
||||
if((this->getMinutesFromLastRefresh() >= snycDelayMinutes) || this->lastEpoch == 0) {
|
||||
if((this->getMinutesFromLast(this->lastEpoch) >= snycDelayMinutes) || this->lastEpoch == 0) {
|
||||
this->debugController->printLn("Updating Time...");
|
||||
this->updateTime();
|
||||
this->lastEpoch = this->getCurrentEpoch();
|
||||
|
|
@ -17,8 +17,8 @@ bool TimeClient::handleSync(int snycDelayMinutes) {
|
|||
return false;
|
||||
}
|
||||
|
||||
int TimeClient::getMinutesFromLastRefresh() {
|
||||
int minutes = (this->getCurrentEpoch() - this->lastEpoch) / 60;
|
||||
int TimeClient::getMinutesFromLast(long lastEpochToUse) {
|
||||
int minutes = (this->getCurrentEpoch() - lastEpochToUse) / 60;
|
||||
return minutes;
|
||||
}
|
||||
|
||||
|
|
@ -26,6 +26,10 @@ void TimeClient::resetLastEpoch() {
|
|||
this->lastEpoch = 0;
|
||||
}
|
||||
|
||||
long TimeClient::getLastEpoch() {
|
||||
return this->lastEpoch;
|
||||
}
|
||||
|
||||
void TimeClient::updateTime() {
|
||||
WiFiClient client;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,9 @@ public:
|
|||
TimeClient(float utcOffset, DebugController * debugController);
|
||||
void updateTime();
|
||||
bool handleSync(int snycDelayMinutes);
|
||||
int getMinutesFromLastRefresh();
|
||||
int getMinutesFromLast(long lastEpochToUse);
|
||||
void resetLastEpoch();
|
||||
long getLastEpoch();
|
||||
|
||||
void setUtcOffset(float utcOffset);
|
||||
String getHours();
|
||||
|
|
|
|||
Loading…
Reference in New Issue