pre-eth-dbg

This commit is contained in:
Siwat Sirichai 2023-12-31 15:53:39 +07:00
parent e8804864b8
commit 443a02c319
7 changed files with 240 additions and 79 deletions

View file

@ -75,12 +75,117 @@ void InternalDisplay::handlePageChange(uint8_t page)
void InternalDisplay::saveNetworkConfig()
{
// TODO: implementation
// 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
// host_set -> a text input to set the hostname
Serial.println("Saving network config");
this->sendStopBytes();
// Save the ip address
IPAddress ip;
// 000.000.000.000, 16 characters, 3 dots, 3 characters per octet, 1 null terminator
char ip_buffer[30];
Serial.println("Getting ip_set.txt");
this->sendStopBytes();
if(!this->getStringToBuffer("ip_set.txt", ip_buffer, 30))
{
Serial.println("Failed to get ip_set.txt");
this->sendStopBytes();
return;
}
Serial.println("Got ip_set.txt");
this->sendStopBytes();
// Validate the ip address
if (!ip.fromString(ip_buffer)) {
Serial.println("Invalid ip address");
Serial.print("The recieved IP is: ");
Serial.println(ip_buffer);
this->sendStopBytes();
return;
}
// Save the netmask
IPAddress netmask;
if (!this->getStringToBuffer("netmask_set.txt", ip_buffer, 30)) {
return;
}
// Validate the netmask
if (!netmask.fromString(ip_buffer)) {
return;
}
// Save the gateway
IPAddress gateway;
if (!this->getStringToBuffer("gateway_set.txt", ip_buffer, 30)) {
return;
}
// Validate the gateway
if (!gateway.fromString(ip_buffer)) {
return;
}
// Save the dns
IPAddress dns;
if(!this->getStringToBuffer("dns_set.txt", ip_buffer, 30))
return;
// Validate the dns
if (!dns.fromString(ip_buffer))
return;
// Save the hostname
if(!this->getStringToBuffer("host_set.txt", this->networkConfig->hostname, 32))
return;
// Write the ip address, netmask and gateway to the network config
this->networkConfig->ip = ip;
this->networkConfig->subnet = netmask;
this->networkConfig->gateway = gateway;
this->networkConfig->dns1 = dns;
this->networkConfig->dns2 = dns;
this->networkConfig->useStaticIp = true;
this->networkConfig->useWifi = false;
this->networkConfig->wifiUseAuth = false;
this->iot->saveNetworkConfig();
ESP.restart();
}
void InternalDisplay::saveMQTTConfig()
{
// TODO: implementation
// 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
// Save the mqtt server
if(!this->getStringToBuffer("mqttsv_set.txt", this->mqttConfig->mqtt_server, 16))
return;
// Save the mqtt port
this->mqttConfig->mqtt_port = this->getNumber("port_set.val");
// Save the mqtt username
if(!this->getStringToBuffer("user_set.txt", this->mqttConfig->mqtt_user, 16))
return;
// Save the mqtt password
if(!this->getStringToBuffer("password_set.txt", this->mqttConfig->mqtt_password, 16))
return;
// Save the mqtt base topic
if(!this->getStringToBuffer("topic_set.txt", this->mqttConfig->base_topic, 16))
return;
// Save the mqtt use auth
this->mqttConfig->mqtt_useauth = this->getNumber("use_auth.val") == 1 ? true : false;
this->iot->saveMqttConfig();
ESP.restart();
}
void InternalDisplay::updateStatusIcons(bool networkStatus, bool mqttStatus)
@ -109,9 +214,19 @@ void InternalDisplay::refreshPage(uint8_t page)
this->refreshDashboard();
break;
case INTERNAL_DISPLAY_INPUT_PAGE:
if (this->inputCard == nullptr)
{
this->jumpToPage(INTERNAL_DISPLAY_INPUT_NULL_PTR_PAGE);
break;
}
this->refreshInput();
break;
case INTERNAL_DISPLAY_OUTPUT_PAGE:
if (this->outputCard == nullptr)
{
this->jumpToPage(INTERNAL_DISPLAY_OUTPUT_NULL_PTR_PAGE);
break;
}
this->refreshOutput();
break;
case INTERNAL_DISPLAY_AC_PAGE:
@ -382,6 +497,14 @@ void InternalDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t type)
case INTERNAL_DISPLAY_PWM_ADJUSTMENT_PAGE:
this->handlePWMAdjustmentTouch(type, component);
break;
case INTERNAL_DISPLAY_NETWORK_CONFIG_PAGE:
if (type == TOUCH_TYPE_RELEASE && component == 7)
this->saveNetworkConfig();
break;
case INTERNAL_DISPLAY_MQTT_CONFIG_PAGE:
if (type == TOUCH_TYPE_RELEASE && component == 2)
this->saveMQTTConfig();
break;
default:
break;
}
@ -495,7 +618,7 @@ void InternalDisplay::refreshNetworkConfig()
// 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
// host_set -> a text input to set the hostname
// Refresh the ip address
this->displayAdapter->print("ip_set.txt=\"");
@ -518,7 +641,7 @@ void InternalDisplay::refreshNetworkConfig()
this->displayAdapter->print("\"");
this->sendStopBytes();
// Refresh the hostname
this->displayAdapter->print("hostname_set.txt=\"");
this->displayAdapter->print("host_set.txt=\"");
this->displayAdapter->print(this->networkConfig->hostname);
this->displayAdapter->print("\"");
this->sendStopBytes();