initial structure

This commit is contained in:
Siwat Sirichai 2023-09-29 23:18:21 +07:00
parent c96ce8a67b
commit 7bf49d0997
7 changed files with 139 additions and 115 deletions

View File

@ -10,6 +10,7 @@
"functional": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp"
"utility": "cpp",
"*.d": "cpp"
}
}

View File

@ -1,17 +1,5 @@
// #define USE_INTERRUPT
#include <ESPMegaPRO.h>
#include <ETH.h>
#include <PubSubClient.h>
#include <PubSubClientTools.h>
#include <Thread.h>
#include <StaticThreadController.h>
#include <IRremote.hpp>
#include <daikin_ir.hpp>
#include <dhtnew.h>
#include <time.h>
#include <EasyNextionLibrary.h>
#include <lcd.hpp>
#include <espmega_iot_core.hpp>
#include <user_code.hpp>
// OS Configuration
#define FASTBOOT
@ -104,77 +92,6 @@ char AC_HUMIDITY_TOPIC[75];
#define EEPROM_ADDRESS_MQTT_SERVER 116 // 04bytes, thru 119
#define EEPROM_ADDRESS_MQTT_PORT 120 // 02bytes, thru 121
// Forward declaration
void virtual_interrupt_loop();
void virtual_interrupt_callback(int pin, int state);
void network_begin();
void mqtt_connect();
void mqtt_subscribe();
void thread_initialization();
void pwm_state_callback(String topic, String message);
void pwm_value_callback(String topic, String message);
void state_request_callback(String topic, String message);
void io_begin();
void ir_loop();
void publish_pwm_states();
void publish_pwm_state(int id);
void pwm_set_state(int id, int state);
void pwm_set_value(int id, int value);
void pwm_toggle(int id);
void pwm_toggle(int id1, int id2);
void pwm_cycle_value(int id);
boolean pwm_group_state(int id1, int id2);
void publish_ac_state();
void publish_env_state();
void ac_state_callback(String topic, String message);
void ac_set_state(int mode, int temperature, int fan_speed);
void publish_input_states();
void publish_input_state(int id);
void publish_input_state(int id, int state);
void lcd_begin();
void lcd_loop();
void lcd_refresh();
void lcd_refresh_pd();
void lcd_top_bar_update();
void trigger0();
void trigger1();
void trigger2();
void trigger3();
void trigger4();
void trigger5();
void trigger6();
void trigger7();
void trigger8();
void trigger9();
void trigger10();
void trigger11();
void trigger12();
void trigger13();
void eeprom_retrieve_init();
void eeprom_pwm_update();
void lcd_ac_refresh_fan();
void lcd_ac_refresh_mode();
void set_ip(String address);
void set_netmask(String address);
void set_dns(String address);
void set_gw(String address);
void set_mqtt_server(String address);
void eeprom_ip_update(uint16_t rom_address, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4);
IPAddress eeprom_ip_retrieve(uint16_t rom_address);
void set_hostname(String hostname);
void eeprom_hostname_retrieve();
void set_basetopic(String topic);
void eeprom_basetopic_retrieve();
void mqtt_port_set(uint16_t port);
void eeprom_mqtt_port_retrieve();
char PWM_STATE_TOPIC[75];
char PWM_VALUE_TOPIC[75];
char INPUTS_TOPIC[75];
@ -197,6 +114,7 @@ StaticThreadController<2> lcd_thread_controller(&top_bar_updater, &page_updater)
void setup()
{
Serial.begin(115200);
Serial2.begin(115200);
panel.begin(115200);
Serial.println("ESPMega R3 Initializing");
ESPMega_begin();
@ -218,11 +136,7 @@ void setup()
thread_initialization();
Serial.println("Initialization Completed.");
Serial.println("Jumping to User Code.");
// Begin User Code
/*
Pre-NTP Implementation
*/
user_init();
lcd_send_command("page dashboard");
}
@ -234,6 +148,7 @@ void loop()
ir_loop();
thread_controller.run();
lcd_loop();
user_loop();
}
void eeprom_retrieve_init()
@ -440,10 +355,7 @@ void virtual_interrupt_callback(int pin, int state)
// Serial.printf("Pin %d changed to %d\n", pin, state);
if (lcd_current_page == 2)
panel.writeNum("I" + String(pin) + ".val", state);
if (pin == 15)
{
pwm_toggle(4);
}
virtual_interrupt_user_callback(pin, state);
}
void virtual_interrupt_loop()

87
src/espmega_iot_core.hpp Normal file
View File

@ -0,0 +1,87 @@
#ifndef CORE_LOADED
#define CORE_LOADED
#include <ESPMegaPRO.h>
#include <ETH.h>
#include <PubSubClient.h>
#include <PubSubClientTools.h>
#include <Thread.h>
#include <StaticThreadController.h>
#include <IRremote.hpp>
#include <daikin_ir.hpp>
#include <dhtnew.h>
#include <time.h>
#include <EasyNextionLibrary.h>
#include <lcd.hpp>
void virtual_interrupt_loop();
void virtual_interrupt_callback(int pin, int state);
void network_begin();
void mqtt_connect();
void mqtt_subscribe();
void thread_initialization();
void pwm_state_callback(String topic, String message);
void pwm_value_callback(String topic, String message);
void state_request_callback(String topic, String message);
void io_begin();
void ir_loop();
void publish_pwm_states();
void publish_pwm_state(int id);
void pwm_set_state(int id, int state);
void pwm_set_value(int id, int value);
void pwm_toggle(int id);
void pwm_toggle(int id1, int id2);
void pwm_cycle_value(int id);
boolean pwm_group_state(int id1, int id2);
void publish_ac_state();
void publish_env_state();
void ac_state_callback(String topic, String message);
void ac_set_state(int mode, int temperature, int fan_speed);
void publish_input_states();
void publish_input_state(int id);
void publish_input_state(int id, int state);
void lcd_begin();
void lcd_loop();
void lcd_refresh();
void lcd_refresh_pd();
void lcd_top_bar_update();
void trigger0();
void trigger1();
void trigger2();
void trigger3();
void trigger4();
void trigger5();
void trigger6();
void trigger7();
void trigger8();
void trigger9();
void trigger10();
void trigger11();
void trigger12();
void trigger13();
void eeprom_retrieve_init();
void eeprom_pwm_update();
void lcd_ac_refresh_fan();
void lcd_ac_refresh_mode();
void set_ip(String address);
void set_netmask(String address);
void set_dns(String address);
void set_gw(String address);
void set_mqtt_server(String address);
void eeprom_ip_update(uint16_t rom_address, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4);
IPAddress eeprom_ip_retrieve(uint16_t rom_address);
void set_hostname(String hostname);
void eeprom_hostname_retrieve();
void set_basetopic(String topic);
void eeprom_basetopic_retrieve();
void mqtt_port_set(uint16_t port);
void eeprom_mqtt_port_retrieve();
#endif

5
src/external_lcd.cpp Normal file
View File

@ -0,0 +1,5 @@
#include <external_lcd.hpp>
void ExternalLCD::callTriggerFunction() {
uint8_t touch_hex = Serial2.read();
external_lcd_callback(touch_hex);
}

12
src/external_lcd.hpp Normal file
View File

@ -0,0 +1,12 @@
#include <EasyNextionLibrary.h>
#ifndef trigger_h
#include "trigger.h"
#endif
#ifndef EXTERNAL_LCD_LOADED
#define EXTERNAL_LCD_LOADED
#include <user_code.hpp>
class ExternalLCD: public EasyNex {
protected:
void callTriggerFunction();
};
#endif

17
src/user_code.cpp Normal file
View File

@ -0,0 +1,17 @@
#include <user_code.hpp>
void user_pre_init() {
}
void user_init() {
}
void user_loop() {
}
void virtual_interrupt_user_callback(int pin, int state) {
}
void timer_tick_callback() {
}

View File

@ -1,23 +1,13 @@
#ifndef USER_CODE
#define USER_CODE
#include <ESPMegaPRO.h>
void user_pre_init() {
}
void user_init() {
}
void user_loop() {
}
void virtual_interrupt_user_callback(int pin, int state) {
}
void timer_tick_callback() {
}
#ifndef CORE_LOADED
#define CORE_LOADED
#include <espmega_iot_core.hpp>
#endif
void user_pre_init();
void user_init();
void user_loop();
void virtual_interrupt_user_callback(int pin, int state);
void timer_tick_callback();
void external_lcd_callback(int touch_hex);
#endif