diff --git a/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateCard.cpp b/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateCard.cpp index e5fc47d..f3fda4e 100644 --- a/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateCard.cpp +++ b/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateCard.cpp @@ -1,8 +1,11 @@ #include -ClimateCard::ClimateCard(uint8_t ir_pin) +ClimateCard::ClimateCard(uint8_t ir_pin, AirConditioner ac, uint8_t sensor_type, uint8_t sensor_pin) { this->ir_pin = ir_pin; + this->ac = ac; + this->sensor_type = sensor_type; + this->sensor_pin = sensor_pin; // Initialize Pointers this->dht = nullptr; this->ds18b20 = nullptr; @@ -21,13 +24,11 @@ ClimateCard::ClimateCard(uint8_t ir_pin) this->state.ac_fan_speed = 0; // Initialize callbacks this->callbacks = std::vector>(); - this->sensor_callbacks = std::vector>(); - // Initialize RMT - gpio_num_t gpio_num = gpio_num_t(ir_pin); - rmt_config_t rmt_tx = RMT_DEFAULT_CONFIG_TX(gpio_num, RMT_TX_CHANNEL); - rmt_tx.clk_div = 80; // 1MHz clock - rmt_config(&rmt_tx); - rmt_driver_install(rmt_tx.channel, 0, 0); +} + +ClimateCard::ClimateCard(uint8_t ir_pin, AirConditioner ac) : ClimateCard(ir_pin, ac, AC_SENSOR_TYPE_NONE, 0) +{ + } ClimateCard::~ClimateCard() @@ -37,11 +38,8 @@ ClimateCard::~ClimateCard() rmt_driver_uninstall(RMT_TX_CHANNEL); } -bool ClimateCard::begin(AirConditioner ac, uint8_t sensor_type, uint8_t sensor_pin) +bool ClimateCard::begin() { - this->ac = ac; - this->sensor_type = sensor_type; - this->sensor_pin = sensor_pin; switch (sensor_type) { case AC_SENSOR_TYPE_DHT22: @@ -54,11 +52,15 @@ bool ClimateCard::begin(AirConditioner ac, uint8_t sensor_type, uint8_t sensor_p } updateAirConditioner(); return true; -} - -bool ClimateCard::begin(AirConditioner ac) -{ - return this->begin(ac, AC_SENSOR_TYPE_NONE, 0); + if (sensor_pin != 0) + { + // Initialize RMT + gpio_num_t gpio_num = gpio_num_t(ir_pin); + rmt_config_t rmt_tx = RMT_DEFAULT_CONFIG_TX(gpio_num, RMT_TX_CHANNEL); + rmt_tx.clk_div = 80; // 1MHz clock + rmt_config(&rmt_tx); + rmt_driver_install(rmt_tx.channel, 0, 0); + } } void ClimateCard::loop() @@ -94,6 +96,11 @@ void ClimateCard::loadStateFromFRAM() void ClimateCard::setTemperature(uint8_t temperature) { + // If temperature is out of range, set to its respective maximum or minimum + if (temperature > ac.max_temperature) + temperature = ac.max_temperature; + else if (temperature < ac.min_temperature) + temperature = ac.min_temperature; this->state.ac_temperature = temperature; updateAirConditioner(); if (fram_auto_save) @@ -161,25 +168,29 @@ void ClimateCard::updateSensor() void ClimateCard::updateAirConditioner() { - size_t itemCount = sizeof(ac.infraredCodes[this->state.ac_mode][this->state.ac_fan_speed][this->state.ac_temperature]) / sizeof(ac.infraredCodes[this->state.ac_mode][this->state.ac_fan_speed][this->state.ac_temperature][0]); - rmt_item32_t items[itemCount]; - // Convert IR timing array to RMT items - for (size_t i = 0; i < itemCount; i++) - { - items[i].level0 = 1; - items[i].duration0 = ac.infraredCodes[this->state.ac_mode][this->state.ac_fan_speed][this->state.ac_temperature][i]; - items[i].level1 = 0; - items[i].duration1 = ac.infraredCodes[this->state.ac_mode][this->state.ac_fan_speed][this->state.ac_temperature][i]; - } - // Send IR signal - rmt_write_items(RMT_TX_CHANNEL, items, itemCount, true); - rmt_wait_tx_done(RMT_TX_CHANNEL, portMAX_DELAY); - // Publish state - for (uint8_t i = 0; i < callbacks.size(); i++) - { - callbacks[i](this->state.ac_mode, this->state.ac_fan_speed, this->state.ac_temperature); - } + // const uint16_t* ir_code_ptr = nullptr; + // size_t itemCount = (*(this->ac.getInfraredCode))(this->state.ac_mode, this->state.ac_fan_speed, this->state.ac_temperature, &ir_code_ptr); + + // if (ir_code_ptr == nullptr) + // return; + // rmt_item32_t items[itemCount]; + // // Convert IR timing array to RMT items + // for (size_t i = 0; i < itemCount; i+=2) + // { + // items[i].level0 = 1; + // items[i].duration0 = ir_code_ptr[i]; + // items[i].level1 = 0; + // items[i].duration1 = ir_code_ptr[i+1]; + // } + // // Send IR signal + // rmt_write_items(RMT_TX_CHANNEL, items, itemCount, true); + // rmt_wait_tx_done(RMT_TX_CHANNEL, portMAX_DELAY); + // // Publish state + // for (uint8_t i = 0; i < callbacks.size(); i++) + // { + // callbacks[i](this->state.ac_mode, this->state.ac_fan_speed, this->state.ac_temperature); + // } } uint8_t ClimateCard::getSensorType() @@ -215,4 +226,5 @@ uint8_t ClimateCard::getFanSpeed() void ClimateCard::registerSensorCallback(std::function callback) { sensor_callbacks.push_back(callback); -} \ No newline at end of file +} + diff --git a/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateCard.hpp b/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateCard.hpp index 45fd00a..5364e93 100644 --- a/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateCard.hpp +++ b/ESPMegaPRO-firmware/lib/ESPMegaPRO/ClimateCard.hpp @@ -28,19 +28,22 @@ struct AirConditioner { uint8_t max_temperature; uint8_t min_temperature; uint8_t modes; - char **mode_names; + const char **mode_names; uint8_t fan_speeds; - char **fan_speed_names; - uint16_t ****infraredCodes; + const char **fan_speed_names; + // function to get IR code + // takes 3 arguments: mode, fan speed, temperature, all uint8_t + // return size of IR code array + size_t (*getInfraredCode)(uint8_t, uint8_t, uint8_t, const uint16_t**); }; // This requires 3 bytes of FRAM class ClimateCard : public ExpansionCard { public: - ClimateCard(uint8_t ir_pin); + ClimateCard(uint8_t ir_pin, AirConditioner ac, uint8_t sensor_type, uint8_t sensor_pin); + ClimateCard(uint8_t ir_pin, AirConditioner ac); ~ClimateCard(); - bool begin(AirConditioner ac, uint8_t sensor_type, uint8_t sensor_pin); - bool begin(AirConditioner ac); + bool begin(); void loop(); void bindFRAM(FRAM *fram, uint16_t fram_address); void setFRAMAutoSave(bool autoSave); @@ -83,4 +86,5 @@ class ClimateCard : public ExpansionCard { FRAM *fram; uint8_t fram_address; bool fram_auto_save; + uint16_t* getIrIndex(uint8_t mode, uint8_t fan_speed, uint8_t temperature); }; diff --git a/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp b/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp index cdbc3d1..80f6234 100644 --- a/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp +++ b/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.cpp @@ -121,6 +121,10 @@ void InternalDisplay::refreshPage(uint8_t page) { this->refreshOutput(); break; case INTERNAL_DISPLAY_AC_PAGE: + if (this->climateCard == nullptr) { + this->jumpToPage(INTERNAL_DISPLAY_CLIMATE_NULL_PTR_PAGE); + break; + } this->refreshAC(); break; case INTERNAL_DISPLAY_PWM_ADJUSTMENT_PAGE: @@ -145,8 +149,6 @@ void InternalDisplay::refreshDashboard() { // Send the MQTT server and port this->displayAdapter->print("server_address.txt=\""); this->displayAdapter->print(this->mqttConfig->mqtt_server); - this->displayAdapter->print(":"); - this->displayAdapter->print(this->mqttConfig->mqtt_port); this->displayAdapter->print("\""); this->sendStopBytes(); // Send the MQTT connection status @@ -167,7 +169,52 @@ void InternalDisplay::refreshOutput() { } void InternalDisplay::refreshAC() { - // TODO: implementation + this->displayAdapter->print("temp.txt=\""); + this->displayAdapter->print(this->climateCard->getTemperature()); + this->displayAdapter->print(" C\""); + this->sendStopBytes(); + this->displayAdapter->print("fan_auto.pic="); + this->displayAdapter->print(this->climateCard->getFanSpeed() == AC_FAN_SPEED_AUTO ? PIC_AC_FAN_SPEED_AUTO_ACTIVE : PIC_AC_FAN_SPEED_AUTO_INACTIVE); + this->sendStopBytes(); + this->displayAdapter->print("fan_low.pic="); + this->displayAdapter->print(this->climateCard->getFanSpeed() == AC_FAN_SPEED_LOW ? PIC_AC_FAN_SPEED_LOW_ACTIVE : PIC_AC_FAN_SPEED_LOW_INACTIVE); + this->sendStopBytes(); + this->displayAdapter->print("fan_med.pic="); + this->displayAdapter->print(this->climateCard->getFanSpeed() == AC_FAN_SPEED_MEDIUM ? PIC_AC_FAN_SPEED_MEDIUM_ACTIVE : PIC_AC_FAN_SPEED_MEDIUM_INACTIVE); + this->sendStopBytes(); + this->displayAdapter->print("fan_high.pic="); + this->displayAdapter->print(this->climateCard->getFanSpeed() == AC_FAN_SPEED_HIGH ? PIC_AC_FAN_SPEED_HIGH_ACTIVE : PIC_AC_FAN_SPEED_HIGH_INACTIVE); + this->sendStopBytes(); + this->displayAdapter->print("mode_off.pic="); + this->displayAdapter->print(this->climateCard->getMode() == AC_MODE_OFF ? PIC_AC_MODE_OFF_ACTIVE : PIC_AC_MODE_OFF_INACTIVE); + this->sendStopBytes(); + this->displayAdapter->print("mode_fan.pic="); + this->displayAdapter->print(this->climateCard->getMode() == AC_MODE_FAN_ONLY ? PIC_AC_MODE_FAN_ACTIVE : PIC_AC_MODE_FAN_INACTIVE); + this->sendStopBytes(); + this->displayAdapter->print("mode_cool.pic="); + this->displayAdapter->print(this->climateCard->getMode() == AC_MODE_COOL ? PIC_AC_MODE_COOL_ACTIVE : PIC_AC_MODE_COOL_INACTIVE); + this->sendStopBytes(); + if (this->climateCard->getSensorType() == AC_SENSOR_TYPE_DHT22) { + this->displayAdapter->print("roomtemp.txt=\""); + this->displayAdapter->print(this->climateCard->getRoomTemperature()); + this->displayAdapter->print("C\""); + this->sendStopBytes(); + this->displayAdapter->print("roomhumid.txt=\""); + this->displayAdapter->print(this->climateCard->getHumidity()); + this->displayAdapter->print("%\""); + this->sendStopBytes(); + } + else if(this->climateCard->getSensorType() == AC_SENSOR_TYPE_DS18B20) { + this->displayAdapter->print("roomtemp.txt=\""); + this->displayAdapter->print(this->climateCard->getRoomTemperature()); + this->displayAdapter->print("C\""); + this->sendStopBytes(); + this->setString("roomhumid.txt", "N/A"); + } + else { + this->setString("roomtemp.txt", "N/A"); + this->setString("roomhumid.txt", "N/A"); + } } void InternalDisplay::setPWMAdjustmentSlider(uint16_t value) { @@ -225,6 +272,9 @@ void InternalDisplay::bindOutputCard(DigitalOutputCard *outputCard) { this->outputCard = outputCard; } +// This assume that your ClimeateCard has the mode and fan speed names in the following order: +// mode: [off, fan_only, cool] +// fan_speed: [auto, low, medium, high] void InternalDisplay::bindClimateCard(ClimateCard *climateCard) { this->climateCard = climateCard; } @@ -281,7 +331,64 @@ void InternalDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t type) } void InternalDisplay::handleACTouch(uint8_t type, uint8_t component) { + // b1 [component 18] -> inclement AC temperature by 1 + // b0 [component 17] -> declement AC temperature by 1 + // fan_auto [component 4] -> set the fan speed to auto + // fan_low [component 5] -> set the fan speed to low + // fan_med [component 6] -> set the fan speed to medium + // fan_high [component 7] -> set the fan speed to high + // mode_off [component 10] -> set the mode to off + // mode_fan [component 9] -> set the mode to fan only + // mode_cool [component 8] -> set the mode to cool + // For b0 and b1, if the type is not release then return + // For other components, if the type is not press then return + if ((component == 17 || component == 18) && type != TOUCH_TYPE_RELEASE) return; + if ((component != 17 && component != 18) && type != TOUCH_TYPE_PRESS) return; + + // Switch based on the component + switch (component) { + case 17: + // Decrement the temperature + this->climateCard->setTemperature(this->climateCard->getTemperature() - 1); + break; + case 18: + // Increment the temperature + this->climateCard->setTemperature(this->climateCard->getTemperature() + 1); + break; + case 4: + // Set the fan speed to auto + this->climateCard->setFanSpeed(AC_FAN_SPEED_AUTO); + break; + case 5: + // Set the fan speed to low + this->climateCard->setFanSpeed(AC_FAN_SPEED_LOW); + break; + case 6: + // Set the fan speed to medium + this->climateCard->setFanSpeed(AC_FAN_SPEED_MEDIUM); + break; + case 7: + // Set the fan speed to high + this->climateCard->setFanSpeed(AC_FAN_SPEED_HIGH); + break; + case 10: + // Set the mode to off + this->climateCard->setMode(AC_MODE_OFF); + break; + case 9: + // Set the mode to fan only + this->climateCard->setMode(AC_MODE_FAN_ONLY); + break; + case 8: + // Set the mode to cool + this->climateCard->setMode(AC_MODE_COOL); + break; + default: + break; + } + // Refresh the AC page + this->refreshAC(); } void InternalDisplay::handlePWMAdjustmentTouch(uint8_t type, uint8_t component) { diff --git a/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.hpp b/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.hpp index 5640ed2..4a0051b 100644 --- a/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.hpp +++ b/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.hpp @@ -27,6 +27,29 @@ #define PIC_MQTT_CONNECTED 5 #define PIC_PWM_BAR_ON 33 #define PIC_PWM_BAR_OFF 48 +#define PIC_AC_MODE_OFF_ACTIVE 24 +#define PIC_AC_MODE_OFF_INACTIVE 25 +#define PIC_AC_MODE_FAN_ACTIVE 22 +#define PIC_AC_MODE_FAN_INACTIVE 23 +#define PIC_AC_MODE_COOL_ACTIVE 12 +#define PIC_AC_MODE_COOL_INACTIVE 13 +#define PIC_AC_FAN_SPEED_AUTO_ACTIVE 14 +#define PIC_AC_FAN_SPEED_AUTO_INACTIVE 15 +#define PIC_AC_FAN_SPEED_LOW_ACTIVE 18 +#define PIC_AC_FAN_SPEED_LOW_INACTIVE 19 +#define PIC_AC_FAN_SPEED_MEDIUM_ACTIVE 20 +#define PIC_AC_FAN_SPEED_MEDIUM_INACTIVE 21 +#define PIC_AC_FAN_SPEED_HIGH_ACTIVE 16 +#define PIC_AC_FAN_SPEED_HIGH_INACTIVE 17 + +// AC Fan Speeds and Mode Position Assumptions +#define AC_FAN_SPEED_AUTO 0 +#define AC_FAN_SPEED_LOW 1 +#define AC_FAN_SPEED_MEDIUM 2 +#define AC_FAN_SPEED_HIGH 3 +#define AC_MODE_OFF 0 +#define AC_MODE_FAN_ONLY 1 +#define AC_MODE_COOL 2 // Messages #define MSG_MQTT_CONNECTED "BMS Managed" diff --git a/ESPMegaPRO-firmware/src/analogdemo.cpp.disabled b/ESPMegaPRO-firmware/src/analogdemo.cpp.disabled deleted file mode 100644 index 7627678..0000000 --- a/ESPMegaPRO-firmware/src/analogdemo.cpp.disabled +++ /dev/null @@ -1,22 +0,0 @@ -#include -#define ADC - -void setup() -{ - Serial.begin(115200); - ESPMega_begin(); -} - -void loop() -{ - #ifdef DAC - for(int i=0;i<4096;i++) { - ESPMega_dacWrite(0,i); - double dac_val_sine = 2047.5*sin(i*2*PI/2047.5)+2047.5; - ESPMega_dacWrite(1,(int)dac_val_sine); - } - #endif - #ifdef ADC - Serial.printf("A0: %d",ESPMega_analogRead(0)); - #endif -} \ No newline at end of file diff --git a/ESPMegaPRO-firmware/src/cardsdemo.cpp.disabled b/ESPMegaPRO-firmware/src/cardsdemo.cpp.disabled deleted file mode 100644 index 6f95020..0000000 --- a/ESPMegaPRO-firmware/src/cardsdemo.cpp.disabled +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include - -// This code demonstrates how to use the cards - -ESPMegaPRO espmega = ESPMegaPRO(); -AnalogCard analogCard = AnalogCard(); - -void inputCallback(uint8_t pin, bool state) -{ - Serial.print("Input "); - Serial.print(pin); - Serial.print(" changed to "); - Serial.println(state); -} - -void printInputs() -{ - for (int i = 0; i < 16; i++) - { - Serial.print("Input "); - Serial.print(i); - Serial.print(": "); - Serial.print(espmega.inputs.digitalRead(i)); - Serial.println(); - } -} - -void setup() -{ - // Instantiate ESPMega - espmega.begin(); - Serial.println("ESPMega initialized"); - // Read all the inputs and print them - printInputs(); - // Turn on all the outputs - for (int i = 0; i < 16; i++) - { - espmega.outputs.digitalWrite(i, true); - } - // Set the debounce time for all inputs to 200ms - for (int i = 0; i < 16; i++) - { - espmega.inputs.setDebounceTime(i, 200); - } - // Register the callback function - espmega.inputs.registerCallback(inputCallback); - - // Install the analog card - Serial.println("Installing analog card"); - if (espmega.installCard(0, &analogCard)) - { - Serial.println("Analog card installed"); - } - else - { - Serial.println("Failed to install analog card"); - } -} - -unsigned long previousMillis = 0; -const unsigned long interval = 1000; // 1 second - -void loop() -{ - unsigned long currentMillis = millis(); - - if (currentMillis - previousMillis >= interval) - { - previousMillis = currentMillis; - printInputs(); - } - espmega.loop(); -} \ No newline at end of file diff --git a/ESPMegaPRO-firmware/src/fram_demo.cpp.disabled b/ESPMegaPRO-firmware/src/fram_demo.cpp.disabled deleted file mode 100644 index bd77c2b..0000000 --- a/ESPMegaPRO-firmware/src/fram_demo.cpp.disabled +++ /dev/null @@ -1,37 +0,0 @@ -#include -void setup() -{ - ESPMega_begin(); - Serial.begin(115200); - uint8_t a = 35; - uint8_t b = 42; - uint8_t c = 66; - uint8_t d = 251; - - // ESPMega_FRAM.write8(0,a); - // ESPMega_FRAM.write8(1,b); - // ESPMega_FRAM.write8(2,c); - // ESPMega_FRAM.write8(3,d); - - uint8_t e = ESPMega_FRAM.read8(0); - uint8_t f = ESPMega_FRAM.read8(1); - uint8_t g = ESPMega_FRAM.read8(2); - uint8_t h = ESPMega_FRAM.read8(3); - Serial.println(e); - Serial.println(f); - Serial.println(g); - Serial.println(h); - char ll[2000] = "Everyone has a dream they strive to achieve, and so does the musically talented Kanon Shibuya. However, due to her stage fright, Kanon fails to make it into Yuigaoka Girls' High School's music program and instead ends up in the general curriculum. Even though Kanon makes the conscious decision to quit music altogether, her classmate Tang Keke rekindles Kanon's passion for music with her own: a passion for school idols."; - - // ESPMega_FRAM.write(4,(uint8_t*)ll,2000); - - char llr[2000]; - ESPMega_FRAM.read(4,(uint8_t*)llr,2000); - Serial.println(llr); - - -} - -void loop() -{ -} \ No newline at end of file diff --git a/ESPMegaPRO-firmware/src/input_demo.cpp.disabled b/ESPMegaPRO-firmware/src/input_demo.cpp.disabled deleted file mode 100644 index e1a6995..0000000 --- a/ESPMegaPRO-firmware/src/input_demo.cpp.disabled +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -PCF8574 inputbank1(0x21); - -void setup() { - Wire.begin(14,33); - Serial.begin(9600); - boolean connected = inputbank1.begin(); - Serial.println("connection state = "+String(connected)); - inputbank1.write(0, HIGH); - delay(50); - inputbank1.write(1, HIGH); - delay(50); -} - -void loop() { - for(int i=2;i<8;i++) { - Serial.println(inputbank1.read(i)); - delay(100); - } -} \ No newline at end of file diff --git a/ESPMegaPRO-firmware/src/input_test.cpp.disabled b/ESPMegaPRO-firmware/src/input_test.cpp.disabled deleted file mode 100644 index c2e2915..0000000 --- a/ESPMegaPRO-firmware/src/input_test.cpp.disabled +++ /dev/null @@ -1,17 +0,0 @@ -#include "ESPMegaPRO.h" - -void setup() { - ESPMega_begin(); - Serial.begin(115200); -} - -void loop() { - if(ESPMega_digitalRead(11)) { - ESPMega_digitalWrite(8, HIGH); - Serial.println("11HIGH"); - } else { - ESPMega_digitalWrite(8, LOW); - Serial.println("11LOW"); - } - ESPMega_loop(); -} \ No newline at end of file diff --git a/ESPMegaPRO-firmware/src/iotdemo.cpp.disabled b/ESPMegaPRO-firmware/src/iotdemo.cpp.disabled deleted file mode 100644 index d2846a0..0000000 --- a/ESPMegaPRO-firmware/src/iotdemo.cpp.disabled +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -// Instantiate ESPMega -ESPMegaPRO espmega = ESPMegaPRO(); - -void mqtt_callback(char *topic, char *payload) -{ - Serial.print("MQTT Callback: "); - Serial.print(topic); - Serial.print(" "); - Serial.println(payload); -} - -IPAddress ip(192, 168, 0, 11); -IPAddress gateway(192, 168, 0, 1); -IPAddress subnet(255, 255, 255, 0); - -void setup() -{ - // Initialize ESPMega - espmega.begin(); - espmega.enableIotModule(); - ETH.begin(); - ETH.config(ip, gateway, subnet); - espmega.iot.setBaseTopic("/testmegaoop"); - espmega.iot.connectToMqtt("espmega", "192.168.0.26", 1883); - espmega.iot.publishRelative("test", "test"); - espmega.iot.subscribeRelative("test"); - espmega.iot.registerMqttCallback(mqtt_callback); - espmega.iot.registerCard(1); - espmega.iot.publishCard(1); -} - -void loop() -{ - // Call ESPMega loop - espmega.loop(); -} \ No newline at end of file diff --git a/ESPMegaPRO-firmware/src/iot_framdemo.cpp b/ESPMegaPRO-firmware/src/main.cpp similarity index 75% rename from ESPMegaPRO-firmware/src/iot_framdemo.cpp rename to ESPMegaPRO-firmware/src/main.cpp index f2e8c43..43dd917 100644 --- a/ESPMegaPRO-firmware/src/iot_framdemo.cpp +++ b/ESPMegaPRO-firmware/src/main.cpp @@ -8,6 +8,25 @@ // Demo PLC firmware using the ESPMegaPRO OOP library ESPMegaPRO espmega = ESPMegaPRO(); +const uint16_t irCode[15][4][4][1] = {0}; +const char* mode_names[] = {"Off", "Fan-only", "Cool"}; +const char* fan_speed_names[] = {"Auto", "Low", "Medium", "High"}; + +size_t getInfraredCode(uint8_t mode, uint8_t fan_speed, uint8_t temperature, const uint16_t** codePtr) { + // Change the code pointer to point to the IR timing array + *codePtr = &(irCode[mode][fan_speed][temperature][0]); + return sizeof(irCode[mode][fan_speed][temperature]) / sizeof(uint16_t); +} +AirConditioner ac = { + .max_temperature = 30, + .min_temperature = 16, + .modes = 4, + .mode_names = mode_names, + .fan_speeds = 4, + .fan_speed_names = fan_speed_names, + .getInfraredCode = &getInfraredCode +}; +ClimateCard climateCard = ClimateCard(14, ac); void input_change_callback(uint8_t pin, uint8_t value) { Serial.print("Input change callback: "); @@ -68,8 +87,11 @@ void setup() { espmega.iot->registerCard(1); Serial.println("Registering Input Change Callback"); espmega.inputs.registerCallback(input_change_callback); + Serial.println("Installing Climate Card"); + espmega.installCard(2, &climateCard); Serial.println("Enabling Internal Display"); espmega.enableInternalDisplay(&Serial); + espmega.display->bindClimateCard(&climateCard); Serial.println("Initialization Routine Complete"); } diff --git a/ESPMegaPRO-firmware/src/ntupload.cpp.disabled b/ESPMegaPRO-firmware/src/ntupload.cpp.disabled deleted file mode 100644 index 118262a..0000000 --- a/ESPMegaPRO-firmware/src/ntupload.cpp.disabled +++ /dev/null @@ -1,27 +0,0 @@ -#include - -void lcd_send_stop_bit(); - -void setup() { - Serial.begin(115200); - lcd_send_stop_bit(); - Serial.print("rest"); - lcd_send_stop_bit(); - Serial.print("connect"); - lcd_send_stop_bit(); - delay(1000); - Serial.print("whmi-wri 1024,115200,res0"); - lcd_send_stop_bit(); -} - -void loop() { - while(Serial.available()) { - Serial.write(Serial.read()); - } -} - -void lcd_send_stop_bit() { - Serial.write(0xFF); - Serial.write(0xFF); - Serial.write(0xFF); -} \ No newline at end of file diff --git a/ESPMegaPRO-firmware/src/pwm_demo.cpp.disabled b/ESPMegaPRO-firmware/src/pwm_demo.cpp.disabled deleted file mode 100644 index e4b2891..0000000 --- a/ESPMegaPRO-firmware/src/pwm_demo.cpp.disabled +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include "Wire.h" -#include - -Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x5F); - -void setup() { - Wire.begin(14,33); - pwm.begin(); - pwm.setPin(2, 500); - pwm.setPin(3, 1000); - pwm.setPin(4, 1500); - pwm.setPin(5, 2000); - pwm.setPin(6, 2500); - pwm.setPin(7, 3000); - pwm.setPin(8, 3500); - pwm.setPin(9, 4000); - pwm.setPin(10, 500); - pwm.setPin(11, 1000); - pwm.setPin(12, 1500); - pwm.setPin(13, 2000); - pwm.setPin(14, 2500); - pwm.setPin(15, 3000); - -} - - void loop() { -} \ No newline at end of file diff --git a/ESPMegaPRO-firmware/src/rtc_demo.cpp.disabled b/ESPMegaPRO-firmware/src/rtc_demo.cpp.disabled deleted file mode 100644 index 9e8990e..0000000 --- a/ESPMegaPRO-firmware/src/rtc_demo.cpp.disabled +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include - -uint8_t utc_offset = 7; - -IPAddress IP(192, 168, 0, 241); -IPAddress SUBNET(255, 255, 255, 0); -IPAddress GATEWAY(192, 168, 0, 1); -IPAddress DNS(10, 192, 1, 1); - -void setup() -{ - ESPMega_begin(); - Serial.begin(115200); - ETH.begin(); - ETH.config(IP, GATEWAY, SUBNET, DNS, DNS); - delay(5000); - char ntp[19]; - DNS.toString().toCharArray(ntp, 19); - ESPMega_configNTP(utc_offset * 3600, 0, ntp); - ESPMega_updateTimeFromNTP(); - //ESPMega_setTime(0,10,52,9,11,2008); -} - -void loop() -{ - rtctime_t time = ESPMega_getTime(); - Serial.printf("RTC: %02d:%02d:%02d %02d/%02d/%04d\n", time.hours, time.minutes, time.seconds, time.day, time.month, time.year); - delay(1000); -} \ No newline at end of file