prototype without display

This commit is contained in:
Siwat Sirichai 2024-03-17 15:29:20 +07:00
parent c176a6ce3e
commit 202e49f6cf
2 changed files with 40 additions and 2 deletions

View File

@ -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));
}
}

View File

@ -3,6 +3,7 @@
#include <ir_codes.hpp>
#include <ClimateCard.hpp>
#include <ETH.h>
#include <RemoteVariable.hpp>
/***********************************************
* 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);