debug_fram

This commit is contained in:
Siwat Sirichai 2023-12-31 02:18:57 +07:00
parent b4b7232937
commit 091dc183fe
7 changed files with 126 additions and 48 deletions

View file

@ -2,39 +2,26 @@
void InternalDisplay::begin(ESPMegaIoT *iot, std::function<rtctime_t()> getRtcTime) {
ESP_LOGD("InternalDisplay", "Assigning IoT Module and RTC Time Getter");
this->iot = iot;
this->getRtcTime = getRtcTime;
ESP_LOGD("InternalDisplay", "Acquiring Network and MQTT Configs");
this->mqttConfig = this->iot->getMqttConfig();
this->networkConfig = this->iot->getNetworkConfig();
// Register callbacks
ESP_LOGD("InternalDisplay", "Registering Callbacks");
auto bindedPageChangeCallback = std::bind(&InternalDisplay::handlePageChange, this, std::placeholders::_1);
this->registerPageChangeCallback(bindedPageChangeCallback);
auto bindedTouchCallback = std::bind(&InternalDisplay::handleTouch, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
this->registerTouchCallback(bindedTouchCallback);
ESP_LOGD("InternalDisplay", "Binding Page Change Callback");
auto bindedInputStateChangeCallback = std::bind(&InternalDisplay::handleInputStateChange, this, std::placeholders::_1, std::placeholders::_2);
ESP_LOGD("InternalDisplay", "Binding Input State Change Callback");
auto bindedPwmStateChangeCallback = std::bind(&InternalDisplay::handlePwmStateChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
ESP_LOGD("InternalDisplay", "Registering inputCard Callbacks");
this->inputCard->registerCallback(bindedInputStateChangeCallback);
ESP_LOGD("InternalDisplay", "Registering outputCard Callbacks");
this->outputCard->registerChangeCallback(bindedPwmStateChangeCallback);
// Initialize the display
ESP_LOGD("InternalDisplay", "Initializing DisplayAdapter");
this->displayAdapter->begin(115200);
ESP_LOGD("InternalDisplay", "Setting DisplayAdapter Timeout");
this->displayAdapter->setTimeout(100);
ESP_LOGD("InternalDisplay", "Flushing DisplayAdapter");
this->displayAdapter->flush();
ESP_LOGD("InternalDisplay", "Resetting Display");
this->reset();
delay(500);
ESP_LOGD("InternalDisplay", "Jumping to Page 1");
this->jumpToPage(1);
ESP_LOGD("InternalDisplay", "Display Initialization Complete");
}
@ -99,12 +86,7 @@ void InternalDisplay::updateStatusIcons(bool networkStatus, bool mqttStatus) {
void InternalDisplay::updateClock() {
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->displayAdapter->printf("time.txt=\"%02d:%02d %s\"", time.hours%12, time.minutes, time.hours/12 ? "PM" : "AM");
this->sendStopBytes();
}
@ -134,6 +116,12 @@ void InternalDisplay::refreshPage(uint8_t page) {
case INTERNAL_DISPLAY_PWM_ADJUSTMENT_PAGE:
this->refreshPWMAdjustment();
break;
case INTERNAL_DISPLAY_NETWORK_CONFIG_PAGE:
this->refreshNetworkConfig();
break;
case INTERNAL_DISPLAY_MQTT_CONFIG_PAGE:
this->refreshMQTTConfig();
break;
default:
break;
}
@ -269,6 +257,8 @@ void InternalDisplay::bindOutputCard(DigitalOutputCard *outputCard) {
// fan_speed: [auto, low, medium, high]
void InternalDisplay::bindClimateCard(ClimateCard *climateCard) {
this->climateCard = climateCard;
auto bindedACStateChangeCallback = std::bind(&InternalDisplay::handleACStateChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
this->climateCard->registerChangeCallback(bindedACStateChangeCallback);
}
void InternalDisplay::refreshPWMAdjustment() {
@ -379,8 +369,6 @@ void InternalDisplay::handleACTouch(uint8_t type, uint8_t component) {
default:
break;
}
// Refresh the AC page
this->refreshAC();
}
void InternalDisplay::handlePWMAdjustmentTouch(uint8_t type, uint8_t component) {
@ -468,9 +456,8 @@ void InternalDisplay::refreshMQTTConfig() {
this->displayAdapter->print("\"");
this->sendStopBytes();
// Refresh the mqtt port
this->displayAdapter->print("port_set.txt=\"");
this->displayAdapter->print("port_set.val=");
this->displayAdapter->print(this->mqttConfig->mqtt_port);
this->displayAdapter->print("\"");
this->sendStopBytes();
// Refresh the mqtt username
this->displayAdapter->print("user_set.txt=\"");
@ -487,6 +474,10 @@ void InternalDisplay::refreshMQTTConfig() {
this->displayAdapter->print(this->mqttConfig->base_topic);
this->displayAdapter->print("\"");
this->sendStopBytes();
// Refresh the mqtt use auth
this->displayAdapter->print("use_auth.val=");
this->displayAdapter->print(this->mqttConfig->mqtt_useauth ? 1 : 0);
this->sendStopBytes();
}
void InternalDisplay::sendIpToDisplay(IPAddress ip) {
@ -498,4 +489,14 @@ void InternalDisplay::sendIpToDisplay(IPAddress ip) {
this->displayAdapter->print(ip[2]);
this->displayAdapter->print(".");
this->displayAdapter->print(ip[3]);
}
void InternalDisplay::handleACStateChange(uint8_t mode, uint8_t fan_speed, uint8_t temperature) {
// If the climate card is binded to the display and the current page is the AC page
// then update the respective AC component
Serial.println("AC state changed");
if (this->climateCard==nullptr || this->currentPage != INTERNAL_DISPLAY_AC_PAGE) return;
this->sendStopBytes();
// Update the AC state
this->refreshAC();
}