From a590c38dae6649f4bd22e2e0564cbf3a409660d6 Mon Sep 17 00:00:00 2001 From: reaw Date: Fri, 16 Feb 2024 00:21:33 +0700 Subject: [PATCH] light-not-work-as-expected --- src/ise_display.cpp | 84 ++++++++++++++++++++++++++++++--- src/ise_display.hpp | 12 ++++- src/ise_display_definitions.hpp | 10 ++++ src/main.cpp | 10 +++- 4 files changed, 108 insertions(+), 8 deletions(-) diff --git a/src/ise_display.cpp b/src/ise_display.cpp index ffd32a9..6ee33bb 100644 --- a/src/ise_display.cpp +++ b/src/ise_display.cpp @@ -1,6 +1,9 @@ #include -ISEDisplay::ISEDisplay(HardwareSerial *adapter) : ESPMegaDisplay(adapter, 115200, 912600, 4, 17) +ISEDisplay::ISEDisplay(HardwareSerial *adapter, const uint8_t *light_array, uint8_t row, uint8_t column) : ESPMegaDisplay(adapter, 115200, 912600, 4, 17) { + this->light_array = light_array; + this->row = row; + this->column = column; } // Work left // TODO : Implement @@ -556,21 +559,90 @@ void ISEDisplay::changeUserACmode() } void ISEDisplay::setLightLevel(uint8_t row, uint8_t level) { - for (uint8_t i = 1; i <= 4; i++) + // Set the light level + // this->outputCard->setValue(row, level); + uint8_t primary_pin = *(light_array + 2*(row - 1)); + uint8_t secondary_pin = *(light_array + 2*(row - 1) + 1); + + bool primary = false; + bool secondary = false; + + switch (level) { - if (row == i) - this->outputCard->setValue(row, level); + case 0: + primary = false; + secondary = false; + break; + case 1: + primary = false; + secondary = true; + break; + case 2: + primary = true; + secondary = false; + break; + case 3: + primary = true; + secondary = true; + break; + default: + break; } + + this->outputCard->setValue(primary_pin, primary); + this->outputCard->setValue(secondary_pin, secondary); } u_int8_t ISEDisplay::getLightLevel(uint8_t row) { u_int8_t lightLevel = 0; - lightLevel = this->outputCard->getValue(row); + + //lightLevel = this->outputCard->getValue(row); + uint8_t primary_pin = *(light_array + 2*(row - 1)); + uint8_t secondary_pin = *(light_array + 2*(row - 1) + 1); + bool primary = this->outputCard->getValue(primary_pin); + bool secondary = this->outputCard->getValue(secondary_pin); + if (primary && secondary) + { + lightLevel = 3; + } + else if (primary) + { + lightLevel = 2; + } + else if (secondary) + { + lightLevel = 1; + } + else + { + lightLevel = 0; + } + return lightLevel; - } +//change to light with the assignment + +lightPosition ISEDisplay::getRowCol(uint8_t pin){ + lightPosition position; + //uint8_t row = this->row; + //uint8_t column = this->column; + //const uint8_t *light_array = this->light_array; + // should return the row and column of the light from pin in a row by column array pointer pass from main using pointer arithmetic + for (uint8_t i = 0; i < row*column; i++) + { + uint8_t value = *(light_array + i); + if (value == pin) + { + position.row = i / column; + position.column = i % column; + return position; + } + } +} + + void ISEDisplay::updateLightGroupStatePageStandby() { // Calculate the state diff --git a/src/ise_display.hpp b/src/ise_display.hpp index 321bf41..3074d30 100644 --- a/src/ise_display.hpp +++ b/src/ise_display.hpp @@ -16,10 +16,14 @@ +struct lightPosition { + uint8_t row; + uint8_t column; +}; class ISEDisplay : public ESPMegaDisplay { public: - ISEDisplay(HardwareSerial* adapter); + ISEDisplay(HardwareSerial* adapter, const uint8_t *light_array, uint8_t row, uint8_t column); void begin(DigitalInputCard* inputCard, DigitalOutputCard* outputCard, ClimateCard* climateCard, RemoteVariable* pm_switch, RemoteVariable* pm_fan_speed); void updateLightGroupStatePageDashboard(); void updateLightGroupStatePageStandby(); @@ -43,10 +47,16 @@ class ISEDisplay : public ESPMegaDisplay { void setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_temperature); void setLightLevel(uint8_t row, uint8_t level); u_int8_t getLightLevel(uint8_t row); + lightPosition getRowCol(uint8_t pin); DigitalInputCard* inputCard; DigitalOutputCard *outputCard; ClimateCard *climateCard; + + const uint8_t *light_array; + uint8_t row; + uint8_t column; + RemoteVariable *pm_switch; RemoteVariable *remote_pm_fan_speed; uint8_t outputCallbackHandle; diff --git a/src/ise_display_definitions.hpp b/src/ise_display_definitions.hpp index 6e1aa9b..aae6adb 100644 --- a/src/ise_display_definitions.hpp +++ b/src/ise_display_definitions.hpp @@ -20,8 +20,18 @@ change light assignment 6: row 3 column 2 7: row 4 column 1 8: row 4 column 2 +*/ +#define LIGHT_ROW1_COLUMN1 1 +#define LIGHT_ROW1_COLUMN2 2 +#define LIGHT_ROW2_COLUMN1 3 +#define LIGHT_ROW2_COLUMN2 4 +#define LIGHT_ROW3_COLUMN1 5 +#define LIGHT_ROW3_COLUMN2 6 +#define LIGHT_ROW4_COLUMN1 7 +#define LIGHT_ROW4_COLUMN2 8 +/* 5: Air Purifier status (on/off) 6: Air Purifier fan speed (0-20) diff --git a/src/main.cpp b/src/main.cpp index 7ffe910..595a6dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,14 @@ RemoteVariable pm_fan_speed = RemoteVariable(); const char *mode_names[] = {"off", "fan_only", "cool"}; const char *fan_speed_names[] = {"auto", "high", "medium", "low"}; +uint8_t row = 4; +uint8_t column = 2; +const uint8_t light_array[4][2] = { + {LIGHT_ROW1_COLUMN1, LIGHT_ROW1_COLUMN2}, + {LIGHT_ROW2_COLUMN1, LIGHT_ROW2_COLUMN2}, + {LIGHT_ROW3_COLUMN1, LIGHT_ROW3_COLUMN2}, + {LIGHT_ROW4_COLUMN1, LIGHT_ROW4_COLUMN2}}; + AirConditioner ac = { .max_temperature = 30, @@ -23,7 +31,7 @@ AirConditioner ac = { ***********************************************/ ESPMegaPRO espmega = ESPMegaPRO(); -ISEDisplay iseDisplay = ISEDisplay(&iseDisplayAdapter); +ISEDisplay iseDisplay = ISEDisplay(&iseDisplayAdapter, &light_array[0][0], row, column); ClimateCard climateCard = ClimateCard(AIR_CONDITIONER_IR_PIN, ac, AIR_CONDITIONER_SENSOR_TYPE, AIR_CONDITIONER_SENSOR_PIN,