migrate mqtt config to struct

This commit is contained in:
Siwat Sirichai 2023-12-29 23:43:12 +07:00
parent 2dee25276c
commit 71475ef2f1
7 changed files with 125 additions and 82 deletions

View file

@ -1,8 +1,7 @@
#include <InternalDisplay.hpp>
void InternalDisplay::begin(ESPMegaPRO *espmega) {
this->espmega = espmega;
void InternalDisplay::begin() {
}
void InternalDisplay::loop() {
@ -26,17 +25,23 @@ void InternalDisplay::bindOutputCard(uint8_t card_id) {
void InternalDisplay::handleInputStateChange(uint8_t pin, bool state) {
// If the input card is binded to the display and the current page is the input page
// then update the respective input component
// TODO: implementation
if (!this->bindedInputCard || this->currentPage != INTERNAL_DISPLAY_INPUT_PAGE) return;
// Update the input state
this->setInputMarker(pin, state);
}
void InternalDisplay::handlePwmStateChange(uint8_t pin, uint16_t value) {
void InternalDisplay::handlePwmStateChange(uint8_t pin, bool state, uint16_t value) {
// If the output card is binded to the display and the current page is the output page
// then update the respective output component
// TODO: implementation
if (!this->bindedOutputCard || this->currentPage != INTERNAL_DISPLAY_OUTPUT_PAGE) return;
// Update the output state
this->setOutputBar(pin, value);
this->setOutputStateColor(pin, state);
}
void InternalDisplay::handlePageChange(uint8_t page) {
// TODO: implementation
// Refresh the page
this->refreshPage(page);
}
void InternalDisplay::saveNetworkConfig() {
@ -47,24 +52,51 @@ void InternalDisplay::saveMQTTConfig() {
// TODO: implementation
}
void InternalDisplay::updateStatusIcons() {
// TODO: implementation
void InternalDisplay::updateStatusIcons(bool networkStatus, bool mqttStatus) {
this->setNumber("server.pic", mqttStatus ? PIC_MQTT_CONNECTED : PIC_MQTT_DISCONNECTED);
this->setNumber("lan.pic", networkStatus ? PIC_LAN_CONNECTED : PIC_LAN_DISCONNECTED);
}
void InternalDisplay::updateClock() {
// TODO: implementation
rtctime_t time = this->getRtcTime();
this->displayAdapter->print("time.txt=");
this->displayAdapter->print(time.hours%12);
this->displayAdapter->print(":");
this->displayAdapter->print(time.minutes);
this->displayAdapter->print(" ");
this->displayAdapter->print(time.hours/12 ? "PM" : "AM");
this->sendStopBytes();
}
void InternalDisplay::refreshPage() {
// TODO: implementation
this->refreshPage(this->currentPage);
}
void InternalDisplay::refreshPage(uint8_t page) {
// TODO: implementation
switch (page) {
case INTERNAL_DISPLAY_DASHBOARD_PAGE:
this->refreshDashboard();
break;
case INTERNAL_DISPLAY_INPUT_PAGE:
this->refreshInput();
break;
case INTERNAL_DISPLAY_OUTPUT_PAGE:
this->refreshOutput();
break;
case INTERNAL_DISPLAY_AC_PAGE:
this->refreshAC();
break;
}
}
void InternalDisplay::refreshDashboard() {
// TODO: implementation
// The dashboard have the following components:
// 1. Hostname
// 2. IP Address
// 3. MQTT Server with port
// 4. MQTT Connection status
this->iot->
}
void InternalDisplay::refreshInput() {