Skip to content

Added methods to change NexButton background picture #9

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

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 22 additions & 0 deletions NexButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
21 changes: 20 additions & 1 deletion NexButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
/**
* @}
Expand Down