iot-firmware/src/user_code.cpp

99 lines
1.6 KiB
C++
Raw Normal View History

2023-09-29 16:18:21 +00:00
#include <user_code.hpp>
2023-09-29 17:56:25 +00:00
2023-10-01 05:32:32 +00:00
//Timer Components
2023-09-29 17:56:36 +00:00
ESPMega_Timer timer1(0, 50, timer1_callback, 15001);
2023-09-29 16:18:21 +00:00
2023-09-30 11:09:03 +00:00
// Display Componets
// Link with Dual state button object with id 2 on page 1 named bt0
2023-09-30 09:29:16 +00:00
NexDSButton bt0 = NexDSButton(1, 2, "bt0");
2023-09-30 11:09:03 +00:00
// List of Component ID Message to listen to
NexTouch *nex_listen_list[] =
{
&bt0,
NULL};
2023-09-30 09:29:16 +00:00
void bt0PopCallback(void *ptr)
{
2023-09-30 11:09:03 +00:00
pwm_toggle(2);
2023-09-30 09:29:16 +00:00
}
2023-09-29 17:06:49 +00:00
/*
This Code will run right after ESPMega PRO's
Peripheral Initialization Routine
*/
2023-09-29 17:37:31 +00:00
void user_pre_init()
{
2023-09-30 09:29:16 +00:00
nexInit();
2023-09-29 16:18:21 +00:00
}
2023-09-29 17:06:49 +00:00
/*
This code will run after every component is initialized
*/
2023-09-29 17:37:31 +00:00
void user_init()
{
2023-09-29 17:56:25 +00:00
timer1.begin();
2023-09-30 08:42:44 +00:00
ESPMega_EXTLCD.print("page home");
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
2023-09-30 09:29:16 +00:00
bt0.attachPop(bt0PopCallback, &bt0);
2023-09-29 16:18:21 +00:00
}
2023-09-29 17:06:49 +00:00
/*
This code will run once every event loop
*/
2023-09-29 17:37:31 +00:00
void user_loop()
{
2023-09-30 09:29:16 +00:00
nexLoop(nex_listen_list);
2023-09-29 16:18:21 +00:00
}
2023-09-29 17:06:49 +00:00
/*
This code will run when an input pin changed state
*/
2023-09-29 17:37:31 +00:00
void virtual_interrupt_user_callback(int pin, int state)
{
2023-09-29 16:18:21 +00:00
}
2023-09-29 17:06:49 +00:00
2023-09-30 09:29:16 +00:00
void pwm_changed_user_callback(int pin)
{
2023-09-30 11:09:03 +00:00
if (pin == 2)
{
// inform the lcd when pwm 2 changed
bt0.setValue(pwm_get_state(2));
}
2023-09-30 08:42:44 +00:00
}
2023-09-29 17:06:49 +00:00
/*
2023-09-29 17:37:31 +00:00
This code will run every 15 seconds
2023-09-29 17:06:49 +00:00
*/
2023-09-29 17:37:31 +00:00
void timer_tick_callback()
{
2023-09-29 17:56:36 +00:00
if (standalone)
{
2023-09-29 17:56:25 +00:00
timer1.loop();
2023-09-29 17:37:31 +00:00
}
2023-09-29 16:18:21 +00:00
}
2023-09-30 09:29:16 +00:00
void timer1_callback()
{
for (int i = 0; i < 16; i++)
{
pwm_set_state(i, 1);
}
2023-10-02 11:02:17 +00:00
}
void ac_changed_user_callback(int mode, int temperature, int fan_speed) {
2023-10-02 19:19:50 +00:00
}
void mqtt_connected_user_callback() {
2023-10-02 19:24:30 +00:00
}
void user_state_request_callback() {
}
void user_mqtt_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length) {
2023-09-30 09:29:16 +00:00
}