a/c logic without iot
This commit is contained in:
parent
fbbba53302
commit
feb399ed2d
|
@ -1,4 +1,4 @@
|
|||
#include "cud_display.hpp"
|
||||
#include "display.hpp"
|
||||
|
||||
CUDDisplay::CUDDisplay(cud_display_conf_t *conf) : ESPMegaDisplay(conf->uart, conf->communication_baudrate, conf->ota_baudrate, conf->tx, conf->rx)
|
||||
{
|
||||
|
@ -10,16 +10,14 @@ CUDDisplay::CUDDisplay(cud_display_conf_t *conf) : ESPMegaDisplay(conf->uart, co
|
|||
.picture_on = {LCD_DASHBOARD_PIC_LIGHT_1_ON, LCD_DASHBOARD_PIC_LIGHT_2_ON, LCD_DASHBOARD_PIC_LIGHT_3_ON, LCD_DASHBOARD_PIC_LIGHT_4_ON},
|
||||
.picture_on_pressed = {LCD_DASHBOARD_PIC_LIGHT_1_ON_PRESSED, LCD_DASHBOARD_PIC_LIGHT_2_ON_PRESSED, LCD_DASHBOARD_PIC_LIGHT_3_ON_PRESSED, LCD_DASHBOARD_PIC_LIGHT_4_ON_PRESSED},
|
||||
.picture_off = {LCD_DASHBOARD_PIC_LIGHT_1_OFF, LCD_DASHBOARD_PIC_LIGHT_2_OFF, LCD_DASHBOARD_PIC_LIGHT_3_OFF, LCD_DASHBOARD_PIC_LIGHT_4_OFF},
|
||||
.picture_off_pressed = {LCD_DASHBOARD_PIC_LIGHT_1_OFF_PRESSED, LCD_DASHBOARD_PIC_LIGHT_2_OFF_PRESSED, LCD_DASHBOARD_PIC_LIGHT_3_OFF_PRESSED, LCD_DASHBOARD_PIC_LIGHT_4_OFF_PRESSED}
|
||||
};
|
||||
.picture_off_pressed = {LCD_DASHBOARD_PIC_LIGHT_1_OFF_PRESSED, LCD_DASHBOARD_PIC_LIGHT_2_OFF_PRESSED, LCD_DASHBOARD_PIC_LIGHT_3_OFF_PRESSED, LCD_DASHBOARD_PIC_LIGHT_4_OFF_PRESSED}};
|
||||
this->fan_group = {
|
||||
.element_id = {LCD_DASHBOARD_ELEMENT_FAN_1, LCD_DASHBOARD_ELEMENT_FAN_2, LCD_DASHBOARD_ELEMENT_FAN_3},
|
||||
.element_name = {LCD_DASHBOARD_ELEMENT_NAME_FAN_1, LCD_DASHBOARD_ELEMENT_NAME_FAN_2, LCD_DASHBOARD_ELEMENT_NAME_FAN_3},
|
||||
.picture_on = {LCD_DASHBOARD_PIC_FAN_1_ON, LCD_DASHBOARD_PIC_FAN_2_ON, LCD_DASHBOARD_PIC_FAN_3_ON},
|
||||
.picture_on_pressed = {LCD_DASHBOARD_PIC_FAN_1_ON_PRESSED, LCD_DASHBOARD_PIC_FAN_2_ON_PRESSED, LCD_DASHBOARD_PIC_FAN_3_ON_PRESSED},
|
||||
.picture_off = {LCD_DASHBOARD_PIC_FAN_1_OFF, LCD_DASHBOARD_PIC_FAN_2_OFF, LCD_DASHBOARD_PIC_FAN_3_OFF},
|
||||
.picture_off_pressed = {LCD_DASHBOARD_PIC_FAN_1_OFF_PRESSED, LCD_DASHBOARD_PIC_FAN_2_OFF_PRESSED, LCD_DASHBOARD_PIC_FAN_3_OFF_PRESSED}
|
||||
};
|
||||
.picture_off_pressed = {LCD_DASHBOARD_PIC_FAN_1_OFF_PRESSED, LCD_DASHBOARD_PIC_FAN_2_OFF_PRESSED, LCD_DASHBOARD_PIC_FAN_3_OFF_PRESSED}};
|
||||
}
|
||||
|
||||
void CUDDisplay::begin()
|
||||
|
@ -30,16 +28,21 @@ void CUDDisplay::begin()
|
|||
auto binded_aqi_callback = std::bind(&CUDDisplay::handle_aqi_change, this, std::placeholders::_1);
|
||||
auto binded_payload_callback = std::bind(&CUDDisplay::handle_payload, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
auto binded_touch_callback = std::bind(&CUDDisplay::handle_touch, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
auto binded_ac_callback = std::bind(&CUDDisplay::handle_ac_change, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
auto binded_ac_sensor_callback = std::bind(&CUDDisplay::handle_ac_sensor, this, std::placeholders::_1, std::placeholders::_2);
|
||||
this->conf->inputCard->registerCallback(binded_input_callback);
|
||||
this->conf->outputCard->registerChangeCallback(binded_output_callback);
|
||||
this->conf->aqi->registerCallback(binded_aqi_callback);
|
||||
this->registerPayloadCallback(binded_payload_callback);
|
||||
this->registerTouchCallback(binded_touch_callback);
|
||||
this->conf->ac->registerChangeCallback(binded_ac_callback);
|
||||
this->conf->ac->registerSensorCallback(binded_ac_sensor_callback);
|
||||
// Initialize the display
|
||||
this->display_init();
|
||||
}
|
||||
|
||||
void CUDDisplay::display_init() {
|
||||
void CUDDisplay::display_init()
|
||||
{
|
||||
// Perform a reset on the display
|
||||
this->reset();
|
||||
// Set the display to the main screen
|
||||
|
@ -177,6 +180,106 @@ void CUDDisplay::handle_touch(uint8_t page_id, uint8_t element_id, uint8_t touch
|
|||
return;
|
||||
}
|
||||
}
|
||||
// Check if element_id is the AC state button
|
||||
if (element_id == LCD_DASHBOARD_ELEMENT_AC_STATE)
|
||||
{
|
||||
// Is the control locked? If it is, we can ignore the touch
|
||||
if (this->ac_locked)
|
||||
return;
|
||||
// Toggle the AC
|
||||
// Is the AC on?
|
||||
if (this->conf->ac->getMode() != 0)
|
||||
{
|
||||
// If it is, turn it off
|
||||
this->conf->ac->setMode(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If it is not, turn it on
|
||||
this->conf->ac->setMode(previous_mode);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Check if element_id is the AC mode fan button
|
||||
if (element_id == LCD_DASHBOARD_ELEMENT_AC_MODE_FAN)
|
||||
{
|
||||
// Is the control locked? If it is, we can ignore the touch
|
||||
if (this->ac_locked)
|
||||
return;
|
||||
// Set the AC mode to fan
|
||||
this->conf->ac->setMode(1);
|
||||
return;
|
||||
}
|
||||
// Check if element_id is the AC mode cool button
|
||||
if (element_id == LCD_DASHBOARD_ELEMENT_AC_MODE_COOL)
|
||||
{
|
||||
// Is the control locked? If it is, we can ignore the touch
|
||||
if (this->ac_locked)
|
||||
return;
|
||||
// Set the AC mode to cool
|
||||
this->conf->ac->setMode(2);
|
||||
return;
|
||||
}
|
||||
// Check if element_id is the AC fan speed auto button
|
||||
if (element_id == LCD_DASHBOARD_ELEMENT_AC_FAN_SPEED_AUTO)
|
||||
{
|
||||
// Is the control locked? If it is, we can ignore the touch
|
||||
if (this->ac_locked)
|
||||
return;
|
||||
// Set the AC fan speed to auto
|
||||
this->conf->ac->setFanSpeed(0);
|
||||
return;
|
||||
}
|
||||
// Check if element_id is the AC fan speed low button
|
||||
if (element_id == LCD_DASHBOARD_ELEMENT_AC_FAN_SPEED_LOW)
|
||||
{
|
||||
// Is the control locked? If it is, we can ignore the touch
|
||||
if (this->ac_locked)
|
||||
return;
|
||||
// Set the AC fan speed to low
|
||||
this->conf->ac->setFanSpeed(1);
|
||||
return;
|
||||
}
|
||||
// Check if element_id is the AC fan speed medium button
|
||||
if (element_id == LCD_DASHBOARD_ELEMENT_AC_FAN_SPEED_MEDIUM)
|
||||
{
|
||||
// Is the control locked? If it is, we can ignore the touch
|
||||
if (this->ac_locked)
|
||||
return;
|
||||
// Set the AC fan speed to medium
|
||||
this->conf->ac->setFanSpeed(2);
|
||||
return;
|
||||
}
|
||||
// Check if element_id is the AC fan speed high button
|
||||
if (element_id == LCD_DASHBOARD_ELEMENT_AC_FAN_SPEED_HIGH)
|
||||
{
|
||||
// Is the control locked? If it is, we can ignore the touch
|
||||
if (this->ac_locked)
|
||||
return;
|
||||
// Set the AC fan speed to high
|
||||
this->conf->ac->setFanSpeed(3);
|
||||
return;
|
||||
}
|
||||
// Check if element_id is the AC temperature up button
|
||||
if (element_id == LCD_DASHBOARD_ELEMENT_AC_TEMP_UP_BUTTON)
|
||||
{
|
||||
// Is the control locked? If it is, we can ignore the touch
|
||||
if (this->ac_locked)
|
||||
return;
|
||||
// Increase the AC temperature
|
||||
this->conf->ac->setTemperature(this->conf->ac->getTemperature() + 1);
|
||||
return;
|
||||
}
|
||||
// Check if element_id is the AC temperature down button
|
||||
if (element_id == LCD_DASHBOARD_ELEMENT_AC_TEMP_DOWN_BUTTON)
|
||||
{
|
||||
// Is the control locked? If it is, we can ignore the touch
|
||||
if (this->ac_locked)
|
||||
return;
|
||||
// Decrease the AC temperature
|
||||
this->conf->ac->setTemperature(this->conf->ac->getTemperature() - 1);
|
||||
return;
|
||||
}
|
||||
// The element_id is not the one that our display is handling, so we can ignore it
|
||||
}
|
||||
|
||||
|
@ -217,7 +320,7 @@ void CUDDisplay::handle_aqi_change(char *value)
|
|||
|
||||
/**
|
||||
* @brief Handle the payload from the display that is not handled by the parent class
|
||||
*
|
||||
*
|
||||
* @param type Payload type
|
||||
* @param payload The payload itself
|
||||
* @param length The length of the payload excluding the type
|
||||
|
@ -232,6 +335,16 @@ void CUDDisplay::handle_payload(uint8_t type, uint8_t *payload, uint8_t length)
|
|||
}
|
||||
}
|
||||
|
||||
void CUDDisplay::handle_ac_change(uint8_t mode, uint8_t fan_speed, uint8_t temperature)
|
||||
{
|
||||
// Set the previous mode to the current mode if the current mode is not 0
|
||||
if (mode != 0)
|
||||
{
|
||||
previous_mode = mode;
|
||||
}
|
||||
this->refresh_display_ac();
|
||||
}
|
||||
|
||||
void CUDDisplay::set_display_light_state(uint8_t row, bool state)
|
||||
{
|
||||
this->takeSerialMutex();
|
||||
|
@ -267,7 +380,6 @@ void CUDDisplay::set_display_fan_all_state()
|
|||
this->displayAdapter->printf("%s.pic=%d", LCD_DASHBOARD_ELEMENT_NAME_FAN_ALL, fan_on ? LCD_DASHBOARD_PIC_FAN_ALL_ON : LCD_DASHBOARD_PIC_FAN_ALL_OFF);
|
||||
this->displayAdapter->printf("%s.pic2=%d", LCD_DASHBOARD_ELEMENT_NAME_FAN_ALL, fan_on ? LCD_DASHBOARD_PIC_FAN_ALL_ON_PRESSED : LCD_DASHBOARD_PIC_FAN_ALL_OFF_PRESSED);
|
||||
this->sendStopBytes();
|
||||
|
||||
}
|
||||
|
||||
void CUDDisplay::set_display_mosquito_zapper_state(bool state)
|
||||
|
@ -301,4 +413,77 @@ void CUDDisplay::refresh_display()
|
|||
{
|
||||
this->set_display_fan_state(i, this->conf->outputCard->getState(this->conf->fan_pins[i]));
|
||||
}
|
||||
}
|
||||
|
||||
void CUDDisplay::refresh_display_ac()
|
||||
{
|
||||
// Fetch data from the AC
|
||||
uint8_t mode = this->conf->ac->getMode();
|
||||
bool state = mode != 0;
|
||||
previous_mode = previous_mode == 0 ? 2 : previous_mode;
|
||||
bool drawn_mode = mode == 0? previous_mode : mode;
|
||||
uint8_t fan_speed = this->conf->ac->getFanSpeed();
|
||||
uint8_t temperature = this->conf->ac->getTemperature();
|
||||
// Draw the state picture set
|
||||
// Is the AC locked?
|
||||
if (this->ac_locked)
|
||||
{
|
||||
// When the display is locked
|
||||
// the state picture set we use is the locked state picture set
|
||||
this->takeSerialMutex();
|
||||
this->displayAdapter->printf("%s.pic=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_STATE, state ? LCD_DASHBOARD_PIC_AC_STATE_ON_LOCKED : LCD_DASHBOARD_PIC_AC_STATE_OFF_LOCKED);
|
||||
// Since the display is locked, when pressed, the state picture set should not change
|
||||
this->displayAdapter->printf("%s.pic2=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_STATE, state ? LCD_DASHBOARD_PIC_AC_STATE_ON_LOCKED : LCD_DASHBOARD_PIC_AC_STATE_OFF_LOCKED);
|
||||
this->giveSerialMutex();
|
||||
}
|
||||
else
|
||||
{
|
||||
// When the display is not locked
|
||||
// the state picture set we use is the unlocked state picture set
|
||||
this->takeSerialMutex();
|
||||
this->displayAdapter->printf("%s.pic=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_STATE, state ? LCD_DASHBOARD_PIC_AC_STATE_ON : LCD_DASHBOARD_PIC_AC_STATE_OFF);
|
||||
// When pressed, the state picture set should change
|
||||
this->displayAdapter->printf("%s.pic2=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_STATE, state ? LCD_DASHBOARD_PIC_AC_STATE_ON_PRESSED : LCD_DASHBOARD_PIC_AC_STATE_OFF_PRESSED);
|
||||
this->giveSerialMutex();
|
||||
}
|
||||
// Draw the mode picture set
|
||||
this->takeSerialMutex();
|
||||
this->displayAdapter->printf("%s.pic=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_MODE_COOL, drawn_mode == 2 ? LCD_DASHBOARD_PIC_AC_MODE_COOL_ACTIVE : LCD_DASHBOARD_PIC_AC_MODE_COOL_INACTIVE);
|
||||
this->displayAdapter->printf("%s.pic2=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_MODE_COOL, drawn_mode == 2 ? LCD_DASHBOARD_PIC_AC_MODE_COOL_ACTIVE_PRESS : LCD_DASHBOARD_PIC_AC_MODE_COOL_INACTIVE_PRESS);
|
||||
this->displayAdapter->printf("%s.pic=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_MODE_FAN, drawn_mode == 1 ? LCD_DASHBOARD_PIC_AC_MODE_FAN_ACTIVE : LCD_DASHBOARD_PIC_AC_MODE_FAN_INACTIVE);
|
||||
this->displayAdapter->printf("%s.pic2=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_MODE_FAN, drawn_mode == 1 ? LCD_DASHBOARD_PIC_AC_MODE_FAN_ACTIVE_PRESS : LCD_DASHBOARD_PIC_AC_MODE_FAN_INACTIVE_PRESS);
|
||||
this->giveSerialMutex();
|
||||
// Draw the fan speed picture set
|
||||
this->takeSerialMutex();
|
||||
this->displayAdapter->printf("%s.pic=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_FAN_SPEED_AUTO, fan_speed == 0 ? LCD_DASHBOARD_PIC_AC_FAN_SPEED_AUTO_ACTIVE : LCD_DASHBOARD_PIC_AC_FAN_SPEED_AUTO_INACTIVE);
|
||||
this->displayAdapter->printf("%s.pic2=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_FAN_SPEED_AUTO, fan_speed == 0 ? LCD_DASHBOARD_PIC_AC_FAN_SPEED_AUTO_ACTIVE_PRESS : LCD_DASHBOARD_PIC_AC_FAN_SPEED_AUTO_INACTIVE_PRESS);
|
||||
this->displayAdapter->printf("%s.pic=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_FAN_SPEED_LOW, fan_speed == 1 ? LCD_DASHBOARD_PIC_AC_FAN_SPEED_LOW_ACTIVE : LCD_DASHBOARD_PIC_AC_FAN_SPEED_LOW_INACTIVE);
|
||||
this->displayAdapter->printf("%s.pic2=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_FAN_SPEED_LOW, fan_speed == 1 ? LCD_DASHBOARD_PIC_AC_FAN_SPEED_LOW_ACTIVE_PRESS : LCD_DASHBOARD_PIC_AC_FAN_SPEED_LOW_INACTIVE_PRESS);
|
||||
this->displayAdapter->printf("%s.pic=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_FAN_SPEED_MEDIUM, fan_speed == 2 ? LCD_DASHBOARD_PIC_AC_FAN_SPEED_MEDIUM_ACTIVE : LCD_DASHBOARD_PIC_AC_FAN_SPEED_MEDIUM_INACTIVE);
|
||||
this->displayAdapter->printf("%s.pic2=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_FAN_SPEED_MEDIUM, fan_speed == 2 ? LCD_DASHBOARD_PIC_AC_FAN_SPEED_MEDIUM_ACTIVE_PRESS : LCD_DASHBOARD_PIC_AC_FAN_SPEED_MEDIUM_INACTIVE_PRESS);
|
||||
this->displayAdapter->printf("%s.pic=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_FAN_SPEED_HIGH, fan_speed == 3 ? LCD_DASHBOARD_PIC_AC_FAN_SPEED_HIGH_ACTIVE : LCD_DASHBOARD_PIC_AC_FAN_SPEED_HIGH_INACTIVE);
|
||||
this->displayAdapter->printf("%s.pic2=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_FAN_SPEED_HIGH, fan_speed == 3 ? LCD_DASHBOARD_PIC_AC_FAN_SPEED_HIGH_ACTIVE_PRESS : LCD_DASHBOARD_PIC_AC_FAN_SPEED_HIGH_INACTIVE_PRESS);
|
||||
this->giveSerialMutex();
|
||||
// Draw the temperature
|
||||
this->takeSerialMutex();
|
||||
this->displayAdapter->printf("%s.txt=%d", LCD_DASHBOARD_ELEMENT_NAME_AC_TEMPERATURE, temperature);
|
||||
this->giveSerialMutex();
|
||||
|
||||
}
|
||||
|
||||
void CUDDisplay::system_toggle()
|
||||
{
|
||||
// TODO: Implement this
|
||||
}
|
||||
|
||||
|
||||
void CUDDisplay::set_ac_lock(bool state)
|
||||
{
|
||||
this->ac_locked = state;
|
||||
this->refresh_display_ac();
|
||||
}
|
||||
|
||||
bool CUDDisplay::get_ac_lock()
|
||||
{
|
||||
return this->ac_locked;
|
||||
}
|
|
@ -57,6 +57,8 @@ class CUDDisplay : public ESPMegaDisplay
|
|||
void handle_output_change(uint8_t pin, bool state);
|
||||
void handle_aqi_change(char *value);
|
||||
void handle_payload(uint8_t type, uint8_t* payload, uint8_t length);
|
||||
void handle_ac_change(uint8_t mode, uint8_t fan_speed, uint8_t temperature);
|
||||
void handle_ac_sensor(float temperature, float humidity);
|
||||
void handle_touch(uint8_t page_id, uint8_t element_id, uint8_t touch_type);
|
||||
// Change Display Elements
|
||||
void set_display_light_state(uint8_t row, bool state);
|
||||
|
@ -66,6 +68,14 @@ class CUDDisplay : public ESPMegaDisplay
|
|||
void set_display_mosquito_zapper_state(bool state);
|
||||
void set_display_air_purifier_state(bool state);
|
||||
void refresh_display();
|
||||
void refresh_display_ac();
|
||||
// Helper Functions
|
||||
void system_toggle();
|
||||
// AC Functions and Variables
|
||||
void set_ac_lock(bool state);
|
||||
bool get_ac_lock();
|
||||
bool ac_locked;
|
||||
uint8_t previous_mode; // Used to store mode prior to turning off
|
||||
// Local Variables
|
||||
cud_display_conf_t *conf;
|
||||
cud_display_light_group_t light_group;
|
|
@ -168,6 +168,15 @@
|
|||
#define LCD_DASHBOARD_PIC_AC_FAN_SPEED_LOW_INACTIVE 45
|
||||
#define LCD_DASHBOARD_PIC_AC_FAN_SPEED_LOW_INACTIVE_PRESS 44
|
||||
|
||||
#define LCD_DASHBOARD_ELEMENT_AC_TEMPERATURE 19
|
||||
#define LCD_DASHBOARD_ELEMENT_NAME_AC_TEMPERATURE "ac_temp"
|
||||
|
||||
#define LCD_DASHBOARD_ELEMENT_AC_TEMP_UP_BUTTON 20
|
||||
#define LCD_DASHBOARD_ELEMENT_NAME_AC_TEMP_UP_BUTTON "ac_temp_up"
|
||||
|
||||
#define LCD_DASHBOARD_ELEMENT_AC_TEMP_DOWN_BUTTON 21
|
||||
#define LCD_DASHBOARD_ELEMENT_NAME_AC_TEMP_DOWN_BUTTON "ac_temp_down"
|
||||
|
||||
#define LCD_DASHBOARD_ELEMENT_ROOM_TEMPERATURE 19
|
||||
#define LCD_DASHBOARD_ELEMENT_NAME_ROOM_TEMPERATURE "room_temp"
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <RemoteVariable.hpp>
|
||||
#include "lcd_elements.hpp"
|
||||
#include "ir_codes.hpp"
|
||||
#include "cud_display.hpp"
|
||||
#include "display.hpp"
|
||||
|
||||
/***********************************************
|
||||
* Pin Definitions *
|
||||
|
|
Loading…
Reference in New Issue