Commit 7068e281 authored by MagoKimbra's avatar MagoKimbra

Update Nextion library

parent e7267fe5
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#define NEX_RET_CURRENT_PAGE_ID_HEAD (0x66) #define NEX_RET_CURRENT_PAGE_ID_HEAD (0x66)
#define NEX_RET_STRING_HEAD (0x70) #define NEX_RET_STRING_HEAD (0x70)
#define NEX_RET_NUMBER_HEAD (0x71) #define NEX_RET_NUMBER_HEAD (0x71)
#define NEX_RET_VALUE_HEAD (0x72)
#define NEX_RET_INVALID_CMD (0x00) #define NEX_RET_INVALID_CMD (0x00)
#define NEX_RET_INVALID_COMPONENT_ID (0x02) #define NEX_RET_INVALID_COMPONENT_ID (0x02)
#define NEX_RET_INVALID_PAGE_ID (0x03) #define NEX_RET_INVALID_PAGE_ID (0x03)
...@@ -255,7 +256,7 @@ bool nexInit(void) ...@@ -255,7 +256,7 @@ bool nexInit(void)
void nexLoop(NexTouch *nex_listen_list[]) void nexLoop(NexTouch *nex_listen_list[])
{ {
static uint8_t __buffer[10]; static uint8_t __buffer[20];
uint16_t i; uint16_t i;
uint8_t c; uint8_t c;
...@@ -286,3 +287,126 @@ void nexLoop(NexTouch *nex_listen_list[]) ...@@ -286,3 +287,126 @@ void nexLoop(NexTouch *nex_listen_list[])
} }
} }
/**
* Return current page id.
*
* @param pageId - output parameter,to save page id.
*
* @retval true - success.
* @retval false - failed.
*/
bool sendCurrentPageId(uint8_t* pageId)
{
bool ret = false;
uint8_t temp[5] = {0};
if (!pageId)
{
goto __return;
}
sendCommand("sendme");
delay(50);
nexSerial.setTimeout(100);
if (sizeof(temp) != nexSerial.readBytes((char *)temp, sizeof(temp)))
{
goto __return;
}
if (temp[0] == NEX_RET_CURRENT_PAGE_ID_HEAD
&& temp[2] == 0xFF
&& temp[3] == 0xFF
&& temp[4] == 0xFF
)
{
*pageId = temp[1];
ret = true;
}
__return:
if (ret)
{
dbSerialPrint("recvPageId :");
dbSerialPrintln(*pageId);
}
else
{
dbSerialPrintln("recvPageId err");
}
return ret;
}
/**
* Set current backlight brightness value.
*
* @param dimValue - current backlight brightness value.
*
* @retval true - success.
* @retval false - failed.
*/
bool setCurrentBrightness(uint8_t dimValue)
{
bool ret = false;
char buf[10] = {0};
String cmd;
utoa(dimValue, buf, 10);
cmd += "dim=";
cmd += buf;
sendCommand(cmd.c_str());
delay(10);
if(recvRetCommandFinished())
{
dbSerialPrint("setCurrentBrightness[ ");
dbSerialPrint(dimValue);
dbSerialPrintln("]ok ");
ret = true;
}
else
{
dbSerialPrintln("setCurrentBrightness err ");
}
return ret;
}
/**
* Set default baudrate.
*
* @param defaultBaudrate - default baudrate,it supports 2400,4800,9600,19200,38400,57600,115200.
*
* @retval true - success.
* @retval false - failed.
*/
bool setDefaultBaudrate(uint32_t defaultBaudrate)
{
bool ret = false;
char buf[10] = {0};
String cmd;
utoa(defaultBaudrate, buf, 10);
cmd += "bauds=";
cmd += buf;
sendCommand(cmd.c_str());
delay(10);
if(recvRetCommandFinished())
{
dbSerialPrintln("setDefaultBaudrate ok ");
ret = true;
}
else
{
dbSerialPrintln("setDefaultBaudrate err ");
}
return ret;
}
void sendRefreshAll(void)
{
sendCommand("ref 0");
}
\ No newline at end of file
...@@ -52,4 +52,9 @@ uint16_t recvRetString(char *buffer, uint16_t len, uint32_t timeout = 100); ...@@ -52,4 +52,9 @@ uint16_t recvRetString(char *buffer, uint16_t len, uint32_t timeout = 100);
void sendCommand(const char* cmd); void sendCommand(const char* cmd);
bool recvRetCommandFinished(uint32_t timeout = 100); bool recvRetCommandFinished(uint32_t timeout = 100);
bool sendCurrentPageId(uint8_t* pageId);
bool setCurrentBrightness(uint8_t dimValue);
bool setDefaultBaudrate(uint32_t baudrate);
void sendRefreshAll(void);
#endif /* #ifndef __NEXHARDWARE_H__ */ #endif /* #ifndef __NEXHARDWARE_H__ */
/**
* @file NexNumber.cpp
*
* The implementation of class NexNumber.
*
* @author huang xianming (email:<xianming.huang@itead.cc>)
* @date 2015/8/13
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd.
* 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 "NexNumber.h"
NexNumber::NexNumber(uint8_t pid, uint8_t cid, const char *name)
:NexTouch(pid, cid, name)
{
}
bool NexNumber::getValue(uint32_t *number)
{
String cmd = String("get ");
cmd += getObjName();
cmd += ".val";
sendCommand(cmd.c_str());
return recvRetNumber(number);
}
bool NexNumber::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 NexNumber.h
*
* The definition of class NexNumber.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
*
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd.
* 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 __NEXNUMBER_H__
#define __NEXNUMBER_H__
#include "NexTouch.h"
#include "NexHardware.h"
/**
* @addtogroup Component
* @{
*/
/**
* NexTNumber component.
*/
class NexNumber: public NexTouch
{
public: /* methods */
/**
* @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
*/
NexNumber(uint8_t pid, uint8_t cid, const char *name);
/**
* Get number attribute of component.
*
* @param buffer - buffer storing text returned.
* @param len - length of buffer.
* @return The real length of text returned.
*/
bool getValue(uint32_t *number);
/**
* Set number attribute of component.
*
* @param buffer - number buffer.
* @return true if success, false for failure.
*/
bool setValue(uint32_t number);
};
/**
* @}
*/
#endif /* #ifndef __NEXNUMBER_H__ */
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "NexText.h" #include "NexText.h"
#include "NexWaveform.h" #include "NexWaveform.h"
#include "NexTimer.h" #include "NexTimer.h"
#include "NexNumber.h"
#include "NexVar.h" #include "NexVar.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment