From eaad704b5d54a83de5233df0afff940363e2de2d Mon Sep 17 00:00:00 2001 From: zhangabc Date: Thu, 16 Jul 2015 10:11:58 +0800 Subject: [PATCH] add note to all files --- NexButton.cpp | 123 ++- NexButton.h | 61 +- NexHotspot.cpp | 95 ++- NexHotspot.h | 65 +- NexPage.cpp | 99 ++- NexPage.h | 59 +- NexPicture.cpp | 127 ++- NexPicture.h | 61 +- NexPointer.cpp | 81 +- NexPointer.h | 40 +- NexProgressBar.cpp | 96 ++- NexProgressBar.h | 55 +- NexSlice.cpp | 127 ++- NexSlice.h | 61 +- NexText.cpp | 122 ++- NexText.h | 61 +- NexTouch.cpp | 794 +++++++++++-------- NexTouch.h | 213 ++--- examples/CompButton/CompButton.ino | 107 +-- examples/CompHotspot/CompHotspot.ino | 127 +-- examples/CompPage/CompPage.ino | 133 ++-- examples/CompPicture/CompPicture.ino | 103 ++- examples/CompPointer/CompPointer.ino | 137 ++-- examples/CompProgressBar/CompProgressBar.ino | 141 ++-- examples/CompSlice/CompSlice.ino | 91 ++- examples/CompText/CompText.ino | 171 ++-- readme.md | 104 +-- 27 files changed, 2049 insertions(+), 1405 deletions(-) diff --git a/NexButton.cpp b/NexButton.cpp index 662ca071..80e3ba58 100644 --- a/NexButton.cpp +++ b/NexButton.cpp @@ -1,39 +1,84 @@ -#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(); -} - - +/** + * @file NexButton.cpp + * + * API of NexButton. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#include "NexButton.h" + +/** + * Constructor,inherited NexTouch's constructor function. + * + */ +NexButton::NexButton(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr) + :NexTouch(pid, cid, name, pop, pop_ptr) +{ +} + +/** + * Get text value from button component. + * + * @param buffer - text buffer. + * @param len - text buffer length. + * + * @return the text buffer length + */ +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); +} + +/** + * Set text value of button component. + * + * @param buffer - text buffer. + * + * @retval true - success. + * @retval false - failed. + */ +bool NexButton::setText(const char *buffer) +{ + String cmd; + cmd += getObjName(); + cmd += ".txt=\""; + cmd += buffer; + cmd += "\""; + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + +/** + * Register button pop callback function. + * + * @param pop - the pointer to button pop callback function. + * @param ptr - the parameter to be transmitted to button pop callback function. + */ +void NexButton::attachPop(NexTouchEventCb pop, void *ptr) +{ + NexTouch::attachPop(pop, ptr); +} + +/** + * Unload button pop callback function. + * + */ +void NexButton::detachPop(void) +{ + NexTouch::detachPop(); +} + + diff --git a/NexButton.h b/NexButton.h index 1638975e..6b5ec9fe 100644 --- a/NexButton.h +++ b/NexButton.h @@ -1,23 +1,38 @@ -#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__ */ +/** + * @file NexButton.h + * + * API of NexButton. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#ifndef __NEXBUTTON_H__ +#define __NEXBUTTON_H__ +#ifdef __cplusplus +#include "NexTouch.h" + +/** + * NexButton,subclass of NexTouch,provides simple methods to control button component. + * + */ +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 index c2e6c014..51d78e57 100644 --- a/NexHotspot.cpp +++ b/NexHotspot.cpp @@ -1,28 +1,67 @@ -#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(); -} +/** + * @file NexHotspot.cpp + * + * API of NexHotspot. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#include "NexHotspot.h" + +/** + * Constructor,inherited NexTouch's constructor function. + * + */ +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) +{ +} + +/** + * Register hotspot push callback function. + * + * @param pop - the pointer to hotspot push callback function. + * @param ptr - the parameter to be transmitted to hotspot push callback function. + */ +void NexHotspot::attachPush(NexTouchEventCb push, void *ptr) +{ + NexTouch::attachPush(push, ptr); +} + +/** + * Unload hotsopt push callback function. + * + */ +void NexHotspot::detachPush(void) +{ + NexTouch::detachPush(); +} + +/** + * Register hotspot pop callback function. + * + * @param pop - the pointer to hotspot pot callback function. + * @param ptr - the parameter to be transmitted to hotspot pop callback function. + */ +void NexHotspot::attachPop(NexTouchEventCb pop, void *ptr) +{ + NexTouch::attachPop(pop, ptr); +} + +/** + * Unload hotsopt pop callback function. + * + */ +void NexHotspot::detachPop(void) +{ + NexTouch::detachPop(); +} diff --git a/NexHotspot.h b/NexHotspot.h index 18b20f8b..683e4e2d 100644 --- a/NexHotspot.h +++ b/NexHotspot.h @@ -1,25 +1,40 @@ -#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__ */ +/** + * @file NexHotspot.h + * + * API of NexHotspot. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#ifndef __NEXHOTSPOT_H__ +#define __NEXHOTSPOT_H__ +#ifdef __cplusplus +#include "NexTouch.h" + +/** + * NexHotspot,subclass of NexTouch,provides simple methods to control hotspot component. + * + */ +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 index eff529a0..7b032157 100644 --- a/NexPage.cpp +++ b/NexPage.cpp @@ -1,32 +1,67 @@ -#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(); -} +/** + * @file NexPage.cpp + * + * API of NexPage. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#include "NexPage.h" + +/** + * Constructor,inherited NexTouch's constructor function. + * + */ +NexPage::NexPage(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr) + :NexTouch(pid, cid, name, pop, pop_ptr) +{ +} + +/** + * Change page. + * + * @retval true - success. + * @retval false - failed. + */ +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(); +} + +/** + * Register page pop callback function. + * + * @param pop - the pointer to page pop callback function. + * @param ptr - the parameter to be transmitted to page pop callback function. + */ +void NexPage::attachPop(NexTouchEventCb pop, void *ptr) +{ + NexTouch::attachPop(pop, ptr); +} + +/** + * Unload page pop callback function. + * + */ +void NexPage::detachPop(void) +{ + NexTouch::detachPop(); +} diff --git a/NexPage.h b/NexPage.h index 620007e9..ab45dae6 100644 --- a/NexPage.h +++ b/NexPage.h @@ -1,22 +1,37 @@ -#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__ */ +/** + * @file NexPage.h + * + * API of NexPage. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#ifndef __NEXPAGE_H__ +#define __NEXPAGE_H__ +#ifdef __cplusplus +#include "NexTouch.h" + +/** + * NexPage,subclass of NexTouch,provides simple methods to control page component. + * + */ +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 index bee30f6b..ade3bf9e 100644 --- a/NexPicture.cpp +++ b/NexPicture.cpp @@ -1,42 +1,85 @@ -#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(); -} - +/** + * @file NexPicture.cpp + * + * API of NexPicture. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#include "NexPicture.h" + +/** + * Constructor,inherited NexTouch's constructor function. + * + */ +NexPicture::NexPicture(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr) + :NexTouch(pid, cid, name, pop, pop_ptr) +{ +} + +/** + * Get picture's number. + * + * @param number - an output parameter to save picture number. + * + * @reval true - success. + * @retval false - failed. + */ +bool NexPicture::getPic(uint32_t *number) +{ + String cmd = String("get "); + cmd += getObjName(); + cmd += ".pic"; + sendCommand(cmd.c_str()); + return recvRetNumber(number); +} + +/** + * Set picture's number. + * + * @param number -the picture number. + * + * @retval true - success. + * @retval false - failed. + */ +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(); +} + +/** + * Register picture pop callback function. + * + * @param pop - the pointer to picture pop callback function. + * @param ptr - the parameter to be transmitted to picture pop callback function. + */ +void NexPicture::attachPop(NexTouchEventCb pop, void *ptr) +{ + NexTouch::attachPop(pop, ptr); +} + +/** + * Unload picture pop callback function. + * + */ +void NexPicture::detachPop(void) +{ + NexTouch::detachPop(); +} + diff --git a/NexPicture.h b/NexPicture.h index cb83eef9..5f4c2f52 100644 --- a/NexPicture.h +++ b/NexPicture.h @@ -1,23 +1,38 @@ -#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__ */ +/** + * @file NexPicture.h + * + * API of NexPicture. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#ifndef __NEXPICTURE_H__ +#define __NEXPICTURE_H__ +#ifdef __cplusplus +#include "NexTouch.h" + +/** + * NexPicture,subclass of NexTouch,provides simple methods to control picture component. + * + */ +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 index c6922694..7d6e1d00 100644 --- a/NexPointer.cpp +++ b/NexPointer.cpp @@ -1,31 +1,50 @@ -#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(); -} - +#include "NexPointer.h" + +/** + * Constructor,inherited NexTouch's constructor function. + * + */ +NexPointer::NexPointer(NexPid pid, NexCid cid, char *name) + :NexTouch(pid, cid, name) +{ +} + +/** + * Get the value of pointer. + * + * @param number - an output parameter to save pointer's value. + * + * @retval true - success. + * @retval false - failed. + */ +bool NexPointer::getValue(uint32_t *number) +{ + String cmd = String("get "); + cmd += getObjName(); + cmd += ".val"; + sendCommand(cmd.c_str()); + return recvRetNumber(number); +} + +/** + * Set the value of pointer. + * + * @param number - the value of pointer. + * + * @retval true - success. + * @retval false - failed. + */ +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 index cc9f2430..2d690b12 100644 --- a/NexPointer.h +++ b/NexPointer.h @@ -1,20 +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__ */ +#ifndef __NEXPOINTER_H__ +#define __NEXPOINTER_H__ +#ifdef __cplusplus +#include "NexTouch.h" + +/** + * NexPointer,subclass of NexTouch,provides simple methods to control pointer component. + * + */ +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 index d3966f29..f7fc321a 100644 --- a/NexProgressBar.cpp +++ b/NexProgressBar.cpp @@ -1,31 +1,65 @@ -#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(); -} - +/** + * @file NexProgressBar.cpp + * + * API of NexProgressBar. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#include "NexProgressBar.h" + +/** + * Constructor,inherited NexTouch's constructor function. + * + */ +NexProgressBar::NexProgressBar(NexPid pid, NexCid cid, char *name) + :NexTouch(pid, cid, name) +{ +} + +/** + * Get the value of progress bar. + * + * @param number - an output parameter to save the value of porgress bar. + * + * @retval true - success. + * @retval false - failed. + */ +bool NexProgressBar::getValue(uint32_t *number) +{ + String cmd = String("get "); + cmd += getObjName(); + cmd += ".val"; + sendCommand(cmd.c_str()); + return recvRetNumber(number); +} + +/** + * Set the value of progress bar. + * + * @param number - the value of progress bar. + * + * @retval true - success. + * @retval false - failed. + */ +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 index 9e3f546f..5a99d20e 100644 --- a/NexProgressBar.h +++ b/NexProgressBar.h @@ -1,20 +1,35 @@ -#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__ */ +/** + * @file NexProgressBar.h + * + * API of NexProgressBar. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#ifndef __NEXPROGRESSBAR_H__ +#define __NEXPROGRESSBAR_H__ +#ifdef __cplusplus +#include "NexTouch.h" + +/** + * NexProgressBar,subclass of NexTouch,provides simple methods to control progress bar component. + * + */ +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 index f93b4c8a..6d95c0d3 100644 --- a/NexSlice.cpp +++ b/NexSlice.cpp @@ -1,42 +1,85 @@ -#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(); -} - +/** + * @file NexSlice.cpp + * + * API of NexSlice. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#include "NexSlice.h" + +/** + * Constructor,inherited NexTouch's constructor function. + * + */ +NexSlice::NexSlice(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr) + :NexTouch(pid, cid, name, pop, pop_ptr) +{ +} + +/* + * Get the number of picture. + * + * @param number - an output parameter to save the number of picture. + * + * @retval true - success. + * @retval false - failed. + */ +bool NexSlice::getPic(uint32_t *number) +{ + String cmd = String("get "); + cmd += getObjName(); + cmd += ".picc"; + sendCommand(cmd.c_str()); + return recvRetNumber(number); +} + +/* + * Set the number of picture. + * + * @param number - the number of picture. + * + * @retval true - success. + * @retval false - failed. + */ +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(); +} + +/** + * Register slice pop callback function. + * + * @param pop - the pointer to slice pop callback function. + * @param ptr - the parameter to be transmitted to slice pop callback function. + */ +void NexSlice::attachPop(NexTouchEventCb pop, void *ptr) +{ + NexTouch::attachPop(pop, ptr); +} + +/** + * Unload slice pop callback function. + * + */ +void NexSlice::detachPop(void) +{ + NexTouch::detachPop(); +} + diff --git a/NexSlice.h b/NexSlice.h index 24f21bf1..cbf9c879 100644 --- a/NexSlice.h +++ b/NexSlice.h @@ -1,23 +1,38 @@ -#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__ */ +/** + * @file NexSlice.h + * + * API of NexSlice. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#ifndef __NEXSLICE_H__ +#define __NEXSLICE_H__ +#ifdef __cplusplus +#include "NexTouch.h" + +/** + * NexSlice,subclass of NexTouch,provides simple methods to control slice component. + * + */ +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 index 2b45c64a..ce411bd2 100644 --- a/NexText.cpp +++ b/NexText.cpp @@ -1,39 +1,83 @@ -#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(); -} - +/** + * @file NexText.cpp + * + * API of NexText. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#include "NexText.h" + +/** + * Constructor,inherited NexTouch's constructor function. + * + */ +NexText::NexText(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr) + :NexTouch(pid, cid, name, pop, pop_ptr) +{ +} + +/** + * Get the value of text. + * + * @param buffer - text value buffer. + * @param len - the length of text value buffer. + * + * @return the the length of text value buffer. + */ +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); +} + +/** + * Set the value of text. + * + * @param buffer - text value buffer. + * + * @retval true - success. + * @retval false - failed. + */ +bool NexText::setText(const char *buffer) +{ + String cmd; + cmd += getObjName(); + cmd += ".txt=\""; + cmd += buffer; + cmd += "\""; + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + +/** + * Register text pop callback function. + * + * @param pop - the pointer to text pop callback function. + * @param ptr - the parameter to be transmitted to text pop callback function. + */ +void NexText::attachPop(NexTouchEventCb pop, void *ptr) +{ + NexTouch::attachPop(pop, ptr); +} + +/** + * Unload text pop callback function. + * + */ +void NexText::detachPop(void) +{ + NexTouch::detachPop(); +} + diff --git a/NexText.h b/NexText.h index 200a3ac2..1985a5c9 100644 --- a/NexText.h +++ b/NexText.h @@ -1,23 +1,38 @@ -#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__ */ +/** + * @file NexText.h + * + * API of NexText. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#ifndef __NEXTEXT_H__ +#define __NEXTEXT_H__ +#ifdef __cplusplus +#include "NexTouch.h" + +/** + * NexText,subclass of NexTouch,provides simple methods to control text component. + * + */ +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 index 7c45afd6..e35c6e6c 100644 --- a/NexTouch.cpp +++ b/NexTouch.cpp @@ -1,348 +1,446 @@ -#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; -} - - +/** + * @file NexTouch.cpp + * + * API of Nextion. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#include "NexTouch.h" + +uint8_t NexTouch::__buffer[256] = {0}; + +/** + * Watting for Nextion's touch event. + * + * @param list - index to Nextion Components list. + * + */ +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; +} + +/** + * Constructor of Nextouch. + * + * @param pid - page id. + * @param cid - component id. + * @param name - component name. + * @param pop - pop event function pointer. + * @param pop_str - the parameter was transmitted to pop event function pointer. + * @param push - push event function pointer. + * @param push_ptr - the parameter was transmitted to push event function pointer. + * + */ +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; +} + +/** + * Get page id. + * + * @return the id of page. + */ +NexPid NexTouch::getPid(void) +{ + return pid; +} + +/** + * Get component id. + * + * @return the id of component. + */ +NexCid NexTouch::getCid(void) +{ + return cid; +} + +/** + * Get component name. + * + * @return the name of component. + */ +const char* NexTouch::getObjName(void) +{ + return name; +} + +/** + * Print current object address,page id,component id, + * component name,pop event function address,push event function address. + * + */ +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); + } +} + +/** + * Command is executed successfully. + * + * @param timeout - set timeout time. + * + * @retval true - success. + * @retval false - failed. + * + */ +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; +} + +/** + * Send command to Nextion. + * + * @param cmd - the string of command. + */ +void NexTouch::sendCommand(const char* cmd) +{ + while (nexSerial.available()) + { + nexSerial.read(); + } + + nexSerial.print(cmd); + nexSerial.write(0xFF); + nexSerial.write(0xFF); + nexSerial.write(0xFF); +} + +/** + * Receive string data. + * + * @param buffer - save string data. + * @param len - string buffer length. + * @param timeout - set timeout time. + * + * @return the length of string buffer. + * + */ +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; +} + +/** + * Receive uint32_t data. + * + * @param number - save uint32_t data. + * @param timeout - set timeout time. + * + * @retval true - success. + * @retval false - failed. + * + */ +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); +} + + +/** + * Init Nextion's baudrate,page id. + * + * @retval true - success. + * @retval false - failed. + */ +bool nexInit(void) +{ + nexSerial.begin(9600); + NexTouch::sendCommand(""); + NexTouch::sendCommand("page 0"); + delay(100); + return true; +} + + +/** + * Call mainEventLoop,watting for Nextion's touch event. + * + * @param nexListenList - index to Nextion Components list. + * + * @retval false - failed. + */ +bool nexLoop(NexTouch **nexListenList) +{ + NexTouch::mainEventLoop(nexListenList); + return false; +} + + diff --git a/NexTouch.h b/NexTouch.h index cde79d9f..f6773460 100644 --- a/NexTouch.h +++ b/NexTouch.h @@ -1,97 +1,116 @@ -#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__ */ +/** + * @file NexTouch.h + * + * API of Nextion. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#ifndef __NEXTOUCH_H__ +#define __NEXTOUCH_H__ +#ifdef __cplusplus +#include + + +/*Define debug serial*/ +#define dbSerial Serial + +/*Define Nextion 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; + +/*The first byte of Nextoin's return value*/ +#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.ino b/examples/CompButton/CompButton.ino index 642d26ee..44627cfc 100644 --- a/examples/CompButton/CompButton.ino +++ b/examples/CompButton/CompButton.ino @@ -1,46 +1,61 @@ -#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); -} +/** + * @example NexTouch.cpp + * + * @par Show how to use API of class NexButton. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#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/CompHotspot/CompHotspot.ino b/examples/CompHotspot/CompHotspot.ino index 34257ee9..9c6b8401 100644 --- a/examples/CompHotspot/CompHotspot.ino +++ b/examples/CompHotspot/CompHotspot.ino @@ -1,56 +1,71 @@ -#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); -} +/** + * @example NexTouch.cpp + * + * @par Show how to use API of class NexHotspot. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#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/CompPage/CompPage.ino b/examples/CompPage/CompPage.ino index c5ea41cd..5ce07ff7 100644 --- a/examples/CompPage/CompPage.ino +++ b/examples/CompPage/CompPage.ino @@ -1,59 +1,74 @@ -#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); -} +/** + * @example NexTouch.cpp + * + * @par Show how to use API of class NexPage. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#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/CompPicture/CompPicture.ino b/examples/CompPicture/CompPicture.ino index fef9451c..74d4d997 100644 --- a/examples/CompPicture/CompPicture.ino +++ b/examples/CompPicture/CompPicture.ino @@ -1,44 +1,59 @@ -#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); -} - +/** + * @example NexTouch.cpp + * + * @par Show how to use API of class NexPicture. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#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/CompPointer/CompPointer.ino b/examples/CompPointer/CompPointer.ino index 55f97161..f47a37f3 100644 --- a/examples/CompPointer/CompPointer.ino +++ b/examples/CompPointer/CompPointer.ino @@ -1,61 +1,76 @@ -#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); -} - +/** + * @example NexTouch.cpp + * + * @par Show how to use API of class NexPointer. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#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/CompProgressBar/CompProgressBar.ino b/examples/CompProgressBar/CompProgressBar.ino index 913914ad..09b6988a 100644 --- a/examples/CompProgressBar/CompProgressBar.ino +++ b/examples/CompProgressBar/CompProgressBar.ino @@ -1,63 +1,78 @@ -#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); -} - +/** + * @example NexTouch.cpp + * + * @par Show how to use API of class NexProgressBar. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#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/CompSlice/CompSlice.ino b/examples/CompSlice/CompSlice.ino index c0b5e63f..a5ec8c16 100644 --- a/examples/CompSlice/CompSlice.ino +++ b/examples/CompSlice/CompSlice.ino @@ -1,38 +1,53 @@ -#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); -} - +/** + * @example NexTouch.cpp + * + * @par Show how to use API of class NexSlice. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#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/CompText/CompText.ino b/examples/CompText/CompText.ino index 50cdefc5..daba38be 100644 --- a/examples/CompText/CompText.ino +++ b/examples/CompText/CompText.ino @@ -1,78 +1,93 @@ -#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); -} - +/** + * @example NexTouch.cpp + * + * @par Show how to use API of class NexText. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#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/readme.md b/readme.md index 045f60d7..fb50df7b 100644 --- a/readme.md +++ b/readme.md @@ -1,52 +1,52 @@ -# Nextion Library for Arduino - -Nextion Arduino library provides an easy-to-use way to manipulate Nextion serial displays. -Users can use the libarry freely, either in commerical projects or open-source prjects, without any additional condiitons. - -For more information about the Nextion display project, please visit [the wiki。](http://wiki.iteadstudio.com/Nextion_HMI_Solution) -The wiki provdies all the necessary technical documnets, quick start guide, tutorials, demos, as well as some useful resources. - -To get your Nextion display, please visit [iMall.](http://imall.itead.cc/display/nextion.html) - -To discuss the project? Request new features? Report a BUG? please visit the [Forums](http://support.iteadstudio.com/discussions/1000058038) - -​ -# Source - -Latest source code can be download at https://github.com/itead/ITEADLIB_Arduino_Nextion. - -You can clone it by: - - git clone https://github.com/itead/ITEADLIB_Arduino_Nextion - -# Hareware requirement - - - RAM: not less than 2KBytes - - Serial: two serial (communication and debug) - -# Suppported Mainboards: - - - Iteaduino MEGA2560 - - Arduino MEGA2560 - - -------------------------------------------------------------------------------- - - - DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE - Version 2, December 2004 - - Copyright (C) 2014 ITEAD Studio - - Everyone is permitted to copy and distribute verbatim or modified - copies of this license document, and changing it is allowed as long - as the name is changed. - - DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE - - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. You just DO WHAT THE FUCK YOU WANT TO. - - -------------------------------------------------------------------------------- +# Nextion Library for Arduino + +Nextion Arduino library provides an easy-to-use way to manipulate Nextion serial displays. +Users can use the libarry freely, either in commerical projects or open-source prjects, without any additional condiitons. + +For more information about the Nextion display project, please visit [the wiki。](http://wiki.iteadstudio.com/Nextion_HMI_Solution) +The wiki provdies all the necessary technical documnets, quick start guide, tutorials, demos, as well as some useful resources. + +To get your Nextion display, please visit [iMall.](http://imall.itead.cc/display/nextion.html) + +To discuss the project? Request new features? Report a BUG? please visit the [Forums](http://support.iteadstudio.com/discussions/1000058038) + +​ +# Source + +Latest source code can be download at https://github.com/itead/ITEADLIB_Arduino_Nextion. + +You can clone it by: + + git clone https://github.com/itead/ITEADLIB_Arduino_Nextion + +# Hareware requirement + + - RAM: not less than 2KBytes + - Serial: two serial (communication and debug) + +# Suppported Mainboards: + + - Iteaduino MEGA2560 + - Arduino MEGA2560 + + +------------------------------------------------------------------------------- + + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2014 ITEAD Studio + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. + + +-------------------------------------------------------------------------------