diff --git a/src/main.cpp b/src/main.cpp index 226a531..5a91c7a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ /************************************************ * Global Variables * ************************************************/ +RemoteVariable aqi = RemoteVariable(); ESPMegaPRO espmega = ESPMegaPRO(); const char *mode_names[] = AC_MODE_NAMES; const char *fan_speed_names[] = AC_FAN_SPEED_NAMES; @@ -50,8 +51,23 @@ void setup() espmega.iot->connectToMqtt(); // Initialize Internal Display espmega.enableInternalDisplay(&INTERNAL_DISPLAY_UART); - - + // Initialize Air Conditioner + espmega.installCard(2, &ac); + ac.bindFRAM(&espmega.fram, AC_FRAM_ADDR); + espmega.display->bindClimateCard(&ac); // Show our climate card on the display + // Register all cards with iot + espmega.iot->registerCard(0); + espmega.iot->registerCard(1); + espmega.iot->registerCard(2); + // Initialize Remote Variables + aqi.begin(10, AQI_STATE_TOPIC, espmega.iot, true, AQI_REQUEST_TOPIC); + // Input callbacks + // This pre-load the input buffers + // We need to do this to prevent switches that are left on the "on" position from triggering the callback + espmega.inputs.loop(); + espmega.inputs.registerCallback(handle_input_change); + // Start the display routine + // TODO - Write CUDDisplay class } void loop() @@ -64,4 +80,11 @@ void send_stop_bytes(HardwareSerial &uart) uart.write(0xFF); uart.write(0xFF); uart.write(0xFF); +} + +void handle_input_change(uint8_t pin, bool state) { + // When input pin 0 - 6 changes, toggle the corresponding output pin + if (pin >= 0 && pin <= 6) { + espmega.outputs.setState(pin, !espmega.outputs.getState(pin)); + } } \ No newline at end of file diff --git a/src/main.hpp b/src/main.hpp index a141a00..8e06b7b 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -3,6 +3,7 @@ #include #include #include +#include /*********************************************** * Pin Definitions * @@ -54,3 +55,17 @@ #define AC_FRAM_ADDR 5000 // 2 bytes #define AC_LOCK_FRAM_ADDR 5002 // 1 byte #define AC_DISPLAY_MODE_FRAM_ADDR 5003 // 1 byte + +/*********************************************** + * Remote Variables * + ***********************************************/ +#define AQI_STATE_TOPIC "/iqair/usaqi" +#define AQI_REQUEST_TOPIC "/iqair/request" + +/*********************************************** + * Function Prototypes * + ***********************************************/ +void setup(); +void loop(); +void send_stop_bytes(HardwareSerial &uart); +void handle_input_change(uint8_t pin, bool state); \ No newline at end of file