NeoNextion
Arduino library for the Nextion displays.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator
Nextion.h
Go to the documentation of this file.
1 
3 #ifndef __NEONEXTION_NEXTION
4 #define __NEONEXTION_NEXTION
5 
6 #if defined(SPARK) || defined(PLATFORM_ID)
7 #include "application.h"
8 extern char *itoa(int a, char *buffer, unsigned char radix);
9 #else
10 #include <Arduino.h>
11 #endif
12 
13 #include "NextionTypes.h"
14 
15 class INextionTouchable;
16 
22 {
25 };
26 
31 class Nextion
32 {
33 public:
34  Nextion(Stream &stream, bool flushSerialBeforeTx = true);
35 
36  bool init();
37  void poll();
38 
39  bool refresh();
40  bool refresh(const char *objectName);
41 
42  bool sleep();
43  bool wake();
44 
45  uint16_t getBrightness();
46  bool setBrightness(uint16_t val, bool persist = false);
47 
48  uint8_t getCurrentPage();
49 
50  bool clear(uint32_t colour = NEX_COL_WHITE);
51  bool drawPicture(uint16_t x, uint16_t y, uint8_t id);
52  bool drawPicture(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t id);
53  bool drawStr(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t fontID,
54  char *str, uint32_t bgColour = NEX_COL_BLACK,
55  uint32_t fgColour = NEX_COL_WHITE,
56  uint8_t bgType = NEX_BG_SOLIDCOLOUR,
59  bool drawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,
60  uint32_t colour);
61  bool drawRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool filled,
62  uint32_t colour);
63  bool drawCircle(uint16_t x, uint16_t y, uint16_t r, uint32_t colour);
64 
65  void registerTouchable(INextionTouchable *touchable);
66  void sendCommand(char *command);
67  bool checkCommandComplete();
68  bool receiveNumber(uint32_t *number);
69  size_t receiveString(char *buffer, size_t len);
70 
71 private:
72  Stream &m_serialPort;
73  uint32_t m_timeout;
74  bool m_flushSerialBeforeTx;
75  ITouchableListItem *m_touchableList;
76 };
77 
78 #endif
bool checkCommandComplete()
Checks if the last command was successful.
Definition: Nextion.cpp:356
Centre.
Definition: NextionTypes.h:39
bool sleep()
Puts the device into sleep mode.
Definition: Nextion.cpp:102
bool drawPicture(uint16_t x, uint16_t y, uint8_t id)
Draws a pre uploaded picture on the display.
Definition: Nextion.cpp:191
bool drawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint32_t colour)
Draws a line on the display.
Definition: Nextion.cpp:258
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.
Definition: Nextion.cpp:279
bool drawCircle(uint16_t x, uint16_t y, uint16_t r, uint32_t colour)
Draws a circle on the display.
Definition: Nextion.cpp:302
bool clear(uint32_t colour=NEX_COL_WHITE)
Clears the current display.
Definition: Nextion.cpp:175
bool init()
Initialises the device.
Definition: Nextion.cpp:24
void poll()
Polls for new messages and touch events.
Definition: Nextion.cpp:40
bool setBrightness(uint16_t val, bool persist=false)
Sets the backlight brightness.
Definition: Nextion.cpp:138
Solid colour.
Definition: NextionTypes.h:51
ITouchableListItem * next
Pointer to next list node.
Definition: Nextion.h:24
void registerTouchable(INextionTouchable *touchable)
Adds a INextionTouchable to the list of registered touchable elements.
Definition: Nextion.cpp:320
uint8_t getCurrentPage()
Gets the ID of the current displayed page.
Definition: Nextion.cpp:154
size_t receiveString(char *buffer, size_t len)
Receive a string from the device.
Definition: Nextion.cpp:402
Interface for widgets that can be touched.
Definition: INextionTouchable.h:15
void sendCommand(char *command)
Sends a command to the device.
Definition: Nextion.cpp:341
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.
Definition: Nextion.cpp:234
bool receiveNumber(uint32_t *number)
Receive a number from the device.
Definition: Nextion.cpp:376
Nextion(Stream &stream, bool flushSerialBeforeTx=true)
Creates a new device driver.
Definition: Nextion.cpp:12
bool wake()
Wakes the device from sleep mode.
Definition: Nextion.cpp:112
bool refresh()
Refreshes the entire page.
Definition: Nextion.cpp:78
uint16_t getBrightness()
Gets the current backlight brightness.
Definition: Nextion.cpp:122
INextionTouchable * item
Pointer to stored INextionTouchable.
Definition: Nextion.h:23
Linked list node for INextionTouchable objects.
Definition: Nextion.h:21
Driver for a physical Nextion device.
Definition: Nextion.h:31
NextionFontAlignment
Font alignment modes.
Definition: NextionTypes.h:35