Some changes vor display clients
parent
4763a5f008
commit
290fea0311
|
|
@ -1,13 +1,3 @@
|
|||
/**
|
||||
* @file BasePrinterClient.h
|
||||
* @author Robert Stein
|
||||
* @brief Basic implementation for all implemented printer
|
||||
* Clients
|
||||
* @version 0.1
|
||||
* @date 2020-12-12
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*/
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
#define VERSION "4.0"
|
||||
#define HOSTNAME "PrintMon-"
|
||||
#define CONFIG "/conf.txt"
|
||||
// true = Enables debug message on terminal | false = disable all debug messages
|
||||
#define DEBUG_MODE_ENABLE true
|
||||
|
||||
//===========================================================================
|
||||
//========================= MCU & Display config ============================
|
||||
|
|
@ -33,6 +35,7 @@
|
|||
#define DISPLAY_TX_PIN D1
|
||||
#define DISPLAY_RX_PIN D2
|
||||
#endif
|
||||
#define DISPLAY_BAUDRATE 9600
|
||||
#else
|
||||
// I2C Address of your Display (usually 0x3c or 0x3d)
|
||||
#define DISPLAY_I2C_DISPLAY_ADDRESS 0x3c
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
class BaseDisplayClient {
|
||||
public:
|
||||
virtual void preSetup();
|
||||
virtual void postSetup();
|
||||
virtual void handleUpdate();
|
||||
virtual void showBootScreen();
|
||||
virtual void showApAccessScreen(String apSsid, String apIp);
|
||||
virtual void showWebserverSplashScreen(bool isEnabled);
|
||||
};
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
#include "NextionDisplay.h"
|
||||
|
||||
NextionDisplay::NextionDisplay(SoftwareSerial *serialPort, GlobalDataController *globalDataController, DebugController *debugController) {
|
||||
this->debugController = debugController;
|
||||
this->globalDataController = globalDataController;
|
||||
this->serialPort = serialPort;
|
||||
}
|
||||
|
||||
void NextionDisplay::preSetup() {
|
||||
#ifdef DISPLAY_BAUDRATE
|
||||
this->serialPort->begin(DISPLAY_BAUDRATE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void NextionDisplay::postSetup() {
|
||||
|
||||
}
|
||||
|
||||
void NextionDisplay::handleUpdate() {
|
||||
|
||||
}
|
||||
|
||||
void NextionDisplay::showBootScreen() {
|
||||
String command("version.txt=");
|
||||
command += "\"for " + this->globalDataController->getPrinterClient()->getPrinterType() + " V" + this->globalDataController->getVersion() + "\"";
|
||||
this->sendCommand("page 0");
|
||||
this->sendCommand(command.c_str());
|
||||
}
|
||||
|
||||
void NextionDisplay::showApAccessScreen(String apSsid, String apIp) {
|
||||
String commandHostName("WifiHostname.txt=");
|
||||
String commandQrCode("WifiScancode.txt=");
|
||||
commandHostName += "\"" + apSsid + "\"";
|
||||
commandQrCode += "\"WIFI:S:" + apSsid + ";T:WPA;P:;;\"";
|
||||
this->sendCommand("page 1");
|
||||
this->sendCommand(commandHostName.c_str());
|
||||
this->sendCommand(commandQrCode.c_str());
|
||||
}
|
||||
|
||||
void NextionDisplay::showWebserverSplashScreen(bool isEnabled) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NextionDisplay::sendCommand(String cmd) {
|
||||
this->sendCommand(cmd.c_str());
|
||||
}
|
||||
|
||||
void NextionDisplay::sendCommand(const char* cmd) {
|
||||
while (this->serialPort->available())
|
||||
{
|
||||
this->serialPort->read();
|
||||
}
|
||||
|
||||
this->serialPort->print(cmd);
|
||||
this->serialPort->write(0xFF);
|
||||
this->serialPort->write(0xFF);
|
||||
this->serialPort->write(0xFF);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <SoftwareSerial.h>
|
||||
#include "../Global/GlobalDataController.h"
|
||||
#include "BaseDisplayClient.h"
|
||||
|
||||
class NextionDisplay : public BaseDisplayClient {
|
||||
private:
|
||||
GlobalDataController *globalDataController;
|
||||
DebugController *debugController;
|
||||
SoftwareSerial *serialPort;
|
||||
boolean displayOn = true;
|
||||
long displayOffEpoch = 0;
|
||||
|
||||
public:
|
||||
NextionDisplay(SoftwareSerial *serialPort, GlobalDataController *globalDataController, DebugController *debugController);
|
||||
void preSetup();
|
||||
void postSetup();
|
||||
void handleUpdate();
|
||||
void showBootScreen();
|
||||
void showApAccessScreen(String apSsid, String apIp);
|
||||
void showWebserverSplashScreen(bool isEnabled);
|
||||
|
||||
void sendCommand(String cmd);
|
||||
void sendCommand(const char* cmd);
|
||||
};
|
||||
|
|
@ -5,8 +5,9 @@
|
|||
#include <OLEDDisplayUi.h>
|
||||
#include <OLEDDisplay.h>
|
||||
#include "../../include/WeatherStationFonts.h"
|
||||
#include "BaseDisplayClient.h"
|
||||
|
||||
class OledDisplay {
|
||||
class OledDisplay : public BaseDisplayClient {
|
||||
private:
|
||||
GlobalDataController *globalDataController;
|
||||
DebugController *debugController;
|
||||
|
|
|
|||
|
|
@ -1,40 +1,74 @@
|
|||
#include "DebugController.h"
|
||||
|
||||
DebugController::DebugController(bool enabled) {
|
||||
this->enabled = enabled;
|
||||
}
|
||||
|
||||
bool DebugController::isEnabled() {
|
||||
return this->enabled;
|
||||
}
|
||||
|
||||
void DebugController::setup() {
|
||||
if (!this->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
Serial.println("Debugger started");
|
||||
}
|
||||
|
||||
void DebugController::print(const char *data) {
|
||||
if (!this->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
Serial.print(data);
|
||||
}
|
||||
|
||||
void DebugController::print(String data) {
|
||||
if (!this->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
Serial.print(data);
|
||||
}
|
||||
|
||||
void DebugController::print(int8_t data) {
|
||||
if (!this->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
Serial.print(data);
|
||||
}
|
||||
|
||||
void DebugController::printF(const char *data, unsigned int uInt) {
|
||||
if (!this->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
Serial.printf(data, uInt);
|
||||
}
|
||||
|
||||
void DebugController::printLn(const char *data) {
|
||||
if (!this->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
Serial.println(data);
|
||||
}
|
||||
|
||||
void DebugController::printLn(String data) {
|
||||
if (!this->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
Serial.println(data);
|
||||
}
|
||||
|
||||
void DebugController::printLn(long int data) {
|
||||
if (!this->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
Serial.println(data);
|
||||
}
|
||||
|
||||
void DebugController::printLn(int8_t data) {
|
||||
if (!this->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
Serial.println(data);
|
||||
}
|
||||
|
|
@ -4,7 +4,12 @@
|
|||
#include "Configuration.h"
|
||||
|
||||
class DebugController {
|
||||
private:
|
||||
bool enabled;
|
||||
|
||||
public:
|
||||
DebugController(bool enabled);
|
||||
bool isEnabled();
|
||||
void setup();
|
||||
|
||||
void print(const char *data);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ GlobalDataController::GlobalDataController(TimeClient *timeClient, OpenWeatherMa
|
|||
}
|
||||
|
||||
void GlobalDataController::setup() {
|
||||
|
||||
this->listSettingFiles();
|
||||
this->readSettings();
|
||||
}
|
||||
|
|
@ -71,15 +70,10 @@ void GlobalDataController::readSettings() {
|
|||
this->PrinterHasPsu = line.substring(line.lastIndexOf("printerHasPsu=") + 14).toInt();
|
||||
this->debugController->printLn("PrinterHasPsu=" + String(this->PrinterHasPsu));
|
||||
}
|
||||
|
||||
|
||||
#ifndef USE_NEXTION_DISPLAY
|
||||
if(line.indexOf("displayInvertDisplay=") >= 0) {
|
||||
this->DisplayInvertDisplay = line.substring(line.lastIndexOf("displayInvertDisplay=") + 21).toInt();
|
||||
this->debugController->printLn("DisplayInvertDisplay=" + String(this->DisplayInvertDisplay));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (line.indexOf("webserverTheme=") >= 0) {
|
||||
this->WebserverTheme = line.substring(line.lastIndexOf("webserverTheme=") + 15);
|
||||
this->WebserverTheme.trim();
|
||||
|
|
@ -166,9 +160,7 @@ void GlobalDataController::writeSettings() {
|
|||
f.println("printerAuthUser=" + this->PrinterAuthUser);
|
||||
f.println("printerAuthPass=" + this->PrinterAuthPass);
|
||||
f.println("printerHasPsu=" + String(this->PrinterHasPsu));
|
||||
#ifndef USE_NEXTION_DISPLAY
|
||||
f.println("displayInvertDisplay=" + String(this->DisplayInvertDisplay));
|
||||
#endif
|
||||
f.println("webserverTheme=" + this->WebserverTheme);
|
||||
f.println("webserverIsBasicAuth=" + String(this->WebserverIsBasicAuth));
|
||||
f.println("webserverUsername=" + String(this->WebserverUsername));
|
||||
|
|
@ -212,6 +204,14 @@ BasePrinterClient *GlobalDataController::getPrinterClient() {
|
|||
return this->basePrinterClient;
|
||||
}
|
||||
|
||||
void GlobalDataController::setDisplayClient(BaseDisplayClient *baseDisplayClient) {
|
||||
this->baseDisplayClient = baseDisplayClient;
|
||||
}
|
||||
|
||||
BaseDisplayClient *GlobalDataController::setDisplayClient() {
|
||||
return this->baseDisplayClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration parameters
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "../Network/OpenWeatherMapClient.h"
|
||||
#include "../Clients/BasePrinterClient.h"
|
||||
#include "DebugController.h"
|
||||
#include "../Display/BaseDisplayClient.h"
|
||||
|
||||
class GlobalDataController {
|
||||
private:
|
||||
|
|
@ -18,6 +19,7 @@ private:
|
|||
BasePrinterClient *basePrinterClient;
|
||||
OpenWeatherMapClient *weatherClient;
|
||||
DebugController *debugController;
|
||||
BaseDisplayClient *baseDisplayClient;
|
||||
|
||||
/**
|
||||
* Configuration variables
|
||||
|
|
@ -29,28 +31,25 @@ private:
|
|||
String PrinterAuthUser = PRINTERCLIENT_AUTHUSER;
|
||||
String PrinterAuthPass = PRINTERCLIENT_AUTHPASS;
|
||||
bool PrinterHasPsu = PRINTERCLIENT_HASPSU;
|
||||
|
||||
int WebserverPort = WEBSERVER_PORT;
|
||||
bool WebserverIsBasicAuth = WEBSERVER_IS_BASIC_AUTH;
|
||||
String WebserverUsername = WEBSERVER_USERNAME;
|
||||
String WebserverPassword = WEBSERVER_PASSWORD;
|
||||
String WebserverTheme = WEBSERVER_THEMECOLOR;
|
||||
|
||||
int ClockUtcOffset = TIME_UTCOFFSET;
|
||||
bool DisplayClock = DISPLAYCLOCK;
|
||||
bool ClockIs24h = TIME_IS_24HOUR;
|
||||
int ClockResyncMinutes = TIME_RESYNC_MINUTES_DELAY;
|
||||
|
||||
bool UseLedFlash = USE_FLASH;
|
||||
|
||||
bool WeatherShow = DISPLAYWEATHER;
|
||||
String WeatherApiKey = WEATHER_APIKEY;
|
||||
int WeatherCityId = WEATHER_CITYID;
|
||||
bool WeatherIsMetric = WEATHER_METRIC;
|
||||
String WeatherLang = WEATHER_LANGUAGE;
|
||||
|
||||
#ifndef USE_NEXTION_DISPLAY
|
||||
#ifdef DISPLAY_INVERT_DISPLAY
|
||||
bool DisplayInvertDisplay = DISPLAY_INVERT_DISPLAY;
|
||||
#else
|
||||
bool DisplayInvertDisplay = false;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
|
@ -61,9 +60,11 @@ public:
|
|||
void writeSettings();
|
||||
|
||||
void setPrinterClient(BasePrinterClient *basePrinterClient);
|
||||
void setDisplayClient(BaseDisplayClient *baseDisplayClient);
|
||||
TimeClient *getTimeClient();
|
||||
OpenWeatherMapClient *getWeatherClient();
|
||||
BasePrinterClient *getPrinterClient();
|
||||
BaseDisplayClient *setDisplayClient();
|
||||
String getLastReportStatus();
|
||||
String getVersion();
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#include "Clients/OctoPrintClient.h"
|
||||
#endif
|
||||
#ifdef USE_NEXTION_DISPLAY
|
||||
#include "Display/NextionDisplay.h"
|
||||
#else
|
||||
#include <SSD1306Wire.h>
|
||||
#include <SH1106Wire.h>
|
||||
|
|
@ -26,7 +27,7 @@
|
|||
#endif
|
||||
|
||||
// Initilize all needed data
|
||||
DebugController debugController;
|
||||
DebugController debugController(DEBUG_MODE_ENABLE);
|
||||
TimeClient timeClient(TIME_UTCOFFSET, &debugController);
|
||||
OpenWeatherMapClient weatherClient(WEATHER_APIKEY, WEATHER_CITYID, 1, WEATHER_METRIC, WEATHER_LANGUAGE, &debugController);
|
||||
GlobalDataController globalDataController(&timeClient, &weatherClient, &debugController);
|
||||
|
|
@ -45,6 +46,8 @@ WebServer webServer(&globalDataController, &debugController);
|
|||
|
||||
// Construct correct display client
|
||||
#ifdef USE_NEXTION_DISPLAY
|
||||
SoftwareSerial displaySerialPort(DISPLAY_RX_PIN, DISPLAY_TX_PIN);
|
||||
NextionDisplay displayClient(&displaySerialPort, &globalDataController, &debugController);
|
||||
#else
|
||||
#if DISPLAY_SH1106
|
||||
SH1106Wire display(DISPLAY_I2C_DISPLAY_ADDRESS, DISPLAY_SDA_PIN, DISPLAY_SCL_PIN);
|
||||
|
|
|
|||
|
|
@ -9,12 +9,14 @@ void setup() {
|
|||
LittleFS.begin();
|
||||
debugController.setup();
|
||||
globalDataController.setPrinterClient(&printerClient);
|
||||
globalDataController.setDisplayClient(&displayClient);
|
||||
globalDataController.setup();
|
||||
displayClient.preSetup();
|
||||
displayClient.showBootScreen();
|
||||
|
||||
// WiFiManager - Local intialization. Once its business is done, there is no need to keep it around
|
||||
WiFiManager wifiManager;
|
||||
wifiManager.setDebugOutput(DEBUG_MODE_ENABLE);
|
||||
//wifiManager.resetSettings(); // Uncomment for testing wifi manager
|
||||
wifiManager.setAPCallback(configModeCallback);
|
||||
String hostname(HOSTNAME);
|
||||
|
|
|
|||
Loading…
Reference in New Issue