light-not-work-as-expected

This commit is contained in:
reaw 2024-02-16 00:21:33 +07:00
parent 2698363317
commit a590c38dae
4 changed files with 108 additions and 8 deletions

View file

@ -1,6 +1,9 @@
#include <ise_display.hpp> #include <ise_display.hpp>
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 // Work left
// TODO : Implement // TODO : Implement
@ -556,21 +559,90 @@ void ISEDisplay::changeUserACmode()
} }
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++) // 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) case 0:
this->outputCard->setValue(row, level); 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 ISEDisplay::getLightLevel(uint8_t row)
{ {
u_int8_t lightLevel = 0; 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; 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() void ISEDisplay::updateLightGroupStatePageStandby()
{ {
// Calculate the state // Calculate the state

View file

@ -16,10 +16,14 @@
struct lightPosition {
uint8_t row;
uint8_t column;
};
class ISEDisplay : public ESPMegaDisplay { class ISEDisplay : public ESPMegaDisplay {
public: 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 begin(DigitalInputCard* inputCard, DigitalOutputCard* outputCard, ClimateCard* climateCard, RemoteVariable* pm_switch, RemoteVariable* pm_fan_speed);
void updateLightGroupStatePageDashboard(); void updateLightGroupStatePageDashboard();
void updateLightGroupStatePageStandby(); 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 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);
u_int8_t getLightLevel(uint8_t row); u_int8_t getLightLevel(uint8_t row);
lightPosition getRowCol(uint8_t pin);
DigitalInputCard* inputCard; DigitalInputCard* inputCard;
DigitalOutputCard *outputCard; DigitalOutputCard *outputCard;
ClimateCard *climateCard; ClimateCard *climateCard;
const uint8_t *light_array;
uint8_t row;
uint8_t column;
RemoteVariable *pm_switch; RemoteVariable *pm_switch;
RemoteVariable *remote_pm_fan_speed; RemoteVariable *remote_pm_fan_speed;
uint8_t outputCallbackHandle; uint8_t outputCallbackHandle;

View file

@ -20,8 +20,18 @@ change light assignment
6: row 3 column 2 6: row 3 column 2
7: row 4 column 1 7: row 4 column 1
8: row 4 column 2 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) 5: Air Purifier status (on/off)
6: Air Purifier fan speed (0-20) 6: Air Purifier fan speed (0-20)

View file

@ -9,6 +9,14 @@ RemoteVariable pm_fan_speed = RemoteVariable();
const char *mode_names[] = {"off", "fan_only", "cool"}; const char *mode_names[] = {"off", "fan_only", "cool"};
const char *fan_speed_names[] = {"auto", "high", "medium", "low"}; 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 = { AirConditioner ac = {
.max_temperature = 30, .max_temperature = 30,
@ -23,7 +31,7 @@ AirConditioner ac = {
***********************************************/ ***********************************************/
ESPMegaPRO espmega = ESPMegaPRO(); 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, ClimateCard climateCard = ClimateCard(AIR_CONDITIONER_IR_PIN, ac,
AIR_CONDITIONER_SENSOR_TYPE, AIR_CONDITIONER_SENSOR_PIN, AIR_CONDITIONER_SENSOR_TYPE, AIR_CONDITIONER_SENSOR_PIN,