display setting updating

This commit is contained in:
Siwat Sirichai 2023-12-31 00:51:34 +07:00
parent 19aae95252
commit b4b7232937
3 changed files with 85 additions and 1 deletions

View File

@ -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]);
}

View File

@ -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);

View File

@ -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");