From b08c6a82d531490cfc6d53c61998761db809c38b Mon Sep 17 00:00:00 2001 From: geekfactory Date: Sun, 7 Feb 2016 10:27:01 -0600 Subject: [PATCH] Added methods to change NexButton background picture --- NexButton.cpp | 22 ++++++++++++++++++++++ NexButton.h | 21 ++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/NexButton.cpp b/NexButton.cpp index c8a8fc36..134c206f 100644 --- a/NexButton.cpp +++ b/NexButton.cpp @@ -41,3 +41,25 @@ bool NexButton::setText(const char *buffer) return recvRetCommandFinished(); } +bool NexButton::getPIC(uint32_t * number) +{ + String cmd = String("get "); + cmd += getObjName(); + cmd += ".pic"; + sendCommand(cmd.c_str()); + return recvRetNumber(number); +} + +bool NexButton::setPIC(uint32_t number) +{ + char buf[10] = {0}; + String cmd; + + utoa(number, buf, 10); + cmd += getObjName(); + cmd += ".pic="; + cmd += buf; + + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} diff --git a/NexButton.h b/NexButton.h index 8dae2ac7..cf310092 100644 --- a/NexButton.h +++ b/NexButton.h @@ -56,7 +56,26 @@ class NexButton: public NexTouch * @param buffer - text buffer terminated with '\0'. * @return true if success, false for failure. */ - bool setText(const char *buffer); + bool setText(const char *buffer); + + /** + * Sets the background picture property of the button. + * + * @param number - Pointer to buffer that will store the ID of the image + * resource on Nextion Editor. + * + * @return true if command succeeded, false otherwise + */ + bool getPic(uint32_t number); + + /** + * Sets the background picture property of the button. + * + * @param number - ID of the image resource on Nextion Editor. + * + * @return true if command succeeded, false otherwise + */ + bool setPic(uint32_t number); }; /** * @}