diff --git a/NexVariable.cpp b/NexVariable.cpp index 187ba114..4e3b1b0b 100755 --- a/NexVariable.cpp +++ b/NexVariable.cpp @@ -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}; @@ -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; @@ -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; @@ -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(); } \ No newline at end of file diff --git a/NexVariable.h b/NexVariable.h index ebbba132..b720c4b3 100755 --- a/NexVariable.h +++ b/NexVariable.h @@ -34,6 +34,7 @@ */ class NexVariable: public NexTouch { + public: /* methods */ /** @@ -50,6 +51,15 @@ 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. * @@ -57,7 +67,15 @@ class NexVariable: public NexTouch * @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 * @@ -65,7 +83,15 @@ class NexVariable: public NexTouch * @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 * @@ -73,6 +99,15 @@ class NexVariable: public NexTouch * @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); + }; /** * @}