Update minor things.

Signed-off-by: shennongmin <wupangfee@gmail.com>
This commit is contained in:
shennongmin
2015-08-12 15:38:29 +08:00
parent ec21d9d890
commit d8e5d01d60
3 changed files with 42 additions and 38 deletions

View File

@@ -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]);
}
}

View File

@@ -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;
}
}
}

View File

@@ -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 */