mirror of
https://github.com/itead/ITEADLIB_Arduino_Nextion.git
synced 2026-03-03 08:44:00 +01:00
Rename NexPointer class as NexGauge and other minor changes.
Signed-off-by: shennongmin <wupangfee@gmail.com>
This commit is contained in:
@@ -1,65 +1,65 @@
|
||||
/**
|
||||
* @file Nexpointer.cpp
|
||||
*
|
||||
* API of Nexpointer.
|
||||
*
|
||||
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
|
||||
* @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"
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @file NexGauge.cpp
|
||||
*
|
||||
* API of NexGauge.
|
||||
*
|
||||
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
|
||||
* @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 "NexGauge.h"
|
||||
|
||||
/**
|
||||
* Constructor,inherited NexTouch's constructor function.
|
||||
*
|
||||
*/
|
||||
NexGauge::NexGauge(NexPid pid, NexCid cid, char *name)
|
||||
:NexTouch(pid, cid, name)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of gauge.
|
||||
*
|
||||
* @param number - an output parameter to save gauge's value.
|
||||
*
|
||||
* @retval true - success.
|
||||
* @retval false - failed.
|
||||
*/
|
||||
bool NexGauge::getValue(uint32_t *number)
|
||||
{
|
||||
String cmd = String("get ");
|
||||
cmd += getObjName();
|
||||
cmd += ".val";
|
||||
sendCommand(cmd.c_str());
|
||||
return recvRetNumber(number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of gauge.
|
||||
*
|
||||
* @param number - the value of gauge.
|
||||
*
|
||||
* @retval true - success.
|
||||
* @retval false - failed.
|
||||
*/
|
||||
bool NexGauge::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();
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
/**
|
||||
* @file NexPointer.h
|
||||
*
|
||||
* API of NexPointer.
|
||||
*
|
||||
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
|
||||
* @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 __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__ */
|
||||
/**
|
||||
* @file NexGauge.h
|
||||
*
|
||||
* API of NexGauge.
|
||||
*
|
||||
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
|
||||
* @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 __NEXGAUGE_H__
|
||||
#define __NEXGAUGE_H__
|
||||
#ifdef __cplusplus
|
||||
#include "NexTouch.h"
|
||||
|
||||
/**
|
||||
* NexGauge,subclass of NexTouch,provides simple methods to control gauge component.
|
||||
*
|
||||
*/
|
||||
class NexGauge: public NexTouch
|
||||
{
|
||||
public: /* methods */
|
||||
NexGauge(NexPid pid, NexCid cid, char *name);
|
||||
|
||||
bool getValue(uint32_t *number);
|
||||
bool setValue(uint32_t number);
|
||||
};
|
||||
|
||||
#endif /* #ifdef __cplusplus */
|
||||
#endif /* #ifndef __NEXGAUGE_H__ */
|
||||
@@ -13,8 +13,8 @@
|
||||
* the License, or (at your option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef __NEXPOINTER_H__
|
||||
#define __NEXPOINTER_H__
|
||||
#ifndef __NEXWAVEFORM_H__
|
||||
#define __NEXWAVEFORM_H__
|
||||
#ifdef __cplusplus
|
||||
#include "NexTouch.h"
|
||||
|
||||
@@ -30,4 +30,4 @@ public: /* methods */
|
||||
};
|
||||
|
||||
#endif /* #ifdef __cplusplus */
|
||||
#endif /* #ifndef __NEXPOINTER_H__ */
|
||||
#endif /* #ifndef __NEXWAVEFORM_H__ */
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
/**
|
||||
* @example CompPointer.ino
|
||||
*
|
||||
* @par Show how to use API of class NexPointer.
|
||||
*
|
||||
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
|
||||
* @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 *nex_listen_list[] =
|
||||
{
|
||||
&btn_up,
|
||||
&btn_down,
|
||||
NULL
|
||||
};
|
||||
|
||||
void buttonUpPopCallback(void *ptr)
|
||||
{
|
||||
uint32_t number = 0;
|
||||
dbSerialPrintln("buttonUpPopCallback");
|
||||
|
||||
pointer.getValue(&number);
|
||||
|
||||
number += 5;
|
||||
if (number >= 360)
|
||||
{
|
||||
number = 0;
|
||||
}
|
||||
|
||||
pointer.setValue(number);
|
||||
}
|
||||
void buttonDownPopCallback(void *ptr)
|
||||
{
|
||||
uint32_t number = 0;
|
||||
dbSerialPrintln("buttonDownPopCallback");
|
||||
|
||||
pointer.getValue(&number);
|
||||
|
||||
if (number >= 5)
|
||||
{
|
||||
number -= 5;
|
||||
}
|
||||
|
||||
pointer.setValue(number);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
nexInit();
|
||||
btn_up.attachPop(buttonUpPopCallback);
|
||||
btn_down.attachPop(buttonDownPopCallback);
|
||||
dbSerialPrintln("setup done");
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
nexLoop(nex_listen_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example CompGauge.ino
|
||||
*
|
||||
* @par Show how to use API of class NexGauge.
|
||||
*
|
||||
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
|
||||
* @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 "NexGauge.h"
|
||||
#include "NexButton.h"
|
||||
|
||||
NexGauge pointer = NexGauge(0, 1, "pointer");
|
||||
NexButton btn_up = NexButton(0, 2, "btn_up");
|
||||
NexButton btn_down = NexButton(0, 3, "btn_down");
|
||||
|
||||
NexTouch *nex_listen_list[] =
|
||||
{
|
||||
&btn_up,
|
||||
&btn_down,
|
||||
NULL
|
||||
};
|
||||
|
||||
void buttonUpPopCallback(void *ptr)
|
||||
{
|
||||
uint32_t number = 0;
|
||||
dbSerialPrintln("buttonUpPopCallback");
|
||||
|
||||
pointer.getValue(&number);
|
||||
|
||||
number += 5;
|
||||
if (number >= 360)
|
||||
{
|
||||
number = 0;
|
||||
}
|
||||
|
||||
pointer.setValue(number);
|
||||
}
|
||||
void buttonDownPopCallback(void *ptr)
|
||||
{
|
||||
uint32_t number = 0;
|
||||
dbSerialPrintln("buttonDownPopCallback");
|
||||
|
||||
pointer.getValue(&number);
|
||||
|
||||
if (number >= 5)
|
||||
{
|
||||
number -= 5;
|
||||
}
|
||||
|
||||
pointer.setValue(number);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
nexInit();
|
||||
btn_up.attachPop(buttonUpPopCallback);
|
||||
btn_down.attachPop(buttonDownPopCallback);
|
||||
dbSerialPrintln("setup done");
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
nexLoop(nex_listen_list);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user