WIP, light should 'work' hopefully

This commit is contained in:
reaw55 2024-02-03 05:48:59 +07:00
parent 70f6ae0092
commit f0bdfe0d03
4 changed files with 432 additions and 22 deletions

Binary file not shown.

View file

@ -103,17 +103,17 @@ picture id:
36 light-master-off-p 36 light-master-off-p
37 light-master-on 37 light-master-on
38 light-master-on-p 38 light-master-on-p
39 light-level-1 39 light-level-0
40 light-level-2 40 light-level-1
41 light-level-3 41 light-level-2
42 light-level-4 42 light-level-3
object id: object id:
0 main 0 main
1 ac_temp (number) 1 ac_temp (number)
2 pm_fan (number 0-20) 2 pm_speed (number 0-20)
3 ac_sw 3 ac_sw
4 ac_mode 4 ac_mode
5 ac_speed 5 ac_speed

View file

@ -34,6 +34,7 @@ ISEDisplay(HardwareSerial* adapter);
auto bindedHandleTouch = std::bind(&ISEDisplay::handleTouch, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); auto bindedHandleTouch = std::bind(&ISEDisplay::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->user_mode = 1; // set to cool by default
this->registerTouchCallback(bindedHandleTouch); this->registerTouchCallback(bindedHandleTouch);
this->reset(); this->reset();
delay(1000); delay(1000);
@ -46,8 +47,195 @@ ISEDisplay(HardwareSerial* adapter);
} }
void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type){
if (page == PAGE_STANDBY){
switch (component)
{
case COMPONENT_STANDBY_OPEN_ALL_TOGGLE:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
this->jumpToPage(2);
break;
case COMPONENT_STANDBY_LIGHT_TOGGLE:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
updateLightGroupStatePageStandby();
break;
case COMPONENT_STANDBY_AC_TOGGLE:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
this->climateCard->setMode(this->climateCard->getMode() == 0 ? 1 : 0);
// need fix
break;
case COMPONENT_STANDBY_PM_TOGGLE:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
this->outputCard->setState(5, !this->outputCard->getState(5));
break;
default:
break;
}
}
else if (page == PAGE_DASHBOARD){
switch (component)
{
case COMPONENT_LIGHT_MASTER_BUTTON:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
updateLightGroupStatePageDashboard();
break;
case COMPONENT_LIGHT_ROW1_LEVEL0_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(1, 0);
break;
case COMPONENT_LIGHT_ROW1_LEVEL1_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(1, 1);
break;
case COMPONENT_LIGHT_ROW1_LEVEL2_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(1, 2);
break;
case COMPONENT_LIGHT_ROW1_LEVEL3_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(1, 3);
break;
case COMPONENT_LIGHT_ROW2_LEVEL0_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(2, 0);
break;
case COMPONENT_LIGHT_ROW2_LEVEL1_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(2, 1);
break;
case COMPONENT_LIGHT_ROW2_LEVEL2_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(2, 2);
break;
case COMPONENT_LIGHT_ROW2_LEVEL3_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(2, 3);
break;
case COMPONENT_LIGHT_ROW3_LEVEL0_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(3, 0);
break;
case COMPONENT_LIGHT_ROW3_LEVEL1_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(3, 1);
break;
case COMPONENT_LIGHT_ROW3_LEVEL2_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(3, 2);
break;
case COMPONENT_LIGHT_ROW3_LEVEL3_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(3, 3);
break;
case COMPONENT_LIGHT_ROW4_LEVEL0_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(4, 0);
break;
case COMPONENT_LIGHT_ROW4_LEVEL1_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(4, 1);
break;
case COMPONENT_LIGHT_ROW4_LEVEL2_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(4, 2);
break;
case COMPONENT_LIGHT_ROW4_LEVEL3_TOUCHPOINT:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
setLightLevel(4, 3);
break;
case COMPONENT_AC_TOGGLE_BUTTON:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
this->climateCard->setMode(this->climateCard->getMode() == 0 ? 1 : 0);
// need fix
break;
case COMPONENT_AC_MODE:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
this->climateCard->setMode(this->climateCard->getMode() == 0 ? 1 : 0);
// need fix
break;
case COMPONENT_AC_FAN_SPEED:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
uint8_t fan_speed = this->climateCard->getFanSpeed();
this->climateCard->setFanSpeed((fan_speed + 1)%3);
break;
case COMPONENT_AC_TEMP_DOWN_BUTTON:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
this->climateCard->setTemperature(this->climateCard->getTemperature() - 1);
break;
case COMPONENT_AC_TEMP_UP_BUTTON:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
this->climateCard->setTemperature(this->climateCard->getTemperature() + 1);
break;
case COMPONENT_PM_TOGGLE_BUTTON:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
this->outputCard->setState(5, !this->outputCard->getState(5));
break;
case COMPONENT_PM_FAN_SPEED_DECREASE:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
uint8_t pm_fan_speed = this->outputCard->getState(6);
if (pm_fan_speed >= 0 && pm_fan_speed <= 20)
this->outputCard->setState(5, (pm_fan_speed - 1));
break;
case COMPONENT_PM_FAN_SPEED_INCREASE:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
uint8_t pm_fan_speed = this->outputCard->getState(6);
if (pm_fan_speed >= 0 && pm_fan_speed <= 20)
this->outputCard->setState(5, (pm_fan_speed + 1));
break;
default:
break;
}
}
else{
return;
}
}
void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value){
if (pin >= 1 && pin <= 4)
{
// Light
updateLightGroupStatePageDashboard();
updateLightGroupStatePageStandby();
}
else if (pin == 0)
{
// Air Purifier
updateAirPurifierState();
}
}
void ISEDisplay::updateDateTimeText(rtctime_t time){ void ISEDisplay::updateDateTimeText(rtctime_t time){
this->takeSerialMutex(); this->takeSerialMutex();
// Send the time to the display // Send the time to the display
@ -76,35 +264,234 @@ void ISEDisplay::updatePMinside(float pm25_inside){
} }
void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type){
}
void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value){
}
void ISEDisplay::setPMstate(bool is_pm_on, uint8_t pm_fan_speed){ void ISEDisplay::setPMstate(bool is_pm_on, uint8_t pm_fan_speed){
} }
void ISEDisplay::setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_temperature){ void ISEDisplay::setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_temperature){
updateACState();
} }
void ISEDisplay::setLightLevel(uint8_t row, uint8_t level){ void ISEDisplay::setLightLevel(uint8_t row, uint8_t level){
for (uint8_t i = 1; i <= 4; i++) {
if(row == i)
this->outputCard->setState(row, level);
}
} }
void ISEDisplay::updateLightGroupState(){ void ISEDisplay::updateLightGroupStatePageStandby(){
// Calculate the state
bool state = calculateLightGroupState();
// Send the state to the display
this->takeSerialMutex();
this->displayAdapter->print("s_light_toggle.pic=");
this->displayAdapter->print(state ? COMPONENT_STANDBY_LIGHT_PIC_ON : COMPONENT_STANDBY_LIGHT_PIC_OFF);
this->sendStopBytes();
this->displayAdapter->print("s_light_toggle.pic2=");
this->displayAdapter->print(state ? COMPONENT_STANDBY_LIGHT_PIC_ON_PRESSED : COMPONENT_STANDBY_LIGHT_PIC_OFF_PRESSED);
this->sendStopBytes();
this->giveSerialMutex();
}
void ISEDisplay::updateLightGroupStatePageDashboard(){
// Calculate the state
bool state = calculateLightGroupState();
// Send the state to the display
this->takeSerialMutex();
this->displayAdapter->print("light_master.pic=");
this->displayAdapter->print(state ? COMPONENT_LIGHT_MASTER_ON : COMPONENT_LIGHT_MASTER_OFF);
this->sendStopBytes();
this->displayAdapter->print("light_master.pic2=");
this->displayAdapter->print(state ? COMPONENT_LIGHT_MASTER_ON_PRESSED : COMPONENT_LIGHT_MASTER_OFF_PRESSED);
this->sendStopBytes();
for (uint8_t i = 1; i <= 4; i++) {
u_int8_t state = this->outputCard->getState(i);
switch (state)
{
case 0:
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print(".pic=");
this->displayAdapter->print(COMPONENT_LIGHT_LEVEL_0);
this->sendStopBytes();
break;
case 1:
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print(".pic=");
this->displayAdapter->print(COMPONENT_LIGHT_LEVEL_1);
this->sendStopBytes();
break;
case 2:
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print(".pic=");
this->displayAdapter->print(COMPONENT_LIGHT_LEVEL_2);
this->sendStopBytes();
break;
case 3:
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print(".pic=");
this->displayAdapter->print(COMPONENT_LIGHT_LEVEL_3);
this->sendStopBytes();
break;
default:
break;
}
} }
this->giveSerialMutex();
}
bool ISEDisplay::calculateLightGroupState() {
// Check if all lights are on
bool lightOn = false;
for (uint8_t i = 1; i <= 4; i++) {
if (this->outputCard->getState(i) != 0) {
lightOn = true;
break;
}
}
return lightOn;
}
void ISEDisplay::updateAirPurifierState(){ void ISEDisplay::updateAirPurifierState(){
// Get the state
bool state = this->outputCard->getState(5);
uint8_t fan_speed = this->outputCard->getState(5);
// Send the state to the display
this->takeSerialMutex();
this->displayAdapter->print("pm_sw.pic=");
this->displayAdapter->print(state ? COMPONENT_PM_TOGGLE_PIC_ON : COMPONENT_PM_TOGGLE_PIC_OFF);
this->sendStopBytes();
this->displayAdapter->print("pm_sw.pic2=");
this->displayAdapter->print(state ? COMPONENT_PM_TOGGLE_PIC_ON_PRESSED : COMPONENT_PM_TOGGLE_PIC_OFF_PRESSED);
this->sendStopBytes();
this->displayAdapter->print("pm_speed.txt=\"");
this->displayAdapter->print(fan_speed);
this->displayAdapter->print("\"");
this->sendStopBytes();
this->displayAdapter->print("pm_speed.pco=");
this->displayAdapter->print(state ? 34486 : 33841);
this->sendStopBytes();
this->giveSerialMutex();
} }
void ISEDisplay::updateACState(){ void ISEDisplay::updateACState(){
// Get the state
uint8_t mode = this->climateCard->getMode();
if(mode == 0){
} }
uint8_t fan_speed = this->climateCard->getFanSpeed();
uint8_t temperature = this->climateCard->getTemperature();
this->takeSerialMutex();
// Send the state to the display
if (mode == 0 ){
this->displayAdapter->print("ac_temp.pco=");
this->displayAdapter->print(33841);
this->sendStopBytes();
this->displayAdapter->print("ac_temp.pic=");
this->displayAdapter->print(COMPONENT_AC_STATUS_OFF);
this->sendStopBytes();
}
else{
this->displayAdapter->print("ac_temp.pco=");
this->displayAdapter->print(34486);
this->sendStopBytes();
this->displayAdapter->print("ac_temp.pic=");
this->displayAdapter->print(COMPONENT_AC_STATUS_ON);
this->sendStopBytes();
user_mode = mode;
}
this->displayAdapter->print("ac_sw.pic=");
this->displayAdapter->print(mode != 0 ? COMPONENT_AC_TOGGLE_PIC_ON : COMPONENT_AC_TOGGLE_PIC_OFF);
this->sendStopBytes();
this->displayAdapter->print("ac_sw.pic2=");
this->displayAdapter->print(mode != 0 ? COMPONENT_AC_TOGGLE_PIC_ON_PRESSED : COMPONENT_AC_TOGGLE_PIC_OFF_PRESSED);
this->sendStopBytes();
switch (user_mode)
{
case 1:
this->displayAdapter->print("ac_mode.pic=");
this->displayAdapter->print(COMPONENT_AC_MODE_COOL_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_mode.pic2=");
this->displayAdapter->print(COMPONENT_AC_MODE_COOL_PIC_PRESSED);
this->sendStopBytes();
break;
case 2:
this->displayAdapter->print("ac_mode.pic=");
this->displayAdapter->print(COMPONENT_AC_MODE_FAN_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_mode.pic2=");
this->displayAdapter->print(COMPONENT_AC_MODE_FAN_PIC_PRESSED);
this->sendStopBytes();
break;
default:
break;
}
switch (fan_speed)
{
case 0:
this->displayAdapter->print("ac_fan.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_AUTO_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_AUTO_PIC_PRESSED);
this->sendStopBytes();
break;
case 1:
this->displayAdapter->print("ac_fan.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_HIGH_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_HIGH_PIC_PRESSED);
this->sendStopBytes();
break;
case 2:
this->displayAdapter->print("ac_fan.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_MID_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_MID_PIC_PRESSED);
this->sendStopBytes();
break;
case 3:
this->displayAdapter->print("ac_fan.pic=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_LOW_PIC);
this->sendStopBytes();
this->displayAdapter->print("ac_fan.pic2=");
this->displayAdapter->print(COMPONENT_AC_FAN_MODE_LOW_PIC_PRESSED);
this->sendStopBytes();
break;
default:
break;
}
this->displayAdapter->print("ac_temp.txt=\"");
this->displayAdapter->print(temperature);
this->displayAdapter->print("\"");
this->sendStopBytes();
this->giveSerialMutex();
}

View file

@ -6,6 +6,27 @@
#include <ClimateCard.hpp> #include <ClimateCard.hpp>
/*
tentetive pin mapping
1-4 Lights
1: row 1
2: row 2
3: row 3
4: row 4
5: Air Purifier status (on/off)
6: Air Purifier fan speed (0-20)
lights have 4 states
0: off
1: low
2: mid
3: high
*/
// Touch Types // Touch Types
#define TOUCH_TYPE_PRESS 1 #define TOUCH_TYPE_PRESS 1
#define TOUCH_TYPE_RELEASE 0 #define TOUCH_TYPE_RELEASE 0
@ -172,10 +193,10 @@
#define COMPONENT_LIGHT_MASTER_ON_PRESSED 38 #define COMPONENT_LIGHT_MASTER_ON_PRESSED 38
//light level component //light level component
#define COMPONENT_LIGHT_LEVEL_1 39 #define COMPONENT_LIGHT_LEVEL_0 39
#define COMPONENT_LIGHT_LEVEL_2 40 #define COMPONENT_LIGHT_LEVEL_1 40
#define COMPONENT_LIGHT_LEVEL_3 41 #define COMPONENT_LIGHT_LEVEL_2 41
#define COMPONENT_LIGHT_LEVEL_4 42 #define COMPONENT_LIGHT_LEVEL_3 42
@ -235,7 +256,6 @@ class ISEDisplay : public ESPMegaDisplay {
void handleTouch(uint8_t page, uint8_t component, uint8_t touch_type); void handleTouch(uint8_t page, uint8_t component, uint8_t touch_type);
void handlePWMChange(uint8_t pin, bool state, uint16_t value); void handlePWMChange(uint8_t pin, bool state, uint16_t value);
void setPMstate(bool is_pm_on, uint8_t pm_fan_speed); void setPMstate(bool is_pm_on, uint8_t pm_fan_speed);
void setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_temperature); void setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_temperature);
void setLightLevel(uint8_t row, uint8_t level); void setLightLevel(uint8_t row, uint8_t level);
@ -245,8 +265,11 @@ class ISEDisplay : public ESPMegaDisplay {
ClimateCard *climateCard; ClimateCard *climateCard;
uint8_t outputCallbackHandle; uint8_t outputCallbackHandle;
uint8_t climateCallbackHandle; uint8_t climateCallbackHandle;
uint8_t user_mode;
void updateLightGroupState(); void updateLightGroupStatePageDashboard();
void updateLightGroupStatePageStandby();
void updateAirPurifierState(); void updateAirPurifierState();
void updateACState(); void updateACState();
bool calculateLightGroupState();
}; };