ESPMegaPRO-v3-SDK/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateCard.hpp

87 lines
2.5 KiB
C++
Raw Normal View History

2023-12-29 18:08:35 +00:00
#pragma once
#include <ExpansionCard.hpp>
2023-12-30 08:39:16 +00:00
#include <driver/rmt.h>
2023-12-29 18:08:35 +00:00
#include <FRAM.h>
2023-12-30 06:49:37 +00:00
#include <OneWire.h>
#include <DS18B20.h>
#include <dhtnew.h>
2023-12-29 18:08:35 +00:00
#include <vector>
2023-12-30 08:39:16 +00:00
#define RMT_TX_CHANNEL RMT_CHANNEL_0
2023-12-29 18:08:35 +00:00
#define CARD_TYPE_CLIMATE 0x03
#define AC_SENSOR_TYPE_NONE 0x00
#define AC_SENSOR_TYPE_DHT22 0x01
#define AC_SENSOR_TYPE_DS18B20 0x02
2023-12-30 06:49:37 +00:00
#define AC_SENSOR_READ_INTERVAL 5000
#define AC_SENSOR_READ_TIMEOUT 250
2023-12-29 18:08:35 +00:00
struct ClimateCardData {
uint8_t ac_temperature;
uint8_t ac_mode;
uint8_t ac_fan_speed;
};
2023-12-30 06:49:37 +00:00
struct AirConditioner {
uint8_t max_temperature;
uint8_t min_temperature;
uint8_t modes;
char **mode_names;
uint8_t fan_speeds;
char **fan_speed_names;
uint16_t ****infraredCodes;
};
2023-12-29 18:08:35 +00:00
// This requires 3 bytes of FRAM
class ClimateCard : public ExpansionCard {
public:
2023-12-30 06:49:37 +00:00
ClimateCard(uint8_t ir_pin);
~ClimateCard();
bool begin(AirConditioner ac, uint8_t sensor_type, uint8_t sensor_pin);
bool begin(AirConditioner ac);
2023-12-29 18:08:35 +00:00
void loop();
void bindFRAM(FRAM *fram, uint16_t fram_address);
void setFRAMAutoSave(bool autoSave);
void saveStateToFRAM();
void loadStateFromFRAM();
void setTemperature(uint8_t temperature);
2023-12-30 06:49:37 +00:00
uint8_t getTemperature();
2023-12-29 18:08:35 +00:00
void setMode(uint8_t mode);
2023-12-30 06:49:37 +00:00
uint8_t getMode();
2023-12-29 18:08:35 +00:00
void setFanSpeed(uint8_t fan_speed);
2023-12-30 06:49:37 +00:00
uint8_t getFanSpeed();
float getRoomTemperature();
float getHumidity();
2023-12-30 07:32:40 +00:00
uint8_t getSensorType();
void registerChangeCallback(std::function<void(uint8_t, uint8_t, uint8_t)> callback);
void registerSensorCallback(std::function<void(float, float)> callback);
2023-12-29 18:08:35 +00:00
uint8_t getType();
private:
2023-12-30 06:49:37 +00:00
// Sensor objects
// We use pointers here because we don't know which sensor will be used
DHTNEW *dht;
DS18B20 *ds18b20;
2023-12-29 18:08:35 +00:00
// Callbacks
std::vector<std::function<void(uint8_t, uint8_t, uint8_t)>> callbacks;
2023-12-30 07:32:40 +00:00
std::vector<std::function<void(float, float)>> sensor_callbacks;
2023-12-29 18:08:35 +00:00
// Update functions
void updateSensor();
void updateAirConditioner();
// IR variables
2023-12-30 06:49:37 +00:00
uint8_t ir_pin;
2023-12-29 18:08:35 +00:00
// Air conditioner variables
2023-12-30 06:49:37 +00:00
AirConditioner ac;
ClimateCardData state;
2023-12-29 18:08:35 +00:00
// Sensor variables
uint8_t sensor_type;
uint8_t sensor_pin;
float humidity;
float room_temperature;
// FRAM variables
FRAM *fram;
uint8_t fram_address;
2023-12-30 06:49:37 +00:00
bool fram_auto_save;
2023-12-29 18:08:35 +00:00
};