air conditioner initial support

This commit is contained in:
Siwat Sirichai 2023-12-30 01:08:35 +07:00
parent 011710fe82
commit 5f0dedc7eb
5 changed files with 60 additions and 3 deletions

View File

@ -0,0 +1,56 @@
#pragma once
#include <ExpansionCard.hpp>
#include <IRremote.hpp>
#include <FRAM.h>
#include <vector>
#define CARD_TYPE_CLIMATE 0x03
#define AC_SENSOR_TYPE_NONE 0x00
#define AC_SENSOR_TYPE_DHT22 0x01
#define AC_SENSOR_TYPE_DS18B20 0x02
struct ClimateCardData {
uint8_t ac_temperature;
uint8_t ac_mode;
uint8_t ac_fan_speed;
};
// This requires 3 bytes of FRAM
class ClimateCard : public ExpansionCard {
public:
bool begin(uint16_t *infraredCodes, uint8_t sensor_type, uint8_t sensor_pin);
bool begin(uint16_t *infraredCodes);
void loop();
void bindFRAM(FRAM *fram, uint16_t fram_address);
void setFRAMAutoSave(bool autoSave);
void saveStateToFRAM();
void loadStateFromFRAM();
void setTemperature(uint8_t temperature);
void setMode(uint8_t mode);
void setFanSpeed(uint8_t fan_speed);
void registerCallback(std::function<void(uint8_t, uint8_t, uint8_t)> callback);
uint8_t getType();
private:
// Callbacks
std::vector<std::function<void(uint8_t, uint8_t, uint8_t)>> callbacks;
// Update functions
void updateSensor();
void updateAirConditioner();
void updateAirConditioner(uint8_t mode, uint8_t fan_speed, uint8_t temperature);
// IR variables
IRsend irsender;
uint16_t *infraredCodes;
// Air conditioner variables
int ac_temperature;
int ac_mode;
int ac_fan_speed;
// Sensor variables
uint8_t sensor_type;
uint8_t sensor_pin;
float humidity;
float room_temperature;
// FRAM variables
FRAM *fram;
uint8_t fram_address;
};

View File

@ -1,4 +1,3 @@
#pragma once
#include <DigitalInputCard.hpp>
// Instantiate the card with the specified address

View File

@ -162,7 +162,7 @@ uint32_t ESPMegaDisplay::getNumber(const char* component) {
* @return The value of the string component.
* @note The returned char array must be freed after use.
*/
char* ESPMegaDisplay::getString(const char* component) {
const char* ESPMegaDisplay::getString(const char* component) {
uint32_t start = millis();
// Send the get command
this->displayAdapter->print("get ");

View File

@ -1,3 +1,4 @@
#pragma once
#include <Arduino.h>
#include <ESPMegaPRO_OOP.hpp>
@ -15,7 +16,7 @@ class ESPMegaDisplay
void jumpToPage(int page);
void setString(const char* component, const char* value);
void setNumber(const char* component, int value);
char* getString(const char* component);
const char* getString(const char* component);
bool getStringToBuffer(const char* component, char* buffer, uint8_t buffer_size);
uint32_t getNumber(const char* component);
void handlePwmStateChange(uint8_t pin, uint16_t value);

View File

@ -25,5 +25,6 @@ lib_deps = adafruit/Adafruit PWM Servo Driver Library@^2.4.1
paulstoffregen/DS1307RTC@0.0.0-alpha+sha.c2590c0033
knolleary/pubsubclient@^2.8.0
seithan/Easy Nextion Library@^1.0.6
z3t0/IRremote@^4.2.0
monitor_speed = 115200