From b4b7232937f140ba1de90360d6611bfad95d22fd Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sun, 31 Dec 2023 00:51:34 +0700 Subject: [PATCH] display setting updating --- .../lib/ESPMegaPRO/InternalDisplay.cpp | 81 ++++++++++++++++++- .../lib/ESPMegaPRO/InternalDisplay.hpp | 3 + ESPMegaPRO-firmware/src/main.cpp | 2 + 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp b/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp index 4be284b..d0c4cbc 100644 --- a/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp +++ b/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp @@ -416,7 +416,86 @@ void InternalDisplay::handlePWMAdjustmentTouch(uint8_t type, uint8_t component) default: break; } - +} +void InternalDisplay::refreshNetworkConfig() { + // The network config page have the following components: + // ip_set -> a text input to set the ip address + // netmask_set -> a text input to set the netmask + // gateway_set -> a text input to set the gateway + // dns_set -> a text input to set the dns + // hostname_set -> a text input to set the hostnam + // Refresh the ip address + this->displayAdapter->print("ip_set.txt=\""); + this->sendIpToDisplay(this->networkConfig->ip); + this->displayAdapter->print("\""); + this->sendStopBytes(); + // Refresh the netmask + this->displayAdapter->print("netmask_set.txt=\""); + this->sendIpToDisplay(this->networkConfig->subnet); + this->displayAdapter->print("\""); + this->sendStopBytes(); + // Refresh the gateway + this->displayAdapter->print("gateway_set.txt=\""); + this->sendIpToDisplay(this->networkConfig->gateway); + this->displayAdapter->print("\""); + this->sendStopBytes(); + // Refresh the dns + this->displayAdapter->print("dns_set.txt=\""); + this->sendIpToDisplay(this->networkConfig->dns1); + this->displayAdapter->print("\""); + this->sendStopBytes(); + // Refresh the hostname + this->displayAdapter->print("hostname_set.txt=\""); + this->displayAdapter->print(this->networkConfig->hostname); + this->displayAdapter->print("\""); + this->sendStopBytes(); +} + +void InternalDisplay::refreshMQTTConfig() { + // The MQTT config page have the following components: + // mqttsv_set -> a text input to set the mqtt server + // port_set -> a text input to set the mqtt port + // use_auth -> a checkbox to enable/disable mqtt authentication + // user_set -> a text input to set the mqtt username + // password_set -> a text input to set the mqtt password + // topic_set -> a text input to set the mqtt base topic + + // Refresh the mqtt server + this->displayAdapter->print("mqttsv_set.txt=\""); + this->displayAdapter->print(this->mqttConfig->mqtt_server); + this->displayAdapter->print("\""); + this->sendStopBytes(); + // Refresh the mqtt port + this->displayAdapter->print("port_set.txt=\""); + this->displayAdapter->print(this->mqttConfig->mqtt_port); + this->displayAdapter->print("\""); + this->sendStopBytes(); + // Refresh the mqtt username + this->displayAdapter->print("user_set.txt=\""); + this->displayAdapter->print(this->mqttConfig->mqtt_user); + this->displayAdapter->print("\""); + this->sendStopBytes(); + // Refresh the mqtt password + this->displayAdapter->print("password_set.txt=\""); + this->displayAdapter->print(this->mqttConfig->mqtt_password); + this->displayAdapter->print("\""); + this->sendStopBytes(); + // Refresh the mqtt base topic + this->displayAdapter->print("topic_set.txt=\""); + this->displayAdapter->print(this->mqttConfig->base_topic); + this->displayAdapter->print("\""); + this->sendStopBytes(); +} + +void InternalDisplay::sendIpToDisplay(IPAddress ip) { + // Send the ip address + this->displayAdapter->print(ip[0]); + this->displayAdapter->print("."); + this->displayAdapter->print(ip[1]); + this->displayAdapter->print("."); + this->displayAdapter->print(ip[2]); + this->displayAdapter->print("."); + this->displayAdapter->print(ip[3]); } \ No newline at end of file diff --git a/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.hpp b/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.hpp index 2927916..559e11c 100644 --- a/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.hpp +++ b/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.hpp @@ -98,6 +98,9 @@ class InternalDisplay : public ESPMegaDisplay { void refreshPWMAdjustmentSlider(); void refreshPWMAdjustmentState(); void refreshPWMAdjustmentId(); + void refreshNetworkConfig(); + void refreshMQTTConfig(); + void sendIpToDisplay(IPAddress ip); uint8_t pmwAdjustmentPin; // Touch handlers void handleTouch(uint8_t page, uint8_t component, uint8_t type); diff --git a/ESPMegaPRO-firmware/src/main.cpp b/ESPMegaPRO-firmware/src/main.cpp index 06fd5c1..1dd0e57 100644 --- a/ESPMegaPRO-firmware/src/main.cpp +++ b/ESPMegaPRO-firmware/src/main.cpp @@ -67,6 +67,7 @@ void setup() { strcpy(config.hostname, "espmega"); Serial.println("Setting network config"); espmega.iot->setNetworkConfig(config); + espmega.iot->saveNetworkConfig(); Serial.println("Connecting to network"); espmega.iot->connectNetwork(); Serial.println("Begin MQTT Modules"); @@ -79,6 +80,7 @@ void setup() { strcpy(mqtt_config.base_topic, "/espmegaoop"); Serial.println("Loading MQTT Config Struct to IoT Module"); espmega.iot->setMqttConfig(mqtt_config); + espmega.iot->saveMqttConfig(); Serial.println("Connecting to MQTT"); espmega.iot->connectToMqtt(); Serial.println("Registering Output Card");