diff --git a/NexButton.cpp b/NexButton.cpp new file mode 100644 index 00000000..662ca07 --- /dev/null +++ b/NexButton.cpp @@ -0,0 +1,39 @@ +#include "NexButton.h" + +NexButton::NexButton(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr) + :NexTouch(pid, cid, name, pop, pop_ptr) +{ +} + +uint16_t NexButton::getText(char *buffer, uint16_t len) +{ + String cmd; + cmd += "get "; + cmd += getObjName(); + cmd += ".txt"; + sendCommand(cmd.c_str()); + return recvRetString(buffer,len); +} + +bool NexButton::setText(const char *buffer) +{ + String cmd; + cmd += getObjName(); + cmd += ".txt=\""; + cmd += buffer; + cmd += "\""; + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + +void NexButton::attachPop(NexTouchEventCb pop, void *ptr) +{ + NexTouch::attachPop(pop, ptr); +} + +void NexButton::detachPop(void) +{ + NexTouch::detachPop(); +} + + diff --git a/NexButton.h b/NexButton.h new file mode 100644 index 00000000..1638975 --- /dev/null +++ b/NexButton.h @@ -0,0 +1,23 @@ +#ifndef __NEXBUTTON_H__ +#define __NEXBUTTON_H__ +#ifdef __cplusplus +#include "NexTouch.h" + + +/* + * Button + */ +class NexButton: public NexTouch +{ +public: /* methods */ + NexButton(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL); + + void attachPop(NexTouchEventCb pop, void *ptr = NULL); + void detachPop(void); + + uint16_t getText(char *buffer, uint16_t len); + bool setText(const char *buffer); +}; + +#endif /* #ifdef __cplusplus */ +#endif /* #ifndef __NEXBUTTON_H__ */ diff --git a/NexHotspot.cpp b/NexHotspot.cpp new file mode 100644 index 00000000..c2e6c01 --- /dev/null +++ b/NexHotspot.cpp @@ -0,0 +1,28 @@ +#include "NexHotspot.h" + +NexHotspot::NexHotspot(NexPid pid, NexCid cid, char *name, + NexTouchEventCb pop, void *pop_ptr, + NexTouchEventCb push, void *push_ptr) + :NexTouch(pid, cid, name, pop, pop_ptr, push, push_ptr) +{ +} + +void NexHotspot::attachPush(NexTouchEventCb push, void *ptr) +{ + NexTouch::attachPush(push, ptr); +} + +void NexHotspot::detachPush(void) +{ + NexTouch::detachPush(); +} + +void NexHotspot::attachPop(NexTouchEventCb pop, void *ptr) +{ + NexTouch::attachPop(pop, ptr); +} + +void NexHotspot::detachPop(void) +{ + NexTouch::detachPop(); +} diff --git a/NexHotspot.h b/NexHotspot.h new file mode 100644 index 00000000..18b20f8 --- /dev/null +++ b/NexHotspot.h @@ -0,0 +1,25 @@ +#ifndef __NEXHOTSPOT_H__ +#define __NEXHOTSPOT_H__ +#ifdef __cplusplus +#include "NexTouch.h" + + +/* + * Hotspot + */ +class NexHotspot: public NexTouch +{ +public: /* methods */ + NexHotspot(NexPid pid, NexCid cid, char *name, + NexTouchEventCb pop = NULL, void *pop_ptr = NULL, + NexTouchEventCb push = NULL, void *push_ptr = NULL); + + void attachPush(NexTouchEventCb push, void *ptr = NULL); + void detachPush(void); + void attachPop(NexTouchEventCb pop, void *ptr = NULL); + void detachPop(void); + +}; + +#endif /* #ifdef __cplusplus */ +#endif /* #ifndef __NEXHOTSPOT_H__ */ diff --git a/NexPage.cpp b/NexPage.cpp new file mode 100644 index 00000000..eff529a --- /dev/null +++ b/NexPage.cpp @@ -0,0 +1,32 @@ +#include "NexPage.h" + +NexPage::NexPage(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr) + :NexTouch(pid, cid, name, pop, pop_ptr) +{ +} + +bool NexPage::show(void) +{ + uint8_t buffer[4] = {0}; + + const char *name = getObjName(); + if (!name) + { + return false; + } + + String cmd = String("page "); + cmd += name; + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + +void NexPage::attachPop(NexTouchEventCb pop, void *ptr) +{ + NexTouch::attachPop(pop, ptr); +} + +void NexPage::detachPop(void) +{ + NexTouch::detachPop(); +} diff --git a/NexPage.h b/NexPage.h new file mode 100644 index 00000000..620007e --- /dev/null +++ b/NexPage.h @@ -0,0 +1,22 @@ +#ifndef __NEXPAGE_H__ +#define __NEXPAGE_H__ +#ifdef __cplusplus +#include "NexTouch.h" + + +/* + * Page + */ +class NexPage: public NexTouch +{ +public: /* methods */ + NexPage(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL); + bool show(void); + + void attachPop(NexTouchEventCb pop, void *ptr = NULL); + void detachPop(void); + +}; + +#endif /* #ifdef __cplusplus */ +#endif /* #ifndef __NEXPAGE_H__ */ diff --git a/NexPicture.cpp b/NexPicture.cpp new file mode 100644 index 00000000..bee30f6 --- /dev/null +++ b/NexPicture.cpp @@ -0,0 +1,42 @@ +#include "NexPicture.h" + + +NexPicture::NexPicture(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr) + :NexTouch(pid, cid, name, pop, pop_ptr) +{ +} + +bool NexPicture::getPic(uint32_t *number) +{ + String cmd = String("get "); + cmd += getObjName(); + cmd += ".pic"; + sendCommand(cmd.c_str()); + return recvRetNumber(number); +} + +bool NexPicture::setPic(uint32_t number) +{ + char buf[10] = {0}; + String cmd; + + utoa(number, buf, 10); + cmd += getObjName(); + cmd += ".pic="; + cmd += buf; + + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + + +void NexPicture::attachPop(NexTouchEventCb pop, void *ptr) +{ + NexTouch::attachPop(pop, ptr); +} + +void NexPicture::detachPop(void) +{ + NexTouch::detachPop(); +} + diff --git a/NexPicture.h b/NexPicture.h new file mode 100644 index 00000000..cb83eef --- /dev/null +++ b/NexPicture.h @@ -0,0 +1,23 @@ +#ifndef __NEXPICTURE_H__ +#define __NEXPICTURE_H__ +#ifdef __cplusplus +#include "NexTouch.h" + + +/* + * NexPicture + */ +class NexPicture: public NexTouch +{ +public: /* methods */ + NexPicture(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL); + + void attachPop(NexTouchEventCb pop, void *ptr = NULL); + void detachPop(void); + + bool getPic(uint32_t *number); + bool setPic(uint32_t number); +}; + +#endif /* #ifdef __cplusplus */ +#endif /* #ifndef __NEXPICTURE_H__ */ diff --git a/NexPointer.cpp b/NexPointer.cpp new file mode 100644 index 00000000..c692269 --- /dev/null +++ b/NexPointer.cpp @@ -0,0 +1,31 @@ +#include "NexPointer.h" + + +NexPointer::NexPointer(NexPid pid, NexCid cid, char *name) + :NexTouch(pid, cid, name) +{ +} + +bool NexPointer::getValue(uint32_t *number) +{ + String cmd = String("get "); + cmd += getObjName(); + cmd += ".val"; + sendCommand(cmd.c_str()); + return recvRetNumber(number); +} + +bool NexPointer::setValue(uint32_t number) +{ + char buf[10] = {0}; + String cmd; + + utoa(number, buf, 10); + cmd += getObjName(); + cmd += ".val="; + cmd += buf; + + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + diff --git a/NexPointer.h b/NexPointer.h new file mode 100644 index 00000000..cc9f243 --- /dev/null +++ b/NexPointer.h @@ -0,0 +1,20 @@ +#ifndef __NEXPOINTER_H__ +#define __NEXPOINTER_H__ +#ifdef __cplusplus +#include "NexTouch.h" + + +/* + * NexPointer + */ +class NexPointer: public NexTouch +{ +public: /* methods */ + NexPointer(NexPid pid, NexCid cid, char *name); + + bool getValue(uint32_t *number); + bool setValue(uint32_t number); +}; + +#endif /* #ifdef __cplusplus */ +#endif /* #ifndef __NEXPOINTER_H__ */ diff --git a/NexProgressBar.cpp b/NexProgressBar.cpp new file mode 100644 index 00000000..d3966f2 --- /dev/null +++ b/NexProgressBar.cpp @@ -0,0 +1,31 @@ +#include "NexProgressBar.h" + + +NexProgressBar::NexProgressBar(NexPid pid, NexCid cid, char *name) + :NexTouch(pid, cid, name) +{ +} + +bool NexProgressBar::getValue(uint32_t *number) +{ + String cmd = String("get "); + cmd += getObjName(); + cmd += ".val"; + sendCommand(cmd.c_str()); + return recvRetNumber(number); +} + +bool NexProgressBar::setValue(uint32_t number) +{ + char buf[10] = {0}; + String cmd; + + utoa(number, buf, 10); + cmd += getObjName(); + cmd += ".val="; + cmd += buf; + + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + diff --git a/NexProgressBar.h b/NexProgressBar.h new file mode 100644 index 00000000..9e3f546 --- /dev/null +++ b/NexProgressBar.h @@ -0,0 +1,20 @@ +#ifndef __NEXPROGRESSBAR_H__ +#define __NEXPROGRESSBAR_H__ +#ifdef __cplusplus +#include "NexTouch.h" + + +/* + * NexProgressBar + */ +class NexProgressBar: public NexTouch +{ +public: /* methods */ + NexProgressBar(NexPid pid, NexCid cid, char *name); + + bool getValue(uint32_t *number); + bool setValue(uint32_t number); +}; + +#endif /* #ifdef __cplusplus */ +#endif /* #ifndef __NEXPROGRESSBAR_H__ */ diff --git a/NexSlice.cpp b/NexSlice.cpp new file mode 100644 index 00000000..f93b4c8 --- /dev/null +++ b/NexSlice.cpp @@ -0,0 +1,42 @@ +#include "NexSlice.h" + + +NexSlice::NexSlice(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr) + :NexTouch(pid, cid, name, pop, pop_ptr) +{ +} + +bool NexSlice::getPic(uint32_t *number) +{ + String cmd = String("get "); + cmd += getObjName(); + cmd += ".picc"; + sendCommand(cmd.c_str()); + return recvRetNumber(number); +} + +bool NexSlice::setPic(uint32_t number) +{ + char buf[10] = {0}; + String cmd; + + utoa(number, buf, 10); + cmd += getObjName(); + cmd += ".picc="; + cmd += buf; + + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + + +void NexSlice::attachPop(NexTouchEventCb pop, void *ptr) +{ + NexTouch::attachPop(pop, ptr); +} + +void NexSlice::detachPop(void) +{ + NexTouch::detachPop(); +} + diff --git a/NexSlice.h b/NexSlice.h new file mode 100644 index 00000000..24f21bf --- /dev/null +++ b/NexSlice.h @@ -0,0 +1,23 @@ +#ifndef __NEXSLICE_H__ +#define __NEXSLICE_H__ +#ifdef __cplusplus +#include "NexTouch.h" + + +/* + * NexSlice + */ +class NexSlice: public NexTouch +{ +public: /* methods */ + NexSlice(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL); + + void attachPop(NexTouchEventCb pop, void *ptr = NULL); + void detachPop(void); + + bool getPic(uint32_t *number); + bool setPic(uint32_t number); +}; + +#endif /* #ifdef __cplusplus */ +#endif /* #ifndef __NEXSLICE_H__ */ diff --git a/NexText.cpp b/NexText.cpp new file mode 100644 index 00000000..2b45c64 --- /dev/null +++ b/NexText.cpp @@ -0,0 +1,39 @@ +#include "NexText.h" + + +NexText::NexText(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr) + :NexTouch(pid, cid, name, pop, pop_ptr) +{ +} + +uint16_t NexText::getText(char *buffer, uint16_t len) +{ + String cmd; + cmd += "get "; + cmd += getObjName(); + cmd += ".txt"; + sendCommand(cmd.c_str()); + return recvRetString(buffer,len); +} + +bool NexText::setText(const char *buffer) +{ + String cmd; + cmd += getObjName(); + cmd += ".txt=\""; + cmd += buffer; + cmd += "\""; + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + +void NexText::attachPop(NexTouchEventCb pop, void *ptr) +{ + NexTouch::attachPop(pop, ptr); +} + +void NexText::detachPop(void) +{ + NexTouch::detachPop(); +} + diff --git a/NexText.h b/NexText.h new file mode 100644 index 00000000..200a3ac --- /dev/null +++ b/NexText.h @@ -0,0 +1,23 @@ +#ifndef __NEXTEXT_H__ +#define __NEXTEXT_H__ +#ifdef __cplusplus +#include "NexTouch.h" + + +/* + * NexText + */ +class NexText: public NexTouch +{ +public: /* methods */ + NexText(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL); + + void attachPop(NexTouchEventCb pop, void *ptr = NULL); + void detachPop(void); + + uint16_t getText(char *buffer, uint16_t len); + bool setText(const char *buffer); +}; + +#endif /* #ifdef __cplusplus */ +#endif /* #ifndef __NEXTEXT_H__ */ diff --git a/NexTouch.cpp b/NexTouch.cpp new file mode 100644 index 00000000..7c45afd --- /dev/null +++ b/NexTouch.cpp @@ -0,0 +1,348 @@ +#include "NexTouch.h" + +uint8_t NexTouch::__buffer[256] = {0}; + +uint8_t NexTouch::mainEventLoop(NexTouch **list) +{ + uint16_t i; + uint8_t c; + + while (true) + { + while (nexSerial.available() > 0) + { + delay(10); + c = nexSerial.read(); + + if (NEX_RET_EVENT_TOUCH_HEAD == c) + { + if (nexSerial.available() >= 6) + { + //memset(__buffer, 0, sizeof(__buffer)); + __buffer[0] = c; + for (i = 1; i < 7; i++) + { + __buffer[i] = nexSerial.read(); + } + __buffer[i] = 0x00; + + if (0xFF == __buffer[4] && 0xFF == __buffer[5] && 0xFF == __buffer[6]) + { + iterate(list, (NexPid)__buffer[1], (NexCid)__buffer[2], (NexEventType)__buffer[3]); + } + + } + } + } + } + return 0; +} + +NexTouch::NexTouch(NexPid pid, NexCid cid, char *name, + NexTouchEventCb pop, void *pop_ptr, + NexTouchEventCb push, void *push_ptr) +{ + this->pid = pid; + this->cid = cid; + this->name = name; + this->cbPush = push; + this->cbPop = pop; + this->__cbpop_ptr = pop_ptr; + this->__cbpush_ptr = push_ptr; +} + +NexPid NexTouch::getPid(void) +{ + return pid; +} + +NexCid NexTouch::getCid(void) +{ + return cid; +} + +const char* NexTouch::getObjName(void) +{ + return name; +} + +void NexTouch::print(void) +{ + dbSerial.print("["); + dbSerial.print((uint32_t)this); + dbSerial.print(":"); + dbSerial.print(pid); + dbSerial.print(","); + dbSerial.print(cid); + dbSerial.print(","); + if (name) + { + dbSerial.print(name); + } + else + { + dbSerial.print("(null)"); + } + dbSerial.print(","); + dbSerial.print((uint32_t)cbPush); + dbSerial.print(","); + dbSerial.print((uint32_t)cbPop); + dbSerial.println("]"); +} + +void NexTouch::attachPush(NexTouchEventCb push, void *ptr) +{ + this->cbPush = push; + this->__cbpush_ptr = ptr; +} + +void NexTouch::detachPush(void) +{ + this->cbPush = NULL; + this->__cbpush_ptr = NULL; +} + +void NexTouch::attachPop(NexTouchEventCb pop, void *ptr) +{ + this->cbPop = pop; + this->__cbpop_ptr = ptr; +} + +void NexTouch::detachPop(void) +{ + this->cbPop = NULL; + this->__cbpop_ptr = NULL; +} + + +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; + } + } +} + + +void NexTouch::push(void) +{ + if (cbPush) + { + cbPush(__cbpush_ptr); + } +} + +void NexTouch::pop(void) +{ + if (cbPop) + { + cbPop(__cbpop_ptr); + } +} + +bool NexTouch::recvRetCommandFinished(uint32_t timeout) +{ + bool ret = false; + uint8_t temp[4] = {0}; + + nexSerial.setTimeout(timeout); + if (sizeof(temp) != nexSerial.readBytes((char *)temp, sizeof(temp))) + { + ret = false; + } + + if (temp[0] == NEX_RET_CMD_FINISHED + && temp[1] == 0xFF + && temp[2] == 0xFF + && temp[3] == 0xFF + ) + { + ret = true; + } + + if (ret) + { + dbSerial.println("recvRetCommandFinished ok"); + } + else + { + dbSerial.println("recvRetCommandFinished err"); + } + + return ret; +} + +void NexTouch::sendCommand(const char* cmd) +{ + while (nexSerial.available()) + { + nexSerial.read(); + } + + nexSerial.print(cmd); + nexSerial.write(0xFF); + nexSerial.write(0xFF); + nexSerial.write(0xFF); +} + +/* 0X70 0X61 0X62 0X63 0x... 0XFF 0XFF 0XFF */ +uint16_t NexTouch::recvRetString(char *buffer, uint16_t len, uint32_t timeout) +{ + uint16_t ret = 0; + bool str_start_flag = false; + uint8_t cnt_0xff = 0; + String temp = String(""); + uint8_t c = 0; + long start; + + if (!buffer || len == 0) + { + goto __return; + } + + start = millis(); + while (millis() - start <= timeout) + { + while (nexSerial.available()) + { + c = nexSerial.read(); + if (str_start_flag) + { + if (0xFF == c) + { + cnt_0xff++; + if (cnt_0xff >= 3) + { + break; + } + } + else + { + temp += (char)c; + } + } + else if (NEX_RET_STRING_HEAD == c) + { + str_start_flag = true; + } + } + + if (cnt_0xff >= 3) + { + break; + } + } + + ret = temp.length(); + ret = ret > len ? len : ret; + strncpy(buffer, temp.c_str(), ret); + +__return: + + dbSerial.print("recvRetString["); + dbSerial.print(temp.length()); + dbSerial.print(","); + dbSerial.print(temp); + dbSerial.println("]"); + + return ret; +} + +/* 0X71 0X66 0X00 0X00 0X00 0XFF 0XFF 0XFF */ +bool NexTouch::recvRetNumber(uint32_t *number, uint32_t timeout) +{ + bool ret = false; + uint8_t temp[8] = {0}; + + if (!number) + { + goto __return; + } + + nexSerial.setTimeout(timeout); + if (sizeof(temp) != nexSerial.readBytes((char *)temp, sizeof(temp))) + { + goto __return; + } + + if (temp[0] == NEX_RET_NUMBER_HEAD + && temp[5] == 0xFF + && temp[6] == 0xFF + && temp[7] == 0xFF + ) + { + *number = (temp[4] << 24) | (temp[3] << 16) | (temp[2] << 8) | (temp[1]); + ret = true; + } + +__return: + + if (ret) + { + dbSerial.print("recvRetNumber :"); + dbSerial.println(*number); + } + else + { + dbSerial.println("recvRetNumber err"); + } + + return ret; +} + +bool NexTouch::setBrightness(uint32_t brightness) +{ + char buf[10] = {0}; + String cmd; + + utoa(brightness, buf, 10); + cmd += "dim="; + cmd += buf; + + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + +bool NexTouch::getBrightness(uint32_t *brightness) +{ + sendCommand("get dim"); + return recvRetNumber(brightness); +} + +bool nexInit(void) +{ + nexSerial.begin(9600); + NexTouch::sendCommand(""); + NexTouch::sendCommand("page 0"); + delay(100); + return true; +} + +bool nexLoop(NexTouch **nexListenList) +{ + NexTouch::mainEventLoop(nexListenList); + return false; +} + + diff --git a/NexTouch.h b/NexTouch.h new file mode 100644 index 00000000..cde79d9 --- /dev/null +++ b/NexTouch.h @@ -0,0 +1,97 @@ +#ifndef __NEXTOUCH_H__ +#define __NEXTOUCH_H__ +#ifdef __cplusplus +#include + +#define dbSerial Serial +#define nexSerial Serial2 + +typedef uint8_t NexPid; +typedef uint8_t NexCid; + +typedef enum { + NEX_EVENT_POP = 0x00, + NEX_EVENT_PUSH = 0x01, + NEX_EVENT_NULL +} NexEventType; + +#define NEX_RET_CMD_FINISHED (0x01) +#define NEX_RET_EVENT_LAUNCHED (0x88) +#define NEX_RET_EVENT_UPGRADED (0x89) + +#define NEX_RET_EVENT_TOUCH_HEAD (0x65) +#define NEX_RET_EVENT_POSITION_HEAD (0x67) +#define NEX_RET_EVENT_SLEEP_POSITION_HEAD (0x68) +#define NEX_RET_CURRENT_PAGE_ID_HEAD (0x66) +#define NEX_RET_STRING_HEAD (0x70) +#define NEX_RET_NUMBER_HEAD (0x71) + +#define NEX_RET_INVALID_CMD (0x00) +#define NEX_RET_INVALID_COMPONENT_ID (0x02) +#define NEX_RET_INVALID_PAGE_ID (0x03) +#define NEX_RET_INVALID_PICTURE_ID (0x04) +#define NEX_RET_INVALID_FONT_ID (0x05) +#define NEX_RET_INVALID_BAUD (0x11) +#define NEX_RET_INVALID_VARIABLE (0x1A) +#define NEX_RET_INVALID_OPERATION (0x1B) + + +typedef void (*NexTouchEventCb)(void *ptr); + +/* + * Root Class of Nextion Components + */ +class NexTouch +{ +public: /* static methods */ + static uint8_t mainEventLoop(NexTouch **list); + static void sendCommand(const char *cmd); + static bool recvRetCommandFinished(uint32_t timeout = 100); + static uint16_t recvRetString(char *buffer, uint16_t len, uint32_t timeout = 500); + static bool recvRetNumber(uint32_t *number, uint32_t timeout = 500); + +public: /* methods */ + NexTouch(NexPid pid, NexCid cid, char *name, + NexTouchEventCb pop = NULL, void *pop_ptr = NULL, + NexTouchEventCb push = NULL, void *push_ptr = NULL); + + NexPid getPid(void); + NexCid getCid(void); + const char *getObjName(void); + void print(void); + +protected: /* static methods */ + static bool setBrightness(uint32_t brightness); + static bool getBrightness(uint32_t *brightness); + +protected: /* methods */ + void attachPush(NexTouchEventCb push, void *ptr = NULL); + void detachPush(void); + void attachPop(NexTouchEventCb pop, void *ptr = NULL); + void detachPop(void); + +private: /* static methods */ + static void iterate(NexTouch **list, NexPid pid, NexCid cid, NexEventType event); + +private: /* methods */ + void push(void); + void pop(void); + +private: /* static data */ + static uint8_t __buffer[256]; + +private: /* data */ + NexPid pid; /* Page ID */ + NexCid cid; /* Component ID */ + char *name; /* An unique name */ + NexTouchEventCb cbPush; + void *__cbpush_ptr; + NexTouchEventCb cbPop; + void *__cbpop_ptr; +}; + +bool nexInit(void); +bool nexLoop(NexTouch **nexListenList); + +#endif /* #ifdef __cplusplus */ +#endif /* #ifndef __NEXTOUCH_H__ */ diff --git a/examples/CompButton/CompButton.HMI b/examples/CompButton/CompButton.HMI new file mode 100644 index 00000000..ba6a450 Binary files /dev/null and b/examples/CompButton/CompButton.HMI differ diff --git a/examples/CompButton/CompButton.ino b/examples/CompButton/CompButton.ino new file mode 100644 index 00000000..642d26e --- /dev/null +++ b/examples/CompButton/CompButton.ino @@ -0,0 +1,46 @@ +#include "NexButton.h" + +NexButton b0 = NexButton(0, 1, "b0"); +char buffer[100] = {0}; + +NexTouch *nexListenList[] = +{ + &b0, + NULL +}; + +void b0PopCallback(void *ptr) +{ + uint16_t len; + uint16_t number; + NexButton *btn = (NexButton *)ptr; + + dbSerial.println("b0PopCallback"); + dbSerial.print("ptr="); + dbSerial.println((uint32_t)ptr); + + memset(buffer, 0, sizeof(buffer)); + btn->getText(buffer, sizeof(buffer)); + + number = atoi(buffer); + number += 1; + + memset(buffer, 0, sizeof(buffer)); + itoa(number, buffer, 10); + + btn->setText(buffer); +} + +void setup(void) +{ + dbSerial.begin(9600); + nexInit(); + b0.attachPop(b0PopCallback, &b0); + dbSerial.println("setup done"); +} + +void loop(void) +{ + dbSerial.println("nexLoop"); + nexLoop(nexListenList); +} diff --git a/examples/CompButton/CompButton.tft b/examples/CompButton/CompButton.tft new file mode 100644 index 00000000..966e921 Binary files /dev/null and b/examples/CompButton/CompButton.tft differ diff --git a/examples/CompHotspot/CompHotspot.HMI b/examples/CompHotspot/CompHotspot.HMI new file mode 100644 index 00000000..34ddc97 Binary files /dev/null and b/examples/CompHotspot/CompHotspot.HMI differ diff --git a/examples/CompHotspot/CompHotspot.ino b/examples/CompHotspot/CompHotspot.ino new file mode 100644 index 00000000..34257ee --- /dev/null +++ b/examples/CompHotspot/CompHotspot.ino @@ -0,0 +1,56 @@ +#include "NexHotspot.h" + +NexHotspot hot0 = NexHotspot(0, 1, "hot0"); +NexHotspot hot1 = NexHotspot(0, 2, "hot1"); + +NexTouch *nexListenList[] = +{ + &hot0, + &hot1, + NULL +}; + +void hot0PushCallback(void *ptr) +{ + dbSerial.println("hot0PushCallback"); + dbSerial.print("ptr="); + dbSerial.println((uint32_t)ptr); +} + +void hot1PushCallback(void *ptr) +{ + dbSerial.println("hot1PushCallback"); + dbSerial.print("ptr="); + dbSerial.println((uint32_t)ptr); +} + +void hot0PopCallback(void *ptr) +{ + dbSerial.println("hot0PopCallback"); + dbSerial.print("ptr="); + dbSerial.println((uint32_t)ptr); +} + +void hot1PopCallback(void *ptr) +{ + dbSerial.println("hot1PopCallback"); + dbSerial.print("ptr="); + dbSerial.println((uint32_t)ptr); +} + +void setup(void) +{ + dbSerial.begin(9600); + nexInit(); + hot0.attachPush(hot0PushCallback, &hot0); + hot0.attachPop(hot0PopCallback, &hot0); + hot1.attachPush(hot1PushCallback, &hot1); + hot1.attachPop(hot1PopCallback, &hot1); + dbSerial.println("setup done"); +} + +void loop(void) +{ + dbSerial.println("nexLoop"); + nexLoop(nexListenList); +} diff --git a/examples/CompHotspot/CompHotspot.tft b/examples/CompHotspot/CompHotspot.tft new file mode 100644 index 00000000..2b87099 Binary files /dev/null and b/examples/CompHotspot/CompHotspot.tft differ diff --git a/examples/CompPage/CompPage.HMI b/examples/CompPage/CompPage.HMI new file mode 100644 index 00000000..0672293 Binary files /dev/null and b/examples/CompPage/CompPage.HMI differ diff --git a/examples/CompPage/CompPage.ino b/examples/CompPage/CompPage.ino new file mode 100644 index 00000000..c5ea41c --- /dev/null +++ b/examples/CompPage/CompPage.ino @@ -0,0 +1,59 @@ +#include "NexPage.h" + +NexPage page0 = NexPage(0, 0, "page0"); +NexPage page1 = NexPage(1, 0, "page1"); +NexPage page2 = NexPage(2, 0, "page2"); +NexPage page3 = NexPage(3, 0, "page3"); + +NexTouch *nexListenList[] = +{ + &page0, + &page1, + &page2, + &page3, + NULL +}; + +void page0PopCallback(void *ptr) +{ + dbSerial.println("page0PopCallback"); + page1.show(); +} + +void page1PopCallback(void *ptr) +{ + dbSerial.println("page1PopCallback"); + page2.show(); +} + +void page2PopCallback(void *ptr) +{ + dbSerial.println("page2PopCallback"); + page3.show(); +} + +void page3PopCallback(void *ptr) +{ + dbSerial.println("page3PopCallback"); + page0.show(); +} + +void setup(void) +{ + dbSerial.begin(9600); + nexInit(); + dbSerial.println("setup begin"); + + page0.attachPop(page0PopCallback); + page1.attachPop(page1PopCallback); + page2.attachPop(page2PopCallback); + page3.attachPop(page3PopCallback); + + dbSerial.println("setup end"); +} + +void loop(void) +{ + dbSerial.println("nexLoop"); + nexLoop(nexListenList); +} diff --git a/examples/CompPage/CompPage.tft b/examples/CompPage/CompPage.tft new file mode 100644 index 00000000..40cd9b8 Binary files /dev/null and b/examples/CompPage/CompPage.tft differ diff --git a/examples/CompPicture/CompPicture.HMI b/examples/CompPicture/CompPicture.HMI new file mode 100644 index 00000000..5d0705a Binary files /dev/null and b/examples/CompPicture/CompPicture.HMI differ diff --git a/examples/CompPicture/CompPicture.ino b/examples/CompPicture/CompPicture.ino new file mode 100644 index 00000000..fef9451 --- /dev/null +++ b/examples/CompPicture/CompPicture.ino @@ -0,0 +1,44 @@ +#include "NexPicture.h" + +NexPicture p0 = NexPicture(0, 1, "p0"); + +NexTouch *nexListenList[] = +{ + &p0, + NULL +}; + +void p0PopCallback(void *ptr) +{ + uint32_t number = 0; + dbSerial.println("p0PopCallback"); + + p0.getPic(&number); + + if (number == 1) + { + number = 2; + } + else + { + number = 1; + } + + p0.setPic(number); +} + + +void setup(void) +{ + dbSerial.begin(9600); + nexInit(); + p0.attachPop(p0PopCallback); + dbSerial.println("setup done"); +} + +void loop(void) +{ + dbSerial.println("nexLoop"); + nexLoop(nexListenList); +} + diff --git a/examples/CompPicture/CompPicture.tft b/examples/CompPicture/CompPicture.tft new file mode 100644 index 00000000..34d3471 Binary files /dev/null and b/examples/CompPicture/CompPicture.tft differ diff --git a/examples/CompPointer/CompPointer.HMI b/examples/CompPointer/CompPointer.HMI new file mode 100644 index 00000000..290e1bf Binary files /dev/null and b/examples/CompPointer/CompPointer.HMI differ diff --git a/examples/CompPointer/CompPointer.ino b/examples/CompPointer/CompPointer.ino new file mode 100644 index 00000000..55f9716 --- /dev/null +++ b/examples/CompPointer/CompPointer.ino @@ -0,0 +1,61 @@ +#include "NexPointer.h" +#include "NexButton.h" + +NexPointer pointer = NexPointer(0, 1, "pointer"); +NexButton btn_up = NexButton(0, 2, "btn_up"); +NexButton btn_down = NexButton(0, 3, "btn_down"); + +NexTouch *nexListenList[] = +{ + &btn_up, + &btn_down, + NULL +}; + +void buttonUpPopCallback(void *ptr) +{ + uint32_t number = 0; + dbSerial.println("buttonUpPopCallback"); + + pointer.getValue(&number); + + number += 5; + if (number >= 360) + { + number = 0; + } + + pointer.setValue(number); +} +void buttonDownPopCallback(void *ptr) +{ + uint32_t number = 0; + dbSerial.println("buttonDownPopCallback"); + + pointer.getValue(&number); + + if (number >= 5) + { + number -= 5; + } + + pointer.setValue(number); +} + + + +void setup(void) +{ + dbSerial.begin(9600); + nexInit(); + btn_up.attachPop(buttonUpPopCallback); + btn_down.attachPop(buttonDownPopCallback); + dbSerial.println("setup done"); +} + +void loop(void) +{ + dbSerial.println("nexLoop"); + nexLoop(nexListenList); +} + diff --git a/examples/CompPointer/CompPointer.tft b/examples/CompPointer/CompPointer.tft new file mode 100644 index 00000000..0b149d3 Binary files /dev/null and b/examples/CompPointer/CompPointer.tft differ diff --git a/examples/CompProgressBar/CompProgressBar.HMI b/examples/CompProgressBar/CompProgressBar.HMI new file mode 100644 index 00000000..d0d982b Binary files /dev/null and b/examples/CompProgressBar/CompProgressBar.HMI differ diff --git a/examples/CompProgressBar/CompProgressBar.ino b/examples/CompProgressBar/CompProgressBar.ino new file mode 100644 index 00000000..913914a --- /dev/null +++ b/examples/CompProgressBar/CompProgressBar.ino @@ -0,0 +1,63 @@ +#include "NexProgressBar.h" +#include "NexButton.h" + +NexProgressBar j0 = NexProgressBar(0, 3, "j0"); +NexButton btn_up = NexButton(0, 1, "btn_up"); +NexButton btn_down = NexButton(0, 2, "btn_down"); + +NexTouch *nexListenList[] = +{ + &btn_up, + &btn_down, + NULL +}; + +void buttonUpPopCallback(void *ptr) +{ + uint32_t number = 0; + dbSerial.println("buttonUpPopCallback"); + + j0.getValue(&number); + + number += 5; + if (number >= 100) + { + number = 100; + } + + j0.setValue(number); +} +void buttonDownPopCallback(void *ptr) +{ + uint32_t number = 0; + dbSerial.println("buttonDownPopCallback"); + + j0.getValue(&number); + + if (number >= 5) + { + number -= 5; + } + + j0.setValue(number); +} + + + +void setup(void) +{ + uint32_t brightness = 0; + + dbSerial.begin(9600); + nexInit(); + btn_up.attachPop(buttonUpPopCallback); + btn_down.attachPop(buttonDownPopCallback); + dbSerial.println("setup done"); +} + +void loop(void) +{ + dbSerial.println("nexLoop"); + nexLoop(nexListenList); +} + diff --git a/examples/CompProgressBar/CompProgressBar.tft b/examples/CompProgressBar/CompProgressBar.tft new file mode 100644 index 00000000..f458eab Binary files /dev/null and b/examples/CompProgressBar/CompProgressBar.tft differ diff --git a/examples/CompSlice/CompSlice.HMI b/examples/CompSlice/CompSlice.HMI new file mode 100644 index 00000000..08aeacd Binary files /dev/null and b/examples/CompSlice/CompSlice.HMI differ diff --git a/examples/CompSlice/CompSlice.ino b/examples/CompSlice/CompSlice.ino new file mode 100644 index 00000000..c0b5e63 --- /dev/null +++ b/examples/CompSlice/CompSlice.ino @@ -0,0 +1,38 @@ +#include "NexSlice.h" + +NexSlice q0 = NexSlice(0, 1, "q0"); + +NexTouch *nexListenList[] = +{ + &q0, + NULL +}; + +void q0PopCallback(void *ptr) +{ + uint32_t number = 0; + dbSerial.println("q0PopCallback"); + + q0.getPic(&number); + + number += 1; + number %= 2; + + q0.setPic(number); +} + + +void setup(void) +{ + dbSerial.begin(9600); + nexInit(); + q0.attachPop(q0PopCallback); + dbSerial.println("setup done"); +} + +void loop(void) +{ + dbSerial.println("nexLoop"); + nexLoop(nexListenList); +} + diff --git a/examples/CompSlice/CompSlice.tft b/examples/CompSlice/CompSlice.tft new file mode 100644 index 00000000..bb0b083 Binary files /dev/null and b/examples/CompSlice/CompSlice.tft differ diff --git a/examples/CompText/CompText.HMI b/examples/CompText/CompText.HMI new file mode 100644 index 00000000..4a62088 Binary files /dev/null and b/examples/CompText/CompText.HMI differ diff --git a/examples/CompText/CompText.ino b/examples/CompText/CompText.ino new file mode 100644 index 00000000..50cdefc --- /dev/null +++ b/examples/CompText/CompText.ino @@ -0,0 +1,78 @@ +#include "NexButton.h" +#include "NexText.h" + +void t0PopCallback(void *ptr); +void b0PopCallback(void *ptr); +void b1PopCallback(void *ptr); + +NexText t0 = NexText(0, 1, "t0", t0PopCallback); +NexButton b0 = NexButton(0, 2, "b0", b0PopCallback); +NexButton b1 = NexButton(0, 3, "b1", b1PopCallback); + +char buffer[100] = {0}; + +NexTouch *nexListenList[] = +{ + &t0, + &b0, + &b1, + NULL +}; + +void t0PopCallback(void *ptr) +{ + dbSerial.println("t0PopCallback"); + t0.setText("50"); +} + +void b0PopCallback(void *ptr) +{ + uint16_t len; + uint16_t number; + + dbSerial.println("b0PopCallback"); + + memset(buffer, 0, sizeof(buffer)); + t0.getText(buffer, sizeof(buffer)); + + number = atoi(buffer); + number += 1; + + memset(buffer, 0, sizeof(buffer)); + itoa(number, buffer, 10); + + t0.setText(buffer); +} + +void b1PopCallback(void *ptr) +{ + uint16_t len; + uint16_t number; + + dbSerial.println("b1PopCallback"); + + memset(buffer, 0, sizeof(buffer)); + t0.getText(buffer, sizeof(buffer)); + + number = atoi(buffer); + number -= 1; + + memset(buffer, 0, sizeof(buffer)); + itoa(number, buffer, 10); + + t0.setText(buffer); +} + +void setup(void) +{ + dbSerial.begin(9600); + nexInit(); + dbSerial.println("setup done"); +} + +void loop(void) +{ + dbSerial.println("nexLoop"); + nexLoop(nexListenList); +} + diff --git a/examples/CompText/CompText.tft b/examples/CompText/CompText.tft new file mode 100644 index 00000000..0a5dee0 Binary files /dev/null and b/examples/CompText/CompText.tft differ diff --git a/examples/HMIHardwareSerial/HMIHardwareSerial.ino b/examples/HMIHardwareSerial/HMIHardwareSerial.ino deleted file mode 100644 index 6e722b3..00000000 --- a/examples/HMIHardwareSerial/HMIHardwareSerial.ino +++ /dev/null @@ -1,50 +0,0 @@ -#include -/*For UNO board,we advice you to use software serial,because hardware serial has been used to output log in this example.*/ - -HMI myhmi(Serial2); //For MEGA board,if you want to use another hardware serial,please edit this line. -void setup() -{ - Serial.begin(9600); -} - -void loop() -{ - if (myhmi.pictureEdit("p3",10) == 1) - Serial.println("picture edit success"); - else - Serial.println("picture edit failure"); - - if (myhmi.pageChange(0) == 1) - Serial.println("page change success"); - else - Serial.println("page change failure"); - delay(2000); //delaly 2 sconds ,for debug - - if (myhmi.cutPicture("q0",12) == 1) - Serial.println("cut picture success"); - else - Serial.println("cut picture failure"); - delay(2000); //delaly 2 sconds ,for debug - - if(myhmi.textEdit("t3","13") == 1) - Serial.println("text edit success"); - else - Serial.println("text edit failure"); - - /* test progressBarEdit() */ - delay(2000); //delaly 2 sconds ,for debug - if (myhmi.pageChange(2) == 1) - Serial.println("page change success"); - else - Serial.println("page change failure"); - if(myhmi.progressBarEdit("j0",10) == 1) - Serial.println("progress bar edit success"); - else - Serial.println("progress bar edit failure"); - while(1); -} - - - - - diff --git a/examples/HMISoftwareSerial/HMISoftwareSerial.ino b/examples/HMISoftwareSerial/HMISoftwareSerial.ino deleted file mode 100644 index a0d9c82..00000000 --- a/examples/HMISoftwareSerial/HMISoftwareSerial.ino +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include "SoftwareSerial.h" - -/** - *If you want to use SoftwareSerial to communicate with LCD touch screen, you need to modify the line in file hmi.h - * //#define HMI_SOFTWARE_SERIAL ---> #define HMI_SOFTWARE_SERIAL - */ -SoftwareSerial mySerial(3,2); -HMI myhmi(mySerial); - -void setup() -{ - Serial.begin(9600); -} -void loop() -{ - if (myhmi.pictureEdit("p3",10) == 1) - Serial.println("picture edit success"); - else - Serial.println("picture edit failure"); - - if (myhmi.pageChange(0) == 1) - Serial.println("page change success"); - else - Serial.println("page change failure"); - delay(2000); //delaly 2 sconds ,for debug - - if (myhmi.cutPicture("q0",12) == 1) - Serial.println("cut picture success"); - else - Serial.println("cut picture failure"); - delay(2000); //delaly 2 sconds ,for debug - - if(myhmi.textEdit("t3","13") == 1) - Serial.println("text edit success"); - else - Serial.println("text edit failure"); - - /* test progressBarEdit() */ - delay(2000); //delaly 2 sconds ,for debug - if (myhmi.pageChange(2) == 1) - Serial.println("page change success"); - else - Serial.println("page change failure"); - if(myhmi.progressBarEdit("j0",10) == 1) - Serial.println("progress bar edit success"); - else - Serial.println("progress bar edit failure"); - while(1); -} - - - - - diff --git a/hmi.cpp b/hmi.cpp deleted file mode 100644 index 09a2355..00000000 --- a/hmi.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/** - * @file hmi.cpp - * @brief The implementation of class HMI. - * @author laicheng.zhang@itead.cc - * @date 2015.04 - */ - -#include "hmi.h" -HMI::HMI(HMISerial &uart,uint32_t baud) -{ - my_uart = &uart; - my_uart->begin(baud); - setRxEmpty(); -} - -bool HMI::textEdit(char *text_id,char *value) -{ - /*t0.txt="abc"*/ - char cmd[50] = {0}; - strcat(cmd,text_id); - strcat(cmd,".txt=\""); - strcat(cmd,value); - strcat(cmd,"\""); - my_uart->print(cmd); - commandEnd(); - - if (returnIsRight() == 0) - return true; - else - return false; -} - -bool HMI::pictureEdit(char *picture_id,uint32_t value) -{ - /*p0.pic=6*/ - char cmd[50] = {0}; - char valuetemp[25] = {0}; - itoa(value,valuetemp,10); - strcat(cmd,picture_id); - strcat(cmd,".pic="); - strcat(cmd,valuetemp); - - my_uart->print(cmd); - commandEnd(); - - if (returnIsRight() == 0) - return true; - else - return false; -} - -bool HMI::progressBarEdit(char *bar_id,uint32_t value) -{ - char cmd[50] = {0}; - char valuetemp[25] = {0}; - itoa(value,valuetemp,10); - strcat(cmd,bar_id); - strcat(cmd,".val="); - strcat(cmd,valuetemp); - - my_uart->print(cmd); - commandEnd(); - - if (returnIsRight() == 0) - return true; - else - return false; -} - -bool HMI::cutPicture(char *picture_id,uint32_t value) -{ - char cmd[50] = {0}; - char valuetemp[25] = {0}; - itoa(value,valuetemp,10); - strcat(cmd,picture_id); - strcat(cmd,".pic="); - strcat(cmd,valuetemp); - - my_uart->print(cmd); - commandEnd(); - - if (returnIsRight() == 0) - return true; - else - return false; -} - -bool HMI::pageChange(uint32_t page_id) -{ - char cmd[50] = {0}; - char page_idtemp[25] = {0}; - itoa(page_id,page_idtemp,10); - strcat(cmd,"page"); - strcat(cmd," "); - strcat(cmd,page_idtemp); - my_uart->print(cmd); - - commandEnd(); - delay(200); - if (returnIsRight() == 0) - return true; - else - return false; -} - -void HMI::readLcdData(unsigned char *data_buffer) -{ - delay(10); - cleanBuffer(); - uint32_t i = 0; - while(my_uart->available() <= 0); - while(my_uart->available() > 0) - { - delay(3); - buffer[i] = (unsigned char)my_uart->read(); - i++; - } - if (buffer[0] == 0x70) - { - uint32_t j = 0; - uint32_t k = 1; - for(j=0;javailable(); - uint32_t i = 0; - while(my_uart->available()) - { - temp[i] = (unsigned char)my_uart->read(); - i++; - } - if((tempid==4)&&(strncmp((char*)temp1,(char*)temp,4)==0)) - { - return 0; - } - else - { - return -1; - } -} - -bool HMI::touchCalibration(void) -{ - /*Serial.println("touch Calibration");*/ - my_uart->print("touch_j"); - commandEnd(); - delay(5000); - if (returnIsRight() == 0) - return true; - else - return false; - -} - -bool HMI::disableTouchFocus(void) -{ - /*Serial.println("disableTouchFocus");*/ - my_uart->print("cle_c"); - commandEnd(); - if (returnIsRight() == 0) - return true; - else - return false; -} - -bool HMI::pauseSerialCommand(void) -{ - /*Serial.println("pauseSerialCommand");*/ - my_uart->print("com_stop"); - commandEnd(); - if (returnIsRight() == 0) - return true; - else - return false; -} - -bool HMI::recoverySerialCommand(void) -{ - /*Serial.println("recoverySerialCommand");*/ - my_uart->print("com_star"); - commandEnd(); - if (returnIsRight() == 0) - return true; - else - return false; -} - -bool HMI::emptySerialCommand(void) -{ - /*Serial.println("emptySerialCommand");*/ - my_uart->print("code_c"); - commandEnd(); - if (returnIsRight() == 0) - return true; - else - return false; -} - -uint32_t HMI::returnPageId(void) -{ - my_uart->print("sendme"); - commandEnd(); - - delay(50); - unsigned char temp1[] = {0x66,0xFF,0xFF,0xFF}; - unsigned char temp[10] = {0}; - uint32_t j = 0; - while(my_uart->available() > 0) - { - temp[j] = (unsigned char)my_uart->read(); - delay(3); - j++; - } - - if(!strcmp((char*)temp1[0],(char*)temp[0])) - { - return (uint32_t)temp[1]; - } - else - return -1; -} - -void HMI::setRxEmpty(void) -{ - while(my_uart->available() > 0) - { - my_uart->read(); - } -} - -void HMI::cleanBuffer(void) -{ - memset(buffer,0,strlen((char*)buffer)); -} - -void HMI::commandEnd(void) -{ - my_uart->write(0xFF); - my_uart->write(0xFF); - my_uart->write(0xFF); -} - - - diff --git a/hmi.h b/hmi.h deleted file mode 100644 index 1892f7d..00000000 --- a/hmi.h +++ /dev/null @@ -1,205 +0,0 @@ -/** - * @file hmi.h - * @brief The definition of class HMI. - * @author laicheng.zhang@itead.cc - * @date 2015.04 - */ -#ifndef __HMI_H__ -#define __HMI_H__ -#include "arduino.h" - -/** - * You can modify the macro to choose sofware serial or hardware serial. - */ -//#define HMI_SOFTWARE_SERIAL - -#ifdef HMI_SOFTWARE_SERIAL -#include "SoftwareSerial.h" -typedef SoftwareSerial HMISerial; -#else -typedef HardwareSerial HMISerial; -#endif /* #ifdef HMI_SOFTWARE_SERIAL */ - -/** - * HMI class. - * - * used to operate LCD touch screen. - */ -class HMI -{ -public: - - /** - * Constuctor. - * - * @param uart - an reference of user serial object. - * @param baud - the buad rate to communicate with LCD touch screen(default:9600). - * - */ - HMI(HMISerial &uart, uint32_t baud = 9600); - - /** - * Edit text. - * - * @param text_id - text id. - * @param value - text value. - * @retval true - success. - * @retval false - failure. - * - */ - bool textEdit(char *text_id,char *value); - - /** - * Edit picture. - * - * @param picture_id - picture name. - * @param value - picture value. - * @retval true - success. - * @retval false - failure. - * - */ - bool pictureEdit(char *picture_id,uint32_t value); - - /** - * Progress bar edit. - * - * @param bar_id - progress bar name. - * @param value - progress bar value. - * @retval true - success. - * @retval false - failure. - * - */ - bool progressBarEdit(char *bar_id,uint32_t value); - - /** - * Cut picture. - * - * @param picture_id - picture name. - * @param value - picture value. - * @retval true - success. - * @retval false - failure. - * - */ - bool cutPicture(char *picture_id,uint32_t value); - - /** - * Page change. - * - * @param page_id - page id. - * @retval true - success. - * @retval false - failure. - * - */ - bool pageChange(uint32_t page_id); - - /** - * The LCD touch screen calibration. - * - * @param data_buffer - get data from LCD ,it is a input parameter. - * - */ - void readLcdData(unsigned char *data_buffer); - - /** - * The LCD touch screen calibration. - * - * @retval true - success. - * @retval false - failure. - * - */ - bool touchCalibration(void); - - /** - * Disable touch focus. - * - * @retval true - success. - * @retval false - failure. - * - */ - bool disableTouchFocus(void); - - /** - * Pause serial command from UNO. - * - * @retval true - success. - * @retval false - failure. - * - */ - bool pauseSerialCommand(void); - - /** - * Recovery serial command from UNO. - * - * @retval true - success. - * @retval false - failure. - * - */ - bool recoverySerialCommand(void); - - /** - * Empty serial command from UNO. - * - * @retval true - success. - * @retval false - failure. - * - */ - bool emptySerialCommand(void); - - /** - * Return current page id. - * - * @retval >=0 - current page id. - * @retval <0 - return page id failure. - * - */ - uint32_t returnPageId(void); -private: - - /** - * The return value judgement. - * - * @retval true - success. - * @retval false - failure. - * - */ - bool returnIsRight(void); - - /** - * Clean data receive buffer,from LCD serial. - */ - void cleanBuffer(void); - - /** - * Clear serial buffer. - */ - void setRxEmpty(void); - - /** - * Data receive buffer, from LCD serial. - */ - unsigned char buffer[100]; - - /** - * Command end flag. - */ - void commandEnd(void); - - /** - * Point to the current user serial. - */ - HMISerial *my_uart; -}; -#endif - - - - - - - - - - - - -