refactor for integration of InternalDisplay
This commit is contained in:
parent
d0e4825c2d
commit
c224aba193
|
@ -50,11 +50,12 @@ bool ClimateCard::begin(AirConditioner ac, uint8_t sensor_type, uint8_t sensor_p
|
|||
break;
|
||||
}
|
||||
updateAirConditioner();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ClimateCard::begin(AirConditioner ac)
|
||||
{
|
||||
this->begin(ac, AC_SENSOR_TYPE_NONE, 0);
|
||||
return this->begin(ac, AC_SENSOR_TYPE_NONE, 0);
|
||||
}
|
||||
|
||||
void ClimateCard::loop()
|
||||
|
|
|
@ -26,7 +26,7 @@ void ESPMegaPRO::loop() {
|
|||
cards[i]->loop();
|
||||
}
|
||||
}
|
||||
iot.loop();
|
||||
iot->loop();
|
||||
}
|
||||
bool ESPMegaPRO::installCard(uint8_t slot, ExpansionCard* card) {
|
||||
if (slot > 255) return false;
|
||||
|
@ -88,7 +88,10 @@ void ESPMegaPRO::setTime(int hours, int minutes, int seconds, int day, int month
|
|||
}
|
||||
|
||||
void ESPMegaPRO::enableIotModule() {
|
||||
iot.intr_begin(cards);
|
||||
if (iotEnabled) return;
|
||||
this->iot = new ESPMegaIoT();
|
||||
this->iot->intr_begin(cards);
|
||||
iotEnabled = true;
|
||||
}
|
||||
|
||||
ExpansionCard* ESPMegaPRO::getCard(uint8_t slot) {
|
||||
|
@ -96,3 +99,16 @@ ExpansionCard* ESPMegaPRO::getCard(uint8_t slot) {
|
|||
if (!cardInstalled[slot]) return nullptr;
|
||||
return cards[slot];
|
||||
}
|
||||
|
||||
void ESPMegaPRO::enableInternalDisplay(HardwareSerial *serial) {
|
||||
if (internalDisplayEnabled) return;
|
||||
if (!iotEnabled) {
|
||||
Serial.println("Cannot Enable Internal Display without IoT Module being enabled!");
|
||||
return;
|
||||
}
|
||||
display = new InternalDisplay(serial);
|
||||
auto bindedGetTime = std::bind(&ESPMegaPRO::getTime, this);
|
||||
display->begin(this->iot,bindedGetTime);
|
||||
internalDisplayEnabled = true;
|
||||
|
||||
}
|
|
@ -29,14 +29,18 @@ class ESPMegaPRO {
|
|||
bool installCard(uint8_t slot, ExpansionCard* card);
|
||||
bool updateTimeFromNTP();
|
||||
void enableIotModule();
|
||||
void enableInternalDisplay(HardwareSerial *serial);
|
||||
rtctime_t getTime();
|
||||
void setTime(int hours, int minutes, int seconds, int day, int month, int year);
|
||||
ExpansionCard* getCard(uint8_t slot);
|
||||
FRAM fram;
|
||||
DigitalInputCard inputs = DigitalInputCard(INPUT_BANK_A_ADDRESS, INPUT_BANK_B_ADDRESS);
|
||||
DigitalOutputCard outputs = DigitalOutputCard(PWM_BANK_ADDRESS);
|
||||
ESPMegaIoT iot = ESPMegaIoT();
|
||||
InternalDisplay *display;
|
||||
ESPMegaIoT *iot;
|
||||
private:
|
||||
bool iotEnabled = false;
|
||||
bool internalDisplayEnabled = false;
|
||||
ExpansionCard* cards[255];
|
||||
bool cardInstalled[255];
|
||||
uint8_t cardCount = 0;
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
#include "driver/rmt.h"
|
||||
|
||||
#define RMT_TX_CHANNEL RMT_CHANNEL_0
|
||||
#define RMT_TX_GPIO_NUM GPIO_NUM_4
|
||||
|
||||
void app_main() {
|
||||
// Configure RMT transmitter
|
||||
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(RMT_TX_GPIO_NUM, RMT_TX_CHANNEL);
|
||||
config.clk_div = 80; // Set clock divider for desired frequency (80MHz / 80 = 1MHz)
|
||||
rmt_config(&config);
|
||||
rmt_driver_install(config.channel, 0, 0);
|
||||
|
||||
// Define NEC IR protocol parameters
|
||||
uint16_t irTimingArray[] = { /* Your IR timing array here */ };
|
||||
size_t itemCount = sizeof(irTimingArray) / sizeof(irTimingArray[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 = irTimingArray[i];
|
||||
items[i].level1 = 0;
|
||||
items[i].duration1 = irTimingArray[i];
|
||||
}
|
||||
|
||||
// Send IR signal
|
||||
rmt_write_items(config.channel, items, itemCount, true);
|
||||
rmt_wait_tx_done(config.channel, portMAX_DELAY);
|
||||
|
||||
// Cleanup RMT driver
|
||||
rmt_driver_uninstall(config.channel);
|
||||
}
|
|
@ -16,7 +16,7 @@ void setup() {
|
|||
espmega.begin();
|
||||
espmega.enableIotModule();
|
||||
ETH.begin();
|
||||
espmega.iot.bindEthernetInterface(Ð);
|
||||
espmega.iot->bindEthernetInterface(Ð);
|
||||
NetworkConfig config = {
|
||||
.ip = {192, 168, 0, 11},
|
||||
.gateway = {192, 168, 0, 1},
|
||||
|
@ -31,9 +31,9 @@ void setup() {
|
|||
strcpy(config.password, "password");
|
||||
strcpy(config.hostname, "espmega");
|
||||
Serial.println("Setting network config");
|
||||
espmega.iot.setNetworkConfig(config);
|
||||
espmega.iot->setNetworkConfig(config);
|
||||
Serial.println("Connecting to network");
|
||||
espmega.iot.connectNetwork();
|
||||
espmega.iot->connectNetwork();
|
||||
Serial.println("Begin MQTT Modules");
|
||||
MqttConfig mqtt_config = {
|
||||
.mqtt_port = 1883,
|
||||
|
@ -43,14 +43,15 @@ void setup() {
|
|||
strcpy(mqtt_config.mqtt_server, "192.168.0.26");
|
||||
strcpy(mqtt_config.base_topic, "/espmegaoop");
|
||||
Serial.println("Loading MQTT Config Struct to IoT Module");
|
||||
espmega.iot.setMqttConfig(mqtt_config);
|
||||
espmega.iot->setMqttConfig(mqtt_config);
|
||||
Serial.println("Connecting to MQTT");
|
||||
espmega.iot.connectToMqtt();
|
||||
espmega.iot->connectToMqtt();
|
||||
Serial.println("Registering cards");
|
||||
espmega.iot.registerCard(0);
|
||||
espmega.iot.registerCard(1);
|
||||
espmega.iot->registerCard(0);
|
||||
espmega.iot->registerCard(1);
|
||||
Serial.println("Initialization Routine Complete");
|
||||
espmega.inputs.registerCallback(input_change_callback);
|
||||
espmega.enableInternalDisplay(&Serial);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
|
Loading…
Reference in New Issue