adjust IR behaviour

This commit is contained in:
reaw55 2024-04-07 17:30:34 +07:00
parent 6a15d99e52
commit d4604d28c3
4 changed files with 253 additions and 133 deletions

View file

@ -6,8 +6,9 @@ ISEDisplay::ISEDisplay(HardwareSerial *adapter, const uint8_t *light_array, uint
this->column = column;
}
void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCard, ClimateCard *climateCard_daikin, ClimateCard *climateCard_york, RemoteVariable *pm_switch, RemoteVariable *pm_fan_speed, RemoteVariable *ac_lock, RemoteVariable *pm_lock)
void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCard, ClimateCard *climateCard_daikin, ClimateCard *climateCard_york, RemoteVariable *pm_switch, RemoteVariable *pm_fan_speed, RemoteVariable *ac_lock, RemoteVariable *pm_lock, ESPMegaIoT *iot)
{
this->iot = iot;
this->inputCard = inputCard;
this->outputCard = outputCard;
this->climateCard_daikin = climateCard_daikin;
@ -23,7 +24,7 @@ void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCar
this->climateCallbackHandle = this->climateCard_daikin->registerChangeCallback(bindedHandleACChange);
// this->climateCallbackHandle = this->climateCard_york->registerChangeCallback(bindedHandleACChange);
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_fan_speed = 10;
// remote_pm_fan_speed->setValue(pm_fan_speed);
@ -49,11 +50,10 @@ void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCar
this->updateLightGroupStatePageDashboard();
// intialize AC state
if(ac_lock_state == false)
if (ac_lock_state == false)
{
setACstate(ac_fan_speed, ac_mode, ac_temperature); // default to off with temp 25 and fan on Auto
}
}
void ISEDisplay::loop()
{
@ -64,8 +64,11 @@ void ISEDisplay::loop()
// Check if the AC state has been changed
if (ac_press_pending && (millis() - time_since_last_ac_change) > 5000)
{
ESP_LOGI("ISEDisplay", "Sending AC IR code");
sendACIRcode();
ESP_LOGI("ISEDisplay", "AC IR code sent");
ac_press_pending = false;
ESP_LOGI("ISEDisplay", "AC press pending set to false");
}
// Check if the MQTT connection has been lost
@ -73,23 +76,28 @@ void ISEDisplay::loop()
if (last_mqtt_connected_check == 0)
{
last_mqtt_connected_check = millis() + 15000; // Wait 15 seconds before checking
ESP_LOGD("ISE Display", "Waiting 15 seconds before checking MQTT connection");
}
static bool first_disconnect = true;
// ESP_LOGI("ISEDisplay", "init first disconnect set to true");
if (millis() - last_mqtt_connected_check > 3000)
{
ESP_LOGD("ISE Display", "Checking MQTT Connection, Connection is %s", this->cards.iot->mqttConnected() ? "true" : "false");
ESP_LOGD("ISE Display", "Checking MQTT Connection, Connection is %s", this->iot->mqttConnected() ? "true" : "false");
if (!this->iot->mqttConnected())
{
ESP_LOGI("ISEDisplay", "MQTT is disconnected");
if (first_disconnect)
{
// When MQTT is disconnected, enter standalone mode
// A/C lock is lifted
// PM lock are lifted
ESP_LOGI("ISEDisplay", "Entering standalone mode");
this->ac_lock_state = false;
ESP_LOGI("ISEDisplay", "AC lock state set to false");
this->pm_lock_state = false;
ESP_LOGI("ISEDisplay", "PM lock state set to false");
first_disconnect = false;
ESP_LOGI("ISEDisplay", "first disconnect set to false");
}
}
else
@ -97,18 +105,27 @@ void ISEDisplay::loop()
if (first_disconnect == false)
{
// When MQTT is connected, exit standalone mode
// In standalone mode, socket contactor is turned off
// A/C lock is set
// PM lock is set
ESP_LOGI("ISEDisplay", "Exiting standalone mode");
first_disconnect = true;
ESP_LOGI("ISEDisplay", "first disconnect set to true");
this->ac_lock_state = strcmp(ac_lock->getValue(), "on") == 0;
ESP_LOGI("ISEDisplay", "AC lock state set to %d", this->ac_lock_state);
this->pm_lock_state = strcmp(pm_lock->getValue(), "on") == 0;
ESP_LOGI("ISEDisplay", "PM lock state set to %d", this->pm_lock_state);
updateACState();
ESP_LOGI("ISEDisplay", "AC state updated");
updateAirPurifierState();
ESP_LOGI("ISEDisplay", "Air purifier state updated");
}
}
last_mqtt_connected_check = millis();
ESP_LOGI("ISEDisplay", "last mqtt connected check set to current time");
}
// ESP_LOGV("ISEDisplay", "this Loop is finish");
}
void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type)
@ -134,6 +151,10 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
case COMPONENT_OBJ_STANDBY_BTN_AC_TOGGLE:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
if (this->ac_lock_state == true){
ESP_LOGI("ISEDisplay", "AC lock is on, do nothing");
break;
}
toggleAC();
break;
case COMPONENT_OBJ_STANDBY_BTN_PM_TOGGLE:
@ -155,29 +176,37 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
case COMPONENT_OBJ_DASHBOARD_BTN_AC_TOGGLE:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
//if ac_lock is true do nothing
if (strcmp(ac_lock->getValue(), "on") == 0)
// if ac_lock is true do nothing
if (this->ac_lock_state == true)
{
ESP_LOGI("ISEDisplay", "AC lock is on, do nothing");
break;
}
toggleAC();
break;
case COMPONENT_OBJ_DASHBOARD_BTN_AC_MODE:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
//if ac_lock is true do nothing
if (strcmp(ac_lock->getValue(), "on") == 0)
// if ac_lock is true do nothing
if (this->ac_lock_state == true)
{
ESP_LOGI("ISEDisplay", "AC lock is on, do nothing");
break;
}
changeUserACmode();
break;
case COMPONENT_OBJ_DASHBOARD_BTN_AC_FAN_SPEED:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
//if ac_lock is true do nothing
if (strcmp(ac_lock->getValue(), "on") == 0)
// if ac_lock is true do nothing
if (this->ac_lock_state == true){
ESP_LOGI("ISEDisplay", "AC lock is on, do nothing");
break;
ac_fan_speed = this->climateCard_daikin->getFanSpeed();
}
// ac_fan_speed = this->climateCard_daikin->getFanSpeed();
ac_fan_speed = this->ac_fan_speed;
// mode= auto, high, mid, low
ESP_LOGI("ISEDisplay", "Current AC fan speed: %d", ac_fan_speed);
ac_fan_speed = (ac_fan_speed + 1) % 4;
@ -187,30 +216,35 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
case COMPONENT_OBJ_DASHBOARD_BTN_AC_TEMP_MINUS:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
//if ac_lock is true do nothing
if (strcmp(ac_lock->getValue(), "on") == 0)
// if ac_lock is true do nothing
if (this->ac_lock_state == true){
ESP_LOGI("ISEDisplay", "AC lock is on, do nothing");
break;
ac_temperature = this->climateCard_daikin->getTemperature() - 1;
}
// ac_temperature = this->climateCard_daikin->getTemperature() - 1;
ac_temperature = this->ac_temperature - 1;
setACstate(ac_fan_speed, ac_mode, ac_temperature);
break;
case COMPONENT_OBJ_DASHBOARD_BTN_AC_TEMP_PLUS:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
//if ac_lock is true do nothing
if (strcmp(ac_lock->getValue(), "on") == 0)
// if ac_lock is true do nothing
if (this->ac_lock_state == true){
ESP_LOGI("ISEDisplay", "AC lock is on, do nothing");
break;
ac_temperature = this->climateCard_daikin->getTemperature() + 1;
}
// ac_temperature = this->climateCard_daikin->getTemperature() + 1;
ac_temperature = this->ac_temperature + 1;
setACstate(ac_fan_speed, ac_mode, ac_temperature);
break;
case COMPONENT_OBJ_DASHBOARD_BTN_PM_TOGGLE:
if (touch_type != TOUCH_TYPE_RELEASE)
break;
//if pm_lock is true do nothing
if (strcmp(pm_lock->getValue(), "on") == 0)
// if pm_lock is true do nothing
if (this->pm_lock_state == true){
ESP_LOGI("ISEDisplay", "PM lock is on, do nothing");
break;
}
togglePM();
break;
case COMPONENT_OBJ_DASHBOARD_TXT_PM_INSIDE:
@ -411,6 +445,8 @@ void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value)
}
void ISEDisplay::updateDateTimeText(rtctime_t time)
{
if (this->currentPage == 1)
{
if (!this->takeSerialMutex())
return;
// Send the time to the display
@ -422,6 +458,7 @@ void ISEDisplay::updateDateTimeText(rtctime_t time)
this->sendStopBytes();
this->giveSerialMutex();
}
}
// TODO : Implement
// user remote var
@ -497,9 +534,17 @@ void ISEDisplay::setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_te
this->ac_fan_speed = ac_fan_speed;
this->ac_mode = ac_mode;
this->ac_temperature = ac_temperature;
//check ac_temp is within bound of daikin
if (this->ac_temperature < DAIKIN_MIN_TEMP)
{
this->ac_temperature = DAIKIN_MIN_TEMP;
}
else if (this->ac_temperature > DAIKIN_MAX_TEMP)
{
this->ac_temperature = DAIKIN_MAX_TEMP;
}
this->time_since_last_ac_change = millis();
this->ac_press_pending = true;
updateACState();
}
void ISEDisplay::sendACIRcode()
@ -532,6 +577,13 @@ void ISEDisplay::sendACIRcode()
{
this->climateCard_york->setState(cur_ac_mode, cur_ac_fan_speed, york_temp);
}
// get value of mode fanspeed and temp and print compare to store value
ESP_LOGI("ISEDisplay", "AC IR code sent");
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", "getting value of mode, fanspeed and temp from climate card");
ESP_LOGI("ISEDisplay", "Daikin fan speed: %d, Daikin mode: %d, Daikin temperature: %d", this->climateCard_daikin->getFanSpeed(), this->climateCard_daikin->getMode(), this->climateCard_daikin->getTemperature());
ESP_LOGI("ISEDisplay", "York fan speed: %d, York mode: %d, York temperature: %d", this->climateCard_york->getFanSpeed(), this->climateCard_york->getMode(), this->climateCard_york->getTemperature());
}
void ISEDisplay::toggleLightGroupState()
@ -610,32 +662,41 @@ void ISEDisplay::togglePMStandby()
void ISEDisplay::toggleAC()
{
// Get the current group state
uint8_t mode = this->climateCard_daikin->getMode();
// get fan speed and temperature
uint8_t fan_speed = this->climateCard_daikin->getFanSpeed();
uint8_t temperature = this->climateCard_daikin->getTemperature();
// uint8_t mode = this->climateCard_daikin->getMode();
uint8_t mode = this->ac_mode;
ESP_LOGI("ISEDisplay", "Current AC mode: %d", mode);
ESP_LOGI("ISEDisplay", "Current user mode: %d", user_mode);
// get value of mode, fanspeed and temp and print compare to store value
ESP_LOGI("ISEDisplay", "Daikin fan speed: %d, Daikin mode: %d, Daikin temperature: %d", this->climateCard_daikin->getFanSpeed(), this->climateCard_daikin->getMode(), this->climateCard_daikin->getTemperature());
ESP_LOGI("ISEDisplay", "York fan speed: %d, York mode: %d, York temperature: %d", this->climateCard_york->getFanSpeed(), this->climateCard_york->getMode(), this->climateCard_york->getTemperature());
// Toggle the state
if (mode == 0)
if (mode != 0)
{
ESP_LOGI("ISEDisplay", " User mode: %d", user_mode);
setACstate(fan_speed, user_mode, temperature);
// update mode to new mode
mode = 0;
ESP_LOGI("ISEDisplay", "change actual AC mode to off: %d", mode);
}
else
{
ESP_LOGI("ISEDisplay", "User mode BEFORE: %d", user_mode);
// update user mode to new mode
user_mode = mode;
// change actual mode to off
ESP_LOGI("ISEDisplay", "User mode AFTER: %d", user_mode);
setACstate(fan_speed, 0, temperature);
{ // ie mode is off
// do nothing as the state is keep in user_mode
// 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);
mode = user_mode;
}
// get fan speed and temperature
// uint8_t fan_speed = this->climateCard_daikin->getFanSpeed();
// uint8_t temperature = this->climateCard_daikin->getTemperature();
uint8_t fan_speed = this->ac_fan_speed;
uint8_t temperature = this->ac_temperature;
ESP_LOGI("ISEDisplay", "Current AC mode: %d", mode);
// Toggle the state
setACstate(fan_speed, mode, temperature);
}
void ISEDisplay::changeUserACmode()
{
// Get the current group state
uint8_t mode = this->climateCard_daikin->getMode();
uint8_t mode = this->ac_mode;
// uint8_t mode = this->climateCard_daikin->getMode();
ESP_LOGI("ISEDisplay", "Current actual AC mode: %d", mode);
// Toggle the state
// user mode alternate between 1 and 2
@ -795,6 +856,7 @@ void ISEDisplay::updateLightGroupStatePageDashboard()
for (uint8_t i = 1; i <= 4; i++)
{
u_int8_t state = getLightLevel(i);
updateLightSwitch();
switch (state)
{
case 0:
@ -832,6 +894,60 @@ void ISEDisplay::updateLightGroupStatePageDashboard()
this->giveSerialMutex();
}
void ISEDisplay::updateLightSwitch()
{
// Calculate the state
bool state_master = calculateLightGroupState();
// Send the state to the display
if (!this->takeSerialMutex())
return;
this->displayAdapter->print("light_m_sw.pic=");
this->displayAdapter->print(state_master ? 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_master ? COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_ON_PRESSED : COMPONENT_DASHBOARD_PIC_LIGHT_MASTER_OFF_PRESSED);
this->sendStopBytes();
this->giveSerialMutex();
// check state and set for each individual light row
// if state is 0 set to off and other(1,2,3) to on
for (uint8_t i = 1; i <= 4; i++)
{
u_int8_t state = getLightLevel(i);
if (state == 0)
{
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print("_sw.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_SWITCH_OFF);
this->sendStopBytes();
this->displayAdapter->print("light_row");
this->displayAdapter->print(i);
this->displayAdapter->print("_sw.pic2=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_LIGHT_SWITCH_OFF_PRESSED);
this->sendStopBytes();
}
else
{
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();
}
}
}
bool ISEDisplay::calculateLightGroupState()
{
// Check if all lights are on
@ -862,8 +978,8 @@ bool ISEDisplay::calculateAllState()
void ISEDisplay::toggleSystem()
{
toggleLightGroupState();
//check for ac lock and pm lock, if lock is on do nothing
if (strcmp(ac_lock->getValue(), "on") == 0)
// check for ac lock and pm lock, if lock is on do nothing
if (this->ac_lock_state == true)
{
ESP_LOGI("ISEDisplay", "AC lock is on, do nothing");
}
@ -871,7 +987,7 @@ void ISEDisplay::toggleSystem()
{
toggleAC();
}
if (strcmp(pm_lock->getValue(), "on") == 0)
if (this->pm_lock_state == true)
{
ESP_LOGI("ISEDisplay", "PM lock is on, do nothing");
}
@ -884,7 +1000,7 @@ void ISEDisplay::allOn()
{
setLightGroupState(3);
setPMstate(true, pm_fan_speed);
setACstate(ac_mode, ac_fan_speed, ac_temperature);
setACstate(2, ac_fan_speed, ac_temperature);
}
void ISEDisplay::toggleLightIndividual(uint8_t row)
@ -927,11 +1043,11 @@ void ISEDisplay::updateAirPurifierStateStandby()
return;
this->displayAdapter->print("s_pm_toggle.pic=");
this->displayAdapter->print(state ? COMPONENT_STANDBY_PIC_AC_TOGGLE_ON : COMPONENT_STANDBY_PIC_AC_TOGGLE_OFF);
this->displayAdapter->print(state ? COMPONENT_STANDBY_PIC_PM_TOGGLE_ON : COMPONENT_STANDBY_PIC_PM_TOGGLE_OFF);
this->sendStopBytes();
this->displayAdapter->print("s_pm_toggle.pic2=");
this->displayAdapter->print(state ? COMPONENT_STANDBY_PIC_AC_TOGGLE_ON_PRESSED : COMPONENT_STANDBY_PIC_AC_TOGGLE_OFF_PRESSED);
this->displayAdapter->print(state ? COMPONENT_STANDBY_PIC_PM_TOGGLE_ON_PRESSED : COMPONENT_STANDBY_PIC_PM_TOGGLE_OFF_PRESSED);
this->sendStopBytes();
this->giveSerialMutex();
@ -989,7 +1105,8 @@ void ISEDisplay::handleACChange(uint8_t mode, uint8_t fan_speed, uint8_t tempera
}
void ISEDisplay::updateuserACmode()
{
uint8_t mode = this->climateCard_daikin->getMode();
// uint8_t mode = this->climateCard_daikin->getMode();
uint8_t mode = this->ac_mode;
if (!this->takeSerialMutex())
return;
ESP_LOGI("ISEDisplay", "updating display user AC mode to: %d", user_mode);
@ -1063,8 +1180,10 @@ void ISEDisplay::updateuserACmode()
}
void ISEDisplay::updateACfanSpeed()
{
uint8_t fan_speed = this->climateCard_daikin->getFanSpeed();
uint8_t mode = this->climateCard_daikin->getMode();
// uint8_t fan_speed = this->climateCard_daikin->getFanSpeed();
// uint8_t mode = this->climateCard_daikin->getMode();
uint8_t fan_speed = this->ac_fan_speed;
uint8_t mode = this->ac_mode;
this->ac_lock_state = strcmp(ac_lock->getValue(), "on") == 0;
ESP_LOGI("ISEDisplay", "updating display AC fan speed to: %d", fan_speed);
@ -1162,8 +1281,10 @@ void ISEDisplay::updateACState()
// TODOlater : The cognitive complexity here is so high, maybe break up the method a bit?
// Get the state
uint8_t mode = this->climateCard_daikin->getMode();
uint8_t temperature = this->climateCard_daikin->getTemperature();
// uint8_t mode = this->climateCard_daikin->getMode();
// uint8_t temperature = this->climateCard_daikin->getTemperature();
uint8_t mode = this->ac_mode;
uint8_t temperature = this->ac_temperature;
this->ac_lock_state = strcmp(ac_lock->getValue(), "on") == 0;
if (currentPage != 1)
@ -1191,8 +1312,6 @@ void ISEDisplay::updateACState()
this->displayAdapter->print("c_degree.pic=");
this->displayAdapter->print(COMPONENT_DASHBOARD_PIC_DEGREE_C_ON);
this->sendStopBytes();
user_mode = mode;
}
this->displayAdapter->print("ac_sw.pic=");
this->displayAdapter->print(mode != 0 ? COMPONENT_DASHBOARD_PIC_AC_TOGGLE_ON : COMPONENT_DASHBOARD_PIC_AC_TOGGLE_OFF);

View file

@ -25,7 +25,7 @@ struct lightPosition {
class ISEDisplay : public ESPMegaDisplay {
public:
ISEDisplay(HardwareSerial* adapter, const uint8_t *light_array, uint8_t row, uint8_t column);
void begin(DigitalInputCard* inputCard, DigitalOutputCard* outputCard, ClimateCard* climateCard_daikin, ClimateCard* climateCard_york, RemoteVariable* pm_switch, RemoteVariable* pm_fan_speed, RemoteVariable* ac_lock, RemoteVariable* pm_lock);
void begin(DigitalInputCard* inputCard, DigitalOutputCard* outputCard, ClimateCard* climateCard_daikin, ClimateCard* climateCard_york, RemoteVariable* pm_switch, RemoteVariable* pm_fan_speed, RemoteVariable* ac_lock, RemoteVariable* pm_lock, ESPMegaIoT *iot);
void updateLightGroupStatePageDashboard();
void updateLightGroupStatePageStandby();
void updateAirPurifierState();
@ -68,7 +68,7 @@ class ISEDisplay : public ESPMegaDisplay {
RemoteVariable *pm_lock;
uint8_t outputCallbackHandle;
uint8_t climateCallbackHandle;
uint8_t time_since_last_ac_change;
uint32_t time_since_last_ac_change;
uint8_t user_mode;
uint8_t ac_lock_state;
uint8_t pm_lock_state;
@ -86,6 +86,7 @@ class ISEDisplay : public ESPMegaDisplay {
void updateuserACmode();
void updateACfanSpeed();
void updateLightSwitch();
bool calculateLightGroupState();
bool calculateAllState();
void toggleSystem();

View file

@ -6,15 +6,15 @@
***********************************************/
// Analog Card & Current Transformer Configuration
bool analogCardAvailable = false;
AnalogCard analogCard = AnalogCard();
float voltage = CT_RMS_VOLTAGE;
CurrentTransformerCard ct1 = CurrentTransformerCard(&analogCard, 0, &voltage, &adc2current, 5000);
CurrentTransformerCard ct2 = CurrentTransformerCard(&analogCard, 1, &voltage, &adc2current, 5000);
CurrentTransformerCard ct3 = CurrentTransformerCard(&analogCard, 2, &voltage, &adc2current, 5000);
CurrentTransformerCard ct4 = CurrentTransformerCard(&analogCard, 3, &voltage, &adc2current, 5000);
CurrentTransformerCard ct5 = CurrentTransformerCard(&analogCard, 4, &voltage, &adc2current, 5000);
CurrentTransformerCard ct6 = CurrentTransformerCard(&analogCard, 5, &voltage, &adc2current, 5000);
// bool analogCardAvailable = false;
// AnalogCard analogCard = AnalogCard();
// float voltage = CT_RMS_VOLTAGE;
// CurrentTransformerCard ct1 = CurrentTransformerCard(&analogCard, 0, &voltage, &adc2current, 5000);
// CurrentTransformerCard ct2 = CurrentTransformerCard(&analogCard, 1, &voltage, &adc2current, 5000);
// CurrentTransformerCard ct3 = CurrentTransformerCard(&analogCard, 2, &voltage, &adc2current, 5000);
// CurrentTransformerCard ct4 = CurrentTransformerCard(&analogCard, 3, &voltage, &adc2current, 5000);
// CurrentTransformerCard ct5 = CurrentTransformerCard(&analogCard, 4, &voltage, &adc2current, 5000);
// CurrentTransformerCard ct6 = CurrentTransformerCard(&analogCard, 5, &voltage, &adc2current, 5000);
// Remote Variables
RemoteVariable pm25_in = RemoteVariable();
@ -165,29 +165,29 @@ void setup()
climateCard_daikin.setFRAMAutoSave(true);
espmega.display->bindClimateCard(&climateCard_daikin);
// Current Transformers
espmega.installCard(4, &analogCard);
// // Current Transformers
// espmega.installCard(4, &analogCard);
espmega.installCard(5, &ct1);
ct1.bindFRAM(&espmega.fram, 6000);
espmega.iot->registerCard(5);
// espmega.installCard(5, &ct1);
// ct1.bindFRAM(&espmega.fram, 6000);
// espmega.iot->registerCard(5);
espmega.installCard(6, &ct2);
ct2.bindFRAM(&espmega.fram, 6100);
espmega.iot->registerCard(6);
// espmega.installCard(6, &ct2);
// ct2.bindFRAM(&espmega.fram, 6100);
// espmega.iot->registerCard(6);
espmega.installCard(7, &ct3);
ct3.bindFRAM(&espmega.fram, 6200);
espmega.iot->registerCard(7);
espmega.installCard(8, &ct4);
ct4.bindFRAM(&espmega.fram, 6300);
espmega.iot->registerCard(8);
espmega.installCard(9, &ct5);
ct5.bindFRAM(&espmega.fram, 6400);
espmega.iot->registerCard(9);
espmega.installCard(10, &ct6);
ct6.bindFRAM(&espmega.fram, 6500);
espmega.iot->registerCard(10);
// espmega.installCard(7, &ct3);
// ct3.bindFRAM(&espmega.fram, 6200);
// espmega.iot->registerCard(7);
// espmega.installCard(8, &ct4);
// ct4.bindFRAM(&espmega.fram, 6300);
// espmega.iot->registerCard(8);
// espmega.installCard(9, &ct5);
// ct5.bindFRAM(&espmega.fram, 6400);
// espmega.iot->registerCard(9);
// espmega.installCard(10, &ct6);
// ct6.bindFRAM(&espmega.fram, 6500);
// espmega.iot->registerCard(10);
// ------------ Climate Cards Initialization Routine ------------
ESP_LOGD("ISE OS", "Setting up climate cards");
@ -210,40 +210,40 @@ void setup()
// ------------ End Climate Cards Initialization Routine ------------
// ------------ Current Transformer Cards Initialization Routine ------------
ESP_LOGD("ISE OS", "Installing current transformer cards");
//ESP_LOGD("ISE OS", "Installing current transformer cards");
// 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 not available, current transformer cards will not be installed
// 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
if (analogCardAvailable || CT_FORCE_ENABLE)
{
ESP_LOGV("ISE OS", "Analog card available, installing current transformer cards");
espmega.installCard(5, &ct1);
ct1.bindFRAM(&espmega.fram, 5010);
espmega.installCard(6, &ct2);
ct2.bindFRAM(&espmega.fram, 5020);
espmega.installCard(7, &ct3);
ct3.bindFRAM(&espmega.fram, 5030);
espmega.installCard(8, &ct4);
ct4.bindFRAM(&espmega.fram, 5040);
espmega.installCard(9, &ct5);
ct5.bindFRAM(&espmega.fram, 5050);
espmega.installCard(10, &ct5);
ct6.bindFRAM(&espmega.fram, 5060);
espmega.iot->registerCard(5);
espmega.iot->registerCard(6);
espmega.iot->registerCard(7);
espmega.iot->registerCard(8);
espmega.iot->registerCard(9);
espmega.iot->registerCard(10);
}
else
{
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");
// if (analogCardAvailable || CT_FORCE_ENABLE)
// {
// ESP_LOGV("ISE OS", "Analog card available, installing current transformer cards");
// // espmega.installCard(5, &ct1);
// // ct1.bindFRAM(&espmega.fram, 5010);
// // espmega.installCard(6, &ct2);
// // ct2.bindFRAM(&espmega.fram, 5020);
// // espmega.installCard(7, &ct3);
// // ct3.bindFRAM(&espmega.fram, 5030);
// // espmega.installCard(8, &ct4);
// // ct4.bindFRAM(&espmega.fram, 5040);
// // espmega.installCard(9, &ct5);
// // ct5.bindFRAM(&espmega.fram, 5050);
// // espmega.installCard(10, &ct5);
// // ct6.bindFRAM(&espmega.fram, 5060);
// espmega.iot->registerCard(5);
// espmega.iot->registerCard(6);
// espmega.iot->registerCard(7);
// espmega.iot->registerCard(8);
// espmega.iot->registerCard(9);
// espmega.iot->registerCard(10);
// }
// else
// {
// 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")
// ------------ End Current Transformer Cards Initialization Routine ------------
@ -291,7 +291,7 @@ void setup()
// ------------ External Display Initialization Routine ------------
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);
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);
iseDisplay.registerPageChangeCallback(&handlePageChange);
// ------------ End External Display Initialization Routine ------------

View file

@ -26,15 +26,15 @@ SET_LOOP_TASK_STACK_SIZE(32*1024);
#define AIR_CONDITIONER_RMT_CHANNEL0 RMT_CHANNEL_0
#define AIR_CONDITIONER_RMT_CHANNEL1 RMT_CHANNEL_1
// CT Configuration
#define CT_FORCE_ENABLE false
#define CT_RMS_VOLTAGE 1.0
#define CT_PIN_LIGHT_PHASE1 0
#define CT_PIN_LIGHT_PHASE2 1
#define CT_PIN_SOCKET 2
#define CT_PIN_AC_PHASE1 3
#define CT_PIN_AC_PHASE2 4
#define CT_PIN_AC_PHASE3 5
// // CT Configuration
// #define CT_FORCE_ENABLE false
// #define CT_RMS_VOLTAGE 1.0
// #define CT_PIN_LIGHT_PHASE1 0
// #define CT_PIN_LIGHT_PHASE2 1
// #define CT_PIN_SOCKET 2
// #define CT_PIN_AC_PHASE1 3
// #define CT_PIN_AC_PHASE2 4
// #define CT_PIN_AC_PHASE3 5
void handleMqttMessage(char *topic, char *payload);
void subscribeToMqttTopics();