API
For Arduino developers
NexButton.cpp
Go to the documentation of this file.
1 
16 #include "NexButton.h"
17 
22 NexButton::NexButton(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr)
23  :NexTouch(pid, cid, name, pop, pop_ptr)
24 {
25 }
26 
35 uint16_t NexButton::getText(char *buffer, uint16_t len)
36 {
37  String cmd;
38  cmd += "get ";
39  cmd += getObjName();
40  cmd += ".txt";
41  sendCommand(cmd.c_str());
42  return recvRetString(buffer,len);
43 }
44 
53 bool NexButton::setText(const char *buffer)
54 {
55  String cmd;
56  cmd += getObjName();
57  cmd += ".txt=\"";
58  cmd += buffer;
59  cmd += "\"";
60  sendCommand(cmd.c_str());
61  return recvRetCommandFinished();
62 }
63 
70 void NexButton::attachPop(NexTouchEventCb pop, void *ptr)
71 {
72  NexTouch::attachPop(pop, ptr);
73 }
74 
80 {
81  NexTouch::detachPop();
82 }
83 
84 
NexButton(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop=NULL, void *pop_ptr=NULL)
Constructor,inherited NexTouch's constructor function.
Definition: NexButton.cpp:22
uint16_t getText(char *buffer, uint16_t len)
Get text value from button component.
Definition: NexButton.cpp:35
API of NexButton.
void attachPop(NexTouchEventCb pop, void *ptr=NULL)
Register button pop callback function.
Definition: NexButton.cpp:70
static void sendCommand(const char *cmd)
Send command to Nextion.
Definition: NexTouch.cpp:256
const char * getObjName(void)
Get component name.
Definition: NexTouch.cpp:107
bool setText(const char *buffer)
Set text value of button component.
Definition: NexButton.cpp:53
static uint16_t recvRetString(char *buffer, uint16_t len, uint32_t timeout=500)
Receive string data.
Definition: NexTouch.cpp:279
void detachPop(void)
Unload button pop callback function.
Definition: NexButton.cpp:79
static bool recvRetCommandFinished(uint32_t timeout=100)
Command is executed successfully.
Definition: NexTouch.cpp:219
Root Class of Nextion Components.
Definition: NexTouch.h:57