Compare commits

..

3 commits

Author SHA1 Message Date
reaw55
553eae0566 change AC behavior; comfirmed work 2024-04-22 14:26:40 +07:00
reaw55
d4b36336cd update CT to be with current on old main 2024-04-20 14:31:37 +07:00
reaw55
88931f3001 add toogle; adjust code behavior 2024-04-20 14:25:12 +07:00
16 changed files with 529 additions and 176 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -26,7 +26,8 @@ void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCar
this->user_mode = 2; // initialized to cool by default this->user_mode = 2; // initialized to cool by default
this->ac_lock_state = strcmp(ac_lock->getValue(), "on") == 0; // initialized to get value this->ac_lock_state = strcmp(ac_lock->getValue(), "on") == 0; // initialized to get value
this->pm_lock_state = strcmp(pm_lock->getValue(), "on") == 0; // initialized to get value this->pm_lock_state = strcmp(pm_lock->getValue(), "on") == 0; // initialized to get value
this->pm_fan_speed = 10; this->pm_fan_speed = 18;
remote_pm_fan_speed->setIntValue(this->pm_fan_speed);
// remote_pm_fan_speed->setValue(pm_fan_speed); // remote_pm_fan_speed->setValue(pm_fan_speed);
this->ac_fan_speed = 0; this->ac_fan_speed = 0;
this->ac_mode = 0; this->ac_mode = 0;
@ -37,6 +38,8 @@ void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCar
this->lightLevelRow4 = 0; this->lightLevelRow4 = 0;
this->time_since_last_ac_change = 0; this->time_since_last_ac_change = 0;
this->ac_press_pending = false; this->ac_press_pending = false;
this->time_since_ac_staggered_start_call = 0;
this->ac_staggered_start_call_pending = false;
// this->time_since_last_screen_update = 0; // this->time_since_last_screen_update = 0;
this->registerTouchCallback(bindedHandleTouch); this->registerTouchCallback(bindedHandleTouch);
this->reset(); this->reset();
@ -46,6 +49,7 @@ void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCar
delay(100); delay(100);
this->updateAirPurifierState(); this->updateAirPurifierState();
this->updateSystemtoggle(); this->updateSystemtoggle();
this->updateAllStandbyToggle();
this->updateACState(); this->updateACState();
this->updateLightGroupStatePageDashboard(); this->updateLightGroupStatePageDashboard();
@ -62,7 +66,7 @@ void ISEDisplay::loop()
recieveSerialCommand(); recieveSerialCommand();
// Check if the AC state has been changed // Check if the AC state has been changed
if (ac_press_pending && (millis() - time_since_last_ac_change) > 5000) if (ac_press_pending && (millis() - time_since_last_ac_change) > 500)
{ {
ESP_LOGI("ISEDisplay", "Sending AC IR code"); ESP_LOGI("ISEDisplay", "Sending AC IR code");
sendACIRcode(); sendACIRcode();
@ -70,6 +74,15 @@ void ISEDisplay::loop()
ac_press_pending = false; ac_press_pending = false;
ESP_LOGI("ISEDisplay", "AC press pending set to false"); ESP_LOGI("ISEDisplay", "AC press pending set to false");
} }
// check for ac staggered start
if (ac_staggered_start_call_pending && (millis() - time_since_ac_staggered_start_call) > 3000)
{
ESP_LOGI("ISEDisplay", "Sending Staggered AC IR code (York)");
sendACIRcode();
ESP_LOGI("ISEDisplay", "AC Staggered AC IR code (York) sent");
ac_staggered_start_call_pending = false;
ESP_LOGI("ISEDisplay", "AC staggered start call pending set to false");
}
// Check if the MQTT connection has been lost // Check if the MQTT connection has been lost
static uint32_t last_mqtt_connected_check = 0; static uint32_t last_mqtt_connected_check = 0;
@ -136,10 +149,15 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
{ {
switch (component) switch (component)
{ {
case COMPONENT_OBJ_STANDBY_LOGO:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
//this->jumpToPage(2);
break;
case COMPONENT_OBJ_STANDBY_BTN_OPEN_ALL_TOGGLE: case COMPONENT_OBJ_STANDBY_BTN_OPEN_ALL_TOGGLE:
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
break; break;
allOn(); //allToggleStandby();
this->jumpToPage(2); this->jumpToPage(2);
// the function of the button is to open the dashboard from standby // the function of the button is to open the dashboard from standby
break; break;
@ -151,7 +169,8 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
case COMPONENT_OBJ_STANDBY_BTN_AC_TOGGLE: case COMPONENT_OBJ_STANDBY_BTN_AC_TOGGLE:
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
break; break;
if (this->ac_lock_state == true){ if (this->ac_lock_state == true)
{
ESP_LOGI("ISEDisplay", "AC lock is on, do nothing"); ESP_LOGI("ISEDisplay", "AC lock is on, do nothing");
break; break;
} }
@ -201,7 +220,8 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
break; break;
// if ac_lock is true do nothing // if ac_lock is true do nothing
if (this->ac_lock_state == true){ if (this->ac_lock_state == true)
{
ESP_LOGI("ISEDisplay", "AC lock is on, do nothing"); ESP_LOGI("ISEDisplay", "AC lock is on, do nothing");
break; break;
} }
@ -217,7 +237,8 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
break; break;
// if ac_lock is true do nothing // if ac_lock is true do nothing
if (this->ac_lock_state == true){ if (this->ac_lock_state == true)
{
ESP_LOGI("ISEDisplay", "AC lock is on, do nothing"); ESP_LOGI("ISEDisplay", "AC lock is on, do nothing");
break; break;
} }
@ -229,7 +250,8 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
break; break;
// if ac_lock is true do nothing // if ac_lock is true do nothing
if (this->ac_lock_state == true){ if (this->ac_lock_state == true)
{
ESP_LOGI("ISEDisplay", "AC lock is on, do nothing"); ESP_LOGI("ISEDisplay", "AC lock is on, do nothing");
break; break;
} }
@ -241,7 +263,8 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
break; break;
// if pm_lock is true do nothing // if pm_lock is true do nothing
if (this->pm_lock_state == true){ if (this->pm_lock_state == true)
{
ESP_LOGI("ISEDisplay", "PM lock is on, do nothing"); ESP_LOGI("ISEDisplay", "PM lock is on, do nothing");
break; break;
} }
@ -298,6 +321,7 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
break; break;
// implement pm speed change // implement pm speed change
changePMfanspeed();
break; break;
case COMPONENT_OBJ_DASHBOARD_BTN_PM_MODE: case COMPONENT_OBJ_DASHBOARD_BTN_PM_MODE:
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
@ -307,6 +331,7 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
case COMPONENT_OBJ_DASHBOARD_HOLDER_PIC_MASTER_LIGHT: case COMPONENT_OBJ_DASHBOARD_HOLDER_PIC_MASTER_LIGHT:
break; break;
case COMPONENT_OBJ_DASHBOARD_LOGO: case COMPONENT_OBJ_DASHBOARD_LOGO:
jumpToPage(1);
break; break;
case COMPONENT_OBJ_DASHBOARD_HOLDER_PIC_PM_LOCK: case COMPONENT_OBJ_DASHBOARD_HOLDER_PIC_PM_LOCK:
if (touch_type != TOUCH_TYPE_RELEASE) if (touch_type != TOUCH_TYPE_RELEASE)
@ -426,6 +451,7 @@ void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value)
{ {
// Light // Light
updateLightGroupStatePageStandby(); updateLightGroupStatePageStandby();
updateAllStandbyToggle();
// time_since_last_screen_update = millis(); // update time since last activity // time_since_last_screen_update = millis(); // update time since last activity
} }
} }
@ -435,6 +461,7 @@ void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value)
{ {
// Light // Light
updateLightGroupStatePageDashboard(); updateLightGroupStatePageDashboard();
updateSystemtoggle();
// time_since_last_screen_update = millis(); // update time since last activity // time_since_last_screen_update = millis(); // update time since last activity
} }
} }
@ -529,6 +556,7 @@ void ISEDisplay::setAClockstate(bool is_ac_lock_on)
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)
{ {
ESP_LOGI("ISEDisplay", "AC state before change is: fan speed: %d, mode: %d, temperature: %d", this->ac_fan_speed, this->ac_mode, this->ac_temperature);
ESP_LOGI("ISEDisplay", "Setting AC state in memory to: = fan speed: %d, mode: %d, temperature: %d", ac_fan_speed, ac_mode, ac_temperature); ESP_LOGI("ISEDisplay", "Setting AC state in memory to: = fan speed: %d, mode: %d, temperature: %d", ac_fan_speed, ac_mode, ac_temperature);
this->ac_fan_speed = ac_fan_speed; this->ac_fan_speed = ac_fan_speed;
@ -546,21 +574,30 @@ void ISEDisplay::setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_te
this->time_since_last_ac_change = millis(); this->time_since_last_ac_change = millis();
this->ac_press_pending = true; this->ac_press_pending = true;
updateACState(); updateACState();
updateSystemtoggle();
updateAllStandbyToggle();
} }
void ISEDisplay::sendACIRcode() void ISEDisplay::sendACIRcode()
{ {
uint8_t cur_ac_fan_speed = this->ac_fan_speed; uint8_t cur_ac_fan_speed = this->ac_fan_speed;
uint8_t cur_ac_mode = this->ac_mode; uint8_t cur_ac_mode = this->ac_mode;
uint8_t before_change_ac_mode = this->climateCard_daikin->getMode();
uint8_t cur_ac_temperature = this->ac_temperature; uint8_t cur_ac_temperature = this->ac_temperature;
uint8_t york_temp = cur_ac_temperature; uint8_t york_temp = cur_ac_temperature;
// this->climateCard->setFanSpeed(ac_fan_speed); // this->climateCard->setFanSpeed(ac_fan_speed);
ESP_LOGI("ISEDisplay", "AC fan speed set to: %d", cur_ac_fan_speed); ESP_LOGI("ISEDisplay", "AC fan speed set to: %d", cur_ac_fan_speed);
// this->climateCard->setMode(ac_mode); // this->climateCard->setMode(ac_mode);
ESP_LOGI("ISEDisplay", "AC mode before change is set to: %d", before_change_ac_mode);
ESP_LOGI("ISEDisplay", "AC mode set to: %d", cur_ac_mode); ESP_LOGI("ISEDisplay", "AC mode set to: %d", cur_ac_mode);
// this->climateCard->setTemperature(ac_temperature); // this->climateCard->setTemperature(ac_temperature);
ESP_LOGI("ISEDisplay", "AC temperature set to: %d", cur_ac_temperature); ESP_LOGI("ISEDisplay", "AC temperature set to: %d", cur_ac_temperature);
// check if temp is within range of min and max for york if not set an min or max for only york // check if temp is within range of min and max for york if not set an min or max for only york
if (ac_staggered_start_call_pending == false)
{
ESP_LOGI("ISEDisplay", "AC Staggered start call pending is false");
this->climateCard_daikin->setState(cur_ac_mode, cur_ac_fan_speed, cur_ac_temperature); this->climateCard_daikin->setState(cur_ac_mode, cur_ac_fan_speed, cur_ac_temperature);
ESP_LOGI("ISEDisplay", "Daikin AC IR code sent");
}
if (cur_ac_temperature < YORK_MIN_TEMP) if (cur_ac_temperature < YORK_MIN_TEMP)
{ {
york_temp = YORK_MIN_TEMP; york_temp = YORK_MIN_TEMP;
@ -569,16 +606,37 @@ void ISEDisplay::sendACIRcode()
{ {
york_temp = YORK_MAX_TEMP; york_temp = YORK_MAX_TEMP;
} }
if (ac_mode == 3) if (cur_ac_mode == 3 && ac_staggered_start_call_pending == false)
{ {
ESP_LOGI("ISEDisplay", "AC Staggered start call pending is false");
this->climateCard_york->setState(0, cur_ac_fan_speed, york_temp); this->climateCard_york->setState(0, cur_ac_fan_speed, york_temp);
ESP_LOGI("ISEDisplay", "York AC IR code sent to off mode due to swtiching to dry on Daikin");
} }
else else
{ {
// want to stagger start york ac when change state from off (mode 0) to on (mode 1,2,3) by 1 sec without delaying other code
if (before_change_ac_mode == 0 && ac_staggered_start_call_pending == false)
{
ESP_LOGI("ISEDisplay", "cur_ac_mode is 0 and ac_staggered_start_call_pending is false");
this->time_since_ac_staggered_start_call = millis();
this->ac_staggered_start_call_pending = true;
ESP_LOGI("ISEDisplay", "AC staggered start call pending set to true and call time set to current time");
}
else
{
ESP_LOGI("ISEDisplay", "AC Staggered start call pending is true or cur_ac_mode is not 0");
this->climateCard_york->setState(cur_ac_mode, cur_ac_fan_speed, york_temp); this->climateCard_york->setState(cur_ac_mode, cur_ac_fan_speed, york_temp);
ESP_LOGI("ISEDisplay", "York AC IR code sent");
// wondering if there is a case where the ac_staggered_start_call_pending is not set to false after setState have been called
}
} }
// get value of mode fanspeed and temp and print compare to store value // get value of mode fanspeed and temp and print compare to store value
ESP_LOGI("ISEDisplay", "AC IR code sent"); ESP_LOGI("ISEDisplay", "AC IR code sent");
ESP_LOGI("ISEDisplay", "NOTE: ac_staggered_start_call_pending is %d", ac_staggered_start_call_pending);
if (ac_staggered_start_call_pending == true)
{
ESP_LOGI("ISEDisplay", "thus the york ac will not be set to current mode if ac_staggered_start_call_pending is true will be trigger after 1 sec");
}
ESP_LOGI("ISEDisplay", "Daikin fan speed: %d, Daikin mode: %d, Daikin temperature: %d", cur_ac_fan_speed, cur_ac_mode, cur_ac_temperature); ESP_LOGI("ISEDisplay", "Daikin fan speed: %d, Daikin mode: %d, Daikin temperature: %d", cur_ac_fan_speed, cur_ac_mode, cur_ac_temperature);
ESP_LOGI("ISEDisplay", "York fan speed: %d, York mode: %d, York temperature: %d", cur_ac_fan_speed, cur_ac_mode, york_temp); ESP_LOGI("ISEDisplay", "York fan speed: %d, York mode: %d, York temperature: %d", cur_ac_fan_speed, cur_ac_mode, york_temp);
ESP_LOGI("ISEDisplay", "getting value of mode, fanspeed and temp from climate card"); ESP_LOGI("ISEDisplay", "getting value of mode, fanspeed and temp from climate card");
@ -596,6 +654,7 @@ void ISEDisplay::toggleLightGroupState()
{ {
setLightLevel(i, state ? 0 : 3); setLightLevel(i, state ? 0 : 3);
} }
// for loop might slow it down maybe? idk
} }
void ISEDisplay::setLightGroupState(uint8_t level) void ISEDisplay::setLightGroupState(uint8_t level)
{ {
@ -622,6 +681,14 @@ void ISEDisplay::toggleLightGroupStateStandby()
void ISEDisplay::togglePM() void ISEDisplay::togglePM()
{ {
// Get the current group state // Get the current group state
bool ispmlock = this->pm_lock_state;
if (ispmlock)
{
ESP_LOGI("ISEDisplay", "PM lock is on, do nothing");
return;
}
else
{
bool state = strcmp(pm_switch->getValue(), "on") == 0; bool state = strcmp(pm_switch->getValue(), "on") == 0;
ESP_LOGI("ISEDisplay", "Current PM state: %d", state); ESP_LOGI("ISEDisplay", "Current PM state: %d", state);
// Toggle the state // Toggle the state
@ -629,6 +696,7 @@ void ISEDisplay::togglePM()
ESP_LOGI("ISEDisplay", "New PM state: %d", state); ESP_LOGI("ISEDisplay", "New PM state: %d", state);
// updateAirPurifierState(); // updateAirPurifierState();
} }
}
void ISEDisplay::toggleACLock() void ISEDisplay::toggleACLock()
{ {
// Get the current group state // Get the current group state
@ -699,23 +767,71 @@ void ISEDisplay::changeUserACmode()
// uint8_t mode = this->climateCard_daikin->getMode(); // uint8_t mode = this->climateCard_daikin->getMode();
ESP_LOGI("ISEDisplay", "Current actual AC mode: %d", mode); ESP_LOGI("ISEDisplay", "Current actual AC mode: %d", mode);
// Toggle the state // Toggle the state
// user mode alternate between 1 and 2 // user mode alternate between 1, 2, and 3
ESP_LOGI("ISEDisplay", "User mode BEFORE: %d", user_mode); ESP_LOGI("ISEDisplay", "User mode BEFORE: %d", user_mode);
user_mode = (user_mode) % 2 + 1; // user_mode = (user_mode) % 3 + 1; //loop from 1 to 2 to 3 then back to 1
// Cycle user_mode from 2 to 1 to 3
switch (user_mode)
{
case 2: // If current mode is cool (2), change to fan (1)
user_mode = 1;
break;
case 1: // If current mode is fan (1), change to dry (3)
user_mode = 3;
break;
case 3: // If current mode is dry (3), change to cool (2)
default:
user_mode = 2;
break;
}
ESP_LOGI("ISEDisplay", "User mode AFTER: %d", user_mode); ESP_LOGI("ISEDisplay", "User mode AFTER: %d", user_mode);
if (mode != 0) if (mode != 0)
{ {
// update mode to new mode // update mode to new mode
mode = user_mode; mode = user_mode;
ESP_LOGI("ISEDisplay", "change actual AC mode to user mode: %d", mode); ESP_LOGI("ISEDisplay", "change actual AC mode to user mode: %d", mode);
setACstate(this->ac_fan_speed, mode, this->ac_temperature);
} }
else else
{ // ie mode is off { // ie mode is off
// do nothing as the state is keep in user_mode // do nothing as the state is keep in user_mode
// the mode will change to user_mode when turn on by toggleAC() // the mode will change to user_mode when turn on by toggleAC()
ESP_LOGI("ISEDisplay", "do nothing; user mode: %d , actual mode: %d", user_mode, mode); ESP_LOGI("ISEDisplay", "update just user mode display; user mode: %d , actual mode: %d", user_mode, mode);
updateuserACmode();
} }
updateuserACmode(); // call to update mode part of the display seperately
// updateuserACmode(); // call to update mode part of the display seperately
}
void ISEDisplay::changePMfanspeed()
{
// Get the current group state
uint8_t fan_speed = this->pm_fan_speed;
uint8_t new_fan_speed = fan_speed;
// uint8_t fan_speed = this->climateCard_york->getFanSpeed();
ESP_LOGI("ISEDisplay", "Current PM fan speed: %d", fan_speed);
// Toggle the state
// fan_speed have 3 state high mid low switch between them
switch (fan_speed)
{
case PM_FAN_SPEED_LOW:
new_fan_speed = PM_FAN_SPEED_MID;
break;
case PM_FAN_SPEED_MID:
new_fan_speed = PM_FAN_SPEED_HIGH;
break;
case PM_FAN_SPEED_HIGH:
new_fan_speed = PM_FAN_SPEED_LOW;
break;
default:
new_fan_speed = PM_FAN_SPEED_HIGH;
break;
}
ESP_LOGI("ISEDisplay", "New PM fan speed: %d", new_fan_speed);
this->pm_fan_speed = new_fan_speed;
ESP_LOGI("ISEDisplay", "Setting PM fan speed in memory to: %d", this->pm_fan_speed);
remote_pm_fan_speed->setIntValue(this->pm_fan_speed);
ESP_LOGI("ISEDisplay", "Setting PM fan speed in remote var to: %d", remote_pm_fan_speed->getValueAsInt());
updateAirPurifierState();
} }
void ISEDisplay::setLightLevel(uint8_t row, uint8_t level) void ISEDisplay::setLightLevel(uint8_t row, uint8_t level)
{ {
@ -838,66 +954,12 @@ void ISEDisplay::updateLightGroupStatePageStandby()
this->giveSerialMutex(); this->giveSerialMutex();
} }
void ISEDisplay::updateLightGroupStatePageDashboard() void ISEDisplay::updateLightGroupStatePageDashboard()
{
// Calculate the state
bool state = calculateLightGroupState();
// Send the state to the display
if (!this->takeSerialMutex())
return;
this->displayAdapter->print("light_m_sw.pic=");
this->displayAdapter->print(state ? COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_ON : COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_OFF);
this->sendStopBytes();
this->displayAdapter->print("light_m_sw.pic2=");
this->displayAdapter->print(state ? COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_ON_PRESSED : COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_OFF_PRESSED);
this->sendStopBytes();
for (uint8_t i = 1; i <= 4; i++)
{
u_int8_t state = getLightLevel(i);
updateLightSwitch();
switch (state)
{
case 0:
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print(".pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_ROW_LEVEL_0);
this->sendStopBytes();
break;
case 1:
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print(".pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_ROW_LEVEL_1);
this->sendStopBytes();
break;
case 2:
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print(".pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_ROW_LEVEL_2);
this->sendStopBytes();
break;
case 3:
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print(".pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_ROW_LEVEL_3);
this->sendStopBytes();
break;
default:
break;
}
}
this->giveSerialMutex();
}
void ISEDisplay::updateLightSwitch()
{ {
// Calculate the state // Calculate the state
bool state_master = calculateLightGroupState(); bool state_master = calculateLightGroupState();
uint8_t firstState = getLightLevel(1);
bool allMatch = true;
// Send the state to the display // Send the state to the display
if (!this->takeSerialMutex()) if (!this->takeSerialMutex())
return; return;
@ -910,16 +972,32 @@ void ISEDisplay::updateLightSwitch()
this->displayAdapter->print(state_master ? COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_ON_PRESSED : COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_OFF_PRESSED); this->displayAdapter->print(state_master ? COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_ON_PRESSED : COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_OFF_PRESSED);
this->sendStopBytes(); this->sendStopBytes();
this->giveSerialMutex(); // this->displayAdapter->print("light_m_sw.pic=");
// this->displayAdapter->print(state ? COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_ON : COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_OFF);
// this->sendStopBytes();
// check state and set for each individual light row // this->displayAdapter->print("light_m_sw.pic2=");
// if state is 0 set to off and other(1,2,3) to on // this->displayAdapter->print(state ? COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_ON_PRESSED : COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_OFF_PRESSED);
// this->sendStopBytes();
for (uint8_t i = 1; i <= 4; i++) for (uint8_t i = 1; i <= 4; i++)
{ {
u_int8_t state = getLightLevel(i); u_int8_t state = getLightLevel(i);
if (state == 0)
if (i > 1 && state != firstState)
{ {
allMatch = false;
}
switch (state)
{
case 0:
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print(".pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_ROW_LEVEL_0);
this->sendStopBytes();
this->displayAdapter->print("light_row"); this->displayAdapter->print("light_row");
this->displayAdapter->print(i); this->displayAdapter->print(i);
this->displayAdapter->print("_sw.pic="); this->displayAdapter->print("_sw.pic=");
@ -931,9 +1009,14 @@ void ISEDisplay::updateLightSwitch()
this->displayAdapter->print("_sw.pic2="); this->displayAdapter->print("_sw.pic2=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_SWITCH_OFF_PRESSED); this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_SWITCH_OFF_PRESSED);
this->sendStopBytes(); this->sendStopBytes();
} break;
else case 1:
{ this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print(".pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_ROW_LEVEL_1);
this->sendStopBytes();
this->displayAdapter->print("light_row"); this->displayAdapter->print("light_row");
this->displayAdapter->print(i); this->displayAdapter->print(i);
this->displayAdapter->print("_sw.pic="); this->displayAdapter->print("_sw.pic=");
@ -945,8 +1028,100 @@ void ISEDisplay::updateLightSwitch()
this->displayAdapter->print("_sw.pic="); this->displayAdapter->print("_sw.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_SWITCH_ON_PRESSED); this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_SWITCH_ON_PRESSED);
this->sendStopBytes(); this->sendStopBytes();
break;
case 2:
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print(".pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_ROW_LEVEL_2);
this->sendStopBytes();
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print("_sw.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_SWITCH_ON);
this->sendStopBytes();
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print("_sw.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_SWITCH_ON_PRESSED);
this->sendStopBytes();
break;
case 3:
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print(".pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_ROW_LEVEL_3);
this->sendStopBytes();
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print("_sw.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_SWITCH_ON);
this->sendStopBytes();
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print("_sw.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_SWITCH_ON_PRESSED);
this->sendStopBytes();
break;
default:
break;
} }
} }
if (allMatch)
{
// All states match, change the master light level which is the firststate
// use switch case
switch (firstState)
{
case 0:
this->displayAdapter->print("master_light.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_LEVEL_0);
this->sendStopBytes();
break;
case 1:
this->displayAdapter->print("master_light.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_LEVEL_1);
this->sendStopBytes();
break;
case 2:
this->displayAdapter->print("master_light.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_LEVEL_2);
this->sendStopBytes();
break;
case 3:
this->displayAdapter->print("master_light.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_LEVEL_3);
this->sendStopBytes();
break;
default:
this->displayAdapter->print("master_light.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_LEVEL_D);
this->sendStopBytes();
break;
}
}
else
{
this->displayAdapter->print("master_light.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_LEVEL_D);
this->sendStopBytes();
}
this->giveSerialMutex();
}
void ISEDisplay::updateLightSwitch()
{
// DEPRECATED
// Calculate the state
// not in use due to worse performance
// check state and set for each individual light row
// if state is 0 set to off and other(1,2,3) to on
} }
bool ISEDisplay::calculateLightGroupState() bool ISEDisplay::calculateLightGroupState()
{ {
@ -996,13 +1171,50 @@ void ISEDisplay::toggleSystem()
togglePM(); togglePM();
} }
} }
void ISEDisplay::allOn() void ISEDisplay::allToggleStandby()
{ {
setLightGroupState(3); bool lightState = calculateLightGroupState();
setPMstate(true, pm_fan_speed); bool pmState = strcmp(pm_switch->getValue(), "on") == 0;
if (ac_mode != 0)
{
setACstate(0, ac_fan_speed, ac_temperature);
}
else{
setACstate(2, ac_fan_speed, ac_temperature); setACstate(2, ac_fan_speed, ac_temperature);
} }
if (lightState)
{
setLightGroupState(0);
}
else
{
setLightGroupState(3);
}
if (pmState)
{
setPMstate(false, pm_fan_speed);
}
else
{
setPMstate(true, pm_fan_speed);
}
}
void ISEDisplay::updateAllStandbyToggle()
{
bool state = calculateAllState();
if (!this->takeSerialMutex())
return;
this->displayAdapter->print("s_open_all.pic=");
this->displayAdapter->print(state ? COMPONENT_STANDBY_PIC_OPEN_ALL_TOGGLE_ON : COMPONENT_STANDBY_PIC_OPEN_ALL_TOGGLE_OFF);
this->sendStopBytes();
this->displayAdapter->print("s_open_all.pic2=");
this->displayAdapter->print(state ? COMPONENT_STANDBY_PIC_OPEN_ALL_TOGGLE_ON_PRESSED : COMPONENT_STANDBY_PIC_OPEN_ALL_TOGGLE_OFF_PRESSED);
this->sendStopBytes();
this->giveSerialMutex();
}
void ISEDisplay::toggleLightIndividual(uint8_t row) void ISEDisplay::toggleLightIndividual(uint8_t row)
{ {
// Get the current state // Get the current state
@ -1063,7 +1275,8 @@ void ISEDisplay::updateAirPurifierState()
bool state = strcmp(pm_switch->getValue(), "on") == 0; bool state = strcmp(pm_switch->getValue(), "on") == 0;
this->pm_lock_state = strcmp(pm_lock->getValue(), "on") == 0; this->pm_lock_state = strcmp(pm_lock->getValue(), "on") == 0;
ESP_LOGI("ISEDisplay", "Updating air purifier state to: %d", state); ESP_LOGI("ISEDisplay", "Updating air purifier state to: %d", state);
pm_fan_speed = (int)atof(remote_pm_fan_speed->getValue()); pm_fan_speed = this->pm_fan_speed;
ESP_LOGI("ISEDisplay", "Updating air purifier fan speed to: %d", pm_fan_speed);
// Send the state to the display // Send the state to the display
if (!this->takeSerialMutex()) if (!this->takeSerialMutex())
return; return;
@ -1080,6 +1293,86 @@ void ISEDisplay::updateAirPurifierState()
this->displayAdapter->print(this->pm_lock_state ? COMPONENT_DASHBOARD_PIC_LOCK : COMPONENT_DASHBOARD_PIC_UNLOCK); this->displayAdapter->print(this->pm_lock_state ? COMPONENT_DASHBOARD_PIC_LOCK : COMPONENT_DASHBOARD_PIC_UNLOCK);
this->sendStopBytes(); this->sendStopBytes();
this->displayAdapter->print("pm_mode.pic=");
this->displayAdapter->print(state ? COMPONENT_DASHBOARD_PIC_AC_MODE_FAN_ON : COMPONENT_DASHBOARD_PIC_AC_MODE_FAN_OFF);
this->sendStopBytes();
this->displayAdapter->print("pm_mode.pic2=");
this->displayAdapter->print(state ? COMPONENT_DASHBOARD_PIC_AC_MODE_FAN_ON_PRESSED : COMPONENT_DASHBOARD_PIC_AC_MODE_FAN_OFF_PRESSED);
this->sendStopBytes();
switch (pm_fan_speed)
{
case PM_FAN_SPEED_LOW:
if (state)
{ // state is on
this->displayAdapter->print("pm_speed.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_AC_FAN_LOW_ON);
this->sendStopBytes();
this->displayAdapter->print("pm_speed.pic2=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_AC_FAN_LOW_ON_PRESSED);
this->sendStopBytes();
}
else
{ // state is off
this->displayAdapter->print("pm_speed.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_AC_FAN_LOW_OFF);
this->sendStopBytes();
this->displayAdapter->print("pm_speed.pic2=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_AC_FAN_LOW_OFF_PRESSED);
this->sendStopBytes();
}
break;
case PM_FAN_SPEED_MID:
if (state)
{ // state is on
this->displayAdapter->print("pm_speed.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_AC_FAN_MID_ON);
this->sendStopBytes();
this->displayAdapter->print("pm_speed.pic2=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_AC_FAN_MID_ON_PRESSED);
this->sendStopBytes();
}
else
{ // state is off
this->displayAdapter->print("pm_speed.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_AC_FAN_MID_OFF);
this->sendStopBytes();
this->displayAdapter->print("pm_speed.pic2=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_AC_FAN_MID_OFF_PRESSED);
this->sendStopBytes();
}
break;
case PM_FAN_SPEED_HIGH:
if (state)
{ // state is on
this->displayAdapter->print("pm_speed.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_AC_FAN_HIGH_ON);
this->sendStopBytes();
this->displayAdapter->print("pm_speed.pic2=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_AC_FAN_HIGH_ON_PRESSED);
this->sendStopBytes();
}
else
{ // state is off
this->displayAdapter->print("pm_speed.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_AC_FAN_HIGH_OFF);
this->sendStopBytes();
this->displayAdapter->print("pm_speed.pic2=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_AC_FAN_HIGH_OFF_PRESSED);
this->sendStopBytes();
}
break;
default:
break;
}
// this->displayAdapter->print("pm_speed.val="); // this->displayAdapter->print("pm_speed.val=");
// this->displayAdapter->print(pm_fan_speed); // this->displayAdapter->print(pm_fan_speed);
// // this->displayAdapter->print("\""); // // this->displayAdapter->print("\"");
@ -1102,6 +1395,8 @@ void ISEDisplay::handleACChange(uint8_t mode, uint8_t fan_speed, uint8_t tempera
{ {
ESP_LOGI("ISEDisplay", "AC state changed: mode: %d, fan speed: %d, temperature: %d", mode, fan_speed, temperature); ESP_LOGI("ISEDisplay", "AC state changed: mode: %d, fan speed: %d, temperature: %d", mode, fan_speed, temperature);
updateACState(); updateACState();
updateSystemtoggle();
updateAllStandbyToggle();
} }
void ISEDisplay::updateuserACmode() void ISEDisplay::updateuserACmode()
{ {

View file

@ -31,6 +31,7 @@ class ISEDisplay : public ESPMegaDisplay {
void updateAirPurifierState(); void updateAirPurifierState();
void updateAirPurifierStateStandby(); void updateAirPurifierStateStandby();
void updateSystemtoggle(); void updateSystemtoggle();
void updateAllStandbyToggle();
void updateDateTimeText(rtctime_t time); void updateDateTimeText(rtctime_t time);
void updateWeather(char *weather_string); void updateWeather(char *weather_string);
void updateTempOutside(float temp_outside); void updateTempOutside(float temp_outside);
@ -69,6 +70,8 @@ class ISEDisplay : public ESPMegaDisplay {
uint8_t outputCallbackHandle; uint8_t outputCallbackHandle;
uint8_t climateCallbackHandle; uint8_t climateCallbackHandle;
uint32_t time_since_last_ac_change; uint32_t time_since_last_ac_change;
uint32_t time_since_ac_staggered_start_call;
bool ac_staggered_start_call_pending;
uint8_t user_mode; uint8_t user_mode;
uint8_t ac_lock_state; uint8_t ac_lock_state;
uint8_t pm_lock_state; uint8_t pm_lock_state;
@ -95,7 +98,7 @@ class ISEDisplay : public ESPMegaDisplay {
void setAClockstate(bool is_ac_lock_on); void setAClockstate(bool is_ac_lock_on);
void toggleACLock(); void toggleACLock();
void togglePMLock(); void togglePMLock();
void allOn(); void allToggleStandby();
void toggleLightGroupState(); void toggleLightGroupState();
void toggleLightGroupStateStandby(); void toggleLightGroupStateStandby();
void toggleLightIndividual(uint8_t row); void toggleLightIndividual(uint8_t row);
@ -105,5 +108,6 @@ class ISEDisplay : public ESPMegaDisplay {
void setLightGroupState(uint8_t level); void setLightGroupState(uint8_t level);
void toggleACStandby(); void toggleACStandby();
void changeUserACmode(); void changeUserACmode();
void changePMfanspeed();
}; };

View file

@ -66,6 +66,10 @@ lights have 4 states
#define MOTION_FRONT 8 #define MOTION_FRONT 8
#define MOTION_REAR 9 #define MOTION_REAR 9
//PM fanspeed setting
#define PM_FAN_SPEED_LOW 3
#define PM_FAN_SPEED_MID 10
#define PM_FAN_SPEED_HIGH 18
// //
#define DISPLAY_TIMEOUT 5*60*1000 // 5 minutes #define DISPLAY_TIMEOUT 5*60*1000 // 5 minutes

View file

@ -1,20 +1,32 @@
#include <main.hpp> #include <main.hpp>
/*********************************************** /***********************************************
* Begin Configuration * * Begin Configuration *
***********************************************/ ***********************************************/
// Analog Card & Current Transformer Configuration // Analog Card & Current Transformer Configuration
// bool analogCardAvailable = false; #ifdef ANALOG_ENABLE
// AnalogCard analogCard = AnalogCard(); bool analogCardAvailable = false;
// float voltage = CT_RMS_VOLTAGE; AnalogCard analogCard = AnalogCard();
// CurrentTransformerCard ct1 = CurrentTransformerCard(&analogCard, 0, &voltage, &adc2current, 5000); float voltage = CT_RMS_VOLTAGE;
// CurrentTransformerCard ct2 = CurrentTransformerCard(&analogCard, 1, &voltage, &adc2current, 5000); #define CT_INTERVAL 5000
// CurrentTransformerCard ct3 = CurrentTransformerCard(&analogCard, 2, &voltage, &adc2current, 5000); CurrentTransformerCard ct1 = CurrentTransformerCard(&analogCard, 0, &voltage, &adc2current, CT_INTERVAL);
// CurrentTransformerCard ct4 = CurrentTransformerCard(&analogCard, 3, &voltage, &adc2current, 5000); CurrentTransformerCard ct2 = CurrentTransformerCard(&analogCard, 1, &voltage, &adc2current, CT_INTERVAL);
// CurrentTransformerCard ct5 = CurrentTransformerCard(&analogCard, 4, &voltage, &adc2current, 5000); CurrentTransformerCard ct3 = CurrentTransformerCard(&analogCard, 2, &voltage, &adc2current, CT_INTERVAL);
// CurrentTransformerCard ct6 = CurrentTransformerCard(&analogCard, 5, &voltage, &adc2current, 5000); CurrentTransformerCard ct4 = CurrentTransformerCard(&analogCard, 3, &voltage, &adc2current, CT_INTERVAL);
CurrentTransformerCard ct5 = CurrentTransformerCard(&analogCard, 6, &voltage, &adc2current, CT_INTERVAL);
CurrentTransformerCard ct6 = CurrentTransformerCard(&analogCard, 7, &voltage, &adc2current, CT_INTERVAL);
float adc2current(uint16_t adc_val)
{
// float voltage = adc_val * 0.0007-0.1994;
float adc_voltage = adc_val * 0.0007;
// 0-10V Output with 30A Current Rating CT
float ct_current = adc_voltage / 10.0 * 30.0;
return ct_current;
}
#endif
// Remote Variables // Remote Variables
RemoteVariable pm25_in = RemoteVariable(); RemoteVariable pm25_in = RemoteVariable();
@ -26,11 +38,7 @@ RemoteVariable pm_fan_speed = RemoteVariable();
RemoteVariable pm_lock = RemoteVariable(); RemoteVariable pm_lock = RemoteVariable();
RemoteVariable ac_lock = RemoteVariable(); RemoteVariable ac_lock = RemoteVariable();
float adc2current(uint16_t adc_val) {
return adc_val * 1.0;
}
#define CT_INTERVAL 5000
// Light Configuration // Light Configuration
uint8_t row = 4; uint8_t row = 4;
@ -42,8 +50,8 @@ const uint8_t light_array[4][2] = {
{LIGHT_ROW4_COLUMN1, LIGHT_ROW4_COLUMN2}}; {LIGHT_ROW4_COLUMN1, LIGHT_ROW4_COLUMN2}};
// Air Conditioner Configuration // Air Conditioner Configuration
const char *mode_names_daikin[] = {"off", "cool", "fan_only", "dry"}; const char *mode_names_daikin[] = {"off", "fan_only", "cool", "dry"};
const char *mode_names_york[] = {"off", "cool", "fan_only"}; const char *mode_names_york[] = {"off", "fan_only", "cool"};
const char *fan_speed_names[] = {"auto", "high", "medium", "low"}; const char *fan_speed_names[] = {"auto", "high", "medium", "low"};
AirConditioner ac_daikin = { AirConditioner ac_daikin = {
@ -70,6 +78,9 @@ AirConditioner ac_york = {
ESPMegaPRO espmega = ESPMegaPRO(); ESPMegaPRO espmega = ESPMegaPRO();
ISEDisplay iseDisplay = ISEDisplay(&iseDisplayAdapter, &light_array[0][0], row, column); ISEDisplay iseDisplay = ISEDisplay(&iseDisplayAdapter, &light_array[0][0], row, column);
ESPMegaDisplayOTA iseDisplayOTA = ESPMegaDisplayOTA();
ESPMegaDisplayOTA internalDisplayOTA = ESPMegaDisplayOTA();
ClimateCard climateCard_daikin = ClimateCard(AIR_CONDITIONER_DAIKIN_IR_PIN, ac_daikin, ClimateCard climateCard_daikin = ClimateCard(AIR_CONDITIONER_DAIKIN_IR_PIN, ac_daikin,
AIR_CONDITIONER_SENSOR_TYPE, AIR_CONDITIONER_SENSOR_PIN, AIR_CONDITIONER_SENSOR_TYPE, AIR_CONDITIONER_SENSOR_PIN,
AIR_CONDITIONER_RMT_CHANNEL0); AIR_CONDITIONER_RMT_CHANNEL0);
@ -119,10 +130,21 @@ void setup()
espmega.inputs.loop(); espmega.inputs.loop();
// set debounce time to 200 for pin 0-7 // set debounce time to 200 for pin 0-7
for (uint16_t i = 0; i < 8; i++){ for (uint16_t i = 0; i < 8; i++)
{
espmega.inputs.setDebounceTime(i, 200); espmega.inputs.setDebounceTime(i, 200);
} }
// if (clear_fram)
// {
// Serial.print("boot_state.txt=\"Factory Resetting . . .\"");
// sendStopBytes();
// for (uint16_t i = 0; i < 32768; i++)
// {
// espmega.fram.write8(i, 0);
// }
// esp_restart();
// }
// // ------------ End Factory Reset Routine ------------ // // ------------ End Factory Reset Routine ------------
@ -165,29 +187,28 @@ void setup()
climateCard_daikin.setFRAMAutoSave(true); climateCard_daikin.setFRAMAutoSave(true);
espmega.display->bindClimateCard(&climateCard_daikin); espmega.display->bindClimateCard(&climateCard_daikin);
// // Current Transformers // Current Transformers
// espmega.installCard(4, &analogCard); #ifdef ANALOG_ENABLE
espmega.installCard(4, &analogCard);
// espmega.installCard(5, &ct1); espmega.installCard(5, &ct1);
// ct1.bindFRAM(&espmega.fram, 6000); ct1.bindFRAM(&espmega.fram, 6000);
// espmega.iot->registerCard(5); espmega.iot->registerCard(5);
espmega.installCard(6, &ct2);
// espmega.installCard(6, &ct2); ct2.bindFRAM(&espmega.fram, 6100);
// ct2.bindFRAM(&espmega.fram, 6100); espmega.iot->registerCard(6);
// espmega.iot->registerCard(6); espmega.installCard(7, &ct3);
ct3.bindFRAM(&espmega.fram, 6200);
// espmega.installCard(7, &ct3); espmega.iot->registerCard(7);
// ct3.bindFRAM(&espmega.fram, 6200); espmega.installCard(8, &ct4);
// espmega.iot->registerCard(7); ct4.bindFRAM(&espmega.fram, 6300);
// espmega.installCard(8, &ct4); espmega.iot->registerCard(8);
// ct4.bindFRAM(&espmega.fram, 6300); espmega.installCard(9, &ct5);
// espmega.iot->registerCard(8); ct5.bindFRAM(&espmega.fram, 6400);
// espmega.installCard(9, &ct5); espmega.iot->registerCard(9);
// ct5.bindFRAM(&espmega.fram, 6400); espmega.installCard(10, &ct6);
// espmega.iot->registerCard(9); ct6.bindFRAM(&espmega.fram, 6500);
// espmega.installCard(10, &ct6); espmega.iot->registerCard(10);
// ct6.bindFRAM(&espmega.fram, 6500); #endif
// espmega.iot->registerCard(10);
// ------------ Climate Cards Initialization Routine ------------ // ------------ Climate Cards Initialization Routine ------------
ESP_LOGD("ISE OS", "Setting up climate cards"); ESP_LOGD("ISE OS", "Setting up climate cards");
@ -203,47 +224,48 @@ void setup()
// York Climate Card // York Climate Card
ESP_LOGD("ISE OS", "Installing york climate card"); ESP_LOGD("ISE OS", "Installing york climate card");
espmega.installCard(10, &climateCard_york); espmega.installCard(3, &climateCard_york);
climateCard_york.bindFRAM(&espmega.fram, 5005); climateCard_york.bindFRAM(&espmega.fram, 5005);
climateCard_york.loadStateFromFRAM(); climateCard_york.loadStateFromFRAM();
climateCard_york.setFRAMAutoSave(true); climateCard_york.setFRAMAutoSave(true);
// ------------ End Climate Cards Initialization Routine ------------ // ------------ End Climate Cards Initialization Routine ------------
// ------------ Current Transformer Cards Initialization Routine ------------ // ------------ Current Transformer Cards Initialization Routine ------------
//ESP_LOGD("ISE OS", "Installing current transformer cards"); #ifdef ANALOG_ENABLE
ESP_LOGD("ISE OS", "Installing current transformer cards");
// First try to install the analog card // First try to install the analog card
//analogCardAvailable = espmega.installCard(4, &analogCard); analogCardAvailable = espmega.installCard(4, &analogCard);
// If the analog card is available, install the current transformer cards // If the analog card is available, install the current transformer cards
// If the analog card is not available, current transformer cards will not be installed // If the analog card is not available, current transformer cards will not be installed
// Unless CT_FORCE_ENABLE is set to true // Unless CT_FORCE_ENABLE is set to true
// This is to prevent soft locking the device when the device tries to read from an ADC channel that does not exist // This is to prevent soft locking the device when the device tries to read from an ADC channel that does not exist
// if (analogCardAvailable || CT_FORCE_ENABLE) if (analogCardAvailable || CT_FORCE_ENABLE)
// { {
// ESP_LOGV("ISE OS", "Analog card available, installing current transformer cards"); ESP_LOGV("ISE OS", "Analog card available, installing current transformer cards");
// // espmega.installCard(5, &ct1); espmega.installCard(5, &ct1);
// // ct1.bindFRAM(&espmega.fram, 5010); ct1.bindFRAM(&espmega.fram, 5010);
// // espmega.installCard(6, &ct2); espmega.installCard(6, &ct2);
// // ct2.bindFRAM(&espmega.fram, 5020); ct2.bindFRAM(&espmega.fram, 5020);
// // espmega.installCard(7, &ct3); espmega.installCard(7, &ct3);
// // ct3.bindFRAM(&espmega.fram, 5030); ct3.bindFRAM(&espmega.fram, 5030);
// // espmega.installCard(8, &ct4); espmega.installCard(8, &ct4);
// // ct4.bindFRAM(&espmega.fram, 5040); ct4.bindFRAM(&espmega.fram, 5040);
// // espmega.installCard(9, &ct5); espmega.installCard(9, &ct5);
// // ct5.bindFRAM(&espmega.fram, 5050); ct5.bindFRAM(&espmega.fram, 5050);
// // espmega.installCard(10, &ct5); espmega.installCard(10, &ct5);
// // ct6.bindFRAM(&espmega.fram, 5060); ct6.bindFRAM(&espmega.fram, 5060);
// espmega.iot->registerCard(5); espmega.iot->registerCard(5);
// espmega.iot->registerCard(6); espmega.iot->registerCard(6);
// espmega.iot->registerCard(7); espmega.iot->registerCard(7);
// espmega.iot->registerCard(8); espmega.iot->registerCard(8);
// espmega.iot->registerCard(9); espmega.iot->registerCard(9);
// espmega.iot->registerCard(10); espmega.iot->registerCard(10);
// } }
// else else
// { {
// ESP_LOGE("ISE OS", "Analog card not available, current transformer cards cannot and will not be installed."); ESP_LOGE("ISE OS", "Analog card not available, current transformer cards cannot and will not be installed.");
// } }
//ESP_LOGD("ISE OS", "Registering Current Transformer Cards with IoT Module") #endif
// ------------ End Current Transformer Cards Initialization Routine ------------ // ------------ End Current Transformer Cards Initialization Routine ------------
@ -285,7 +307,7 @@ void setup()
espmega.iot->registerCard(0); // Register the Input Card espmega.iot->registerCard(0); // Register the Input Card
espmega.iot->registerCard(1); // Register the Output Card espmega.iot->registerCard(1); // Register the Output Card
espmega.iot->registerCard(2); // Register the Climate Card Daikin espmega.iot->registerCard(2); // Register the Climate Card Daikin
espmega.iot->registerCard(10); // Register the Climate Card York espmega.iot->registerCard(3); // Register the Climate Card York
// ------------ End IoT Card Registration Routine ------------ // ------------ End IoT Card Registration Routine ------------
@ -293,6 +315,8 @@ void setup()
auto bindedGetTime = std::bind(&ESPMegaPRO::getTime, &espmega); auto bindedGetTime = std::bind(&ESPMegaPRO::getTime, &espmega);
iseDisplay.begin(&espmega.inputs, &espmega.outputs, &climateCard_daikin, &climateCard_york, &pm_switch, &pm_fan_speed, &pm_lock, &ac_lock, espmega.iot); iseDisplay.begin(&espmega.inputs, &espmega.outputs, &climateCard_daikin, &climateCard_york, &pm_switch, &pm_fan_speed, &pm_lock, &ac_lock, espmega.iot);
espmega.iot->registerRelativeMqttCallback(&handleMqttMessage); espmega.iot->registerRelativeMqttCallback(&handleMqttMessage);
iseDisplayOTA.begin("/isedisp", &iseDisplay, espmega.webServer);
internalDisplayOTA.begin("/intdisp", espmega.display, espmega.webServer);
iseDisplay.registerPageChangeCallback(&handlePageChange); iseDisplay.registerPageChangeCallback(&handlePageChange);
// ------------ End External Display Initialization Routine ------------ // ------------ End External Display Initialization Routine ------------
} }
@ -321,6 +345,8 @@ void pmswitchupdatedisplay(char *value)
{ {
ESP_LOGI("PM switch", "getting PM switch state from MQTT: %d", pm_switch.getValue()); ESP_LOGI("PM switch", "getting PM switch state from MQTT: %d", pm_switch.getValue());
iseDisplay.updateAirPurifierState(); iseDisplay.updateAirPurifierState();
iseDisplay.updateSystemtoggle();
iseDisplay.updateAllStandbyToggle();
ESP_LOGI("PM switch", "toggling PM switch state from: %d to %d", pm_switch.getValue(), !pm_switch.getValue()); ESP_LOGI("PM switch", "toggling PM switch state from: %d to %d", pm_switch.getValue(), !pm_switch.getValue());
} }
void pmlockupdatedisplay(char *value) void pmlockupdatedisplay(char *value)
@ -350,6 +376,28 @@ void loop()
iseDisplay.updateDateTimeText(time); iseDisplay.updateDateTimeText(time);
last_time_updated = millis(); last_time_updated = millis();
} }
#ifdef ANALOG_ENABLE
// Send out analog Data every 6 seconds
static uint32_t last_analog_sent = 0;
if (millis() - last_analog_sent > 6000)
{
espmega.iot->publish("/debug/up", "1");
if (analogCardAvailable || CT_FORCE_ENABLE)
{
espmega.iot->publish("/debug/log", "Sending Analog Card Data");
char topic_buffer[50];
char payload_buffer[50];
// Publish ADC Pin 0-7
for (uint8_t i = 0; i < 8; i++)
{
sprintf(topic_buffer, "/debug/analog/%d", i);
sprintf(payload_buffer, "%d", analogCard.analogRead(i));
espmega.iot->publish(topic_buffer, payload_buffer);
}
}
last_analog_sent = millis();
}
#endif
} }
void on_pin_change(uint8_t pin, uint8_t value) void on_pin_change(uint8_t pin, uint8_t value)
@ -486,6 +534,7 @@ void handlePageChange(uint8_t page)
case PAGE_STANDBY: case PAGE_STANDBY:
iseDisplay.updateLightGroupStatePageStandby(); iseDisplay.updateLightGroupStatePageStandby();
iseDisplay.updateAirPurifierStateStandby(); iseDisplay.updateAirPurifierStateStandby();
iseDisplay.updateAllStandbyToggle();
break; break;
case PAGE_DASHBOARD: case PAGE_DASHBOARD:
iseDisplay.updateLightGroupStatePageDashboard(); iseDisplay.updateLightGroupStatePageDashboard();

View file

@ -5,6 +5,7 @@ SET_LOOP_TASK_STACK_SIZE(32*1024);
#include <ir_codes_daikin.hpp> #include <ir_codes_daikin.hpp>
#include <ir_codes_york.hpp> #include <ir_codes_york.hpp>
#include <CurrentTransformerCard.hpp> #include <CurrentTransformerCard.hpp>
#include <ESPMegaDisplayOTA.hpp>
@ -25,16 +26,16 @@ SET_LOOP_TASK_STACK_SIZE(32*1024);
#define AIR_CONDITIONER_YORK_IR_PIN 15 #define AIR_CONDITIONER_YORK_IR_PIN 15
#define AIR_CONDITIONER_RMT_CHANNEL0 RMT_CHANNEL_0 #define AIR_CONDITIONER_RMT_CHANNEL0 RMT_CHANNEL_0
#define AIR_CONDITIONER_RMT_CHANNEL1 RMT_CHANNEL_1 #define AIR_CONDITIONER_RMT_CHANNEL1 RMT_CHANNEL_1
// CT Configuration
// // CT Configuration #define ANALOG_ENABLE
// #define CT_FORCE_ENABLE false #define CT_FORCE_ENABLE true
// #define CT_RMS_VOLTAGE 1.0 #define CT_RMS_VOLTAGE 220.0
// #define CT_PIN_LIGHT_PHASE1 0 #define CT_PIN_LIGHT_PHASE1 0
// #define CT_PIN_LIGHT_PHASE2 1 #define CT_PIN_LIGHT_PHASE2 1
// #define CT_PIN_SOCKET 2 #define CT_PIN_SOCKET 2
// #define CT_PIN_AC_PHASE1 3 #define CT_PIN_AC_PHASE1 3
// #define CT_PIN_AC_PHASE2 4 #define CT_PIN_AC_PHASE2 4
// #define CT_PIN_AC_PHASE3 5 #define CT_PIN_AC_PHASE3 5
void handleMqttMessage(char *topic, char *payload); void handleMqttMessage(char *topic, char *payload);
void subscribeToMqttTopics(); void subscribeToMqttTopics();