Skip to content

Alterado os arquivos NexVariable.h e NextVariable.cpp #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions NexVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ uint32_t NexVariable::getValue(uint32_t *number)
return recvRetNumber(number);
}

uint32_t NexVariable::getValueByID(uint32_t *number)
{
String cmd = String("get ");
cmd += String("p[") + getObjPid() + String("].b[") + getObjCid() + String("]");
cmd += ".val";
sendCommand(cmd.c_str());
return recvRetNumber(number);
}

bool NexVariable::setValue(uint32_t number)
{
char buf[10] = {0};
Expand All @@ -42,6 +51,20 @@ bool NexVariable::setValue(uint32_t number)
return recvRetCommandFinished();
}

bool NexVariable::setValueByID(uint32_t number)
{
char buf[10] = {0};
String cmd;

utoa(number, buf, 10);
cmd += String("p[") + getObjPid() + String("].b[") + getObjCid() + String("]");
cmd += ".val=";
cmd += buf;

sendCommand(cmd.c_str());
return recvRetCommandFinished();
}

uint32_t NexVariable::getText(char *buffer, uint32_t len)
{
String cmd;
Expand All @@ -52,6 +75,16 @@ uint32_t NexVariable::getText(char *buffer, uint32_t len)
return recvRetString(buffer,len);
}

uint32_t NexVariable::getTextByID(char *buffer, uint32_t len)
{
String cmd;
cmd += "get ";
cmd += String("p[") + getObjPid() + String("].b[") + getObjCid() + String("]");
cmd += ".txt";
sendCommand(cmd.c_str());
return recvRetString(buffer,len);
}

bool NexVariable::setText(const char *buffer)
{
String cmd;
Expand All @@ -61,4 +94,15 @@ bool NexVariable::setText(const char *buffer)
cmd += "\"";
sendCommand(cmd.c_str());
return recvRetCommandFinished();
}

bool NexVariable::setTextByID(const char *buffer)
{
String cmd;
cmd += String("p[") + getObjPid() + String("].b[") + getObjCid() + String("]");
cmd += ".txt=\"";
cmd += buffer;
cmd += "\"";
sendCommand(cmd.c_str());
return recvRetCommandFinished();
}
39 changes: 37 additions & 2 deletions NexVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/
class NexVariable: public NexTouch
{

public: /* methods */

/**
Expand All @@ -50,29 +51,63 @@ class NexVariable: public NexTouch
*/
uint32_t getText(char *buffer, uint32_t len);

/**
* Get text attribute of component. Use ID Object of Nextion
*
* @param buffer - buffer storing text returned.
* @param len - length of buffer.
* @return The real length of text returned.
*/
uint32_t getTextByID(char *buffer, uint32_t len);

/**
* Set text attribute of component.
*
* @param buffer - text buffer terminated with '\0'.
* @return true if success, false for failure.
*/
bool setText(const char *buffer);


/**
* Set text attribute of component. Useof PID and CID
*
* @param buffer - text buffer terminated with '\0'.
* @return true if success, false for failure.
*/
bool setTextByID(const char *buffer);

/**
* Get val attribute of component
*
* @param number - buffer storing data retur
* @return the length of the data
*/
uint32_t getValue(uint32_t *number);


/**
* Get val attribute of component. Use of PID and CID
*
* @param number - buffer storing data retur
* @return the length of the data
*/
uint32_t getValueByID(uint32_t *number);

/**
* Set val attribute of component
*
* @param number - To set up the data
* @return true if success, false for failure
*/
bool setValue(uint32_t number);

/**
* Set val attribute of component. Use of PID and CID
*
* @param number - To set up the data
* @return true if success, false for failure
*/
bool setValueByID(uint32_t number);

};
/**
* @}
Expand Down