From b4b1f12ba86066402549e20f9e598472d923e317 Mon Sep 17 00:00:00 2001 From: reaw55 <58457329+reaw55@users.noreply.github.com> Date: Sun, 24 Dec 2023 23:41:27 +0700 Subject: [PATCH] initial user code --- src/user_code.cpp | 66 ++++++++++++++++++++++++++++------------------- src/user_code.hpp | 13 ++++++++-- 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/src/user_code.cpp b/src/user_code.cpp index 49d4be7..4f87a5e 100644 --- a/src/user_code.cpp +++ b/src/user_code.cpp @@ -1,20 +1,24 @@ #include -//Timer Components -ESPMega_Timer timer1(0, 50, timer1_callback, 15001); - // Display Componets // Link with Dual state button object with id 2 on page 1 named bt0 -NexDSButton bt0 = NexDSButton(1, 2, "bt0"); +NexButton row1_master = NexButton(1,11,"row1_master"); // List of Component ID Message to listen to NexTouch *nex_listen_list[] = { - &bt0, + &row1_master, NULL}; -void bt0PopCallback(void *ptr) +bool row1_is_on() { + return pwm_get_state(LIGHT_THAW_NAH_THANG_KWAR) && pwm_get_state(LIGHT_THAW_NAH_THANG_SAI); +} + +void row1_master_pop_callback(void *ptr) { - pwm_toggle(2); + bool new_state = !row1_is_on(); + pwm_set_state(LIGHT_THAW_NAH_THANG_KWAR, new_state); + pwm_set_state(LIGHT_THAW_NAH_THANG_SAI, new_state); + } /* @@ -31,12 +35,9 @@ This code will run after every component is initialized */ void user_init() { - timer1.begin(); - ESPMega_EXTLCD.print("page home"); - ESPMega_EXTLCD.write(0xFF); - ESPMega_EXTLCD.write(0xFF); - ESPMega_EXTLCD.write(0xFF); - bt0.attachPop(bt0PopCallback, &bt0); + elcd.print("page main"); + elcd_send_stop_bit(); + row1_master.attachPop(row1_master_pop_callback, &row1_master); } /* @@ -54,13 +55,27 @@ void virtual_interrupt_user_callback(int pin, int state) { } +void update_lcd_row1() { + bool master_state = row1_is_on(); + //Assume 20 off, 21 on + row1_master.Set_background_image_pic(master_state?21:20); + bool lt1_state = pwm_get_state(LIGHT_THAW_NAH_THANG_KWAR); + bool lt2_state = pwm_get_state(LIGHT_THAW_NAH_THANG_SAI); + +} + void pwm_changed_user_callback(int pin) { - if (pin == 2) - { - // inform the lcd when pwm 2 changed - bt0.setValue(pwm_get_state(2)); - } + // switch (pin) + // { + // case LIGHT_THAW_NAH_THANG_KWAR: + // case LIGHT_THAW_NAH_THANG_SAI: + // update_lcd_row1(); + // break; + + // default: + // break; + // } } /* @@ -70,15 +85,6 @@ void timer_tick_callback() { if (standalone) { - timer1.loop(); - } -} - -void timer1_callback() -{ - for (int i = 0; i < 16; i++) - { - pwm_set_state(i, 1); } } @@ -96,4 +102,10 @@ void user_state_request_callback() { void user_mqtt_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length) { +} + +void elcd_send_stop_bit() { + elcd.write(0xFF); + elcd.write(0xFF); + elcd.write(0xFF); } \ No newline at end of file diff --git a/src/user_code.hpp b/src/user_code.hpp index 938316e..d4e2188 100644 --- a/src/user_code.hpp +++ b/src/user_code.hpp @@ -6,6 +6,12 @@ #include "espmega_iot_timer.hpp" #include "espmega_iot_external_lcd.hpp" +// I/O Assignment +#define LIGHT_THAW_NAH_THANG_KWAR 0 +#define LIGHT_THAW_NAH_THANG_SAI 1 + + + // Bus Overclocking Configuration // Do not enable if you are using external I/O cards as it will cause signal integrity issues. // Choose only one mode @@ -45,8 +51,11 @@ #define ANALOG_REPORTING_INTERVAL 500 // User Defined Functions -void timer1_callback(); -void bt0PopCallback(void *ptr); +#define elcd ESPMega_EXTLCD +void elcd_send_stop_bit(); +bool row1_is_on(); +void update_lcd_row1(); +void row1_master_pop_callback(void *ptr); // User Defined IoT Core Callback Functions (Required) void user_mqtt_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length);