From 6ccbc32911622e907710e692bd76a4cbe2b8f1d3 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sat, 30 Sep 2023 16:29:16 +0700 Subject: [PATCH] external nextion display example --- .../NexHardware.cpp | 4 +- ...l_lcd.cpp => espmega_iot_external_lcd.cpp} | 4 +- ...l_lcd.hpp => espmega_iot_external_lcd.hpp} | 4 ++ src/user_code.cpp | 40 ++++++++++++------ src/user_code.hpp | 4 +- user_display/EXTDISP.HMI | Bin 7360346 -> 7360346 bytes 6 files changed, 38 insertions(+), 18 deletions(-) rename src/{external_lcd.cpp => espmega_iot_external_lcd.cpp} (52%) rename src/{external_lcd.hpp => espmega_iot_external_lcd.hpp} (77%) diff --git a/lib/ITEADLIB_Arduino_Nextion-master/NexHardware.cpp b/lib/ITEADLIB_Arduino_Nextion-master/NexHardware.cpp index 153afcf..c2b6788 100644 --- a/lib/ITEADLIB_Arduino_Nextion-master/NexHardware.cpp +++ b/lib/ITEADLIB_Arduino_Nextion-master/NexHardware.cpp @@ -222,8 +222,8 @@ bool nexInit(void) bool ret1 = false; bool ret2 = false; - dbSerialBegin(9600); - nexSerial.begin(9600); + //dbSerialBegin(9600); + nexSerial.begin(115200); sendCommand(""); sendCommand("bkcmd=1"); ret1 = recvRetCommandFinished(); diff --git a/src/external_lcd.cpp b/src/espmega_iot_external_lcd.cpp similarity index 52% rename from src/external_lcd.cpp rename to src/espmega_iot_external_lcd.cpp index cac60f5..34e43dc 100644 --- a/src/external_lcd.cpp +++ b/src/espmega_iot_external_lcd.cpp @@ -1,5 +1,5 @@ -#include +#include void ExternalLCD::callTriggerFunction() { uint8_t touch_hex = Serial2.read(); - external_lcd_callback(touch_hex); + ext_lcd_callback(touch_hex); } \ No newline at end of file diff --git a/src/external_lcd.hpp b/src/espmega_iot_external_lcd.hpp similarity index 77% rename from src/external_lcd.hpp rename to src/espmega_iot_external_lcd.hpp index 3e16ecd..808650a 100644 --- a/src/external_lcd.hpp +++ b/src/espmega_iot_external_lcd.hpp @@ -5,7 +5,11 @@ #ifndef EXTERNAL_LCD_LOADED #define EXTERNAL_LCD_LOADED #include "user_code.hpp" + +extern void ext_lcd_callback(int id); + class ExternalLCD: public EasyNex { + using EasyNex::EasyNex; protected: void callTriggerFunction(); }; diff --git a/src/user_code.cpp b/src/user_code.cpp index f041534..6272b03 100644 --- a/src/user_code.cpp +++ b/src/user_code.cpp @@ -1,21 +1,28 @@ #include -void timer1_callback() -{ - for (int i = 0; i < 16; i++) - { - pwm_set_state(i, 1); - } -} ESPMega_Timer timer1(0, 50, timer1_callback, 15001); +//Display Componets +NexDSButton bt0 = NexDSButton(1, 2, "bt0"); +NexTouch *nex_listen_list[] = +{ + &bt0, + NULL +}; + +void bt0PopCallback(void *ptr) +{ + Serial.println("BTN0!"); +} + /* This Code will run right after ESPMega PRO's Peripheral Initialization Routine */ void user_pre_init() { + nexInit(); } /* @@ -28,7 +35,7 @@ void user_init() ESPMega_EXTLCD.write(0xFF); ESPMega_EXTLCD.write(0xFF); ESPMega_EXTLCD.write(0xFF); - + bt0.attachPop(bt0PopCallback, &bt0); } /* @@ -36,11 +43,10 @@ This code will run once every event loop */ void user_loop() { - if(Serial2.available()) { - Serial.println(Serial2.read()); - } + nexLoop(nex_listen_list); } + /* This code will run when an input pin changed state */ @@ -48,8 +54,8 @@ void virtual_interrupt_user_callback(int pin, int state) { } -void pwm_changed_user_callback(int pin) { - +void pwm_changed_user_callback(int pin) +{ } /* @@ -62,3 +68,11 @@ void timer_tick_callback() timer1.loop(); } } + +void timer1_callback() +{ + for (int i = 0; i < 16; i++) + { + pwm_set_state(i, 1); + } +} \ No newline at end of file diff --git a/src/user_code.hpp b/src/user_code.hpp index e0541f8..d8383cb 100644 --- a/src/user_code.hpp +++ b/src/user_code.hpp @@ -1,9 +1,10 @@ #pragma once #include -#include +#include #include #include #include "espmega_iot_timer.hpp" +#include "espmega_iot_external_lcd.hpp" // External LCD Configuration #define ENABLE_EXTERNAL_LCD @@ -21,6 +22,7 @@ void user_loop(); void virtual_interrupt_user_callback(int pin, int state); void pwm_changed_user_callback(int pin); void timer_tick_callback(); +void timer1_callback(); void bt0PopCallback(void *ptr); diff --git a/user_display/EXTDISP.HMI b/user_display/EXTDISP.HMI index fb654ec4e38ec6bbcd345a3d6794b8ffbc22fd66..3965a1e2ae05c3002accc34b0069aa5c1da0e61a 100644 GIT binary patch delta 726 zcmd6lNlSuJ6o&8p>{D`6v?z$6cDXS4BqPf*Et^vtw0TsU2QNfKn?ib_P2iOl->yxx zYFXeWf@s(TBGe}TLInN->lm%<543o=!#VHaS)ANw6%;=F)D7>E)=C5)*!HwE+mTJI=-EcuBfe@Xt5{3ZEI@|WZzshHJ?$ zO>m$Et#G0Z?Qo$3Zg|j%E_l(69`vFQ{TRR?hTwxA0SsdVqZmUFA&g@JlbFIZW-yC6 z%wqwISV9;PM6rw&tYQu8*uW;Xu#FwWZp4SC?q5_LhV`5#0{k}Rwu!8f8}w7V2&IHW yyeN9cD=O3`d!6Rd8v~*~MQgNPs#?DM>7tZUoT@COv{G87NG!U%yC)hny0dSLhv&=y delta 613 zcmd6kJ4ixd7>57p{9ex*`hgu zkb*Nr@Y@pCbG+ljaPE`^@ zN_@Q7Vkc+PPZlw%GV&&x^iInLsZv#%)4WE)`s-~vM>9EELK0X6Wdf_fX6C3}D`q+M z{L!g2rx`9>xNzaZg$oxhT)1%I)b1_*hr$)7U*&M49UV~72@kr^4KI4oi$3(j2R{Zd zh#?GP1fv+kI5bRP5&;A;g=vH^gIUaB9$`eVfJH1}87o*t6fvw}9UF)vflX{-8#_p1 z_nN&stp1D3o0Re4U>bciy$UPXjAIuInas`Zr8=cXe46bik_U0w*(y7na+^z5d`4Vl djr82ubF*6WP-T${YyRl-`PV&EF#;-U`34xQ*6aWP