diff --git a/Template Project/lib/ESPMegaPRO/ClimateCard.hpp b/Template Project/lib/ESPMegaPRO/ClimateCard.hpp new file mode 100644 index 0000000..8703d3e --- /dev/null +++ b/Template Project/lib/ESPMegaPRO/ClimateCard.hpp @@ -0,0 +1,56 @@ +#pragma once +#include +#include +#include +#include + +#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 callback); + uint8_t getType(); + private: + // Callbacks + std::vector> 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; +}; diff --git a/Template Project/lib/ESPMegaPRO/DigitalInputCard.cpp b/Template Project/lib/ESPMegaPRO/DigitalInputCard.cpp index d736a41..08b95f9 100644 --- a/Template Project/lib/ESPMegaPRO/DigitalInputCard.cpp +++ b/Template Project/lib/ESPMegaPRO/DigitalInputCard.cpp @@ -1,4 +1,3 @@ -#pragma once #include // Instantiate the card with the specified address diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaDisplay.cpp b/Template Project/lib/ESPMegaPRO/ESPMegaDisplay.cpp index 39d981d..d141ee2 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaDisplay.cpp +++ b/Template Project/lib/ESPMegaPRO/ESPMegaDisplay.cpp @@ -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 "); diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaDisplay.hpp b/Template Project/lib/ESPMegaPRO/ESPMegaDisplay.hpp index d6e025d..2fad560 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaDisplay.hpp +++ b/Template Project/lib/ESPMegaPRO/ESPMegaDisplay.hpp @@ -1,3 +1,4 @@ +#pragma once #include #include @@ -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); diff --git a/Template Project/platformio.ini b/Template Project/platformio.ini index 28345f5..09cdb19 100644 --- a/Template Project/platformio.ini +++ b/Template Project/platformio.ini @@ -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