Modified: class tree structure.

Signed-off-by: shennongmin <wupangfee@gmail.com>
This commit is contained in:
shennongmin
2015-08-13 18:05:42 +08:00
parent ced5da9c0a
commit 88290e6e57
25 changed files with 178 additions and 311 deletions

View File

@@ -19,8 +19,8 @@
* Constructor,inherited NexTouch's constructor function.
*
*/
NexButton::NexButton(NexPid pid, NexCid cid, const char *name, NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
NexButton::NexButton(NexPid pid, NexCid cid, const char *name)
:NexTouch(pid, cid, name)
{
}
@@ -61,24 +61,3 @@ bool NexButton::setText(const char *buffer)
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();
}

View File

@@ -26,10 +26,7 @@
class NexButton: public NexTouch
{
public: /* methods */
NexButton(NexPid pid, NexCid cid, const char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL);
void attachPop(NexTouchEventCb pop, void *ptr = NULL);
void detachPop(void);
NexButton(NexPid pid, NexCid cid, const char *name);
uint16_t getText(char *buffer, uint16_t len);
bool setText(const char *buffer);

View File

@@ -19,8 +19,8 @@
* Constructor,inherited NexTouch's constructor function.
*
*/
NexCrop::NexCrop(NexPid pid, NexCid cid, const char *name, NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
NexCrop::NexCrop(NexPid pid, NexCid cid, const char *name)
:NexTouch(pid, cid, name)
{
}
@@ -63,23 +63,3 @@ bool NexCrop::setPic(uint32_t number)
return recvRetCommandFinished();
}
/**
* Register crop pop callback function.
*
* @param pop - the pointer to crop pop callback function.
* @param ptr - the parameter to be transmitted to crop pop callback function.
*/
void NexCrop::attachPop(NexTouchEventCb pop, void *ptr)
{
NexTouch::attachPop(pop, ptr);
}
/**
* Unload crop pop callback function.
*
*/
void NexCrop::detachPop(void)
{
NexTouch::detachPop();
}

View File

@@ -26,11 +26,8 @@
class NexCrop: public NexTouch
{
public: /* methods */
NexCrop(NexPid pid, NexCid cid, const char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL);
NexCrop(NexPid pid, NexCid cid, const char *name);
void attachPop(NexTouchEventCb pop, void *ptr = NULL);
void detachPop(void);
bool getPic(uint32_t *number);
bool setPic(uint32_t number);
};

View File

@@ -20,7 +20,7 @@
*
*/
NexGauge::NexGauge(NexPid pid, NexCid cid, const char *name)
:NexTouch(pid, cid, name)
:NexObject(pid, cid, name)
{
}

View File

@@ -23,7 +23,7 @@
* NexGauge,subclass of NexTouch,provides simple methods to control gauge component.
*
*/
class NexGauge: public NexTouch
class NexGauge: public NexObject
{
public: /* methods */
NexGauge(NexPid pid, NexCid cid, const char *name);

View File

@@ -19,49 +19,8 @@
* Constructor,inherited NexTouch's constructor function.
*
*/
NexHotspot::NexHotspot(NexPid pid, NexCid cid, const char *name,
NexTouchEventCb pop, void *pop_ptr,
NexTouchEventCb push, void *push_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr, push, push_ptr)
NexHotspot::NexHotspot(NexPid pid, NexCid cid, const char *name)
:NexTouch(pid, cid, name)
{
}
/**
* Register hotspot push callback function.
*
* @param push - 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();
}

View File

@@ -26,15 +26,7 @@
class NexHotspot: public NexTouch
{
public: /* methods */
NexHotspot(NexPid pid, NexCid cid, const 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);
NexHotspot(NexPid pid, NexCid cid, const char *name);
};
#endif /* #ifdef __cplusplus */

87
NexObject.cpp Normal file
View File

@@ -0,0 +1,87 @@
/**
* @file NexObject.cpp
*
* The root of all classes in Nextion library.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
* @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 "NexObject.h"
/**
* Constructor
*
* @param pid - page id.
* @param cid - component id.
* @param name - component name.
*/
NexObject::NexObject(NexPid pid, NexCid cid, const char *name)
{
this->pid = pid;
this->cid = cid;
this->name = name;
dbSerialPrintln("NexObject called");
}
/**
* Get page id.
*
* @return the id of page.
*/
NexPid NexObject::getObjPid(void)
{
return pid;
}
/**
* Get component id.
*
* @return the id of component.
*/
NexCid NexObject::getObjCid(void)
{
return cid;
}
/**
* Get component name.
*
* @return the name of component.
*/
const char* NexObject::getObjName(void)
{
return name;
}
/**
* Print current object address,page id,component id,
* component name,pop event function address,push event function address.
*
*/
void NexObject::printObjInfo(void)
{
dbSerialPrint("[");
dbSerialPrint((uint32_t)this);
dbSerialPrint(":");
dbSerialPrint(pid);
dbSerialPrint(",");
dbSerialPrint(cid);
dbSerialPrint(",");
if (name)
{
dbSerialPrint(name);
}
else
{
dbSerialPrint("(null)");
}
dbSerialPrintln("]");
}

45
NexObject.h Normal file
View File

@@ -0,0 +1,45 @@
/**
* @file NexObject.h
*
* The root of all classes in Nextion library.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
* @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 __NEXOBJECT_H__
#define __NEXOBJECT_H__
#ifdef __cplusplus
#include <Arduino.h>
#include "NexSerialConfig.h"
typedef uint8_t NexPid;
typedef uint8_t NexCid;
/**
* Root Class of Nextion Components.
*/
class NexObject
{
public: /* methods */
NexObject(NexPid pid, NexCid cid, const char *name);
NexPid getObjPid(void);
NexCid getObjCid(void);
const char *getObjName(void);
void printObjInfo(void);
private: /* data */
NexPid pid; /* Page ID */
NexCid cid; /* Component ID */
const char *name; /* An unique name */
};
#endif /* #ifdef __cplusplus */
#endif /* #ifndef __NEXOBJECT_H__ */

View File

@@ -19,8 +19,8 @@
* Constructor,inherited NexTouch's constructor function.
*
*/
NexPage::NexPage(NexPid pid, NexCid cid, const char *name, NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
NexPage::NexPage(NexPid pid, NexCid cid, const char *name)
:NexTouch(pid, cid, name)
{
}
@@ -46,22 +46,3 @@ bool NexPage::show(void)
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();
}

View File

@@ -26,12 +26,8 @@
class NexPage: public NexTouch
{
public: /* methods */
NexPage(NexPid pid, NexCid cid, const char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL);
NexPage(NexPid pid, NexCid cid, const char *name);
bool show(void);
void attachPop(NexTouchEventCb pop, void *ptr = NULL);
void detachPop(void);
};
#endif /* #ifdef __cplusplus */

View File

@@ -19,8 +19,8 @@
* Constructor,inherited NexTouch's constructor function.
*
*/
NexPicture::NexPicture(NexPid pid, NexCid cid, const char *name, NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
NexPicture::NexPicture(NexPid pid, NexCid cid, const char *name)
:NexTouch(pid, cid, name)
{
}
@@ -62,24 +62,4 @@ bool NexPicture::setPic(uint32_t number)
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();
}

View File

@@ -26,11 +26,8 @@
class NexPicture: public NexTouch
{
public: /* methods */
NexPicture(NexPid pid, NexCid cid, const char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL);
NexPicture(NexPid pid, NexCid cid, const char *name);
void attachPop(NexTouchEventCb pop, void *ptr = NULL);
void detachPop(void);
bool getPic(uint32_t *number);
bool setPic(uint32_t number);
};

View File

@@ -20,7 +20,7 @@
*
*/
NexProgressBar::NexProgressBar(NexPid pid, NexCid cid, const char *name)
:NexTouch(pid, cid, name)
:NexObject(pid, cid, name)
{
}

View File

@@ -23,7 +23,7 @@
* NexProgressBar,subclass of NexTouch,provides simple methods to control progress bar component.
*
*/
class NexProgressBar: public NexTouch
class NexProgressBar: public NexObject
{
public: /* methods */
NexProgressBar(NexPid pid, NexCid cid, const char *name);

View File

@@ -19,9 +19,8 @@
* Constructor,inherited NexTouch's constructor function.
*
*/
NexSlider::NexSlider(NexPid pid, NexCid cid, const char *name,
NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
NexSlider::NexSlider(NexPid pid, NexCid cid, const char *name)
:NexTouch(pid, cid, name)
{
}
@@ -64,23 +63,3 @@ bool NexSlider::setValue(uint32_t number)
return recvRetCommandFinished();
}
/**
* Register slider 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 NexSlider::attachPop(NexTouchEventCb pop, void *ptr)
{
NexTouch::attachPop(pop, ptr);
}
/**
* Unload slider pop callback function.
*
*/
void NexSlider::detachPop(void)
{
NexTouch::detachPop();
}

View File

@@ -26,11 +26,8 @@
class NexSlider: public NexTouch
{
public: /* methods */
NexSlider(NexPid pid, NexCid cid, const char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL);
void attachPop(NexTouchEventCb pop, void *ptr = NULL);
void detachPop(void);
NexSlider(NexPid pid, NexCid cid, const char *name);
bool getValue(uint32_t *number);
bool setValue(uint32_t number);
};

View File

@@ -19,8 +19,8 @@
* Constructor,inherited NexTouch's constructor function.
*
*/
NexText::NexText(NexPid pid, NexCid cid, const char *name, NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
NexText::NexText(NexPid pid, NexCid cid, const char *name)
:NexTouch(pid, cid, name)
{
}
@@ -61,23 +61,3 @@ bool NexText::setText(const char *buffer)
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();
}

View File

@@ -26,11 +26,8 @@
class NexText: public NexTouch
{
public: /* methods */
NexText(NexPid pid, NexCid cid, const char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL);
NexText(NexPid pid, NexCid cid, const char *name);
void attachPop(NexTouchEventCb pop, void *ptr = NULL);
void detachPop(void);
uint16_t getText(char *buffer, uint16_t len);
bool setText(const char *buffer);
};

View File

@@ -19,85 +19,19 @@
/**
* Constructor of Nextouch.
*
* @param pid - page id.
* @param cid - component id.
* @param name - component name.
* @param pop - pop event function pointer.
* @param pop_ptr - 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, const char *name,
NexTouchEventCb pop, void *pop_ptr,
NexTouchEventCb push, void *push_ptr)
NexTouch::NexTouch(NexPid pid, NexCid cid, const char *name)
:NexObject(pid, cid, name)
{
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)
{
dbSerialPrint("[");
dbSerialPrint((uint32_t)this);
dbSerialPrint(":");
dbSerialPrint(pid);
dbSerialPrint(",");
dbSerialPrint(cid);
dbSerialPrint(",");
if (name)
{
dbSerialPrint(name);
}
else
{
dbSerialPrint("(null)");
}
dbSerialPrint(",");
dbSerialPrint((uint32_t)cbPush);
dbSerialPrint(",");
dbSerialPrint((uint32_t)cbPop);
dbSerialPrintln("]");
this->cbPush = NULL;
this->cbPop = NULL;
this->__cbpop_ptr = NULL;
this->__cbpush_ptr = NULL;
}
void NexTouch::attachPush(NexTouchEventCb push, void *ptr)
@@ -152,9 +86,9 @@ void NexTouch::iterate(NexTouch **list, NexPid pid, NexCid cid, NexEventType eve
for(i = 0; (e = list[i]) != NULL; i++)
{
if (e->getPid() == pid && e->getCid() == cid)
if (e->getObjPid() == pid && e->getObjCid() == cid)
{
e->print();
e->printObjInfo();
if (NEX_EVENT_PUSH == event)
{
e->push();

View File

@@ -18,9 +18,7 @@
#ifdef __cplusplus
#include <Arduino.h>
#include "NexSerialConfig.h"
typedef uint8_t NexPid;
typedef uint8_t NexCid;
#include "NexObject.h"
typedef void (*NexTouchEventCb)(void *ptr);
@@ -34,35 +32,24 @@ typedef enum {
* Root Class of Nextion Components.
*
*/
class NexTouch
class NexTouch: public NexObject
{
public: /* static methods */
static void iterate(NexTouch **list, NexPid pid, NexCid cid, NexEventType event);
public: /* methods */
NexTouch(NexPid pid, NexCid cid, const char *name,
NexTouchEventCb pop = NULL, void *pop_ptr = NULL,
NexTouchEventCb push = NULL, void *push_ptr = NULL);
NexTouch(NexPid pid, NexCid cid, const char *name);
NexPid getPid(void);
NexCid getCid(void);
const char *getObjName(void);
protected: /* methods */
void attachPush(NexTouchEventCb push, void *ptr = NULL);
void detachPush(void);
void attachPop(NexTouchEventCb pop, void *ptr = NULL);
void detachPop(void);
private: /* methods */
void print(void);
void push(void);
void pop(void);
private: /* data */
NexPid pid; /* Page ID */
NexCid cid; /* Component ID */
const char *name; /* An unique name */
NexTouchEventCb cbPush;
void *__cbpush_ptr;
NexTouchEventCb cbPop;

View File

@@ -20,7 +20,7 @@
*
*/
NexWaveform::NexWaveform(NexPid pid, NexCid cid, const char *name)
:NexTouch(pid, cid, name)
:NexObject(pid, cid, name)
{
}
@@ -43,7 +43,7 @@ bool NexWaveform::addValue(uint8_t ch, uint8_t number)
return false;
}
sprintf(buf, "add %u,%u,%u", getCid(), ch, number);
sprintf(buf, "add %u,%u,%u", getObjCid(), ch, number);
sendCommand(buf);
return true;

View File

@@ -22,7 +22,7 @@
* NexWaveform,subclass of NexTouch,provides simple methods to control NexWaveform component.
*
*/
class NexWaveform: public NexTouch
class NexWaveform: public NexObject
{
public: /* methods */
NexWaveform(NexPid pid, NexCid cid, const char *name);

View File

@@ -19,9 +19,9 @@ 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);
NexText t0 = NexText(0, 1, "t0");
NexButton b0 = NexButton(0, 2, "b0");
NexButton b1 = NexButton(0, 3, "b1");
char buffer[100] = {0};
@@ -80,6 +80,9 @@ void b1PopCallback(void *ptr)
void setup(void)
{
nexInit();
t0.attachPop(t0PopCallback);
b0.attachPop(b0PopCallback);
b1.attachPop(b1PopCallback);
dbSerialPrintln("setup done");
}