NeoNextion
Arduino library for the Nextion displays.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator
Public Member Functions | List of all members
Nextion Class Reference

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...
 

Detailed Description

Driver for a physical Nextion device.

Constructor & Destructor Documentation

Nextion::Nextion ( Stream &  stream,
bool  flushSerialBeforeTx = true 
)

Creates a new device driver.

Parameters
streamStream (serial port) the device is connected to
flushSerialBeforeTxIf the serial port should be flushed before transmission

Member Function Documentation

bool Nextion::checkCommandComplete ( )

Checks if the last command was successful.

Returns
True if command was successful
bool Nextion::clear ( uint32_t  colour = NEX_COL_WHITE)

Clears the current display.

Parameters
colourColour to set display to
Returns
True if successful
bool Nextion::drawCircle ( uint16_t  x,
uint16_t  y,
uint16_t  r,
uint32_t  colour 
)

Draws a circle on the display.

Parameters
xX position
yY position
rRadius
colourColour
Returns
True if successful
bool Nextion::drawLine ( uint16_t  x1,
uint16_t  y1,
uint16_t  x2,
uint16_t  y2,
uint32_t  colour 
)

Draws a line on the display.

Parameters
x1X position of first vertex
y1Y position of first vertex
x2X position of second vertex
y2Y position of second vertex
colourColour
Returns
True if successful
bool Nextion::drawPicture ( uint16_t  x,
uint16_t  y,
uint8_t  id 
)

Draws a pre uploaded picture on the display.

Parameters
xX position
yY position
idID of the picture to display
Returns
True if successful
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.

Parameters
xX position
yY position
wWidth
hHeight
idID of the picture to display
Returns
True if successful
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.

Parameters
xX position
yY position
wWidth
hHeight
filledIf the rectangle should be filled with a solid colour
colourColour
Returns
True if successful
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.

Parameters
xX position
yY position
wWidth
hHeight
fontIDID of the font to use
strString to draw
bgColourColour of the background of the bounding box
fgColourColour of the text
bgTypeBackground type
xCentreX alignment
yCentreY alignment
Returns
True if successful
uint16_t Nextion::getBrightness ( )

Gets the current backlight brightness.

Returns
Brightness
uint8_t Nextion::getCurrentPage ( )

Gets the ID of the current displayed page.

Returns
Page ID
bool Nextion::init ( )

Initialises the device.

Returns
True if initialisation was successful.
bool Nextion::receiveNumber ( uint32_t *  number)

Receive a number from the device.

Parameters
numberPointer to the number to store received number in
Returns
True if receive was successful
size_t Nextion::receiveString ( char *  buffer,
size_t  len 
)

Receive a string from the device.

Parameters
bufferPointer to buffer to store string in
lenMaximum length of data to receive
Returns
Actual length of string received
bool Nextion::refresh ( )

Refreshes the entire page.

Returns
True if successful
bool Nextion::refresh ( const char *  objectName)

Refreshes a specific object.

Parameters
objectNameName of the object to refresh
Returns
True if successful
void Nextion::registerTouchable ( INextionTouchable touchable)

Adds a INextionTouchable to the list of registered touchable elements.

Parameters
touchablePointer 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.

Parameters
commandCommand to send
bool Nextion::setBrightness ( uint16_t  val,
bool  persist = false 
)

Sets the backlight brightness.

Parameters
valBrightness value (0-100)
persistIf set to true value will be set as new power on default
Returns
True if successful
bool Nextion::sleep ( )

Puts the device into sleep mode.

Returns
True if successful
bool Nextion::wake ( )

Wakes the device from sleep mode.

Returns
True if successful

The documentation for this class was generated from the following files: