Merge branch 'main' into iot-ay2023
This commit is contained in:
commit
f02629be1b
|
@ -2,7 +2,10 @@
|
|||
|
||||
// OS Configuration
|
||||
// #define FASTBOOT
|
||||
|
||||
#ifndef ESPMEGA_REV
|
||||
#define ESPMEGA_REV "ESPMega PRO R3.3b"
|
||||
#endif
|
||||
|
||||
// Network Connectivity
|
||||
char HOSTNAME[15];
|
||||
|
@ -12,7 +15,9 @@ IPAddress GATEWAY(0, 0, 0, 0);
|
|||
IPAddress DNS(0, 0, 0, 0);
|
||||
IPAddress MQTT_SERVER(0, 0, 0, 0);
|
||||
uint16_t MQTT_PORT = 0;
|
||||
#ifdef ENABLE_WEBUI
|
||||
WebServer otaserver(80);
|
||||
#endif
|
||||
bool standalone = true;
|
||||
// #define MQTT_BASE_TOPIC "/espmega/ProR3"
|
||||
char MQTT_BASE_TOPIC[20];
|
||||
|
@ -22,8 +27,10 @@ bool MQTT_USE_AUTH = false;
|
|||
char MQTT_USERNAME[32];
|
||||
char MQTT_PASSWORD[32];
|
||||
uint8_t utc_offset = 7;
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
float current_room_temp = 0;
|
||||
float current_room_humid = 0;
|
||||
#endif
|
||||
|
||||
// Inputs
|
||||
#define VINT_COUNT 16
|
||||
|
@ -47,16 +54,19 @@ const int PWM_CYCLE_VALUES[PWM_CYCLE_VALUES_COUNT] = {50, 125, 255};
|
|||
char PWM_SET_STATE_TOPIC[70];
|
||||
char PWM_SET_VALUE_TOPIC[70];
|
||||
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
// LCD
|
||||
int lcd_current_page = 1;
|
||||
int lcd_pwmAdj_id = 0;
|
||||
EasyNex panel(Serial);
|
||||
#endif
|
||||
|
||||
// Air Conditioner Control
|
||||
/*
|
||||
Mode 0: Off, 1: Cool, 2: Fan
|
||||
Fan Speed 0: Auto, 1: High, 2: Mid, 3: Low
|
||||
*/
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
#define DHT22_PIN 32
|
||||
uint8_t ac_mode = 0;
|
||||
uint8_t ac_fan_speed = 0;
|
||||
|
@ -69,6 +79,7 @@ char AC_FAN_TOPIC[75];
|
|||
char AC_TEMPERATURE_TOPIC[75];
|
||||
char AC_ROOM_TEMPERATURE_TOPIC[75];
|
||||
char AC_HUMIDITY_TOPIC[75];
|
||||
#endif
|
||||
|
||||
// EEPROM ADDRESS
|
||||
#define EEPROM_ADDRESS_AC_MODE 0 // 01bytes
|
||||
|
@ -96,7 +107,9 @@ WiFiClient eth;
|
|||
PubSubClient mqtt_client(MQTT_SERVER, 1883, eth);
|
||||
PubSubClientTools mqtt(mqtt_client);
|
||||
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
DHTNEW env_sensor(DHT22_PIN);
|
||||
#endif
|
||||
|
||||
Thread mqtt_reconnector = Thread();
|
||||
Thread environment_reporter = Thread();
|
||||
|
@ -104,9 +117,11 @@ Thread eeprom_pwm_updater = Thread();
|
|||
Thread user_timer_tick = Thread();
|
||||
StaticThreadController<4> thread_controller(&mqtt_reconnector, &environment_reporter, &eeprom_pwm_updater, &user_timer_tick);
|
||||
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
Thread top_bar_updater = Thread();
|
||||
Thread page_updater = Thread();
|
||||
StaticThreadController<2> lcd_thread_controller(&top_bar_updater, &page_updater);
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
@ -114,15 +129,19 @@ void setup()
|
|||
#ifdef ENABLE_EXTERNAL_LCD
|
||||
Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
|
||||
#endif
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
panel.begin(115200);
|
||||
#endif
|
||||
Serial.println("ESPMega R3 Initializing");
|
||||
ESPMega_begin();
|
||||
io_begin();
|
||||
eeprom_retrieve_init();
|
||||
user_pre_init();
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
lcd_send_stop_bit();
|
||||
lcd_init();
|
||||
lcd_begin();
|
||||
#endif
|
||||
check_boot_reset();
|
||||
#ifdef ENABLE_EXTERNAL_LCD
|
||||
Serial2.print("rest");
|
||||
|
@ -132,9 +151,11 @@ void setup()
|
|||
#endif
|
||||
lcd_send_command("boot_state.txt=\"Core Initializing . . .\"");
|
||||
Serial.println("Initializing Infrared . . .");
|
||||
#ifdef ENABLE_IR_MODULE
|
||||
lcd_send_command("boot_state.txt=\"Infrared Initializing . . .\"");
|
||||
IrReceiver.begin(IR_RECIEVE_PIN);
|
||||
IrSender.begin(IR_SEND_PIN);
|
||||
#endif
|
||||
lcd_send_command("boot_state.txt=\"Network Initializing . . .\"");
|
||||
network_begin();
|
||||
lcd_send_command("boot_state.txt=\"IoT Core Initializing . . .\"");
|
||||
|
@ -143,7 +164,9 @@ void setup()
|
|||
mqtt_connect();
|
||||
lcd_send_command("boot_state.txt=\"Threads Initializing . . .\"");
|
||||
thread_initialization();
|
||||
#ifdef ENABLE_WEBUI
|
||||
ota_begin();
|
||||
#endif
|
||||
Serial.println("Initialization Completed.");
|
||||
Serial.println("Jumping to User Code.");
|
||||
user_init();
|
||||
|
@ -155,20 +178,29 @@ void loop()
|
|||
virtual_interrupt_loop();
|
||||
mqtt_client.loop();
|
||||
ESPMega_loop();
|
||||
#ifdef ENABLE_IR_MODULE
|
||||
ir_loop();
|
||||
#endif
|
||||
thread_controller.run();
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
lcd_loop();
|
||||
#endif
|
||||
user_loop();
|
||||
#ifdef ENABLE_WEBUI
|
||||
otaserver.handleClient();
|
||||
#endif
|
||||
}
|
||||
|
||||
void eeprom_retrieve_init()
|
||||
{
|
||||
// EEPROM Data Retrival
|
||||
// EEPROM Data Retrival
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
ac_mode = ESPMega_FRAM.read8(EEPROM_ADDRESS_AC_MODE);
|
||||
ac_temperature = ESPMega_FRAM.read8(EEPROM_ADDRESS_AC_TEMPERATURE);
|
||||
ac_fan_speed = ESPMega_FRAM.read8(EEPROM_ADDRESS_AC_FAN_SPEED);
|
||||
// EEPROM Data Retrival Validation
|
||||
#endif
|
||||
// EEPROM Data Retrival Validation
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
if (ac_mode > 2)
|
||||
{
|
||||
ac_mode = 0;
|
||||
|
@ -185,6 +217,7 @@ void eeprom_retrieve_init()
|
|||
ESPMega_FRAM.write8(EEPROM_ADDRESS_AC_TEMPERATURE, ac_fan_speed);
|
||||
}
|
||||
ac_set_state(ac_mode, ac_temperature, ac_fan_speed);
|
||||
#endif
|
||||
ESPMega_FRAM.read(EEPROM_ADDRESS_PWM_STATE, pwm_states_eeprom, 16);
|
||||
memcpy(pwm_states, pwm_states_eeprom, 16);
|
||||
ESPMega_FRAM.read(EEPROM_ADDRESS_PWM_VALUE, pwm_values_eeprom, 32);
|
||||
|
@ -219,6 +252,7 @@ void eeprom_retrieve_init()
|
|||
strcat(PWM_SET_STATE_TOPIC, "/pwm/00/set/state");
|
||||
memcpy(PWM_SET_VALUE_TOPIC, MQTT_BASE_TOPIC, 20);
|
||||
strcat(PWM_SET_VALUE_TOPIC, "/pwm/00/set/value");
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
memcpy(AC_SET_MODE_TOPIC, MQTT_BASE_TOPIC, 20);
|
||||
strcat(AC_SET_MODE_TOPIC, "/ac/set/mode");
|
||||
memcpy(AC_SET_FAN_TOPIC, MQTT_BASE_TOPIC, 20);
|
||||
|
@ -235,6 +269,7 @@ void eeprom_retrieve_init()
|
|||
strcat(AC_ROOM_TEMPERATURE_TOPIC, "/ac/room_temperature");
|
||||
memcpy(AC_HUMIDITY_TOPIC, MQTT_BASE_TOPIC, 20);
|
||||
strcat(AC_HUMIDITY_TOPIC, "/ac/humidity");
|
||||
#endif
|
||||
memcpy(PWM_STATE_TOPIC, MQTT_BASE_TOPIC, 20);
|
||||
strcat(PWM_STATE_TOPIC, "/pwm/00/state");
|
||||
memcpy(PWM_VALUE_TOPIC, MQTT_BASE_TOPIC, 20);
|
||||
|
@ -243,6 +278,7 @@ void eeprom_retrieve_init()
|
|||
strcat(INPUTS_TOPIC, "/input/00");
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WEBUI
|
||||
void ota_begin()
|
||||
{
|
||||
otaserver.on("/", HTTP_GET, []()
|
||||
|
@ -319,9 +355,7 @@ void ota_begin()
|
|||
set_mqtt_useauth(use_auth);
|
||||
otaserver.send(200, "text/html", configbuffer);
|
||||
delay(500);
|
||||
ESP.restart();
|
||||
});
|
||||
|
||||
ESP.restart(); });
|
||||
|
||||
otaserver.on(
|
||||
"/update", HTTP_POST, []()
|
||||
|
@ -338,12 +372,16 @@ void ota_begin()
|
|||
Serial.println(upload.currentSize);
|
||||
|
||||
String otafiletxt = "Downloading File : " + upload.filename;
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
lcd_send_stop_bit();
|
||||
panel.writeStr("otatxt.txt", otafiletxt);
|
||||
#endif
|
||||
Serial.printf("Update: %s\n", upload.filename.c_str());
|
||||
if (!Update.begin(UPDATE_SIZE_UNKNOWN))
|
||||
{
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
panel.writeStr("otatxt.txt", "Update Failed, Rebooting . . .");
|
||||
#endif
|
||||
Update.printError(Serial);
|
||||
}
|
||||
}
|
||||
|
@ -351,7 +389,9 @@ void ota_begin()
|
|||
{
|
||||
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize)
|
||||
{
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
panel.writeStr("otatxt.txt", "Update Failed, Rebooting . . .");
|
||||
#endif
|
||||
Update.printError(Serial);
|
||||
}
|
||||
if (upload.currentSize != 0 && upload.totalSize != 0)
|
||||
|
@ -360,32 +400,41 @@ void ota_begin()
|
|||
uint32_t totalsize_kb = upload.totalSize / 1000;
|
||||
uint32_t upload_pct = 100 * upload.totalSize / 1000000;
|
||||
String otafiletxt = "Downloading File : " + upload.filename + " (" + String(totalsize_kb) + "KB)";
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
panel.writeNum("prog.val", upload_pct);
|
||||
panel.writeStr("otatxt.txt", otafiletxt);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (upload.status == UPLOAD_FILE_END)
|
||||
{
|
||||
if (Update.end(true))
|
||||
{
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
panel.writeStr("otatxt.txt", "Update Completed, Rebooting . . .");
|
||||
#endif
|
||||
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
panel.writeStr("otatxt.txt", "Update Failed, Rebooting . . .");
|
||||
#endif
|
||||
Update.printError(Serial);
|
||||
}
|
||||
}
|
||||
});
|
||||
otaserver.begin();
|
||||
}
|
||||
#endif
|
||||
|
||||
void io_begin()
|
||||
{
|
||||
Serial.println("Initializing I/O . . .");
|
||||
#ifdef ENABLE_IR_MODULE
|
||||
pinMode(IR_RECIEVE_PIN, INPUT_PULLUP);
|
||||
pinMode(IR_SEND_PIN, OUTPUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void network_begin()
|
||||
|
@ -431,7 +480,9 @@ void mqtt_connect()
|
|||
lcd_send_stop_bit();
|
||||
publish_pwm_states();
|
||||
publish_input_states();
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
publish_ac_state();
|
||||
#endif
|
||||
mqtt_connected_user_callback();
|
||||
standalone = false;
|
||||
ESPMega_updateTimeFromNTP();
|
||||
|
@ -443,8 +494,10 @@ void mqtt_connect()
|
|||
lcd_send_stop_bit();
|
||||
}
|
||||
lcd_send_stop_bit();
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
lcd_refresh();
|
||||
lcd_top_bar_update();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -459,9 +512,11 @@ void mqtt_subscribe()
|
|||
mqtt.subscribe(PWM_SET_STATE_TOPIC, pwm_state_callback);
|
||||
mqtt.subscribe(PWM_SET_VALUE_TOPIC, pwm_value_callback);
|
||||
}
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
mqtt.subscribe(AC_SET_FAN_TOPIC, ac_state_callback);
|
||||
mqtt.subscribe(AC_SET_TEMPERATURE_TOPIC, ac_state_callback);
|
||||
mqtt.subscribe(AC_SET_MODE_TOPIC, ac_state_callback);
|
||||
#endif
|
||||
mqtt.subscribe(STATE_REQUEST_TOPIC, state_request_callback);
|
||||
}
|
||||
|
||||
|
@ -471,8 +526,10 @@ void thread_initialization()
|
|||
Serial.println("Initializing MQTT Thread . . .");
|
||||
mqtt_reconnector.onRun(mqtt_connect);
|
||||
mqtt_reconnector.setInterval(15000);
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
environment_reporter.onRun(publish_env_state);
|
||||
environment_reporter.setInterval(5000);
|
||||
#endif
|
||||
eeprom_pwm_updater.onRun(eeprom_pwm_update);
|
||||
eeprom_pwm_updater.setInterval(1000);
|
||||
user_timer_tick.onRun(timer_tick_callback);
|
||||
|
@ -507,9 +564,10 @@ void virtual_interrupt_callback(int pin, int state)
|
|||
{
|
||||
|
||||
publish_input_state(pin, state);
|
||||
// Serial.printf("Pin %d changed to %d\n", pin, state);
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
if (lcd_current_page == 2)
|
||||
panel.writeNum("I" + String(pin) + ".val", state);
|
||||
#endif
|
||||
virtual_interrupt_user_callback(pin, state);
|
||||
}
|
||||
|
||||
|
@ -568,10 +626,12 @@ void pwm_set_state(int id, int state)
|
|||
pwm_states[id] = state;
|
||||
int pwm_value = pwm_values[id];
|
||||
ESPMega_analogWrite(pwm_pins[id], state * (int)(pwm_linear_scaling_m[id] * pwm_value + pwm_linear_scaling_c[id]));
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
if (lcd_current_page == 3)
|
||||
panel.writeNum("j" + String(id) + ".ppic", pwm_states[id] ? 33 : 48);
|
||||
else if (lcd_current_page == 5 && id == lcd_pwmAdj_id)
|
||||
panel.writeStr("pwm_state.txt", pwm_states[lcd_pwmAdj_id] ? "ON" : "OFF");
|
||||
#endif
|
||||
publish_pwm_state(id);
|
||||
pwm_changed_user_callback(id);
|
||||
}
|
||||
|
@ -582,10 +642,12 @@ void pwm_set_value(int id, int value)
|
|||
pwm_values[id] = value;
|
||||
int pwm_state = pwm_states[id];
|
||||
ESPMega_analogWrite(pwm_pins[id], pwm_state * (int)(pwm_linear_scaling_m[id] * value + pwm_linear_scaling_c[id]));
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
if (lcd_current_page == 3)
|
||||
panel.writeNum("j" + String(id) + ".val", int(value / 4095.0 * 100.0));
|
||||
else if (lcd_current_page == 5 && id == lcd_pwmAdj_id)
|
||||
panel.writeNum("pwm_value.val", pwm_values[lcd_pwmAdj_id]);
|
||||
#endif
|
||||
publish_pwm_state(id);
|
||||
pwm_changed_user_callback(id);
|
||||
}
|
||||
|
@ -668,22 +730,23 @@ void state_request_callback(String topic, String message)
|
|||
{
|
||||
publish_input_states();
|
||||
publish_pwm_states();
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
publish_ac_state();
|
||||
#endif
|
||||
user_state_request_callback();
|
||||
}
|
||||
|
||||
#ifdef ENABLE_IR_MODULE
|
||||
void ir_loop()
|
||||
{
|
||||
if (IrReceiver.decode())
|
||||
{
|
||||
// Serial.println();
|
||||
// IrReceiver.compensateAndPrintIRResultAsCArray(&Serial, false);
|
||||
// Serial.println();
|
||||
// Serial.println();
|
||||
IrReceiver.resume();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
void publish_ac_state()
|
||||
{
|
||||
String temp = "";
|
||||
|
@ -776,7 +839,7 @@ void ac_set_state(int mode, int temperature, int fan_speed)
|
|||
ac_temperature = AC_MAX_TEMPERATURE;
|
||||
ac_fan_speed = fan_speed;
|
||||
temperature -= AC_MIN_TEMPERATURE;
|
||||
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
if (lcd_current_page == 4)
|
||||
{
|
||||
lcd_ac_refresh_fan();
|
||||
|
@ -786,6 +849,7 @@ void ac_set_state(int mode, int temperature, int fan_speed)
|
|||
else
|
||||
panel.writeStr("temp.txt", "--C");
|
||||
}
|
||||
#endif
|
||||
publish_ac_state();
|
||||
uint8_t ac_datablock[3] = {ac_mode, ac_temperature, ac_fan_speed};
|
||||
ESPMega_FRAM.write(0, ac_datablock, 3);
|
||||
|
@ -817,6 +881,7 @@ void publish_env_state()
|
|||
mqtt_client.loop();
|
||||
mqtt.publish(String(AC_HUMIDITY_TOPIC), String(current_room_humid));
|
||||
mqtt_client.loop();
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
if (lcd_current_page == 4)
|
||||
{
|
||||
Serial.printf("roomtemp.txt=\"%.01fC\"", current_room_temp);
|
||||
|
@ -824,6 +889,7 @@ void publish_env_state()
|
|||
Serial.printf("roomhumid.txt=\"%d%%\"", (int)current_room_humid);
|
||||
lcd_send_stop_bit();
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
mqtt.publish(String(AC_ROOM_TEMPERATURE_TOPIC), "ERROR");
|
||||
|
@ -832,7 +898,9 @@ void publish_env_state()
|
|||
mqtt_client.loop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
void lcd_begin()
|
||||
{
|
||||
top_bar_updater.onRun(lcd_top_bar_update);
|
||||
|
@ -886,6 +954,7 @@ void lcd_refresh()
|
|||
}
|
||||
break;
|
||||
case 4:
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
Serial.printf("roomtemp.txt=\"%.01fC\"", current_room_temp);
|
||||
lcd_send_stop_bit();
|
||||
Serial.printf("roomhumid.txt=\"%d%%\"", (int)current_room_humid);
|
||||
|
@ -896,6 +965,9 @@ void lcd_refresh()
|
|||
panel.writeStr("temp.txt", "--C");
|
||||
lcd_ac_refresh_fan();
|
||||
lcd_ac_refresh_mode();
|
||||
#else
|
||||
lcd_send_command("page climate_nomod");
|
||||
#endif
|
||||
case 5:
|
||||
panel.writeStr("pwm_id.txt", String("P") + String(lcd_pwmAdj_id));
|
||||
panel.writeStr("pwm_state.txt", pwm_states[lcd_pwmAdj_id] ? "ON" : "OFF");
|
||||
|
@ -929,7 +1001,7 @@ void lcd_top_bar_update()
|
|||
panel.writeNum("server.pic", standalone ? 4 : 5);
|
||||
panel.writeNum("lan.pic", ETH.linkUp() ? 3 : 2);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
void lcd_ac_refresh_mode()
|
||||
{
|
||||
// auto high mid low
|
||||
|
@ -945,6 +1017,7 @@ void lcd_ac_refresh_fan()
|
|||
panel.writeNum("fan_mid.pic", ac_fan_speed == 2 ? 20 : 21);
|
||||
panel.writeNum("fan_high.pic", ac_fan_speed == 1 ? 16 : 17);
|
||||
}
|
||||
#endif
|
||||
|
||||
void trigger0()
|
||||
{
|
||||
|
@ -975,54 +1048,70 @@ void trigger3()
|
|||
lcd_send_stop_bit();
|
||||
pwm_set_value(lcd_pwmAdj_id, value);
|
||||
}
|
||||
|
||||
void trigger4()
|
||||
{
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
if (ac_temperature < AC_MAX_TEMPERATURE && ac_mode != 2)
|
||||
ac_set_state(ac_mode, ac_temperature + 1, ac_fan_speed);
|
||||
#endif
|
||||
}
|
||||
|
||||
void trigger5()
|
||||
{
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
if (ac_temperature > AC_MIN_TEMPERATURE && ac_mode != 2)
|
||||
ac_set_state(ac_mode, ac_temperature - 1, ac_fan_speed);
|
||||
#endif
|
||||
}
|
||||
|
||||
void trigger6()
|
||||
{
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
ac_set_state(ac_mode, ac_temperature, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void trigger7()
|
||||
{
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
ac_set_state(ac_mode, ac_temperature, 3);
|
||||
#endif
|
||||
}
|
||||
|
||||
void trigger8()
|
||||
{
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
ac_set_state(ac_mode, ac_temperature, 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
void trigger9()
|
||||
{
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
ac_set_state(ac_mode, ac_temperature, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
void trigger10()
|
||||
{
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
ac_set_state(1, ac_temperature, ac_fan_speed);
|
||||
#endif
|
||||
}
|
||||
|
||||
void trigger11()
|
||||
{
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
ac_set_state(2, ac_temperature, ac_fan_speed);
|
||||
#endif
|
||||
}
|
||||
|
||||
void trigger12()
|
||||
{
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
ac_set_state(0, ac_temperature, ac_fan_speed);
|
||||
#endif
|
||||
}
|
||||
|
||||
void trigger13()
|
||||
{
|
||||
set_ip(panel.readStr("ip_set.txt"));
|
||||
|
@ -1052,6 +1141,7 @@ void trigger15()
|
|||
delay(100);
|
||||
ESP.restart();
|
||||
}
|
||||
#endif // End Internal LCD Code Block
|
||||
|
||||
void eeprom_pwm_update()
|
||||
{
|
||||
|
@ -1156,6 +1246,7 @@ boolean input_get_state(int id)
|
|||
return virtual_interupt_state[id];
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
uint8_t ac_get_temperature()
|
||||
{
|
||||
return ac_temperature;
|
||||
|
@ -1168,6 +1259,7 @@ uint8_t ac_get_fan_speed()
|
|||
{
|
||||
return ac_fan_speed;
|
||||
}
|
||||
#endif
|
||||
|
||||
void eeprom_mqtt_username_retrieve()
|
||||
{
|
||||
|
@ -1197,34 +1289,47 @@ void set_mqtt_useauth(bool use_auth)
|
|||
ESPMega_FRAM.write8(EEPROM_ADDRESS_MQTT_USEAUTH, MQTT_USE_AUTH);
|
||||
}
|
||||
|
||||
void factory_reset() {
|
||||
for(int i=5;i>0;i--) {
|
||||
if(digitalRead(2)==HIGH) {
|
||||
void factory_reset()
|
||||
{
|
||||
for (int i = 5; i > 0; i--)
|
||||
{
|
||||
if (digitalRead(2) == HIGH)
|
||||
{
|
||||
lcd_send_command("boot_state.txt=\"Factory Reset Canceled, Restarting\"");
|
||||
delay(5000);
|
||||
ESP.restart();
|
||||
}
|
||||
Serial.printf("boot_state.txt=\"Factory Reset in %d\"",i);
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
Serial.printf("boot_state.txt=\"Factory Reset in %d\"", i);
|
||||
lcd_send_stop_bit();
|
||||
#endif
|
||||
delay(1000);
|
||||
}
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
lcd_send_command("boot_state.txt=\"Factory Reseting . . .\"");
|
||||
#endif
|
||||
// Format FRAM
|
||||
for(int i=0;i<32768;i++) {
|
||||
ESPMega_FRAM.write8(i,0);
|
||||
for (int i = 0; i < 32768; i++)
|
||||
{
|
||||
ESPMega_FRAM.write8(i, 0);
|
||||
}
|
||||
// Load Default Values
|
||||
set_ip("192.168.0.10");
|
||||
set_gw("192.168.0.1");
|
||||
set_netmask("255.255.255.0");
|
||||
// Reboot
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
lcd_send_stop_bit();
|
||||
lcd_send_command("boot_state.txt=\"Factory Reset OK. Release Button.\"");
|
||||
delay(3000);
|
||||
#endif
|
||||
ESP.restart();
|
||||
}
|
||||
void check_boot_reset() {
|
||||
void check_boot_reset()
|
||||
{
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
if(digitalRead(2)==LOW) {
|
||||
if (digitalRead(2) == LOW)
|
||||
{
|
||||
factory_reset();
|
||||
}
|
||||
}
|
|
@ -1,23 +1,38 @@
|
|||
#pragma once
|
||||
|
||||
#include <ESPMegaPRO.h>
|
||||
#include "user_code.hpp"
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
#ifndef ENABLE_IR_MODULE
|
||||
#error "The Climate Module Requires the IR Module to be enabled with #define ENABLE_IR_MODULE"
|
||||
#endif
|
||||
#endif
|
||||
#include <ETH.h>
|
||||
#include <PubSubClient.h>
|
||||
#include <PubSubClientTools.h>
|
||||
#include <Thread.h>
|
||||
#include <StaticThreadController.h>
|
||||
#ifdef ENABLE_IR_MODULE
|
||||
#include <IRremote.hpp>
|
||||
#endif
|
||||
#include <dhtnew.h>
|
||||
#include <time.h>
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
#include <EasyNextionLibrary.h>
|
||||
#endif
|
||||
#include <WiFiClient.h>
|
||||
#ifdef ENABLE_WEBUI
|
||||
#include <WebServer.h>
|
||||
#include <Update.h>
|
||||
|
||||
#endif
|
||||
#include "lcd.hpp"
|
||||
#include "user_code.hpp"
|
||||
|
||||
#ifdef ENABLE_CLIMATE_MODULE
|
||||
#include "ir_codes.hpp"
|
||||
#endif
|
||||
#ifdef ENABLE_WEBUI
|
||||
#include "espmega_iot_ota.hpp"
|
||||
#endif
|
||||
#include "espmega_iot_timer.hpp"
|
||||
|
||||
void virtual_interrupt_loop();
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
#pragma once
|
||||
#include <ESPMegaPRO.h>
|
||||
// Infrared Transciever
|
||||
#define IR_RECIEVE_PIN 35
|
||||
#define IR_SEND_PIN 17
|
||||
#define MARK_EXCESS_MICROS 20
|
||||
#define RAW_BUFFER_LENGTH 750
|
||||
#define AC_MAX_TEMPERATURE 30
|
||||
#define AC_MIN_TEMPERATURE 15
|
||||
extern const uint8_t ir_code_cool[3][16][750] = {
|
||||
// Fan Speed High
|
||||
{
|
||||
|
|
21
src/lcd.cpp
21
src/lcd.cpp
|
@ -1,24 +1,37 @@
|
|||
#include <user_code.hpp>
|
||||
#include <lcd.hpp>
|
||||
|
||||
void lcd_send_stop_bit() {
|
||||
void lcd_send_stop_bit()
|
||||
{
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
Serial.write(0xFF);
|
||||
Serial.write(0xFF);
|
||||
Serial.write(0xFF);
|
||||
#endif
|
||||
}
|
||||
|
||||
void lcd_send_command(String command) {
|
||||
void lcd_send_command(String command)
|
||||
{
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
lcd_send_stop_bit();
|
||||
Serial.print(command);
|
||||
lcd_send_stop_bit();
|
||||
#endif
|
||||
}
|
||||
|
||||
void lcd_reset() {
|
||||
void lcd_reset()
|
||||
{
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
lcd_send_stop_bit();
|
||||
lcd_send_command("rest");
|
||||
lcd_send_stop_bit();
|
||||
#endif
|
||||
}
|
||||
|
||||
void lcd_init() {
|
||||
void lcd_init()
|
||||
{
|
||||
#ifdef ENABLE_INTERNAL_LCD
|
||||
lcd_reset();
|
||||
delay(750);
|
||||
#endif
|
||||
}
|
|
@ -5,6 +5,20 @@
|
|||
#include "espmega_iot_timer.hpp"
|
||||
#include "espmega_iot_external_lcd.hpp"
|
||||
|
||||
// Enable Software Module(s)
|
||||
#define ENABLE_INTERNAL_LCD
|
||||
#define ENABLE_IR_MODULE
|
||||
#define ENABLE_CLIMATE_MODULE // Require IR Module
|
||||
#define ENABLE_WEBUI
|
||||
|
||||
// Infrared Transciever
|
||||
#define IR_RECIEVE_PIN 35
|
||||
#define IR_SEND_PIN 17
|
||||
#define MARK_EXCESS_MICROS 20
|
||||
#define RAW_BUFFER_LENGTH 750
|
||||
#define AC_MAX_TEMPERATURE 30
|
||||
#define AC_MIN_TEMPERATURE 15
|
||||
|
||||
// External LCD Configuration
|
||||
//#define ENABLE_EXTERNAL_LCD
|
||||
//#define TXD2 4
|
||||
|
|
Loading…
Reference in New Issue