update ids

This commit is contained in:
Siwat Sirichai 2024-01-11 21:29:49 +07:00
parent 2ca65ec643
commit c718750c45
4 changed files with 84 additions and 49 deletions

View file

@ -12,4 +12,5 @@
platform = espressif32 platform = espressif32
board = wt32-eth01 board = wt32-eth01
framework = arduino framework = arduino
lib_deps = siwats/ESPMegaProR3@^2.0.1 lib_deps = siwats/ESPMegaProR3@^2.0.2
monitor_speed = 115200

View file

@ -8,7 +8,6 @@ void CUDDisplay::begin(std::function<rtctime_t()> getTime, HardwareSerial *seria
DigitalInputCard *inputCard, DigitalOutputCard *outputCard, DigitalInputCard *inputCard, DigitalOutputCard *outputCard,
ClimateCard *climateCard) ClimateCard *climateCard)
{ {
ESPMegaDisplay::begin();
this->getTime = getTime; this->getTime = getTime;
this->sendClock(); this->sendClock();
this->inputCard = inputCard; this->inputCard = inputCard;
@ -16,12 +15,20 @@ void CUDDisplay::begin(std::function<rtctime_t()> getTime, HardwareSerial *seria
this->climateCard = climateCard; this->climateCard = climateCard;
auto bindedHandlePWMChange = std::bind(&CUDDisplay::handlePWMChange, this, std::placeholders::_1, std::placeholders::_2); auto bindedHandlePWMChange = std::bind(&CUDDisplay::handlePWMChange, this, std::placeholders::_1, std::placeholders::_2);
auto bindedHandleACChange = std::bind(&CUDDisplay::handleACChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); auto bindedHandleACChange = std::bind(&CUDDisplay::handleACChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
auto bindedHandleTouch = std::bind(&CUDDisplay::handleTouch, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
this->outputCallbackHandle = this->outputCard->registerChangeCallback(bindedHandlePWMChange); this->outputCallbackHandle = this->outputCard->registerChangeCallback(bindedHandlePWMChange);
this->climateCallbackHandle = this->climateCard->registerChangeCallback(bindedHandleACChange); this->climateCallbackHandle = this->climateCard->registerChangeCallback(bindedHandleACChange);
this->registerTouchCallback(bindedHandleTouch);
this->reset();
delay(500);
this->jumpToPage(1);
delay(100);
this->setACControlEnabled(true);
} }
void CUDDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t event) void CUDDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t event)
{ {
Serial.printf("Touch Event on Page %d, Component %d, Event %d\n", page, component, event);
if (page != PAGE_DASHBOARD) if (page != PAGE_DASHBOARD)
return; return;
switch (component) switch (component)
@ -42,46 +49,55 @@ void CUDDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t event)
this->outputCard->setState(7, !this->outputCard->getState(7)); this->outputCard->setState(7, !this->outputCard->getState(7));
break; break;
case COMPONENT_AC_TEMP_UP_BUTTON: case COMPONENT_AC_TEMP_UP_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE) if (event != TOUCH_TYPE_RELEASE)
break; break;
this->climateCard->setTemperature(this->climateCard->getTemperature() + 1); this->climateCard->setTemperature(this->climateCard->getTemperature() + 1);
break; break;
case COMPONENT_AC_TEMP_DOWN_BUTTON: case COMPONENT_AC_TEMP_DOWN_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE) if (event != TOUCH_TYPE_RELEASE)
break; break;
this->climateCard->setTemperature(this->climateCard->getTemperature() - 1); this->climateCard->setTemperature(this->climateCard->getTemperature() - 1);
break; break;
case COMPONENT_AC_MODE_OFF_BUTTON: case COMPONENT_AC_MODE_OFF_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE) if (event != TOUCH_TYPE_RELEASE)
break; break;
this->climateCard->setMode(0); this->climateCard->setMode(0);
break; break;
case COMPONENT_AC_MODE_FAN_ONLY_BUTTON: case COMPONENT_AC_MODE_FAN_ONLY_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE) if (event != TOUCH_TYPE_RELEASE)
break; break;
this->climateCard->setMode(1); this->climateCard->setMode(1);
break; break;
case COMPONENT_AC_MODE_COOL_BUTTON: case COMPONENT_AC_MODE_COOL_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE) if (event != TOUCH_TYPE_RELEASE)
break; break;
this->climateCard->setMode(2); this->climateCard->setMode(2);
break; break;
case COMPONENT_AC_FAN_MODE_AUTO_BUTTON: case COMPONENT_AC_FAN_MODE_AUTO_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE) if (event != TOUCH_TYPE_RELEASE)
break; break;
this->climateCard->setFanSpeed(0); this->climateCard->setFanSpeed(0);
break; break;
case COMPONENT_AC_FAN_MODE_LOW_BUTTON: case COMPONENT_AC_FAN_MODE_LOW_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE) if (event != TOUCH_TYPE_RELEASE)
break; break;
this->climateCard->setFanSpeed(1); this->climateCard->setFanSpeed(1);
break; break;
case COMPONENT_AC_FAN_MODE_MEDIUM_BUTTON: case COMPONENT_AC_FAN_MODE_MEDIUM_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE) if (event != TOUCH_TYPE_RELEASE)
break; break;
this->climateCard->setFanSpeed(2); this->climateCard->setFanSpeed(2);
break; break;
case COMPONENT_AC_FAN_MODE_HIGH_BUTTON: case COMPONENT_AC_FAN_MODE_HIGH_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE) if (event != TOUCH_TYPE_RELEASE)
break; break;
this->climateCard->setFanSpeed(3); this->climateCard->setFanSpeed(3);
@ -185,7 +201,7 @@ void CUDDisplay::updateLightGroupState() {
// Calculate the state // Calculate the state
bool state = calculateLightGroupState(); bool state = calculateLightGroupState();
// Send the state to the display // Send the state to the display
this->displayAdapter->print("LT_BT.pic="); this->displayAdapter->print("lt_bt.pic=");
this->displayAdapter->println(state ? COMPONENT_LIGHT_TOGGLE_PIC_ON : COMPONENT_LIGHT_TOGGLE_PIC_OFF); this->displayAdapter->println(state ? COMPONENT_LIGHT_TOGGLE_PIC_ON : COMPONENT_LIGHT_TOGGLE_PIC_OFF);
this->sendStopBytes(); this->sendStopBytes();
} }
@ -193,7 +209,7 @@ void CUDDisplay::updateFanGroupState() {
// Calculate the state // Calculate the state
bool state = calculateFanGroupState(); bool state = calculateFanGroupState();
// Send the state to the display // Send the state to the display
this->displayAdapter->print("FAN_BT.pic="); this->displayAdapter->print("fan_bt.pic=");
this->displayAdapter->println(state ? COMPONENT_FAN_TOGGLE_PIC_ON : COMPONENT_FAN_TOGGLE_PIC_OFF); this->displayAdapter->println(state ? COMPONENT_FAN_TOGGLE_PIC_ON : COMPONENT_FAN_TOGGLE_PIC_OFF);
this->sendStopBytes(); this->sendStopBytes();
} }
@ -201,7 +217,7 @@ void CUDDisplay::updateAirPurifierState() {
// Get the state // Get the state
bool state = this->outputCard->getState(7); bool state = this->outputCard->getState(7);
// Send the state to the display // Send the state to the display
this->displayAdapter->print("AIR_BT.pic="); this->displayAdapter->print("puri_bt.pic=");
this->displayAdapter->println(state ? COMPONENT_AIR_PURIFIER_TOGGLE_PIC_ON : COMPONENT_AIR_PURIFIER_TOGGLE_PIC_OFF); this->displayAdapter->println(state ? COMPONENT_AIR_PURIFIER_TOGGLE_PIC_ON : COMPONENT_AIR_PURIFIER_TOGGLE_PIC_OFF);
this->sendStopBytes(); this->sendStopBytes();
} }
@ -211,28 +227,39 @@ void CUDDisplay::updateACState() {
uint8_t fan_speed = this->climateCard->getFanSpeed(); uint8_t fan_speed = this->climateCard->getFanSpeed();
uint8_t temperature = this->climateCard->getTemperature(); uint8_t temperature = this->climateCard->getTemperature();
// Send the state to the display // Send the state to the display
this->displayAdapter->print("AC_MODE_OFF.pic="); this->displayAdapter->print("mode_off_btn.pic=");
this->displayAdapter->println(mode == 0 ? COMPONENT_AC_MODE_OFF_PIC_ACTIVE : COMPONENT_AC_MODE_OFF_PIC_INACTIVE); this->displayAdapter->println(mode == 0 ? COMPONENT_AC_MODE_OFF_PIC_ACTIVE : COMPONENT_AC_MODE_OFF_PIC_INACTIVE);
this->sendStopBytes(); this->sendStopBytes();
this->displayAdapter->print("AC_MODE_FAN_ONLY.pic="); this->displayAdapter->print("mode_fan_btn.pic=");
this->displayAdapter->println(mode == 1 ? COMPONENT_AC_MODE_FAN_ONLY_PIC_ACTIVE : COMPONENT_AC_MODE_FAN_ONLY_PIC_INACTIVE); this->displayAdapter->println(mode == 1 ? COMPONENT_AC_MODE_FAN_ONLY_PIC_ACTIVE : COMPONENT_AC_MODE_FAN_ONLY_PIC_INACTIVE);
this->sendStopBytes(); this->sendStopBytes();
this->displayAdapter->print("AC_MODE_COOL.pic="); this->displayAdapter->print("mode_cool_btn.pic=");
this->displayAdapter->println(mode == 2 ? COMPONENT_AC_MODE_COOL_PIC_ACTIVE : COMPONENT_AC_MODE_COOL_PIC_INACTIVE); this->displayAdapter->println(mode == 2 ? COMPONENT_AC_MODE_COOL_PIC_ACTIVE : COMPONENT_AC_MODE_COOL_PIC_INACTIVE);
this->sendStopBytes(); this->sendStopBytes();
this->displayAdapter->print("AC_FAN_MODE_AUTO.pic="); this->displayAdapter->print("fan_auto_btn.pic=");
this->displayAdapter->println(fan_speed == 0 ? COMPONENT_AC_FAN_MODE_AUTO_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_AUTO_PIC_INACTIVE); this->displayAdapter->println(fan_speed == 0 ? COMPONENT_AC_FAN_MODE_AUTO_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_AUTO_PIC_INACTIVE);
this->sendStopBytes(); this->sendStopBytes();
this->displayAdapter->print("AC_FAN_MODE_HIGH.pic="); this->displayAdapter->print("fan_1_btn.pic=");
this->displayAdapter->println(fan_speed == 1 ? COMPONENT_AC_FAN_MODE_HIGH_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_HIGH_PIC_INACTIVE); this->displayAdapter->println(fan_speed == 1 ? COMPONENT_AC_FAN_MODE_HIGH_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_HIGH_PIC_INACTIVE);
this->sendStopBytes(); this->sendStopBytes();
this->displayAdapter->print("AC_FAN_MODE_MEDIUM.pic="); this->displayAdapter->print("fan_2_btn.pic=");
this->displayAdapter->println(fan_speed == 2 ? COMPONENT_AC_FAN_MODE_MEDIUM_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_MEDIUM_PIC_INACTIVE); this->displayAdapter->println(fan_speed == 2 ? COMPONENT_AC_FAN_MODE_MEDIUM_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_MEDIUM_PIC_INACTIVE);
this->sendStopBytes(); this->sendStopBytes();
this->displayAdapter->print("AC_FAN_MODE_LOW.pic="); this->displayAdapter->print("fan_3_btn.pic=");
this->displayAdapter->println(fan_speed == 3 ? COMPONENT_AC_FAN_MODE_LOW_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_LOW_PIC_INACTIVE); this->displayAdapter->println(fan_speed == 3 ? COMPONENT_AC_FAN_MODE_LOW_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_LOW_PIC_INACTIVE);
this->sendStopBytes(); this->sendStopBytes();
this->displayAdapter->print("AC_TEMP.val="); this->displayAdapter->print("temp_txt.txt=");
this->displayAdapter->println(temperature); this->displayAdapter->println(temperature);
this->displayAdapter->print("C");
this->sendStopBytes(); this->sendStopBytes();
} }
void CUDDisplay::setACControlEnabled(bool enabled) {
ac_control_enabled = enabled;
this->displayAdapter->print("dashboard.pic=");
this->displayAdapter->print(enabled ? COMPONENT_BACKGROUND_AC_UNLOCK : COMPONENT_BACKGROUND_AC_LOCK);
this->sendStopBytes();
}
bool CUDDisplay::getACControlEnabled() {
return ac_control_enabled;
}

View file

@ -13,48 +13,51 @@ Pin Mapping
*/ */
// Touch Types // Touch Types
#define TOUCH_TYPE_PRESS 0 #define TOUCH_TYPE_PRESS 1
#define TOUCH_TYPE_RELEASE 1 #define TOUCH_TYPE_RELEASE 0
// Page IDs // Page IDs
#define PAGE_BOOT 0 #define PAGE_BOOT 0
#define PAGE_DASHBOARD 1 #define PAGE_DASHBOARD 1
// Dashboard Toggle Buttons // Dashboard Toggle Buttons
#define COMPONENT_LIGHT_TOGGLE_BUTTON 1 #define COMPONENT_LIGHT_TOGGLE_BUTTON 11
#define COMPONENT_LIGHT_TOGGLE_PIC_ON 11 #define COMPONENT_LIGHT_TOGGLE_PIC_ON 4
#define COMPONENT_LIGHT_TOGGLE_PIC_OFF 12 #define COMPONENT_LIGHT_TOGGLE_PIC_OFF 3
#define COMPONENT_FAN_TOGGLE_BUTTON 2 #define COMPONENT_FAN_TOGGLE_BUTTON 12
#define COMPONENT_FAN_TOGGLE_PIC_ON 21 #define COMPONENT_FAN_TOGGLE_PIC_ON 6
#define COMPONENT_FAN_TOGGLE_PIC_OFF 22 #define COMPONENT_FAN_TOGGLE_PIC_OFF 5
#define COMPONENT_AIR_PURIFIER_TOGGLE_BUTTON 3 #define COMPONENT_AIR_PURIFIER_TOGGLE_BUTTON 13
#define COMPONENT_AIR_PURIFIER_TOGGLE_PIC_ON 31 #define COMPONENT_AIR_PURIFIER_TOGGLE_PIC_ON 8
#define COMPONENT_AIR_PURIFIER_TOGGLE_PIC_OFF 32 #define COMPONENT_AIR_PURIFIER_TOGGLE_PIC_OFF 7
// Dashboard AC Controls // Dashboard AC Controls
#define COMPONENT_AC_TEMP_UP_BUTTON 4 #define COMPONENT_AC_TEMP_UP_BUTTON 2
#define COMPONENT_AC_TEMP_DOWN_BUTTON 5 #define COMPONENT_AC_TEMP_DOWN_BUTTON 3
#define COMPONENT_AC_MODE_OFF_BUTTON 6 #define COMPONENT_AC_MODE_OFF_BUTTON 4
#define COMPONENT_AC_MODE_OFF_PIC_ACTIVE 61 #define COMPONENT_AC_MODE_OFF_PIC_ACTIVE 14
#define COMPONENT_AC_MODE_OFF_PIC_INACTIVE 62 #define COMPONENT_AC_MODE_OFF_PIC_INACTIVE 13
#define COMPONENT_AC_MODE_FAN_ONLY_BUTTON 7 #define COMPONENT_AC_MODE_FAN_ONLY_BUTTON 5
#define COMPONENT_AC_MODE_FAN_ONLY_PIC_ACTIVE 71 #define COMPONENT_AC_MODE_FAN_ONLY_PIC_ACTIVE 16
#define COMPONENT_AC_MODE_FAN_ONLY_PIC_INACTIVE 72 #define COMPONENT_AC_MODE_FAN_ONLY_PIC_INACTIVE 15
#define COMPONENT_AC_MODE_COOL_BUTTON 8 #define COMPONENT_AC_MODE_COOL_BUTTON 6
#define COMPONENT_AC_MODE_COOL_PIC_ACTIVE 81 #define COMPONENT_AC_MODE_COOL_PIC_ACTIVE 18
#define COMPONENT_AC_MODE_COOL_PIC_INACTIVE 82 #define COMPONENT_AC_MODE_COOL_PIC_INACTIVE 17
#define COMPONENT_AC_FAN_MODE_AUTO_BUTTON 9 #define COMPONENT_AC_FAN_MODE_AUTO_BUTTON 7
#define COMPONENT_AC_FAN_MODE_AUTO_PIC_ACTIVE 91 #define COMPONENT_AC_FAN_MODE_AUTO_PIC_ACTIVE 20
#define COMPONENT_AC_FAN_MODE_AUTO_PIC_INACTIVE 92 #define COMPONENT_AC_FAN_MODE_AUTO_PIC_INACTIVE 19
#define COMPONENT_AC_FAN_MODE_LOW_BUTTON 10 #define COMPONENT_AC_FAN_MODE_LOW_BUTTON 8
#define COMPONENT_AC_FAN_MODE_LOW_PIC_ACTIVE 101 #define COMPONENT_AC_FAN_MODE_LOW_PIC_ACTIVE 22
#define COMPONENT_AC_FAN_MODE_LOW_PIC_INACTIVE 102 #define COMPONENT_AC_FAN_MODE_LOW_PIC_INACTIVE 21
#define COMPONENT_AC_FAN_MODE_MEDIUM_BUTTON 11 #define COMPONENT_AC_FAN_MODE_MEDIUM_BUTTON 9
#define COMPONENT_AC_FAN_MODE_MEDIUM_PIC_ACTIVE 111 #define COMPONENT_AC_FAN_MODE_MEDIUM_PIC_ACTIVE 24
#define COMPONENT_AC_FAN_MODE_MEDIUM_PIC_INACTIVE 112 #define COMPONENT_AC_FAN_MODE_MEDIUM_PIC_INACTIVE 23
#define COMPONENT_AC_FAN_MODE_HIGH_BUTTON 12 #define COMPONENT_AC_FAN_MODE_HIGH_BUTTON 10
#define COMPONENT_AC_FAN_MODE_HIGH_PIC_ACTIVE 121 #define COMPONENT_AC_FAN_MODE_HIGH_PIC_ACTIVE 26
#define COMPONENT_AC_FAN_MODE_HIGH_PIC_INACTIVE 122 #define COMPONENT_AC_FAN_MODE_HIGH_PIC_INACTIVE 25
#define COMPONENT_BACKGROUND_AC_LOCK 2
#define COMPONENT_BACKGROUND_AC_UNLOCK 1
/** /**
* @brief A class for controlling the ESPMegaDisplay. * @brief A class for controlling the ESPMegaDisplay.
@ -69,7 +72,10 @@ class CUDDisplay : public ESPMegaDisplay {
void handlePWMChange(uint8_t pin, uint8_t value); void handlePWMChange(uint8_t pin, uint8_t value);
void handleACChange(uint8_t mode, uint8_t fan_speed, uint8_t temperature); void handleACChange(uint8_t mode, uint8_t fan_speed, uint8_t temperature);
void sendClock(); void sendClock();
void setACControlEnabled(bool enabled);
bool getACControlEnabled();
private: private:
bool ac_control_enabled = true;
std::function<rtctime_t()> getTime; std::function<rtctime_t()> getTime;
DigitalInputCard* inputCard; DigitalInputCard* inputCard;
DigitalOutputCard* outputCard; DigitalOutputCard* outputCard;

View file

@ -8,12 +8,12 @@
// Display Configuration // Display Configuration
#define cudDisplayAdapter Serial2 #define cudDisplayAdapter Serial2
#define CUD_DISPLAY_BAUD_RATE 115200 #define CUD_DISPLAY_BAUD_RATE 115200
#define CUD_DISPLAY_TX_PIN 16 #define CUD_DISPLAY_TX_PIN 4
#define CUD_DISPLAY_RX_PIN 17 #define CUD_DISPLAY_RX_PIN 17
//Air Conditioner Configuration //Air Conditioner Configuration
#define AIR_CONDITIONER_SENSOR_TYPE AC_SENSOR_TYPE_DHT22 #define AIR_CONDITIONER_SENSOR_TYPE AC_SENSOR_TYPE_DHT22
#define AIR_CONDITIONER_SENSOR_PIN 4 #define AIR_CONDITIONER_SENSOR_PIN 32
#define AIR_CONDITIONER_IR_PIN 5 #define AIR_CONDITIONER_IR_PIN 5
#define AIR_CONDITIONER_RMT_CHANNEL RMT_CHANNEL_0 #define AIR_CONDITIONER_RMT_CHANNEL RMT_CHANNEL_0
@ -58,6 +58,7 @@ void setup() {
climateCard.bindFRAM(&espmega.fram, 5000); climateCard.bindFRAM(&espmega.fram, 5000);
climateCard.loadStateFromFRAM(); climateCard.loadStateFromFRAM();
climateCard.setFRAMAutoSave(true); climateCard.setFRAMAutoSave(true);
espmega.display->bindClimateCard(&climateCard);
espmega.iot->registerCard(3); espmega.iot->registerCard(3);
cudDisplayAdapter.begin(CUD_DISPLAY_BAUD_RATE, SERIAL_8N1, CUD_DISPLAY_RX_PIN, CUD_DISPLAY_TX_PIN); cudDisplayAdapter.begin(CUD_DISPLAY_BAUD_RATE, SERIAL_8N1, CUD_DISPLAY_RX_PIN, CUD_DISPLAY_TX_PIN);
auto bindedGetTime = std::bind(&ESPMegaPRO::getTime, &espmega); auto bindedGetTime = std::bind(&ESPMegaPRO::getTime, &espmega);