diff --git a/NexHardware.cpp b/NexHardware.cpp index 831a3e3..9db4c37 100644 --- a/NexHardware.cpp +++ b/NexHardware.cpp @@ -14,12 +14,6 @@ */ #include "NexHardware.h" -typedef enum { - NEX_EVENT_POP = 0x00, - NEX_EVENT_PUSH = 0x01, - NEX_EVENT_NULL -} NexEventType; - /*The first byte of Nextoin's return value*/ #define NEX_RET_CMD_FINISHED (0x01) #define NEX_RET_EVENT_LAUNCHED (0x88) @@ -224,34 +218,6 @@ bool recvRetCommandFinished(uint32_t timeout) } -static void iterate(NexTouch **list, NexPid pid, NexCid cid, NexEventType event) -{ - NexTouch *e = NULL; - uint16_t i = 0; - - if (NULL == list) - { - return; - } - - for(i = 0; (e = list[i]) != NULL; i++) - { - if (e->getPid() == pid && e->getCid() == cid) - { - e->print(); - if (NEX_EVENT_PUSH == event) - { - e->push(); - } - else if (NEX_EVENT_POP == event) - { - e->pop(); - } - - break; - } - } -} /** * Watting for Nextion's touch event. @@ -284,7 +250,7 @@ static void mainEventLoop(NexTouch **list) if (0xFF == __buffer[4] && 0xFF == __buffer[5] && 0xFF == __buffer[6]) { - iterate(list, (NexPid)__buffer[1], (NexCid)__buffer[2], (NexEventType)__buffer[3]); + NexTouch::iterate(list, (NexPid)__buffer[1], (NexCid)__buffer[2], (NexEventType)__buffer[3]); } } diff --git a/NexTouch.cpp b/NexTouch.cpp index 4249d42..7ac2fac 100644 --- a/NexTouch.cpp +++ b/NexTouch.cpp @@ -140,3 +140,32 @@ void NexTouch::pop(void) } } +void NexTouch::iterate(NexTouch **list, NexPid pid, NexCid cid, NexEventType event) +{ + NexTouch *e = NULL; + uint16_t i = 0; + + if (NULL == list) + { + return; + } + + for(i = 0; (e = list[i]) != NULL; i++) + { + if (e->getPid() == pid && e->getCid() == cid) + { + e->print(); + if (NEX_EVENT_PUSH == event) + { + e->push(); + } + else if (NEX_EVENT_POP == event) + { + e->pop(); + } + + break; + } + } +} + diff --git a/NexTouch.h b/NexTouch.h index 006d34e..280a227 100644 --- a/NexTouch.h +++ b/NexTouch.h @@ -24,12 +24,21 @@ typedef uint8_t NexCid; typedef void (*NexTouchEventCb)(void *ptr); +typedef enum { + NEX_EVENT_POP = 0x00, + NEX_EVENT_PUSH = 0x01, + NEX_EVENT_NULL +} NexEventType; + /** * Root Class of Nextion Components. * */ class NexTouch { +public: /* static methods */ + static void iterate(NexTouch **list, NexPid pid, NexCid cid, NexEventType event); + public: /* methods */ NexTouch(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL, @@ -38,9 +47,6 @@ public: /* methods */ NexPid getPid(void); NexCid getCid(void); const char *getObjName(void); - void print(void); - void push(void); - void pop(void); protected: /* methods */ void attachPush(NexTouchEventCb push, void *ptr = NULL); @@ -49,6 +55,9 @@ protected: /* methods */ void detachPop(void); private: /* methods */ + void print(void); + void push(void); + void pop(void); private: /* data */ NexPid pid; /* Page ID */