NeoNextion
Arduino library for the Nextion displays.
|
Driver for a physical Nextion device. More...
#include <Nextion.h>
Public Member Functions | |
Nextion (Stream &stream, bool flushSerialBeforeTx=true) | |
Creates a new device driver. More... | |
bool | init () |
Initialises the device. More... | |
void | poll () |
Polls for new messages and touch events. | |
bool | refresh () |
Refreshes the entire page. More... | |
bool | refresh (const char *objectName) |
Refreshes a specific object. More... | |
bool | sleep () |
Puts the device into sleep mode. More... | |
bool | wake () |
Wakes the device from sleep mode. More... | |
uint16_t | getBrightness () |
Gets the current backlight brightness. More... | |
bool | setBrightness (uint16_t val, bool persist=false) |
Sets the backlight brightness. More... | |
uint8_t | getCurrentPage () |
Gets the ID of the current displayed page. More... | |
bool | clear (uint32_t colour=NEX_COL_WHITE) |
Clears the current display. More... | |
bool | drawPicture (uint16_t x, uint16_t y, uint8_t id) |
Draws a pre uploaded picture on the display. More... | |
bool | drawPicture (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t id) |
Draws a cropped pre uplaoded picture on the display. More... | |
bool | drawStr (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t fontID, char *str, uint32_t bgColour=NEX_COL_BLACK, uint32_t fgColour=NEX_COL_WHITE, uint8_t bgType=NEX_BG_SOLIDCOLOUR, NextionFontAlignment xCentre=NEX_FA_CENTRE, NextionFontAlignment yCentre=NEX_FA_CENTRE) |
Draws a string on the display. More... | |
bool | drawLine (uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint32_t colour) |
Draws a line on the display. More... | |
bool | drawRect (uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool filled, uint32_t colour) |
Draws a rectangle on the display. More... | |
bool | drawCircle (uint16_t x, uint16_t y, uint16_t r, uint32_t colour) |
Draws a circle on the display. More... | |
void | registerTouchable (INextionTouchable *touchable) |
Adds a INextionTouchable to the list of registered touchable elements. More... | |
void | sendCommand (char *command) |
Sends a command to the device. More... | |
bool | checkCommandComplete () |
Checks if the last command was successful. More... | |
bool | receiveNumber (uint32_t *number) |
Receive a number from the device. More... | |
size_t | receiveString (char *buffer, size_t len) |
Receive a string from the device. More... | |
Driver for a physical Nextion device.
Nextion::Nextion | ( | Stream & | stream, |
bool | flushSerialBeforeTx = true |
||
) |
Creates a new device driver.
stream | Stream (serial port) the device is connected to |
flushSerialBeforeTx | If the serial port should be flushed before transmission |
bool Nextion::checkCommandComplete | ( | ) |
Checks if the last command was successful.
bool Nextion::clear | ( | uint32_t | colour = NEX_COL_WHITE | ) |
Clears the current display.
colour | Colour to set display to |
bool Nextion::drawCircle | ( | uint16_t | x, |
uint16_t | y, | ||
uint16_t | r, | ||
uint32_t | colour | ||
) |
Draws a circle on the display.
x | X position |
y | Y position |
r | Radius |
colour | Colour |
bool Nextion::drawLine | ( | uint16_t | x1, |
uint16_t | y1, | ||
uint16_t | x2, | ||
uint16_t | y2, | ||
uint32_t | colour | ||
) |
Draws a line on the display.
x1 | X position of first vertex |
y1 | Y position of first vertex |
x2 | X position of second vertex |
y2 | Y position of second vertex |
colour | Colour |
bool Nextion::drawPicture | ( | uint16_t | x, |
uint16_t | y, | ||
uint8_t | id | ||
) |
Draws a pre uploaded picture on the display.
x | X position |
y | Y position |
id | ID of the picture to display |
bool Nextion::drawPicture | ( | uint16_t | x, |
uint16_t | y, | ||
uint16_t | w, | ||
uint16_t | h, | ||
uint8_t | id | ||
) |
Draws a cropped pre uplaoded picture on the display.
x | X position |
y | Y position |
w | Width |
h | Height |
id | ID of the picture to display |
bool Nextion::drawRect | ( | uint16_t | x, |
uint16_t | y, | ||
uint16_t | w, | ||
uint16_t | h, | ||
bool | filled, | ||
uint32_t | colour | ||
) |
Draws a rectangle on the display.
x | X position |
y | Y position |
w | Width |
h | Height |
filled | If the rectangle should be filled with a solid colour |
colour | Colour |
bool Nextion::drawStr | ( | uint16_t | x, |
uint16_t | y, | ||
uint16_t | w, | ||
uint16_t | h, | ||
uint8_t | fontID, | ||
char * | str, | ||
uint32_t | bgColour = NEX_COL_BLACK , |
||
uint32_t | fgColour = NEX_COL_WHITE , |
||
uint8_t | bgType = NEX_BG_SOLIDCOLOUR , |
||
NextionFontAlignment | xCentre = NEX_FA_CENTRE , |
||
NextionFontAlignment | yCentre = NEX_FA_CENTRE |
||
) |
Draws a string on the display.
x | X position |
y | Y position |
w | Width |
h | Height |
fontID | ID of the font to use |
str | String to draw |
bgColour | Colour of the background of the bounding box |
fgColour | Colour of the text |
bgType | Background type |
xCentre | X alignment |
yCentre | Y alignment |
uint16_t Nextion::getBrightness | ( | ) |
Gets the current backlight brightness.
uint8_t Nextion::getCurrentPage | ( | ) |
Gets the ID of the current displayed page.
bool Nextion::init | ( | ) |
Initialises the device.
bool Nextion::receiveNumber | ( | uint32_t * | number | ) |
Receive a number from the device.
number | Pointer to the number to store received number in |
size_t Nextion::receiveString | ( | char * | buffer, |
size_t | len | ||
) |
Receive a string from the device.
buffer | Pointer to buffer to store string in |
len | Maximum length of data to receive |
bool Nextion::refresh | ( | ) |
Refreshes the entire page.
bool Nextion::refresh | ( | const char * | objectName | ) |
Refreshes a specific object.
objectName | Name of the object to refresh |
void Nextion::registerTouchable | ( | INextionTouchable * | touchable | ) |
Adds a INextionTouchable to the list of registered touchable elements.
touchable | Pointer to the INextionTouchable |
Required for touch events from an INextionTouchable to be polled.
Should be called automatically by INextionTouchable::INextionTouchable.
void Nextion::sendCommand | ( | char * | command | ) |
Sends a command to the device.
command | Command to send |
bool Nextion::setBrightness | ( | uint16_t | val, |
bool | persist = false |
||
) |
Sets the backlight brightness.
val | Brightness value (0-100) |
persist | If set to true value will be set as new power on default |
bool Nextion::sleep | ( | ) |
Puts the device into sleep mode.
bool Nextion::wake | ( | ) |
Wakes the device from sleep mode.