it fucking builds!

This commit is contained in:
reaw55 2024-01-31 00:09:40 +07:00
parent f2c0eb6bf1
commit e5ecd5f3a0
5 changed files with 162 additions and 272 deletions

View file

@ -5,271 +5,106 @@ ISEDisplay::ISEDisplay(HardwareSerial *adapter) : ESPMegaDisplay(adapter)
}
void ISEDisplay::begin(std::function<rtctime_t()> getTime, DigitalInputCard *inputCard,
DigitalOutputCard *outputCard, ClimateCard *climateCard)
void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCard, ClimateCard *climateCard)
{
this->getTime = getTime;
/*
ISEDisplay(HardwareSerial* adapter);
void begin(DigitalInputCard* inputCard, DigitalOutputCard* outputCard, ClimateCard* climateCard);
void updateDateTimeText(rtctime_t time);
void updateWeather(uint8_t weather_code, float outside_temp);
void updatePMoutside(float pm25_outside);
void updatePMinside(float pm25_inside);
private:
void handleTouch(uint8_t page, uint8_t component, uint8_t touch_type);
void handlePWMChange(uint8_t pin, bool state, uint16_t value);
void setPMstate(bool is_pm_on, uint8_t pm_fan_speed);
void setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_temperature);
void setLightLevel(uint8_t row, uint8_t level);
*/
this->inputCard = inputCard;
this->outputCard = outputCard;
this->climateCard = climateCard;
auto bindedHandlePWMChange = std::bind(&ISEDisplay::handlePWMChange, this, std::placeholders::_1, std::placeholders::_2);
auto bindedHandleACChange = std::bind(&ISEDisplay::handleACChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
auto bindedHandlePWMChange = std::bind(&ISEDisplay::handlePWMChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
auto bindedHandleACChange = std::bind(&ISEDisplay::setACstate, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
auto bindedHandleTouch = std::bind(&ISEDisplay::handleTouch, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
auto bindedHandlePayload = std::bind(&ISEDisplay::handlePayload, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
this->outputCallbackHandle = this->outputCard->registerChangeCallback(bindedHandlePWMChange);
this->climateCallbackHandle = this->climateCard->registerChangeCallback(bindedHandleACChange);
this->registerTouchCallback(bindedHandleTouch);
this->registerPayloadCallback(bindedHandlePayload);
this->reset();
delay(1000);
this->jumpToPage(1);
delay(100);
this->sendClock();
this->setACControlEnabled(true);
this->updateLightGroupState();
this->updateFanGroupState();
this->updateAirPurifierState();
this->updateACState();
}
void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t event)
{
if (page != PAGE_DASHBOARD)
return;
switch (component)
{
case COMPONENT_LIGHT_TOGGLE_BUTTON:
if (event != TOUCH_TYPE_RELEASE)
break;
toggleLightGroupState();
break;
case COMPONENT_FAN_TOGGLE_BUTTON:
if (event != TOUCH_TYPE_RELEASE)
break;
toggleFanGroupState();
break;
case COMPONENT_AIR_PURIFIER_TOGGLE_BUTTON:
if (event != TOUCH_TYPE_RELEASE)
break;
this->outputCard->setState(7, !this->outputCard->getState(7));
break;
case COMPONENT_AC_TEMP_UP_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE)
break;
this->climateCard->setTemperature(this->climateCard->getTemperature() + 1);
break;
case COMPONENT_AC_TEMP_DOWN_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE)
break;
this->climateCard->setTemperature(this->climateCard->getTemperature() - 1);
break;
case COMPONENT_AC_MODE_OFF_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE)
break;
this->climateCard->setMode(0);
break;
case COMPONENT_AC_MODE_FAN_ONLY_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE)
break;
this->climateCard->setMode(1);
break;
case COMPONENT_AC_MODE_COOL_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE)
break;
this->climateCard->setMode(2);
break;
case COMPONENT_AC_FAN_MODE_AUTO_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE)
break;
this->climateCard->setFanSpeed(0);
break;
case COMPONENT_AC_FAN_MODE_LOW_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE)
break;
this->climateCard->setFanSpeed(3);
break;
case COMPONENT_AC_FAN_MODE_MEDIUM_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE)
break;
this->climateCard->setFanSpeed(2);
break;
case COMPONENT_AC_FAN_MODE_HIGH_BUTTON:
if (!ac_control_enabled) break;
if (event != TOUCH_TYPE_RELEASE)
break;
this->climateCard->setFanSpeed(1);
break;
default:
break;
}
}
void ISEDisplay::handlePWMChange(uint8_t pin, uint8_t value)
{
// Is the pin a light, fan, or air purifier?
if (pin >= 0 && pin <= 3)
{
// Light
updateLightGroupState();
}
else if (pin >= 4 && pin <= 6)
{
// Fan
updateFanGroupState();
}
else if (pin == 7)
{
// Air Purifier
updateAirPurifierState();
}
}
void ISEDisplay::handleACChange(uint8_t mode, uint8_t fan_speed, uint8_t temperature)
{
// Update AC Controls
updateACState();
}
void ISEDisplay::sendClock()
{
// Get the time
rtctime_t time = this->getTime();
// Send the time to the display
this->displayAdapter->print("clock.txt=");
// We use 24 hour format, HH:MM
this->displayAdapter->print(time.hours);
this->displayAdapter->print(":");
this->displayAdapter->print(time.minutes);
this->sendStopBytes();
}
bool ISEDisplay::calculateLightGroupState() {
// Check if all lights are on
bool lightOn = false;
for (uint8_t i = 0; i < 4; i++) {
if (this->outputCard->getState(i)) {
lightOn = true;
break;
}
}
return lightOn;
}
bool ISEDisplay::calculateFanGroupState() {
// Check if all fans are on
bool fanOn = false;
for (uint8_t i = 4; i < 7; i++) {
if (this->outputCard->getState(i)) {
fanOn = true;
break;
}
}
return fanOn;
}
void ISEDisplay::setLightGrouptState(bool state) {
// Set all lights to state
for (uint8_t i = 0; i < 4; i++) {
this->outputCard->setState(i, state);
}
}
void ISEDisplay::setFanGroupState(bool state) {
// Set all fans to state
for (uint8_t i = 4; i < 7; i++) {
this->outputCard->setState(i, state);
}
}
void ISEDisplay::toggleLightGroupState() {
// Get the current group state
bool state = calculateLightGroupState();
// Toggle the state
state = !state;
// Set the state
setLightGrouptState(state);
}
void ISEDisplay::toggleFanGroupState() {
// Get the current group state
bool state = calculateFanGroupState();
// Toggle the state
state = !state;
// Set the state
setFanGroupState(state);
}
void ISEDisplay::updateLightGroupState() {
// Calculate the state
bool state = calculateLightGroupState();
// Send the state to the display
this->displayAdapter->print("lt_bt.pic=");
this->displayAdapter->print(state ? COMPONENT_LIGHT_TOGGLE_PIC_ON : COMPONENT_LIGHT_TOGGLE_PIC_OFF);
this->sendStopBytes();
}
void ISEDisplay::updateFanGroupState() {
// Calculate the state
bool state = calculateFanGroupState();
// Send the state to the display
this->displayAdapter->print("fan_bt.pic=");
this->displayAdapter->print(state ? COMPONENT_FAN_TOGGLE_PIC_ON : COMPONENT_FAN_TOGGLE_PIC_OFF);
this->sendStopBytes();
}
void ISEDisplay::updateAirPurifierState() {
// Get the state
bool state = this->outputCard->getState(7);
// Send the state to the display
this->displayAdapter->print("puri_bt.pic=");
this->displayAdapter->print(state ? COMPONENT_AIR_PURIFIER_TOGGLE_PIC_ON : COMPONENT_AIR_PURIFIER_TOGGLE_PIC_OFF);
this->sendStopBytes();
}
void ISEDisplay::updateACState() {
// Get the state
uint8_t mode = this->climateCard->getMode();
uint8_t fan_speed = this->climateCard->getFanSpeed();
uint8_t temperature = this->climateCard->getTemperature();
// Send the state to the display
this->displayAdapter->print("mode_off_btn.pic=");
this->displayAdapter->print(mode == 0 ? COMPONENT_AC_MODE_OFF_PIC_ACTIVE : COMPONENT_AC_MODE_OFF_PIC_INACTIVE);
this->sendStopBytes();
this->displayAdapter->print("mode_fan_btn.pic=");
this->displayAdapter->print(mode == 1 ? COMPONENT_AC_MODE_FAN_ONLY_PIC_ACTIVE : COMPONENT_AC_MODE_FAN_ONLY_PIC_INACTIVE);
this->sendStopBytes();
this->displayAdapter->print("mode_cool_btn.pic=");
this->displayAdapter->print(mode == 2 ? COMPONENT_AC_MODE_COOL_PIC_ACTIVE : COMPONENT_AC_MODE_COOL_PIC_INACTIVE);
this->sendStopBytes();
this->displayAdapter->print("fan_auto_btn.pic=");
this->displayAdapter->print(fan_speed == 0 ? COMPONENT_AC_FAN_MODE_AUTO_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_AUTO_PIC_INACTIVE);
this->sendStopBytes();
this->displayAdapter->print("fan_1_btn.pic=");
this->displayAdapter->print(fan_speed == 3 ? COMPONENT_AC_FAN_MODE_HIGH_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_HIGH_PIC_INACTIVE);
this->sendStopBytes();
this->displayAdapter->print("fan_2_btn.pic=");
this->displayAdapter->print(fan_speed == 2 ? COMPONENT_AC_FAN_MODE_MEDIUM_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_MEDIUM_PIC_INACTIVE);
this->sendStopBytes();
this->displayAdapter->print("fan_3_btn.pic=");
this->displayAdapter->print(fan_speed == 1 ? COMPONENT_AC_FAN_MODE_LOW_PIC_ACTIVE : COMPONENT_AC_FAN_MODE_LOW_PIC_INACTIVE);
this->sendStopBytes();
this->displayAdapter->print("temp_txt.txt=\"");
this->displayAdapter->print(temperature);
this->displayAdapter->print("C\"");
this->sendStopBytes();
}
void ISEDisplay::setACControlEnabled(bool enabled) {
ac_control_enabled = enabled;
this->displayAdapter->print("dashboard.pic=");
this->displayAdapter->print(enabled ? COMPONENT_BACKGROUND_AC_UNLOCK : COMPONENT_BACKGROUND_AC_LOCK);
this->sendStopBytes();
}
bool ISEDisplay::getACControlEnabled() {
return ac_control_enabled;
}
void ISEDisplay::handlePayload(uint8_t payload_type, uint8_t *payload, uint8_t length)
{
}
}
void ISEDisplay::updateDateTimeText(rtctime_t time){
this->takeSerialMutex();
// Send the time to the display
this->displayAdapter->printf("time.txt=%02d:%02d", time.hours, time.minutes);
this->sendStopBytes();
this->displayAdapter->printf("date.txt=%02d.%02d.%d", time.day, time.month, time.year);
this->sendStopBytes();
this->displayAdapter->printf("s_time.txt=%02d:%02d", time.hours, time.minutes);
this->sendStopBytes();
this->displayAdapter->printf("s_date.txt=%02d.%02d.%d", time.day, time.month, time.year);
this->sendStopBytes();
this->giveSerialMutex();
}
void ISEDisplay::updateWeather(uint8_t weather_code, float outside_temp){
}
void ISEDisplay::updatePMoutside(float pm25_outside){
}
void ISEDisplay::updatePMinside(float pm25_inside){
}
void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type){
}
void ISEDisplay::handlePWMChange(uint8_t pin, bool state, uint16_t value){
}
void ISEDisplay::setPMstate(bool is_pm_on, uint8_t pm_fan_speed){
}
void ISEDisplay::setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_temperature){
}
void ISEDisplay::setLightLevel(uint8_t row, uint8_t level){
}
void ISEDisplay::updateLightGroupState(){
}
void ISEDisplay::updateAirPurifierState(){
}
void ISEDisplay::updateACState(){
}