├── examples ├── Crop │ ├── .esp8266.test.skip │ └── Crop.ino ├── Gauge │ ├── .esp8266.test.skip │ └── Gauge.ino ├── Page │ ├── .esp8266.test.skip │ └── Page.ino ├── Text │ ├── .esp8266.test.skip │ └── Text.ino ├── Timer │ ├── .esp8266.test.skip │ └── Timer.ino ├── Button │ ├── .esp8266.test.skip │ └── Button.ino ├── Checkbox │ ├── .esp8266.test.skip │ └── Checkbox.ino ├── Hotspot │ ├── .esp8266.test.skip │ └── Hotspot.ino ├── Number │ ├── .esp8266.test.skip │ └── Number.ino ├── Picture │ ├── .esp8266.test.skip │ └── Picture.ino ├── SerialThru │ ├── .esp8266.test.skip │ └── SerialThru.ino ├── Slider │ ├── .esp8266.test.skip │ └── Slider.ino ├── Variables │ ├── .esp8266.test.skip │ └── Variables.ino ├── Waveform │ ├── .esp8266.test.skip │ └── Waveform.ino ├── BasicGraphics │ ├── .esp8266.test.skip │ └── BasicGraphics.ino ├── DualStateButton │ ├── .esp8266.test.skip │ └── DualStateButton.ino ├── ProgressBar │ ├── .esp8266.test.skip │ └── ProgressBar.ino ├── RadioButton │ ├── .esp8266.test.skip │ └── RadioButton.ino ├── SlidingText │ ├── .esp8266.test.skip │ └── SlidingText.ino ├── SystemSettings │ ├── .esp8266.test.skip │ └── SystemSettings.ino ├── ButtonCallbackClass │ ├── .esp8266.test.skip │ └── ButtonCallbackClass.ino ├── ButtonHardwareSerial │ ├── .uno.test.skip │ └── ButtonHardwareSerial.ino ├── SerialThruHardwareSerial │ ├── .uno.test.skip │ └── SerialThruHardwareSerial.ino ├── SliderHardwareSerial │ ├── .uno.test.skip │ └── SliderHardwareSerial.ino ├── VariablesHardwareSerial │ ├── .uno.test.skip │ └── VariablesHardwareSerial.ino ├── BasicGraphicsHardwareSerial │ ├── .uno.test.skip │ └── BasicGraphicsHardwareSerial.ino ├── SystemSettingsHardwareSerial │ ├── .uno.test.skip │ └── SystemSettingsHardwareSerial.ino └── ButtonCallbackClassHardwareSerial │ ├── .uno.test.skip │ └── ButtonCallbackClassHardwareSerial.ino ├── .gitignore ├── extra ├── Home.png ├── arial.zi ├── Tools.png ├── arial24.zi └── Example.HMI ├── library.properties ├── .clang-format ├── NextionPage.h ├── NextionCrop.h ├── NextionTimer.h ├── NextionPicture.h ├── .travis_deploy_docs.sh ├── library.json ├── INextionCallback.h ├── NextionHotspot.h ├── NextionCrop.cpp ├── NextionVariableNumeric.h ├── NextionVariableString.h ├── NextionPage.cpp ├── INextionTouchable.h ├── NextionPicture.cpp ├── NextionGauge.h ├── NextionSlider.h ├── INextionFontStyleable.h ├── NextionCheckbox.h ├── NextionWaveform.h ├── NextionRadioButton.h ├── NextionProgressBar.h ├── NextionDualStateButton.h ├── NextionText.h ├── NextionButton.h ├── NextionNumber.h ├── INextionColourable.h ├── INextionWidget.h ├── NextionSlidingText.h ├── NextionCallbackFunctionHandler.h ├── README.md ├── .travis.yml ├── INextionBooleanValued.h ├── INextionNumericalValued.h ├── NextionTimer.cpp ├── INextionStringValued.h ├── INextionTouchable.cpp ├── NextionTypes.h ├── Nextion.h ├── NextionSlidingText.cpp ├── keywords.txt ├── NextionWaveform.cpp ├── INextionWidget.cpp ├── INextionFontStyleable.cpp ├── INextionColourable.cpp ├── Nextion.cpp └── LICENSE /examples/Crop/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/Gauge/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/Page/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/Text/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/Timer/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/Button/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/Checkbox/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/Hotspot/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/Number/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/Picture/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/SerialThru/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/Slider/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/Variables/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/Waveform/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/BasicGraphics/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/DualStateButton/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/ProgressBar/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/RadioButton/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/SlidingText/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/SystemSettings/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/ButtonCallbackClass/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/ButtonHardwareSerial/.uno.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/SerialThruHardwareSerial/.uno.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/SliderHardwareSerial/.uno.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/VariablesHardwareSerial/.uno.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/BasicGraphicsHardwareSerial/.uno.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/SystemSettingsHardwareSerial/.uno.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/ButtonCallbackClassHardwareSerial/.uno.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Temp. files 2 | *~ 3 | 4 | # Generated docs 5 | docs/ 6 | -------------------------------------------------------------------------------- /extra/Home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanNixon/NeoNextion/HEAD/extra/Home.png -------------------------------------------------------------------------------- /extra/arial.zi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanNixon/NeoNextion/HEAD/extra/arial.zi -------------------------------------------------------------------------------- /extra/Tools.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanNixon/NeoNextion/HEAD/extra/Tools.png -------------------------------------------------------------------------------- /extra/arial24.zi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanNixon/NeoNextion/HEAD/extra/arial24.zi -------------------------------------------------------------------------------- /extra/Example.HMI: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanNixon/NeoNextion/HEAD/extra/Example.HMI -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=NeoNextion 2 | version=2.2.0 3 | author=Dan Nixon 4 | maintainer=Dan Nixon 5 | sentence=Arduino library for controlling Nextion displays 6 | paragraph=Arduino library for controlling Nextion displays 7 | category=Display 8 | url=https://dannixon.github.io/NeoNextion 9 | architectures=* 10 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | 3 | ColumnLimit: 80 4 | IndentWidth: 2 5 | TabWidth: 2 6 | UseTab: Never 7 | BreakBeforeBraces: Allman 8 | BreakConstructorInitializersBeforeComma: true 9 | AllowShortBlocksOnASingleLine: false 10 | AllowShortCaseLabelsOnASingleLine: false 11 | AllowShortFunctionsOnASingleLine: false 12 | AllowShortIfStatementsOnASingleLine: false 13 | AllowShortLoopsOnASingleLine: false 14 | -------------------------------------------------------------------------------- /NextionPage.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONPAGE 4 | #define __NEONEXTION_NEXTIONPAGE 5 | 6 | #include "Nextion.h" 7 | #include "INextionWidget.h" 8 | 9 | /*! 10 | * \class NextionPage 11 | * \brief Represents a page of widgets. 12 | */ 13 | class NextionPage : public INextionWidget 14 | { 15 | public: 16 | NextionPage(Nextion &nex, uint8_t page, uint8_t component, const char *name); 17 | 18 | bool show(); 19 | bool isShown(); 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /NextionCrop.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONCROP 4 | #define __NEONEXTION_NEXTIONCROP 5 | 6 | #include "Nextion.h" 7 | #include "INextionTouchable.h" 8 | 9 | /*! 10 | * \class NextionCrop 11 | * \brief Represents a cropped picture widget. 12 | */ 13 | class NextionCrop : public INextionTouchable 14 | { 15 | public: 16 | NextionCrop(Nextion &nex, uint8_t page, uint8_t component, const char *name); 17 | 18 | uint16_t getPictureID(); 19 | bool setPictureID(uint16_t id); 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /NextionTimer.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONTIMER 4 | #define __NEONEXTION_NEXTIONTIMER 5 | 6 | #include "Nextion.h" 7 | #include "INextionTouchable.h" 8 | 9 | /*! 10 | * \class NextionTimer 11 | * \brief Represents a timer. 12 | */ 13 | class NextionTimer : public INextionTouchable 14 | { 15 | public: 16 | NextionTimer(Nextion &nex, uint8_t page, uint8_t component, const char *name); 17 | 18 | uint32_t getCycle(); 19 | bool setCycle(uint32_t cycle); 20 | 21 | bool enable(); 22 | bool disable(); 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /NextionPicture.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONPICTURE 4 | #define __NEONEXTION_NEXTIONPICTURE 5 | 6 | #include "Nextion.h" 7 | #include "INextionTouchable.h" 8 | 9 | /*! 10 | * \class NextionPicture 11 | * \brief Represents a full size picture widget. 12 | */ 13 | class NextionPicture : public INextionTouchable 14 | { 15 | public: 16 | NextionPicture(Nextion &nex, uint8_t page, uint8_t component, 17 | const char *name); 18 | 19 | uint16_t getPictureID(); 20 | bool setPictureID(uint16_t id); 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /.travis_deploy_docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "master" ]; 4 | then 5 | echo Not publishing documentation. 6 | exit 0; 7 | fi 8 | 9 | git config --global user.email "nobody@nobody.org" 10 | git config --global user.name "Travis CI" 11 | 12 | # Publish the PlatformIO library.json 13 | cp library.json docs/html 14 | 15 | cd docs/html 16 | git init 17 | 18 | git add . 19 | git commit -m "Deploy Doxygen documentation" 20 | git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" master:gh-pages > /dev/null 2>&1 21 | -------------------------------------------------------------------------------- /examples/SerialThruHardwareSerial/SerialThruHardwareSerial.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * A simple script to allow programming and debugging 3 | * of a display device using the Nextion editor when 4 | * the display its self is still connected in situ. 5 | */ 6 | 7 | #define HOST_PORT Serial 8 | #define NEXTION_PORT Serial1 9 | 10 | #define BAUD 9600 11 | 12 | void setup() 13 | { 14 | HOST_PORT.begin(BAUD); 15 | NEXTION_PORT.begin(BAUD); 16 | } 17 | 18 | void loop() 19 | { 20 | while(HOST_PORT.available()) 21 | NEXTION_PORT.write(HOST_PORT.read()); 22 | 23 | while(NEXTION_PORT.available()) 24 | HOST_PORT.write(NEXTION_PORT.read()); 25 | } 26 | -------------------------------------------------------------------------------- /examples/SerialThru/SerialThru.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * A simple script to allow programming and debugging 3 | * of a display device using the Nextion editor when 4 | * the display its self is still connected in situ. 5 | */ 6 | 7 | #include 8 | 9 | SoftwareSerial nextionSerial(10, 11); // RX, TX 10 | 11 | #define HOST_PORT Serial 12 | 13 | #define BAUD 9600 14 | 15 | void setup() 16 | { 17 | HOST_PORT.begin(BAUD); 18 | nextionSerial.begin(BAUD); 19 | } 20 | 21 | void loop() 22 | { 23 | while(HOST_PORT.available()) 24 | nextionSerial.write(HOST_PORT.read()); 25 | 26 | while(nextionSerial.available()) 27 | HOST_PORT.write(nextionSerial.read()); 28 | } 29 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "NeoNextion", 3 | "keywords": "neonextion, nextion, hmi, display", 4 | "description": "Arduino library for controlling Nextion displays", 5 | "url": "https://dannixon.github.io/NeoNextion", 6 | "repository": 7 | { 8 | "type": "git", 9 | "url": "https://github.com/DanNixon/NeoNextion.git" 10 | }, 11 | "version": "2.2.0", 12 | "exclude": [ 13 | "extra", 14 | "Doxyfile" 15 | ], 16 | "authors": 17 | { 18 | "name": "Dan Nixon", 19 | "email": "dan@dan-nixon.com", 20 | "url": "http://www.dan-nixon.com" 21 | }, 22 | "frameworks": "arduino", 23 | "platforms": ["atmelavr", "atmelsam", "espressif", "espressif32"] 24 | } 25 | -------------------------------------------------------------------------------- /INextionCallback.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_INEXTIONCALLBACK 4 | #define __NEONEXTION_INEXTIONCALLBACK 5 | 6 | #include "INextionTouchable.h" 7 | 8 | /*! 9 | * \class INextionCallback 10 | * \brief Interface for classes that handle callbacks from a display device. 11 | */ 12 | class INextionCallback 13 | { 14 | public: 15 | INextionCallback() 16 | { 17 | } 18 | 19 | /*! 20 | * \brief Handle a callback. 21 | * \param type Event type 22 | * \param widget Pointer to the widget that fired the event 23 | */ 24 | virtual void handleNextionEvent(NextionEventType type, 25 | INextionTouchable *widget) = 0; 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /NextionHotspot.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONHOTSPOT 4 | #define __NEONEXTION_NEXTIONHOTSPOT 5 | 6 | #include "Nextion.h" 7 | #include "INextionWidget.h" 8 | #include "INextionTouchable.h" 9 | 10 | /*! 11 | * \class NextionHotspot 12 | * \brief Represents a hotspot widget. 13 | */ 14 | class NextionHotspot : public INextionTouchable 15 | { 16 | public: 17 | /*! 18 | * \copydoc INextionWidget::INextionWidget 19 | */ 20 | NextionHotspot(Nextion &nex, uint8_t page, uint8_t component, 21 | const char *name) 22 | : INextionWidget(nex, page, component, name) 23 | , INextionTouchable(nex, page, component, name) 24 | { 25 | } 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /NextionCrop.cpp: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #include "NextionCrop.h" 4 | #include "INextionWidget.h" 5 | 6 | /*! 7 | * \copydoc INextionWidget::INextionWidget 8 | */ 9 | NextionCrop::NextionCrop(Nextion &nex, uint8_t page, uint8_t component, 10 | const char *name) 11 | : INextionWidget(nex, page, component, name) 12 | , INextionTouchable(nex, page, component, name) 13 | { 14 | } 15 | 16 | /*! 17 | * \copydoc NextionPicture::getPictureID 18 | */ 19 | uint16_t NextionCrop::getPictureID() 20 | { 21 | return getNumberProperty("pic"); 22 | } 23 | 24 | /*! 25 | * \copydoc NextionPicture::setPictureID 26 | */ 27 | bool NextionCrop::setPictureID(uint16_t id) 28 | { 29 | return setNumberProperty("pic", id); 30 | } 31 | -------------------------------------------------------------------------------- /examples/SystemSettingsHardwareSerial/SystemSettingsHardwareSerial.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define NEXTION_PORT Serial1 5 | 6 | Nextion nex(NEXTION_PORT); 7 | 8 | void setup() 9 | { 10 | Serial.begin(9600); 11 | 12 | NEXTION_PORT.begin(9600); 13 | nex.init(); 14 | 15 | Serial.println(nex.clear(NEX_COL_BLUE)); 16 | 17 | Serial.println(nex.sleep()); 18 | delay(1000); 19 | Serial.println(nex.wake()); 20 | delay(1000); 21 | Serial.println(nex.setBrightness(50)); 22 | Serial.println(nex.getBrightness()); 23 | delay(1000); 24 | Serial.println(nex.setBrightness(20, true)); 25 | Serial.println(nex.getBrightness()); 26 | } 27 | 28 | void loop() 29 | { 30 | nex.poll(); 31 | } 32 | -------------------------------------------------------------------------------- /NextionVariableNumeric.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONVARIABLENUMERIC 4 | #define __NEONEXTION_NEXTIONVARIABLENUMERIC 5 | 6 | #include "Nextion.h" 7 | #include "INextionNumericalValued.h" 8 | 9 | /*! 10 | * \class NextionVariableNumeric 11 | * \brief Represents a numeric variable. 12 | */ 13 | class NextionVariableNumeric : public INextionNumericalValued 14 | { 15 | public: 16 | /*! 17 | * \copydoc INextionWidget::INextionWidget 18 | */ 19 | NextionVariableNumeric(Nextion &nex, uint8_t page, uint8_t component, 20 | const char *name) 21 | : INextionWidget(nex, page, component, name) 22 | , INextionNumericalValued(nex, page, component, name) 23 | { 24 | } 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /examples/SystemSettings/SystemSettings.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | SoftwareSerial nextionSerial(10, 11); // RX, TX 6 | 7 | Nextion nex(nextionSerial); 8 | 9 | void setup() 10 | { 11 | Serial.begin(9600); 12 | 13 | nextionSerial.begin(9600); 14 | nex.init(); 15 | 16 | Serial.println(nex.clear(NEX_COL_BLUE)); 17 | 18 | Serial.println(nex.sleep()); 19 | delay(1000); 20 | Serial.println(nex.wake()); 21 | delay(1000); 22 | Serial.println(nex.setBrightness(50)); 23 | Serial.println(nex.getBrightness()); 24 | delay(1000); 25 | Serial.println(nex.setBrightness(20, true)); 26 | Serial.println(nex.getBrightness()); 27 | } 28 | 29 | void loop() 30 | { 31 | nex.poll(); 32 | } 33 | -------------------------------------------------------------------------------- /NextionVariableString.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONVARIABLESTRING 4 | #define __NEONEXTION_NEXTIONVARIABLESTRING 5 | 6 | #include "Nextion.h" 7 | #include "INextionWidget.h" 8 | #include "INextionStringValued.h" 9 | 10 | /*! 11 | * \class NextionVariableString 12 | * \brief Represents a string variable. 13 | */ 14 | class NextionVariableString : public INextionStringValued 15 | { 16 | public: 17 | /*! 18 | * \copydoc INextionWidget::INextionWidget 19 | */ 20 | NextionVariableString(Nextion &nex, uint8_t page, uint8_t component, 21 | const char *name) 22 | : INextionWidget(nex, page, component, name) 23 | , INextionStringValued(nex, page, component, name) 24 | { 25 | } 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /examples/Crop/Crop.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgCrop(nex, 4, 0, "pgCrop"); 10 | NextionCrop crop(nex, 4, 2, "crExCrop"); 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | pinMode(13, OUTPUT); 16 | 17 | nextionSerial.begin(9600); 18 | nex.init(); 19 | 20 | Serial.println(pgCrop.show()); 21 | 22 | Serial.println(crop.attachCallback(&callback)); 23 | } 24 | 25 | void loop() 26 | { 27 | nex.poll(); 28 | } 29 | 30 | void callback(NextionEventType type, INextionTouchable *widget) 31 | { 32 | if (type == NEX_EVENT_PUSH) 33 | digitalWrite(13, HIGH); 34 | else if (type == NEX_EVENT_POP) 35 | digitalWrite(13, LOW); 36 | } 37 | -------------------------------------------------------------------------------- /NextionPage.cpp: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #include "NextionPage.h" 4 | 5 | /*! 6 | * \copydoc INextionWidget::INextionWidget 7 | */ 8 | NextionPage::NextionPage(Nextion &nex, uint8_t page, uint8_t component, 9 | const char *name) 10 | : INextionWidget(nex, page, component, name) 11 | { 12 | } 13 | 14 | /*! 15 | * \brief Sets this page as the currently displayed page. 16 | * \return True if successful 17 | */ 18 | bool NextionPage::show() 19 | { 20 | size_t commandLen = 6 + strlen(m_name); 21 | char command[commandLen]; 22 | snprintf(command, commandLen, "page %s", m_name); 23 | return sendCommand(command); 24 | } 25 | 26 | /*! 27 | * \brief Determines if this page is currently displayed. 28 | * \return True if displayed 29 | */ 30 | bool NextionPage::isShown() 31 | { 32 | return m_nextion.getCurrentPage() == m_pageID; 33 | } 34 | -------------------------------------------------------------------------------- /examples/Hotspot/Hotspot.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgHotspot(nex, 5, 0, "pgHotspot"); 10 | NextionHotspot hotspot(nex, 5, 2, "hsExHotspot"); 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | pinMode(13, OUTPUT); 16 | 17 | nextionSerial.begin(9600); 18 | nex.init(); 19 | 20 | Serial.println(pgHotspot.show()); 21 | 22 | Serial.println(hotspot.attachCallback(&callback)); 23 | } 24 | 25 | void loop() 26 | { 27 | nex.poll(); 28 | } 29 | 30 | void callback(NextionEventType type, INextionTouchable *widget) 31 | { 32 | if (type == NEX_EVENT_PUSH) 33 | digitalWrite(13, HIGH); 34 | else if (type == NEX_EVENT_POP) 35 | digitalWrite(13, LOW); 36 | } 37 | -------------------------------------------------------------------------------- /examples/BasicGraphicsHardwareSerial/BasicGraphicsHardwareSerial.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define NEXTION_PORT Serial1 5 | 6 | Nextion nex(NEXTION_PORT); 7 | 8 | void setup() 9 | { 10 | Serial.begin(9600); 11 | 12 | NEXTION_PORT.begin(9600); 13 | nex.init(); 14 | 15 | Serial.println(nex.clear(NEX_COL_BLUE)); 16 | 17 | Serial.println(nex.drawCircle(50, 30, 10, NEX_COL_WHITE)); 18 | Serial.println(nex.drawRect(70, 40, 15, 5, false, NEX_COL_GREEN)); 19 | Serial.println(nex.drawRect(20, 60, 15, 5, true, NEX_COL_RED)); 20 | Serial.println(nex.drawLine(150, 150, 200, 180, NEX_COL_YELLOW)); 21 | Serial.println(nex.drawPicture(180, 180, 0)); 22 | /* Serial.println(nex.drawPicture(50, 180, 10, 10, 0)); */ 23 | Serial.println(nex.drawStr(50, 80, 200, 30, 0, "Hello, world!")); 24 | } 25 | 26 | void loop() 27 | { 28 | nex.poll(); 29 | } 30 | -------------------------------------------------------------------------------- /INextionTouchable.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_INEXTIONTOUCHABLE 4 | #define __NEONEXTION_INEXTIONTOUCHABLE 5 | 6 | #include "Nextion.h" 7 | #include "INextionWidget.h" 8 | #include "INextionCallback.h" 9 | #include "NextionCallbackFunctionHandler.h" 10 | 11 | /*! 12 | * \class INextionTouchable 13 | * \brief Interface for widgets that can be touched. 14 | */ 15 | class INextionTouchable : public virtual INextionWidget 16 | { 17 | public: 18 | INextionTouchable(Nextion &nex, uint8_t page, uint8_t component, 19 | const char *name); 20 | 21 | bool processEvent(uint8_t pageID, uint8_t componentID, uint8_t eventType); 22 | 23 | bool attachCallback(NextionCallbackFunctionHandler::NextionFunction cb); 24 | bool attachCallback(INextionCallback *obj); 25 | void detachCallback(); 26 | 27 | private: 28 | INextionCallback *m_callback; 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /NextionPicture.cpp: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #include "NextionPicture.h" 4 | #include "INextionWidget.h" 5 | 6 | /*! 7 | * \copydoc INextionWidget::INextionWidget 8 | */ 9 | NextionPicture::NextionPicture(Nextion &nex, uint8_t page, uint8_t component, 10 | const char *name) 11 | : INextionWidget(nex, page, component, name) 12 | , INextionTouchable(nex, page, component, name) 13 | { 14 | } 15 | 16 | /*! 17 | * \brief Gets the ID of the currently displayed picture. 18 | * \return PIcture ID (may also return 0 in case of error) 19 | */ 20 | uint16_t NextionPicture::getPictureID() 21 | { 22 | return getNumberProperty("pic"); 23 | } 24 | 25 | /*! 26 | * \brief Sets the picture to be displayed. 27 | * \param id Picture ID 28 | * \return True if successful 29 | */ 30 | bool NextionPicture::setPictureID(uint16_t id) 31 | { 32 | return setNumberProperty("pic", id); 33 | } 34 | -------------------------------------------------------------------------------- /examples/BasicGraphics/BasicGraphics.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | SoftwareSerial nextionSerial(10, 11); // RX, TX 6 | 7 | Nextion nex(nextionSerial); 8 | 9 | void setup() 10 | { 11 | Serial.begin(9600); 12 | 13 | nextionSerial.begin(9600); 14 | nex.init(); 15 | 16 | Serial.println(nex.clear(NEX_COL_BLUE)); 17 | 18 | Serial.println(nex.drawCircle(50, 30, 10, NEX_COL_WHITE)); 19 | Serial.println(nex.drawRect(70, 40, 15, 5, false, NEX_COL_GREEN)); 20 | Serial.println(nex.drawRect(20, 60, 15, 5, true, NEX_COL_RED)); 21 | Serial.println(nex.drawLine(150, 150, 200, 180, NEX_COL_YELLOW)); 22 | Serial.println(nex.drawPicture(180, 180, 0)); 23 | /* Serial.println(nex.drawPicture(50, 180, 10, 10, 0)); */ 24 | Serial.println(nex.drawStr(50, 80, 200, 30, 0, "Hello, world!")); 25 | } 26 | 27 | void loop() 28 | { 29 | nex.poll(); 30 | } 31 | -------------------------------------------------------------------------------- /NextionGauge.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONGAUGE 4 | #define __NEONEXTION_NEXTIONGAUGE 5 | 6 | #include "Nextion.h" 7 | #include "INextionTouchable.h" 8 | #include "INextionColourable.h" 9 | #include "INextionNumericalValued.h" 10 | 11 | /*! 12 | * \class NextionGauge 13 | * \brief Represents a gauge widget/ 14 | */ 15 | class NextionGauge : public INextionTouchable, 16 | public INextionColourable, 17 | public INextionNumericalValued 18 | { 19 | public: 20 | /*! 21 | * \copydoc INextionWidget::INextionWidget 22 | */ 23 | NextionGauge(Nextion &nex, uint8_t page, uint8_t component, const char *name) 24 | : INextionWidget(nex, page, component, name) 25 | , INextionTouchable(nex, page, component, name) 26 | , INextionColourable(nex, page, component, name) 27 | , INextionNumericalValued(nex, page, component, name) 28 | { 29 | } 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /NextionSlider.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONSLIDER 4 | #define __NEONEXTION_NEXTIONSLIDER 5 | 6 | #include "Nextion.h" 7 | #include "INextionTouchable.h" 8 | #include "INextionColourable.h" 9 | #include "INextionNumericalValued.h" 10 | 11 | /*! 12 | * \class NextionSlider 13 | * \brief Represents a slider widget. 14 | */ 15 | class NextionSlider : public INextionTouchable, 16 | public INextionColourable, 17 | public INextionNumericalValued 18 | { 19 | public: 20 | /*! 21 | * \copydoc INextionWidget::INextionWidget 22 | */ 23 | NextionSlider(Nextion &nex, uint8_t page, uint8_t component, const char *name) 24 | : INextionWidget(nex, page, component, name) 25 | , INextionTouchable(nex, page, component, name) 26 | , INextionColourable(nex, page, component, name) 27 | , INextionNumericalValued(nex, page, component, name) 28 | { 29 | } 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /INextionFontStyleable.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_INEXTIONFONTSTYLEABLE 4 | #define __NEONEXTION_INEXTIONFONTSTYLEABLE 5 | 6 | #include "Nextion.h" 7 | #include "INextionWidget.h" 8 | #include "NextionTypes.h" 9 | 10 | /*! 11 | * \class INextionFontStyleable 12 | * \brief Interface for widgets that can have their fonts styled. 13 | */ 14 | class INextionFontStyleable : public virtual INextionWidget 15 | { 16 | public: 17 | INextionFontStyleable(Nextion &nex, uint8_t page, uint8_t component, 18 | const char *name); 19 | 20 | bool setFont(uint8_t id, bool refresh = true); 21 | uint8_t getFont(); 22 | 23 | bool setHAlignment(NextionFontAlignment align, bool refresh = true); 24 | NextionFontAlignment getHAlignment(); 25 | 26 | bool setVAlignment(NextionFontAlignment align, bool refresh = true); 27 | NextionFontAlignment getVAlignment(); 28 | 29 | bool afterSet(bool result, bool refresh); 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /examples/VariablesHardwareSerial/VariablesHardwareSerial.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define NEXTION_PORT Serial1 7 | 8 | Nextion nex(NEXTION_PORT); 9 | NextionPage pgVariable(nex, 10, 0, "pgVariable"); 10 | NextionVariableNumeric var1(nex, 10, 2, "vaExVariableN"); 11 | NextionVariableString var2(nex, 10, 3, "vaExVariableS"); 12 | 13 | /* 14 | * This example should print the following to the serial port: 15 | * 1 16 | * 4 17 | * Hello! 18 | */ 19 | 20 | void setup() 21 | { 22 | Serial.begin(9600); 23 | 24 | NEXTION_PORT.begin(9600); 25 | nex.init(); 26 | 27 | Serial.println(pgVariable.show()); 28 | 29 | var1.setValue(4); 30 | Serial.println(var1.getValue()); 31 | 32 | var2.setText("Hello!"); 33 | char buffer[20]; 34 | if (var2.getText(buffer, 20)) 35 | Serial.println(buffer); 36 | } 37 | 38 | void loop() 39 | { 40 | nex.poll(); 41 | } 42 | -------------------------------------------------------------------------------- /NextionCheckbox.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONCHECKBOX 4 | #define __NEONEXTION_NEXTIONCHECKBOX 5 | 6 | #include "Nextion.h" 7 | #include "INextionTouchable.h" 8 | #include "INextionColourable.h" 9 | #include "INextionBooleanValued.h" 10 | 11 | /*! 12 | * \class NextionCheckbox 13 | * \brief Represents a checkbox. 14 | */ 15 | class NextionCheckbox : public INextionTouchable, 16 | public INextionColourable, 17 | public INextionBooleanValued 18 | { 19 | public: 20 | /*! 21 | * \copydoc INextionWidget::INextionWidget 22 | */ 23 | NextionCheckbox(Nextion &nex, uint8_t page, uint8_t component, 24 | const char *name) 25 | : INextionWidget(nex, page, component, name) 26 | , INextionTouchable(nex, page, component, name) 27 | , INextionColourable(nex, page, component, name) 28 | , INextionBooleanValued(nex, page, component, name) 29 | { 30 | } 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /examples/Variables/Variables.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | SoftwareSerial nextionSerial(10, 11); // RX, TX 8 | 9 | Nextion nex(nextionSerial); 10 | NextionPage pgVariable(nex, 10, 0, "pgVariable"); 11 | NextionVariableNumeric var1(nex, 10, 2, "vaExVariableN"); 12 | NextionVariableString var2(nex, 10, 3, "vaExVariableS"); 13 | 14 | /* 15 | * This example should print the following to the serial port: 16 | * 1 17 | * 4 18 | * Hello! 19 | */ 20 | 21 | void setup() 22 | { 23 | Serial.begin(9600); 24 | 25 | nextionSerial.begin(9600); 26 | nex.init(); 27 | 28 | Serial.println(pgVariable.show()); 29 | 30 | var1.setValue(4); 31 | Serial.println(var1.getValue()); 32 | 33 | var2.setText("Hello!"); 34 | char buffer[20]; 35 | if (var2.getText(buffer, 20)) 36 | Serial.println(buffer); 37 | } 38 | 39 | void loop() 40 | { 41 | nex.poll(); 42 | } 43 | -------------------------------------------------------------------------------- /NextionWaveform.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONWAVEFORM 4 | #define __NEONEXTION_NEXTIONWAVEFORM 5 | 6 | #include "Nextion.h" 7 | #include "INextionTouchable.h" 8 | #include "INextionColourable.h" 9 | 10 | /*! 11 | * \class NextionWaveform 12 | * \brief Represents a waveform widget. 13 | */ 14 | class NextionWaveform : public INextionTouchable, public INextionColourable 15 | { 16 | public: 17 | NextionWaveform(Nextion &nex, uint8_t page, uint8_t component, 18 | const char *name); 19 | 20 | bool addValue(uint8_t channel, uint8_t value); 21 | 22 | bool setChannelColour(uint8_t channel, uint32_t colour, bool refresh = true); 23 | uint32_t getChannelColour(uint8_t channel); 24 | 25 | bool setGridColour(uint32_t colour, bool refresh = true); 26 | uint32_t getGridColour(); 27 | 28 | bool setGridWidth(uint16_t width); 29 | uint16_t getGridWidth(); 30 | 31 | bool setGridHeight(uint16_t height); 32 | uint16_t getGridHeight(); 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /examples/Picture/Picture.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgPicture(nex, 3, 0, "pgPicture"); 10 | NextionPicture picture(nex, 3, 2, "pExPicture"); 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | pinMode(13, OUTPUT); 16 | 17 | nextionSerial.begin(9600); 18 | nex.init(); 19 | 20 | Serial.println(pgPicture.show()); 21 | 22 | Serial.println(picture.attachCallback(&callback)); 23 | 24 | Serial.println(picture.getPictureID()); 25 | Serial.println(picture.setPictureID(1)); 26 | Serial.println(picture.getPictureID()); 27 | } 28 | 29 | void loop() 30 | { 31 | nex.poll(); 32 | } 33 | 34 | void callback(NextionEventType type, INextionTouchable *widget) 35 | { 36 | if (type == NEX_EVENT_PUSH) 37 | digitalWrite(13, HIGH); 38 | else if (type == NEX_EVENT_POP) 39 | digitalWrite(13, LOW); 40 | } 41 | -------------------------------------------------------------------------------- /NextionRadioButton.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONRADIOBUTTON 4 | #define __NEONEXTION_NEXTIONRADIOBUTTON 5 | 6 | #include "Nextion.h" 7 | #include "INextionTouchable.h" 8 | #include "INextionColourable.h" 9 | #include "INextionBooleanValued.h" 10 | 11 | /*! 12 | * \class NextionRadioButton 13 | * \brief Represents a basic button widget. 14 | */ 15 | class NextionRadioButton : public INextionTouchable, 16 | public INextionColourable, 17 | public INextionBooleanValued 18 | { 19 | public: 20 | /*! 21 | * \copydoc INextionWidget::INextionWidget 22 | */ 23 | NextionRadioButton(Nextion &nex, uint8_t page, uint8_t component, 24 | const char *name) 25 | : INextionWidget(nex, page, component, name) 26 | , INextionTouchable(nex, page, component, name) 27 | , INextionColourable(nex, page, component, name) 28 | , INextionBooleanValued(nex, page, component, name) 29 | { 30 | } 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /NextionProgressBar.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONPROGRESSBAR 4 | #define __NEONEXTION_NEXTIONPROGRESSBAR 5 | 6 | #include "Nextion.h" 7 | #include "INextionTouchable.h" 8 | #include "INextionColourable.h" 9 | #include "INextionNumericalValued.h" 10 | 11 | /*! 12 | * \class NextionProgressBar 13 | * \brief Represents a progress bar widget. 14 | */ 15 | class NextionProgressBar : public INextionTouchable, 16 | public INextionColourable, 17 | public INextionNumericalValued 18 | { 19 | public: 20 | /*! 21 | * \copydoc INextionWidget::INextionWidget 22 | */ 23 | NextionProgressBar(Nextion &nex, uint8_t page, uint8_t component, 24 | const char *name) 25 | : INextionWidget(nex, page, component, name) 26 | , INextionTouchable(nex, page, component, name) 27 | , INextionColourable(nex, page, component, name) 28 | , INextionNumericalValued(nex, page, component, name) 29 | { 30 | } 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /examples/SliderHardwareSerial/SliderHardwareSerial.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define NEXTION_PORT Serial1 6 | 7 | Nextion nex(NEXTION_PORT); 8 | NextionPage pgSlider(nex, 8, 0, "pgSlider"); 9 | NextionSlider slider(nex, 8, 2, "sExSlider"); 10 | 11 | void setup() 12 | { 13 | Serial.begin(9600); 14 | pinMode(13, OUTPUT); 15 | 16 | NEXTION_PORT.begin(9600); 17 | nex.init(); 18 | 19 | Serial.println(pgSlider.show()); 20 | 21 | Serial.println(slider.setBackgroundColour(NEX_COL_BLUE)); 22 | Serial.println(slider.setForegroundColour(NEX_COL_YELLOW)); 23 | 24 | Serial.println(slider.attachCallback(&callback)); 25 | } 26 | 27 | void loop() 28 | { 29 | nex.poll(); 30 | } 31 | 32 | void callback(NextionEventType type, INextionTouchable *widget) 33 | { 34 | if (type == NEX_EVENT_PUSH) 35 | digitalWrite(13, HIGH); 36 | else if (type == NEX_EVENT_POP) 37 | { 38 | Serial.println(slider.getValue()); 39 | digitalWrite(13, LOW); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /NextionDualStateButton.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONDUALSTATEBUTTON 4 | #define __NEONEXTION_NEXTIONDUALSTATEBUTTON 5 | 6 | #include "Nextion.h" 7 | #include "INextionTouchable.h" 8 | #include "INextionColourable.h" 9 | #include "INextionBooleanValued.h" 10 | 11 | /*! 12 | * \class NextionDualStateButton 13 | * \brief Represents a dual state button widget. 14 | */ 15 | class NextionDualStateButton : public INextionTouchable, 16 | public INextionColourable, 17 | public INextionBooleanValued 18 | { 19 | public: 20 | /*! 21 | * \copydoc INextionWidget::INextionWidget 22 | */ 23 | NextionDualStateButton(Nextion &nex, uint8_t page, uint8_t component, 24 | const char *name) 25 | : INextionWidget(nex, page, component, name) 26 | , INextionTouchable(nex, page, component, name) 27 | , INextionColourable(nex, page, component, name) 28 | , INextionBooleanValued(nex, page, component, name) 29 | { 30 | } 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /examples/SlidingText/SlidingText.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgScrollingText(nex, 15, 0, "pgScrollText"); 10 | NextionSlidingText text(nex, 15, 2, "stExScrollText"); 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | pinMode(13, OUTPUT); 16 | 17 | nextionSerial.begin(9600); 18 | nex.init(); 19 | 20 | Serial.println(pgScrollingText.show()); 21 | 22 | Serial.println(text.attachCallback(&callback)); 23 | 24 | Serial.println(text.setText("Press me!")); 25 | } 26 | 27 | void loop() 28 | { 29 | nex.poll(); 30 | } 31 | 32 | void callback(NextionEventType type, INextionTouchable *widget) 33 | { 34 | if (type == NEX_EVENT_PUSH) 35 | { 36 | digitalWrite(13, HIGH); 37 | text.setText("Hyah!"); 38 | } 39 | else if (type == NEX_EVENT_POP) 40 | { 41 | digitalWrite(13, LOW); 42 | text.setText("You pressed me"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /examples/Text/Text.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgText(nex, 1, 0, "pgText"); 10 | NextionText text(nex, 1, 2, "tExText"); 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | pinMode(13, OUTPUT); 16 | 17 | nextionSerial.begin(9600); 18 | nex.init(); 19 | 20 | Serial.println(pgText.show()); 21 | 22 | Serial.println(text.attachCallback(&callback)); 23 | 24 | Serial.println(text.setText("Press me!")); 25 | 26 | Serial.println(text.setBackgroundColour(NEX_COL_BLUE)); 27 | } 28 | 29 | void loop() 30 | { 31 | nex.poll(); 32 | } 33 | 34 | void callback(NextionEventType type, INextionTouchable *widget) 35 | { 36 | if (type == NEX_EVENT_PUSH) 37 | { 38 | digitalWrite(13, HIGH); 39 | text.setText("Hyah!"); 40 | } 41 | else if (type == NEX_EVENT_POP) 42 | { 43 | digitalWrite(13, LOW); 44 | text.setText("You pressed me"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /examples/Number/Number.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgNumber(nex, 12, 0, "pgNumber"); 10 | NextionNumber number(nex, 12, 2, "nExNumber"); 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | pinMode(13, OUTPUT); 16 | 17 | nextionSerial.begin(9600); 18 | nex.init(); 19 | 20 | Serial.println(pgNumber.show()); 21 | 22 | Serial.println(number.attachCallback(&callback)); 23 | 24 | Serial.println(number.setValue(42)); 25 | 26 | Serial.println(number.setBackgroundColour(NEX_COL_BLUE)); 27 | } 28 | 29 | void loop() 30 | { 31 | nex.poll(); 32 | } 33 | 34 | void callback(NextionEventType type, INextionTouchable *widget) 35 | { 36 | if (type == NEX_EVENT_PUSH) 37 | { 38 | digitalWrite(13, HIGH); 39 | number.setValue(12345); 40 | } 41 | else if (type == NEX_EVENT_POP) 42 | { 43 | digitalWrite(13, LOW); 44 | number.setValue(99); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /NextionText.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONTEXT 4 | #define __NEONEXTION_NEXTIONTEXT 5 | 6 | #include "Nextion.h" 7 | #include "INextionTouchable.h" 8 | #include "INextionColourable.h" 9 | #include "INextionStringValued.h" 10 | #include "INextionFontStyleable.h" 11 | 12 | /*! 13 | * \class NextionText 14 | * \brief Represents a text widget. 15 | */ 16 | class NextionText : public INextionTouchable, 17 | public INextionColourable, 18 | public INextionStringValued, 19 | public INextionFontStyleable 20 | { 21 | public: 22 | /*! 23 | * \copydoc INextionWidget::INextionWidget 24 | */ 25 | NextionText(Nextion &nex, uint8_t page, uint8_t component, const char *name) 26 | : INextionWidget(nex, page, component, name) 27 | , INextionTouchable(nex, page, component, name) 28 | , INextionColourable(nex, page, component, name) 29 | , INextionStringValued(nex, page, component, name) 30 | , INextionFontStyleable(nex, page, component, name) 31 | { 32 | } 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /examples/Checkbox/Checkbox.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgCheckbox(nex, 13, 0, "pgCheckbox"); 10 | NextionCheckbox checkbox(nex, 13, 2, "cbExCheckbox"); 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | pinMode(13, OUTPUT); 16 | 17 | nextionSerial.begin(9600); 18 | nex.init(); 19 | 20 | Serial.println(pgCheckbox.show()); 21 | 22 | Serial.println(checkbox.attachCallback(&callback)); 23 | 24 | Serial.println(checkbox.isActive()); 25 | Serial.println(checkbox.setActive(true)); 26 | Serial.println(checkbox.isActive()); 27 | } 28 | 29 | void loop() 30 | { 31 | nex.poll(); 32 | } 33 | 34 | void callback(NextionEventType type, INextionTouchable *widget) 35 | { 36 | if (type == NEX_EVENT_PUSH) 37 | { 38 | digitalWrite(13, HIGH); 39 | } 40 | else if (type == NEX_EVENT_POP) 41 | { 42 | Serial.println(checkbox.isActive()); 43 | digitalWrite(13, LOW); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /NextionButton.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONBUTTON 4 | #define __NEONEXTION_NEXTIONBUTTON 5 | 6 | #include "Nextion.h" 7 | #include "INextionTouchable.h" 8 | #include "INextionColourable.h" 9 | #include "INextionStringValued.h" 10 | #include "INextionFontStyleable.h" 11 | 12 | /*! 13 | * \class NextionButton 14 | * \brief Represents a basic button widget. 15 | */ 16 | class NextionButton : public INextionTouchable, 17 | public INextionColourable, 18 | public INextionStringValued, 19 | public INextionFontStyleable 20 | { 21 | public: 22 | /*! 23 | * \copydoc INextionWidget::INextionWidget 24 | */ 25 | NextionButton(Nextion &nex, uint8_t page, uint8_t component, const char *name) 26 | : INextionWidget(nex, page, component, name) 27 | , INextionTouchable(nex, page, component, name) 28 | , INextionColourable(nex, page, component, name) 29 | , INextionStringValued(nex, page, component, name) 30 | , INextionFontStyleable(nex, page, component, name) 31 | { 32 | } 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /NextionNumber.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONNUMBER 4 | #define __NEONEXTION_NEXTIONNUMBER 5 | 6 | #include "Nextion.h" 7 | #include "INextionTouchable.h" 8 | #include "INextionColourable.h" 9 | #include "INextionNumericalValued.h" 10 | #include "INextionFontStyleable.h" 11 | 12 | /*! 13 | * \class NextionNumber 14 | * \brief Represents a number widget. 15 | */ 16 | class NextionNumber : public INextionTouchable, 17 | public INextionColourable, 18 | public INextionNumericalValued, 19 | public INextionFontStyleable 20 | { 21 | public: 22 | /*! 23 | * \copydoc INextionWidget::INextionWidget 24 | */ 25 | NextionNumber(Nextion &nex, uint8_t page, uint8_t component, const char *name) 26 | : INextionWidget(nex, page, component, name) 27 | , INextionTouchable(nex, page, component, name) 28 | , INextionColourable(nex, page, component, name) 29 | , INextionNumericalValued(nex, page, component, name) 30 | , INextionFontStyleable(nex, page, component, name) 31 | { 32 | } 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /examples/DualStateButton/DualStateButton.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgDsButton(nex, 11, 0, "pgDsButton"); 10 | NextionDualStateButton button(nex, 11, 2, "bExDsButton"); 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | pinMode(13, OUTPUT); 16 | 17 | nextionSerial.begin(9600); 18 | nex.init(); 19 | 20 | Serial.println(pgDsButton.show()); 21 | 22 | Serial.println(button.attachCallback(&callback)); 23 | 24 | Serial.println(button.isActive()); 25 | Serial.println(button.setActive(true)); 26 | Serial.println(button.isActive()); 27 | } 28 | 29 | void loop() 30 | { 31 | nex.poll(); 32 | } 33 | 34 | void callback(NextionEventType type, INextionTouchable *widget) 35 | { 36 | if (type == NEX_EVENT_PUSH) 37 | { 38 | digitalWrite(13, HIGH); 39 | } 40 | else if (type == NEX_EVENT_POP) 41 | { 42 | Serial.println(button.isActive()); 43 | digitalWrite(13, LOW); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /examples/Timer/Timer.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgTimer(nex, 9, 0, "pgTimer"); 10 | NextionTimer timer(nex, 9, 2, "tmExTimer"); 11 | 12 | /* 13 | * Timer callbacks are only possible when the following is added to the 14 | * event code in the UI file: 15 | * printh 65 PG CO 00 ff ff ff 16 | * Where PG is the page ID and CO is the component ID. 17 | */ 18 | 19 | void setup() 20 | { 21 | Serial.begin(9600); 22 | pinMode(13, OUTPUT); 23 | 24 | nextionSerial.begin(9600); 25 | nex.init(); 26 | 27 | Serial.println(pgTimer.show()); 28 | 29 | Serial.println(timer.attachCallback(&timer_callback)); 30 | Serial.println(timer.setCycle(1000)); 31 | Serial.println(timer.enable()); 32 | } 33 | 34 | void loop() 35 | { 36 | nex.poll(); 37 | } 38 | 39 | // type parameter is not used for timers 40 | void timer_callback(NextionEventType type, INextionTouchable *widget) 41 | { 42 | digitalWrite(13, !digitalRead(13)); 43 | } 44 | -------------------------------------------------------------------------------- /examples/RadioButton/RadioButton.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgRadioButton(nex, 14, 0, "pgRadioButton"); 10 | NextionRadioButton radioButton(nex, 14, 2, "rbExRadButton"); 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | pinMode(13, OUTPUT); 16 | 17 | nextionSerial.begin(9600); 18 | nex.init(); 19 | 20 | Serial.println(pgRadioButton.show()); 21 | 22 | Serial.println(radioButton.attachCallback(&callback)); 23 | 24 | Serial.println(radioButton.isActive()); 25 | Serial.println(radioButton.setActive(true)); 26 | Serial.println(radioButton.isActive()); 27 | } 28 | 29 | void loop() 30 | { 31 | nex.poll(); 32 | } 33 | 34 | void callback(NextionEventType type, INextionTouchable *widget) 35 | { 36 | if (type == NEX_EVENT_PUSH) 37 | { 38 | digitalWrite(13, HIGH); 39 | } 40 | else if (type == NEX_EVENT_POP) 41 | { 42 | Serial.println(radioButton.isActive()); 43 | digitalWrite(13, LOW); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /examples/Slider/Slider.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgSlider(nex, 8, 0, "pgSlider"); 10 | NextionSlider slider(nex, 8, 2, "sExSlider"); 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | pinMode(13, OUTPUT); 16 | 17 | nextionSerial.begin(9600); 18 | nex.init(); 19 | 20 | Serial.println(pgSlider.show()); 21 | 22 | Serial.println(slider.setBackgroundColour(NEX_COL_BLUE)); 23 | Serial.println(slider.setForegroundColour(NEX_COL_YELLOW)); 24 | 25 | Serial.println(slider.getBackgroundColour()); 26 | Serial.println(slider.getForegroundColour()); 27 | 28 | Serial.println(slider.attachCallback(&callback)); 29 | } 30 | 31 | void loop() 32 | { 33 | nex.poll(); 34 | } 35 | 36 | void callback(NextionEventType type, INextionTouchable *widget) 37 | { 38 | if (type == NEX_EVENT_PUSH) 39 | digitalWrite(13, HIGH); 40 | else if (type == NEX_EVENT_POP) 41 | { 42 | Serial.println(slider.getValue()); 43 | digitalWrite(13, LOW); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /examples/Page/Page.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | SoftwareSerial nextionSerial(10, 11); // RX, TX 6 | 7 | Nextion nex(nextionSerial); 8 | 9 | NextionPage pgButton (nex, 0, 0, "pgButton"); 10 | NextionPage pgText (nex, 1, 0, "pgText"); 11 | NextionPage pgProgressBar (nex, 2, 0, "pgProgressBar"); 12 | NextionPage pgPicture (nex, 3, 0, "pgPicture"); 13 | NextionPage pgCrop (nex, 4, 0, "pgCrop"); 14 | NextionPage pgHotspot (nex, 5, 0, "pgHotspot"); 15 | NextionPage pgGauge (nex, 6, 0, "pgGauge"); 16 | NextionPage pgWaveform (nex, 7, 0, "pgWaveform"); 17 | NextionPage pgSlider (nex, 8, 0, "pgSlider"); 18 | NextionPage pgTimer (nex, 9, 0, "pgTimer"); 19 | NextionPage pgVariable (nex, 10, 0, "pgVariable"); 20 | 21 | void setup() 22 | { 23 | Serial.begin(9600); 24 | 25 | nextionSerial.begin(9600); 26 | nex.init(); 27 | 28 | Serial.println(pgGauge.show()); 29 | 30 | Serial.println(nex.getCurrentPage()); 31 | Serial.println(pgGauge.isShown()); 32 | Serial.println(pgButton.isShown()); 33 | } 34 | 35 | void loop() 36 | { 37 | nex.poll(); 38 | } 39 | -------------------------------------------------------------------------------- /INextionColourable.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_INEXTIONCOLOURABLE 4 | #define __NEONEXTION_INEXTIONCOLOURABLE 5 | 6 | #include "Nextion.h" 7 | #include "INextionWidget.h" 8 | #include "NextionTypes.h" 9 | 10 | /*! 11 | * \class INextionColourable 12 | * \brief Interface for widgets that can be coloured. 13 | */ 14 | class INextionColourable : public virtual INextionWidget 15 | { 16 | public: 17 | INextionColourable(Nextion &nex, uint8_t page, uint8_t component, 18 | const char *name); 19 | 20 | bool setForegroundColour(uint32_t colour, bool refresh = true); 21 | uint32_t getForegroundColour(); 22 | 23 | bool setEventForegroundColour(uint32_t colour, bool refresh = true); 24 | uint32_t getEventForegroundColour(); 25 | 26 | bool setBackgroundColour(uint32_t colour, bool refresh = true); 27 | uint32_t getBackgroundColour(); 28 | 29 | bool setEventBackgroundColour(uint32_t colour, bool refresh = true); 30 | uint32_t getEventBackgroundColour(); 31 | 32 | bool setColour(char *type, uint32_t colour, bool refresh); 33 | uint32_t getColour(char *type); 34 | 35 | bool afterSet(bool result, bool refresh); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /INextionWidget.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_INEXTIONWIDGET 4 | #define __NEONEXTION_INEXTIONWIDGET 5 | 6 | #include "Nextion.h" 7 | 8 | /*! 9 | * \class INextionWidget 10 | * \brief Abstract class for all UI widgets. 11 | * 12 | * Widget objects act as a adapter/API for the widgets defined in the Nextion 13 | * Editor software. 14 | */ 15 | class INextionWidget 16 | { 17 | public: 18 | INextionWidget(Nextion &nex, uint8_t page, uint8_t component, 19 | const char *name); 20 | 21 | uint8_t getPageID(); 22 | uint8_t getComponentID(); 23 | 24 | bool setNumberProperty(char *propertyName, uint32_t value); 25 | uint32_t getNumberProperty(char *propertyName); 26 | bool setStringProperty(char *propertyName, char *value); 27 | size_t getStringProperty(char *propertyName, char *value, size_t len); 28 | 29 | protected: 30 | bool sendCommand(char *commandStr, bool checkComplete = true); 31 | 32 | protected: 33 | Nextion &m_nextion; //!< Reference to the Nextion driver 34 | uint8_t m_pageID; //!< ID of page this widget is on 35 | uint8_t m_componentID; //!< Component ID of this widget 36 | const char *m_name; //!< Name of this widget 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /NextionSlidingText.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONSLIDINGTEXT 4 | #define __NEONEXTION_NEXTIONSLIDINGTEXT 5 | 6 | #include "Nextion.h" 7 | #include "INextionTouchable.h" 8 | #include "INextionColourable.h" 9 | #include "INextionStringValued.h" 10 | #include "INextionFontStyleable.h" 11 | 12 | /*! 13 | * \class NextionSlidingText 14 | * \brief Represents a sliding text widget. 15 | */ 16 | class NextionSlidingText : public INextionTouchable, 17 | public INextionColourable, 18 | public INextionStringValued, 19 | public INextionFontStyleable 20 | { 21 | public: 22 | /*! 23 | * \copydoc INextionWidget::INextionWidget 24 | */ 25 | NextionSlidingText(Nextion &nex, uint8_t page, uint8_t component, 26 | const char *name); 27 | 28 | bool setScrolling(bool scroll); 29 | bool isScrolling(); 30 | 31 | bool setScrollDirection(NextionScrollDirection direction); 32 | NextionScrollDirection getScrollDirection(); 33 | 34 | bool setScrollDistance(uint32_t distance); 35 | uint32_t getScrollDistance(); 36 | 37 | bool setScrollDelay(uint32_t delay); 38 | uint32_t getScrollDelay(); 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /NextionCallbackFunctionHandler.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONCALLBACKFUNCTIONHANDLER 4 | #define __NEONEXTION_NEXTIONCALLBACKFUNCTIONHANDLER 5 | 6 | #include "INextionCallback.h" 7 | 8 | /*! 9 | * \class NextionCallbackFunctionHandler 10 | * \brief Event handler for function pointers. 11 | */ 12 | class NextionCallbackFunctionHandler : public INextionCallback 13 | { 14 | public: 15 | /*! 16 | * \typedef NextionFunction 17 | * \brief Event handler function for display events. 18 | */ 19 | typedef void (*NextionFunction)(NextionEventType, INextionTouchable *); 20 | 21 | /*! 22 | * \brief Creates a new function pointer callback handler. 23 | * \param f Pointer to callback function 24 | */ 25 | NextionCallbackFunctionHandler(NextionFunction f) 26 | : m_function(f) 27 | { 28 | } 29 | 30 | /*! 31 | * \copydoc INextionCallback::handleNextionEvent 32 | * 33 | * Displatches the event to the function. 34 | */ 35 | void handleNextionEvent(NextionEventType type, INextionTouchable *widget) 36 | { 37 | if (m_function != NULL) 38 | m_function(type, widget); 39 | } 40 | 41 | private: 42 | NextionFunction m_function; //!< Pointer to the callback function 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NeoNextion 2 | 3 | [![Build Status](https://travis-ci.org/DanNixon/NeoNextion.svg?branch=master)](https://travis-ci.org/DanNixon/NeoNextion) 4 | [![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/) 5 | 6 | An Arduino library for the 7 | [Nextion](http://wiki.iteadstudio.com/Nextion_HMI_Solution) line of displays. 8 | 9 | The code is heavily based on the [official 10 | library](https://github.com/itead/ITEADLIB_Arduino_Nextion) but aims to be 11 | cleaner, more user friendly and with a bit of luck, faster. 12 | 13 | Available through the library manager of the Arduio IDE as `NeoNextion`. 14 | 15 | ## New features 16 | 17 | I don't use Nextion displays in my projects anymore so this library may not 18 | allow all the features in the latest display firmware to be used. However 19 | I still own a few of them and am happy to work on adding new functionality 20 | if it is desired. 21 | 22 | If you find a feature that is missing that you want implemented let me know 23 | and I'll look at adding it for you. 24 | 25 | ## Links 26 | 27 | - Repository: https://github.com/DanNixon/NeoNextion 28 | - Travis CI: https://travis-ci.org/DanNixon/NeoNextion 29 | - Documentation: https://dannixon.github.io/NeoNextion 30 | -------------------------------------------------------------------------------- /examples/Gauge/Gauge.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgGauge(nex, 6, 0, "pgGauge"); 10 | NextionGauge gauge(nex, 6, 2, "gExGauge"); 11 | 12 | uint32_t startTime = 0; 13 | 14 | void setup() 15 | { 16 | Serial.begin(9600); 17 | pinMode(13, OUTPUT); 18 | 19 | nextionSerial.begin(9600); 20 | nex.init(); 21 | 22 | Serial.println(pgGauge.show()); 23 | 24 | Serial.println(gauge.attachCallback(&callback)); 25 | 26 | Serial.println(gauge.setBackgroundColour(NEX_COL_BLACK)); 27 | Serial.println(gauge.setForegroundColour(NEX_COL_RED)); 28 | 29 | startTime = millis(); 30 | } 31 | 32 | void loop() 33 | { 34 | nex.poll(); 35 | 36 | if (millis() - startTime > 500) 37 | { 38 | uint16_t value = gauge.getValue(); 39 | value += 10; 40 | if (value > 400) 41 | value = 0; 42 | gauge.setValue(value); 43 | startTime = millis(); 44 | } 45 | } 46 | 47 | void callback(NextionEventType type, INextionTouchable *widget) 48 | { 49 | if (type == NEX_EVENT_PUSH) 50 | digitalWrite(13, HIGH); 51 | else if (type == NEX_EVENT_POP) 52 | digitalWrite(13, LOW); 53 | } 54 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | sudo: required 4 | dist: trusty 5 | 6 | env: 7 | global: 8 | - GH_REF: github.com/DanNixon/NeoNextion.git 9 | - secure: "ey1GaNkQ5E5W4ulpb7yaiwbO1A1sVTxHVtRZaIK24zOQn3yWpOqh4CIeXkop6JvhRiF0O+oQTlU67SUUDzgPwlFzLBVvRFhfkhSRatwfB6+9DXIG9QcRsEwcII1aIDxU68qqK9ddeyBHqUc5on3WUH2iLlnvRChRkCIn6/5eViUTu6TmBpE/NYsGiuMmYiu99bzdyrHuYEZ6lgiY3v2rD7lSeYBZhF1blZvMC4Y2x0640JR+BK+qxcn5LQ8vp/4eOR2/Qi1xcJEpgrcjgQEmKkpDwUKTFFqB+RtQSRUdIVfamKjBqZsxm/ueGV/xwzGAkBW1jDCbux1iYeXAOs09/LcTOcUQBAZlA/g88Uq6Du9Vb1Qmzr0B1iNk0OckhnU2PoUrzbAhu8ww02SSUR+TB/zmEPaNkzqKGZaaKC7jBJxg9OlWNFBTTIbzMGFplnzDQUiZ1u7a7kCjiUHm//hZLMdxkKysLNqUIaHBHMViVMNOmx8F+I4kuxZ075dxjDg7zOZwlJgCt87Cw+fqOeSLXLMoIhvBppz70EfOGgNWiCxUHQHg/EWtoJv84UpYN+pJi6VST+YVQgtWmDeArLYY04M81wUsrhz/Fq3vxsqPoK+U90XoHDj8805bnDTyUm4pHshEYbMky6LGiA/SMMa4RLKbai7XkpF0V+9hzPrrNNE=" 10 | 11 | before_install: 12 | - sudo apt-get -qq update 13 | - sudo apt-get install -y doxygen graphviz 14 | - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh) 15 | 16 | script: 17 | - build_platform uno 18 | - build_platform leonardo 19 | - build_platform esp8266 20 | - doxygen 21 | - ./.travis_deploy_docs.sh 22 | 23 | notifications: 24 | email: 25 | on_success: change 26 | on_failure: change 27 | -------------------------------------------------------------------------------- /INextionBooleanValued.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_INEXTIONBOOLEANVALUED 4 | #define __NEONEXTION_INEXTIONBOOLEANVALUED 5 | 6 | #include "Nextion.h" 7 | #include "INextionNumericalValued.h" 8 | #include "NextionTypes.h" 9 | 10 | /*! 11 | * \class INextionBooleanValued 12 | * \brief Interface for widgets that store a boolean value. 13 | * 14 | * Assumes that the boolean value is a property named "val". 15 | */ 16 | class INextionBooleanValued : private INextionNumericalValued 17 | { 18 | public: 19 | /*! 20 | * \copydoc INextionWidget::INextionWidget 21 | */ 22 | INextionBooleanValued(Nextion &nex, uint8_t page, uint8_t component, 23 | const char *name) 24 | : INextionWidget(nex, page, component, name) 25 | , INextionNumericalValued(nex, page, component, name) 26 | { 27 | } 28 | 29 | /*! 30 | * \brief Gets the state of the boolean value of the control. 31 | * \return True if boolean state is active 32 | */ 33 | bool isActive() 34 | { 35 | return getValue(); 36 | } 37 | 38 | /*! 39 | * \brief Sets the state of the boolean value. 40 | * \param active State 41 | * \return True if successful 42 | */ 43 | bool setActive(bool active) 44 | { 45 | return setValue((uint32_t)active); 46 | } 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /INextionNumericalValued.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_INEXTIONNUMERICALVALUED 4 | #define __NEONEXTION_INEXTIONNUMERICALVALUED 5 | 6 | #include "Nextion.h" 7 | #include "INextionWidget.h" 8 | #include "NextionTypes.h" 9 | 10 | /*! 11 | * \class INextionNumericalValued 12 | * \brief Interface for widgets that store a numerical value. 13 | * 14 | * Assumes that the numerical value is a property named "val". 15 | */ 16 | class INextionNumericalValued : public virtual INextionWidget 17 | { 18 | public: 19 | /*! 20 | * \copydoc INextionWidget::INextionWidget 21 | */ 22 | INextionNumericalValued(Nextion &nex, uint8_t page, uint8_t component, 23 | const char *name) 24 | : INextionWidget(nex, page, component, name) 25 | { 26 | } 27 | 28 | /*! 29 | * \brief Gets the numerical value. 30 | * \return Value 31 | * \see INextionNumericalValued::setValue 32 | */ 33 | uint32_t getValue() 34 | { 35 | return getNumberProperty("val"); 36 | } 37 | 38 | /*! 39 | * \brief Sets the numerical value. 40 | * \param value Value 41 | * \return True if successful 42 | * \see INextionNumericalValued::getValue 43 | */ 44 | bool setValue(uint32_t value) 45 | { 46 | return setNumberProperty("val", value); 47 | } 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /examples/ButtonHardwareSerial/ButtonHardwareSerial.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define NEXTION_PORT Serial1 6 | 7 | Nextion nex(NEXTION_PORT); 8 | NextionPage pgButton(nex, 0, 0, "pgButton"); 9 | NextionButton button(nex, 0, 1, "bEgButton"); 10 | 11 | void setup() 12 | { 13 | Serial.begin(9600); 14 | pinMode(13, OUTPUT); 15 | 16 | NEXTION_PORT.begin(9600); 17 | nex.init(); 18 | 19 | Serial.println(pgButton.show()); 20 | 21 | Serial.println(button.attachCallback(&callback)); 22 | 23 | Serial.println(button.setHAlignment(NEX_FA_LEFT_UP)); 24 | Serial.println(button.setVAlignment(NEX_FA_LEFT_UP)); 25 | Serial.println(button.setFont(1)); 26 | Serial.println(button.setText("Press me!")); 27 | 28 | char buffer[50]; 29 | button.getText(buffer, 50); 30 | Serial.println(buffer); 31 | 32 | Serial.println(button.setBackgroundColour(NEX_COL_BLUE)); 33 | } 34 | 35 | void loop() 36 | { 37 | nex.poll(); 38 | } 39 | 40 | void callback(NextionEventType type, INextionTouchable *widget) 41 | { 42 | if (type == NEX_EVENT_PUSH) 43 | { 44 | digitalWrite(13, HIGH); 45 | button.setText("Hyah!"); 46 | } 47 | else if (type == NEX_EVENT_POP) 48 | { 49 | digitalWrite(13, LOW); 50 | button.setText("You pressed me"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/Button/Button.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgButton(nex, 0, 0, "pgButton"); 10 | NextionButton button(nex, 0, 1, "bEgButton"); 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | pinMode(13, OUTPUT); 16 | 17 | nextionSerial.begin(9600); 18 | nex.init(); 19 | 20 | Serial.println(pgButton.show()); 21 | 22 | Serial.println(button.attachCallback(&callback)); 23 | 24 | Serial.println(button.setHAlignment(NEX_FA_LEFT_UP)); 25 | Serial.println(button.setVAlignment(NEX_FA_LEFT_UP)); 26 | Serial.println(button.setFont(1)); 27 | Serial.println(button.setText("Press me!")); 28 | 29 | char buffer[50]; 30 | button.getText(buffer, 50); 31 | Serial.println(buffer); 32 | 33 | Serial.println(button.setBackgroundColour(NEX_COL_BLUE)); 34 | } 35 | 36 | void loop() 37 | { 38 | nex.poll(); 39 | } 40 | 41 | void callback(NextionEventType type, INextionTouchable *widget) 42 | { 43 | if (type == NEX_EVENT_PUSH) 44 | { 45 | digitalWrite(13, HIGH); 46 | button.setText("Hyah!"); 47 | } 48 | else if (type == NEX_EVENT_POP) 49 | { 50 | digitalWrite(13, LOW); 51 | button.setText("You pressed me"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /examples/ProgressBar/ProgressBar.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgProgressBar(nex, 2, 0, "pgProgressBar"); 10 | NextionProgressBar progressBar(nex, 2, 2, "pbExProgBar"); 11 | 12 | uint32_t startTime = 0; 13 | 14 | void setup() 15 | { 16 | Serial.begin(9600); 17 | pinMode(13, OUTPUT); 18 | 19 | nextionSerial.begin(9600); 20 | nex.init(); 21 | 22 | Serial.println(pgProgressBar.show()); 23 | 24 | Serial.println(progressBar.attachCallback(&callback)); 25 | 26 | Serial.println(progressBar.setBackgroundColour(NEX_COL_YELLOW)); 27 | Serial.println(progressBar.setForegroundColour(NEX_COL_BLACK)); 28 | 29 | startTime = millis(); 30 | } 31 | 32 | void loop() 33 | { 34 | nex.poll(); 35 | 36 | if (millis() - startTime > 500) 37 | { 38 | uint16_t value = progressBar.getValue(); 39 | value += 10; 40 | if (value > 100) 41 | value = 0; 42 | progressBar.setValue(value); 43 | startTime = millis(); 44 | } 45 | } 46 | 47 | void callback(NextionEventType type, INextionTouchable *widget) 48 | { 49 | if (type == NEX_EVENT_PUSH) 50 | digitalWrite(13, HIGH); 51 | else if (type == NEX_EVENT_POP) 52 | digitalWrite(13, LOW); 53 | } 54 | -------------------------------------------------------------------------------- /examples/Waveform/Waveform.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgWaveform(nex, 7, 0, "pgWaveform"); 10 | NextionWaveform waveform(nex, 7, 2, "wExWaveform"); 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | pinMode(13, OUTPUT); 16 | 17 | nextionSerial.begin(9600); 18 | nex.init(); 19 | 20 | Serial.println(pgWaveform.show()); 21 | 22 | Serial.println(waveform.attachCallback(&callback)); 23 | 24 | Serial.println(waveform.setGridWidth(5)); 25 | Serial.println(waveform.getGridWidth()); 26 | 27 | Serial.println(waveform.setGridHeight(10)); 28 | Serial.println(waveform.getGridHeight()); 29 | 30 | Serial.println(waveform.setChannelColour(0, NEX_COL_WHITE)); 31 | 32 | for (uint16_t i = 0; i < 100; i++) 33 | { 34 | waveform.addValue(0, i); 35 | waveform.addValue(1, i + 10); 36 | waveform.addValue(2, i + 20); 37 | waveform.addValue(3, i + 30); 38 | } 39 | } 40 | 41 | void loop() 42 | { 43 | nex.poll(); 44 | } 45 | 46 | void callback(NextionEventType type, INextionTouchable *widget) 47 | { 48 | if (type == NEX_EVENT_PUSH) 49 | digitalWrite(13, HIGH); 50 | else if (type == NEX_EVENT_POP) 51 | digitalWrite(13, LOW); 52 | } 53 | -------------------------------------------------------------------------------- /examples/ButtonCallbackClassHardwareSerial/ButtonCallbackClassHardwareSerial.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define NEXTION_PORT Serial1 6 | 7 | Nextion nex(NEXTION_PORT); 8 | NextionPage pgButton(nex, 0, 0, "pgButton"); 9 | NextionButton button(nex, 0, 1, "bEgButton"); 10 | 11 | class Handler : public INextionCallback 12 | { 13 | public: 14 | Handler() 15 | : INextionCallback() 16 | { 17 | } 18 | 19 | void handleNextionEvent(NextionEventType type, INextionTouchable *widget) 20 | { 21 | if (type == NEX_EVENT_PUSH) 22 | { 23 | digitalWrite(13, HIGH); 24 | button.setText("Hyah!"); 25 | } 26 | else if (type == NEX_EVENT_POP) 27 | { 28 | digitalWrite(13, LOW); 29 | button.setText("You pressed me"); 30 | } 31 | } 32 | }; 33 | 34 | Handler handle; 35 | 36 | void setup() 37 | { 38 | Serial.begin(9600); 39 | pinMode(13, OUTPUT); 40 | 41 | NEXTION_PORT.begin(9600); 42 | nex.init(); 43 | 44 | Serial.println(pgButton.show()); 45 | 46 | Serial.println(button.attachCallback(&handle)); 47 | 48 | Serial.println(button.setHAlignment(NEX_FA_LEFT_UP)); 49 | Serial.println(button.setVAlignment(NEX_FA_LEFT_UP)); 50 | Serial.println(button.setFont(1)); 51 | Serial.println(button.setText("Press me!")); 52 | 53 | char buffer[50]; 54 | button.getText(buffer, 50); 55 | Serial.println(buffer); 56 | 57 | Serial.println(button.setBackgroundColour(NEX_COL_BLUE)); 58 | } 59 | 60 | void loop() 61 | { 62 | nex.poll(); 63 | } 64 | -------------------------------------------------------------------------------- /examples/ButtonCallbackClass/ButtonCallbackClass.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SoftwareSerial nextionSerial(10, 11); // RX, TX 7 | 8 | Nextion nex(nextionSerial); 9 | NextionPage pgButton(nex, 0, 0, "pgButton"); 10 | NextionButton button(nex, 0, 1, "bEgButton"); 11 | 12 | class Handler : public INextionCallback 13 | { 14 | public: 15 | Handler() 16 | : INextionCallback() 17 | { 18 | } 19 | 20 | void handleNextionEvent(NextionEventType type, INextionTouchable *widget) 21 | { 22 | if (type == NEX_EVENT_PUSH) 23 | { 24 | digitalWrite(13, HIGH); 25 | button.setText("Hyah!"); 26 | } 27 | else if (type == NEX_EVENT_POP) 28 | { 29 | digitalWrite(13, LOW); 30 | button.setText("You pressed me"); 31 | } 32 | } 33 | }; 34 | 35 | Handler handle; 36 | 37 | void setup() 38 | { 39 | Serial.begin(9600); 40 | pinMode(13, OUTPUT); 41 | 42 | nextionSerial.begin(9600); 43 | nex.init(); 44 | 45 | Serial.println(pgButton.show()); 46 | 47 | Serial.println(button.attachCallback(&handle)); 48 | 49 | Serial.println(button.setHAlignment(NEX_FA_LEFT_UP)); 50 | Serial.println(button.setVAlignment(NEX_FA_LEFT_UP)); 51 | Serial.println(button.setFont(1)); 52 | Serial.println(button.setText("Press me!")); 53 | 54 | char buffer[50]; 55 | button.getText(buffer, 50); 56 | Serial.println(buffer); 57 | 58 | Serial.println(button.setBackgroundColour(NEX_COL_BLUE)); 59 | } 60 | 61 | void loop() 62 | { 63 | nex.poll(); 64 | } 65 | -------------------------------------------------------------------------------- /NextionTimer.cpp: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #include "NextionTimer.h" 4 | 5 | /*! 6 | * \copydoc INextionWidget::INextionWidget 7 | */ 8 | NextionTimer::NextionTimer(Nextion &nex, uint8_t page, uint8_t component, 9 | const char *name) 10 | : INextionWidget(nex, page, component, name) 11 | , INextionTouchable(nex, page, component, name) 12 | { 13 | } 14 | 15 | /*! 16 | * \brief Gets the cycle time of the timer. 17 | * \return Time in ms (may also return 0 in case of error) 18 | */ 19 | uint32_t NextionTimer::getCycle() 20 | { 21 | size_t commandLen = 9 + strlen(m_name); 22 | char commandBuffer[commandLen]; 23 | snprintf(commandBuffer, commandLen, "get %s.tim", m_name); 24 | sendCommand(commandBuffer, false); 25 | uint32_t id; 26 | if (m_nextion.receiveNumber(&id)) 27 | return id; 28 | else 29 | return 0; 30 | } 31 | 32 | /*! 33 | * \brief Sets the cycle time of the timer. 34 | * \param cycle Time in ms 35 | * \return True if successful 36 | */ 37 | bool NextionTimer::setCycle(uint32_t cycle) 38 | { 39 | if (cycle < 50) 40 | return false; 41 | 42 | size_t commandLen = 11 + strlen(m_name); 43 | char commandBuffer[commandLen]; 44 | snprintf(commandBuffer, commandLen, "%s.tim=%d", m_name, cycle); 45 | return sendCommand(commandBuffer); 46 | } 47 | 48 | /*! 49 | * \brief Enable/start the timer. 50 | * \return True if successful 51 | */ 52 | bool NextionTimer::enable() 53 | { 54 | size_t commandLen = 6 + strlen(m_name); 55 | char commandBuffer[commandLen]; 56 | snprintf(commandBuffer, commandLen, "%s.en=1", m_name); 57 | return sendCommand(commandBuffer); 58 | } 59 | 60 | /*! 61 | * \brief Disable/stop the timer. 62 | * \return True if successful 63 | */ 64 | bool NextionTimer::disable() 65 | { 66 | size_t commandLen = 6 + strlen(m_name); 67 | char commandBuffer[commandLen]; 68 | snprintf(commandBuffer, commandLen, "%s.en=0", m_name); 69 | return sendCommand(commandBuffer); 70 | } 71 | -------------------------------------------------------------------------------- /INextionStringValued.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_INEXTIONSTRINGVALUED 4 | #define __NEONEXTION_INEXTIONSTRINGVALUED 5 | 6 | #include "Nextion.h" 7 | #include "INextionWidget.h" 8 | #include "NextionTypes.h" 9 | 10 | /*! 11 | * \class INextionStringValued 12 | * \brief Interface for widgets that hold a string value. 13 | * 14 | * Assumes that the string value is a property named "txt". 15 | */ 16 | class INextionStringValued : public virtual INextionWidget 17 | { 18 | public: 19 | /*! 20 | * \copydoc INextionWidget::INextionWidget 21 | */ 22 | INextionStringValued(Nextion &nex, uint8_t page, uint8_t component, 23 | const char *name) 24 | : INextionWidget(nex, page, component, name) 25 | { 26 | } 27 | 28 | /*! 29 | * \brief Gets the value of the string. 30 | * \param buffer Pointer to storage to strore string in 31 | * \param len Maximum length of string 32 | * \return Actual length of string 33 | * \see INextionStringValued::setText 34 | */ 35 | size_t getText(char *buffer, size_t len) 36 | { 37 | return getStringProperty("txt", buffer, len); 38 | } 39 | 40 | /*! 41 | * \brief Sets the value of the string. 42 | * \param buffer Value 43 | * \return True if successful 44 | * \see INextionStringValued::getText 45 | */ 46 | bool setText(char *buffer) 47 | { 48 | return setStringProperty("txt", buffer); 49 | } 50 | 51 | /*! 52 | * \brief Sets the text by a numercal value. 53 | * \param value Numerical value 54 | * \return True if successful 55 | * \see INextionStringValued::getTextAsNumber 56 | */ 57 | bool setTextAsNumber(uint32_t value) 58 | { 59 | char buffer[8]; 60 | snprintf(buffer, 8, "%ld", value); 61 | return setStringProperty("txt", buffer); 62 | } 63 | 64 | /*! 65 | * \brief Gets the text parsed as a number. 66 | * \return Numerical value 67 | * \see INextionStringValued::setTextAsNumber 68 | */ 69 | uint32_t getTextAsNumber() 70 | { 71 | char buffer[8]; 72 | if (getStringProperty("txt", buffer, 8)) 73 | { 74 | uint32_t value; 75 | sscanf(buffer, "%ld", &value); 76 | return value; 77 | } 78 | else 79 | return 0; 80 | } 81 | }; 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /INextionTouchable.cpp: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #include "INextionTouchable.h" 4 | 5 | /*! 6 | * \copydoc INextionWidget::INextionWidget 7 | */ 8 | INextionTouchable::INextionTouchable(Nextion &nex, uint8_t page, 9 | uint8_t component, const char *name) 10 | : INextionWidget(nex, page, component, name) 11 | , m_callback(NULL) 12 | { 13 | nex.registerTouchable(this); 14 | } 15 | 16 | /*! 17 | * \brief Processes a touch event. 18 | * \param pageID Page ID of touch event 19 | * \param componentID Component ID of touch event 20 | * \param eventType Type of touch event 21 | * \return True if the event effects this widget 22 | */ 23 | bool INextionTouchable::processEvent(uint8_t pageID, uint8_t componentID, 24 | uint8_t eventType) 25 | { 26 | if (pageID != m_pageID) 27 | return false; 28 | 29 | if (componentID != m_componentID) 30 | return false; 31 | 32 | switch (eventType) 33 | { 34 | case NEX_EVENT_PUSH: 35 | if (m_callback) 36 | m_callback->handleNextionEvent((NextionEventType)eventType, this); 37 | return true; 38 | 39 | case NEX_EVENT_POP: 40 | if (m_callback) 41 | m_callback->handleNextionEvent((NextionEventType)eventType, this); 42 | return true; 43 | 44 | default: 45 | return false; 46 | } 47 | } 48 | 49 | /*! 50 | * \brief Attaches a callback function to this widget. 51 | * \param function Pointer to callback function 52 | * \return True if successful 53 | * \see INextionTouchable::detachCallback 54 | */ 55 | bool INextionTouchable::attachCallback( 56 | NextionCallbackFunctionHandler::NextionFunction function) 57 | { 58 | if (!function) 59 | return false; 60 | 61 | if (m_callback != NULL) 62 | detachCallback(); 63 | 64 | m_callback = new NextionCallbackFunctionHandler(function); 65 | return true; 66 | } 67 | 68 | /*! 69 | * \brief Attaches a callback handler to this widget. 70 | * \param handler Pointer to handler 71 | * \return True if successful 72 | * \see INextionTouchable::detachCallback 73 | */ 74 | bool INextionTouchable::attachCallback(INextionCallback *handler) 75 | { 76 | if (!handler) 77 | return false; 78 | 79 | if (m_callback != NULL) 80 | detachCallback(); 81 | 82 | m_callback = handler; 83 | return true; 84 | } 85 | 86 | /*! 87 | * \brief Removes the callback handler from this widget 88 | * 89 | * Memory is not freed. 90 | */ 91 | void INextionTouchable::detachCallback() 92 | { 93 | m_callback = NULL; 94 | } 95 | -------------------------------------------------------------------------------- /NextionTypes.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #ifndef __NEONEXTION_NEXTIONTYPES 4 | #define __NEONEXTION_NEXTIONTYPES 5 | 6 | /*! 7 | * \enum NextionValue 8 | * \brief Values used in messages. 9 | */ 10 | enum NextionValue 11 | { 12 | NEX_RET_CMD_FINISHED = (0x01), 13 | NEX_RET_EVENT_LAUNCHED = (0x88), 14 | NEX_RET_EVENT_UPGRADED = (0x89), 15 | NEX_RET_EVENT_TOUCH_HEAD = (0x65), 16 | NEX_RET_EVENT_POSITION_HEAD = (0x67), 17 | NEX_RET_EVENT_SLEEP_POSITION_HEAD = (0x68), 18 | NEX_RET_CURRENT_PAGE_ID_HEAD = (0x66), 19 | NEX_RET_STRING_HEAD = (0x70), 20 | NEX_RET_NUMBER_HEAD = (0x71), 21 | NEX_RET_INVALID_CMD = (0x00), 22 | NEX_RET_INVALID_COMPONENT_ID = (0x02), 23 | NEX_RET_INVALID_PAGE_ID = (0x03), 24 | NEX_RET_INVALID_PICTURE_ID = (0x04), 25 | NEX_RET_INVALID_FONT_ID = (0x05), 26 | NEX_RET_INVALID_BAUD = (0x11), 27 | NEX_RET_INVALID_VARIABLE = (0x1A), 28 | NEX_RET_INVALID_OPERATION = (0x1B) 29 | }; 30 | 31 | /*! 32 | * \enum NextionFontAlignment 33 | * \brief Font alignment modes. 34 | */ 35 | enum NextionFontAlignment 36 | { 37 | NEX_FA_NONE = -1, //!< Undefined 38 | NEX_FA_LEFT_UP = 0, //!< Left (x) or top (y) 39 | NEX_FA_CENTRE = 1, //!< Centre 40 | NEX_FA_RIGHT_DOWN = 2 //!< Right (x) or bottom (y) 41 | }; 42 | 43 | /*! 44 | * \enum NextionBackground 45 | * \brief Background modes for widgets/drawables with backgrounds. 46 | */ 47 | enum NextionBackground 48 | { 49 | NEX_BG_NONE = -1, //!< Undefined 50 | NEX_BG_CROPIMAGE = 0, //!< Cropped image 51 | NEX_BG_SOLIDCOLOUR = 1, //!< Solid colour 52 | NEW_BG_IMAGE = 2 //!< Full size image 53 | }; 54 | 55 | /*! 56 | * \enum NextionColour 57 | * \brief Several default colour values. 58 | */ 59 | enum NextionColour 60 | { 61 | NEX_COL_NONE = -1, 62 | NEX_COL_BLACK = 0, 63 | NEX_COL_WHITE = 65535, 64 | NEX_COL_RED = 63488, 65 | NEX_COL_GREEN = 2016, 66 | NEX_COL_BLUE = 31, 67 | NEX_COL_GRAY = 33840, 68 | NEX_COL_BROWN = 48192, 69 | NEX_COL_YELLOW = 65504 70 | }; 71 | 72 | /*! 73 | * \enum NextionEventType 74 | * \brief Type of events received from device. 75 | */ 76 | enum NextionEventType 77 | { 78 | NEX_EVENT_PUSH = (0x01), 79 | NEX_EVENT_POP = (0x00), 80 | NEX_EVENT_BOTH 81 | }; 82 | 83 | /*! 84 | * \enum NextionScrollDirection 85 | * \brief Directions for scolling. 86 | */ 87 | enum NextionScrollDirection 88 | { 89 | NEX_SCROLL_NONE = -1, 90 | NEX_SCROLL_LEFT = 1, 91 | NEX_SCROLL_RIGHT = 0, 92 | NEX_SCROLL_UP = 3, 93 | NEX_SCROLL_DOWN = 2 94 | }; 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /Nextion.h: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 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 11 | #endif 12 | 13 | #include "NextionTypes.h" 14 | 15 | class INextionTouchable; 16 | 17 | /*! 18 | * \struct ITouchableListItem 19 | * \brief Linked list node for INextionTouchable objects. 20 | */ 21 | struct ITouchableListItem 22 | { 23 | INextionTouchable *item; //!< Pointer to stored INextionTouchable 24 | ITouchableListItem *next; //!< Pointer to next list node 25 | }; 26 | 27 | /*! 28 | * \class Nextion 29 | * \brief Driver for a physical Nextion device. 30 | */ 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, 57 | NextionFontAlignment xCentre = NEX_FA_CENTRE, 58 | NextionFontAlignment yCentre = NEX_FA_CENTRE); 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; //!< Serial port device is attached to 73 | uint32_t m_timeout; //!< Serial communication timeout in ms 74 | bool m_flushSerialBeforeTx; //!< Flush serial port before transmission 75 | ITouchableListItem *m_touchableList; //!< LInked list of INextionTouchable 76 | }; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /NextionSlidingText.cpp: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #include "NextionSlidingText.h" 4 | 5 | /*! 6 | * \copydoc INextionWidget::INextionWidget 7 | */ 8 | NextionSlidingText::NextionSlidingText(Nextion &nex, uint8_t page, 9 | uint8_t component, const char *name) 10 | : INextionWidget(nex, page, component, name) 11 | , INextionTouchable(nex, page, component, name) 12 | , INextionColourable(nex, page, component, name) 13 | , INextionStringValued(nex, page, component, name) 14 | , INextionFontStyleable(nex, page, component, name) 15 | { 16 | } 17 | 18 | bool NextionSlidingText::setScrolling(bool scroll) 19 | { 20 | size_t commandLen = 10 + strlen(m_name); 21 | char commandBuffer[commandLen]; 22 | snprintf(commandBuffer, commandLen, "%s.en=%d", m_name, scroll); 23 | return sendCommand(commandBuffer); 24 | } 25 | 26 | bool NextionSlidingText::isScrolling() 27 | { 28 | size_t commandLen = 8 + strlen(m_name); 29 | char commandBuffer[commandLen]; 30 | snprintf(commandBuffer, commandLen, "get %s.en", m_name); 31 | sendCommand(commandBuffer, false); 32 | uint32_t en; 33 | if (m_nextion.receiveNumber(&en)) 34 | return (bool)en; 35 | else 36 | return 0; 37 | } 38 | 39 | bool NextionSlidingText::setScrollDirection(NextionScrollDirection direction) 40 | { 41 | size_t commandLen = 11 + strlen(m_name); 42 | char commandBuffer[commandLen]; 43 | snprintf(commandBuffer, commandLen, "%s.dir=%d", m_name, direction); 44 | return sendCommand(commandBuffer); 45 | } 46 | 47 | NextionScrollDirection NextionSlidingText::getScrollDirection() 48 | { 49 | size_t commandLen = 9 + strlen(m_name); 50 | char commandBuffer[commandLen]; 51 | snprintf(commandBuffer, commandLen, "get %s.dir", m_name); 52 | sendCommand(commandBuffer, false); 53 | uint32_t val; 54 | if (m_nextion.receiveNumber(&val)) 55 | return (NextionScrollDirection)val; 56 | else 57 | return NEX_SCROLL_NONE; 58 | } 59 | 60 | bool NextionSlidingText::setScrollDistance(uint32_t distance) 61 | { 62 | size_t commandLen = 11 + strlen(m_name); 63 | char commandBuffer[commandLen]; 64 | snprintf(commandBuffer, commandLen, "%s.dis=%d", m_name, distance); 65 | return sendCommand(commandBuffer); 66 | } 67 | 68 | uint32_t NextionSlidingText::getScrollDistance() 69 | { 70 | size_t commandLen = 9 + strlen(m_name); 71 | char commandBuffer[commandLen]; 72 | snprintf(commandBuffer, commandLen, "get %s.dis", m_name); 73 | sendCommand(commandBuffer, false); 74 | uint32_t val; 75 | if (m_nextion.receiveNumber(&val)) 76 | return val; 77 | else 78 | return 0; 79 | } 80 | 81 | bool NextionSlidingText::setScrollDelay(uint32_t delay) 82 | { 83 | size_t commandLen = 11 + strlen(m_name); 84 | char commandBuffer[commandLen]; 85 | snprintf(commandBuffer, commandLen, "%s.tim=%d", m_name, delay); 86 | return sendCommand(commandBuffer); 87 | } 88 | 89 | uint32_t NextionSlidingText::getScrollDelay() 90 | { 91 | size_t commandLen = 9 + strlen(m_name); 92 | char commandBuffer[commandLen]; 93 | snprintf(commandBuffer, commandLen, "get %s.tim", m_name); 94 | sendCommand(commandBuffer, false); 95 | uint32_t val; 96 | if (m_nextion.receiveNumber(&val)) 97 | return val; 98 | else 99 | return 0; 100 | } -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For NeoNextion 3 | ####################################### 4 | # Class 5 | ####################################### 6 | 7 | Nextion KEYWORD1 8 | NextionValue KEYWORD1 9 | NextionFontAlignment KEYWORD1 10 | NextionBackground KEYWORD1 11 | NextionColour KEYWORD1 12 | NextionEventType KEYWORD1 13 | INextionWidget KEYWORD1 14 | INextionColourable KEYWORD1 15 | INextionFontStyleable KEYWORD1 16 | INextionNumericalValued KEYWORD1 17 | INextionStringValued KEYWORD1 18 | INextionTouchable KEYWORD1 19 | NextionButton KEYWORD1 20 | NextionCrop KEYWORD1 21 | NextionGauge KEYWORD1 22 | NextionHotspot KEYWORD1 23 | NextionNumber KEYWORD1 24 | NextionPage KEYWORD1 25 | NextionPicture KEYWORD1 26 | NextionProgressBar KEYWORD1 27 | NextionSlider KEYWORD1 28 | NextionText KEYWORD1 29 | NextionTimer KEYWORD1 30 | NextionVariableNumeric KEYWORD1 31 | NextionVariableString KEYWORD1 32 | NextionWaveform KEYWORD1 33 | NextionDualStateButton KEYWORD1 34 | 35 | ####################################### 36 | # Methods and Functions 37 | ####################################### 38 | 39 | # Nextion 40 | init KEYWORD2 41 | poll KEYWORD2 42 | refresh KEYWORD2 43 | sleep KEYWORD2 44 | wake KEYWORD2 45 | getBrightness KEYWORD2 46 | setBrightness KEYWORD2 47 | getCurrentPage KEYWORD2 48 | clear KEYWORD2 49 | drawPicture KEYWORD2 50 | drawStr KEYWORD2 51 | drawLine KEYWORD2 52 | drawRect KEYWORD2 53 | drawCircle KEYWORD2 54 | 55 | # INextionColourable 56 | setForegroundColour KEYWORD2 57 | setEventForegroundColour KEYWORD2 58 | setBackgroundColour KEYWORD2 59 | setEventBackgroundColour KEYWORD2 60 | getForegroundColour KEYWORD2 61 | getEventForegroundColour KEYWORD2 62 | getBackgroundColour KEYWORD2 63 | getEventBackgroundColour KEYWORD2 64 | 65 | # INextionFontStyleable 66 | setFont KEYWORD2 67 | getFont KEYWORD2 68 | setHAlignment KEYWORD2 69 | getHAlignment KEYWORD2 70 | setVAlignment KEYWORD2 71 | getVAlignment KEYWORD2 72 | 73 | # INextionNumericalValued 74 | getValue KEYWORD2 75 | setValue KEYWORD2 76 | 77 | # INextionStringValued 78 | getText KEYWORD2 79 | setText KEYWORD2 80 | 81 | # INextionTouchable 82 | attachPressEvent KEYWORD2 83 | detachPressEvent KEYWORD2 84 | attachReleaseEvent KEYWORD2 85 | detachReleaseEvent KEYWORD2 86 | 87 | # NextionCrop and NextionPicture 88 | getPictureID KEYWORD2 89 | setPictureID KEYWORD2 90 | 91 | # NextionPage 92 | show KEYWORD2 93 | 94 | # NextionDualStateButton 95 | isActive KEYWORD2 96 | setActive KEYWORD2 97 | 98 | # NextionWaveform 99 | addValue KEYWORD2 100 | setChannelColour KEYWORD2 101 | getChannelColour KEYWORD2 102 | setGridColour KEYWORD2 103 | getGridColour KEYWORD2 104 | setGridWidth KEYWORD2 105 | getGridWidth KEYWORD2 106 | setGridHeight KEYWORD2 107 | getGridHeight KEYWORD2 108 | 109 | ####################################### 110 | # Constants 111 | ####################################### 112 | 113 | NEX_FA_NONE LITERAL1 114 | NEX_FA_LEFT_UP LITERAL1 115 | NEX_FA_CENTRE LITERAL1 116 | NEX_FA_RIGHT_DOWN LITERAL1 117 | NEX_BG_NONE LITERAL1 118 | NEX_BG_CROPIMAGE LITERAL1 119 | NEX_BG_SOLIDCOLOUR LITERAL1 120 | NEW_BG_IMAGE LITERAL1 121 | NEX_COL_NONE LITERAL1 122 | NEX_COL_BLACK LITERAL1 123 | NEX_COL_WHITE LITERAL1 124 | NEX_COL_RED LITERAL1 125 | NEX_COL_GREEN LITERAL1 126 | NEX_COL_BLUE LITERAL1 127 | NEX_COL_GRAY LITERAL1 128 | NEX_COL_BROWN LITERAL1 129 | NEX_COL_YELLOW LITERAL1 130 | -------------------------------------------------------------------------------- /NextionWaveform.cpp: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #include "NextionWaveform.h" 4 | #include "INextionWidget.h" 5 | 6 | /*! 7 | * \copydoc INextionWidget::INextionWidget 8 | */ 9 | NextionWaveform::NextionWaveform(Nextion &nex, uint8_t page, uint8_t component, 10 | const char *name) 11 | : INextionWidget(nex, page, component, name) 12 | , INextionTouchable(nex, page, component, name) 13 | , INextionColourable(nex, page, component, name) 14 | { 15 | } 16 | 17 | /*! 18 | * \brief Adds a value to the waveform display. 19 | * \param channel Channel number 20 | * \param value Value 21 | * \return True if successful 22 | */ 23 | bool NextionWaveform::addValue(uint8_t channel, uint8_t value) 24 | { 25 | if (channel > 3) 26 | return false; 27 | 28 | size_t commandLen = 22; 29 | char commandBuffer[commandLen]; 30 | snprintf(commandBuffer, commandLen, "add %d,%d,%d", m_componentID, channel, 31 | value); 32 | sendCommand(commandBuffer, false); 33 | 34 | /* TODO: this check still fails but the command does actually work */ 35 | /* return m_nextion.checkCommandComplete(); */ 36 | return true; 37 | } 38 | 39 | /*! 40 | * \brief Sets the colour of a channel. 41 | * \param channel Channel number 42 | * \param colour Colour 43 | * \param refresh If the widget should be refreshed 44 | * \return True if successful 45 | */ 46 | bool NextionWaveform::setChannelColour(uint8_t channel, uint32_t colour, 47 | bool refresh) 48 | { 49 | char buffer[5]; 50 | snprintf(buffer, 5, "pco%d", channel); 51 | return setColour(buffer, colour, refresh); 52 | } 53 | 54 | /*! 55 | * \brief Gets the colour of a channel. 56 | * \param channel Channel number 57 | * \return Colour (may return 0 in case of error) 58 | */ 59 | uint32_t NextionWaveform::getChannelColour(uint8_t channel) 60 | { 61 | char buffer[5]; 62 | snprintf(buffer, 5, "pco%d", channel); 63 | return getColour(buffer); 64 | } 65 | 66 | /*! 67 | * \brief Sets the colour of the grid lines. 68 | * \param colour Colour 69 | * \param refresh If the widget should be refreshed 70 | * \return True if successful 71 | */ 72 | bool NextionWaveform::setGridColour(uint32_t colour, bool refresh) 73 | { 74 | return setColour("gdc", colour, refresh); 75 | } 76 | 77 | /*! 78 | * \brief Gets the colour of the grid lines. 79 | * \return Colour (may return 0 in case of error) 80 | */ 81 | uint32_t NextionWaveform::getGridColour() 82 | { 83 | return getColour("gdc"); 84 | } 85 | 86 | /*! 87 | * \brief Sets the width of the grid squares. 88 | * \param width Width 89 | * \return True if successful 90 | */ 91 | bool NextionWaveform::setGridWidth(uint16_t width) 92 | { 93 | return setNumberProperty("gdw", width); 94 | } 95 | 96 | /*! 97 | * \brief Gets the width of the grid squares. 98 | * \return Width (may return 0 in case of error) 99 | */ 100 | uint16_t NextionWaveform::getGridWidth() 101 | { 102 | return getNumberProperty("gdw"); 103 | } 104 | 105 | /*! 106 | * \brief Sets the height of the grid squares. 107 | * \param height Height 108 | * \return True if successful 109 | */ 110 | bool NextionWaveform::setGridHeight(uint16_t height) 111 | { 112 | return setNumberProperty("gdh", height); 113 | } 114 | 115 | /*! 116 | * \brief Gets the height of the grid squares. 117 | * \return Height (may return 0 in case of error) 118 | */ 119 | uint16_t NextionWaveform::getGridHeight() 120 | { 121 | return getNumberProperty("gdh"); 122 | } 123 | -------------------------------------------------------------------------------- /INextionWidget.cpp: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #include "INextionWidget.h" 4 | 5 | /*! 6 | * \brief Create a new widget adapter. 7 | * \param nex Reference to the Nextion driver 8 | * \param page ID of page this widget is on 9 | * \param component Component ID of this widget 10 | * \param name Name of this widget 11 | */ 12 | INextionWidget::INextionWidget(Nextion &nex, uint8_t page, uint8_t component, 13 | const char *name) 14 | : m_nextion(nex) 15 | , m_pageID(page) 16 | , m_componentID(component) 17 | , m_name(name) 18 | { 19 | } 20 | 21 | /*! 22 | * \brief Gets the ID of the page this widget resides on. 23 | * \return Page ID 24 | */ 25 | uint8_t INextionWidget::getPageID() 26 | { 27 | return m_pageID; 28 | } 29 | 30 | /*! 31 | * \brief Gets the component ID of this widget. 32 | * \return Component ID 33 | */ 34 | uint8_t INextionWidget::getComponentID() 35 | { 36 | return m_componentID; 37 | } 38 | 39 | /*! 40 | * \brief Sets the value of a numerical property of this widget. 41 | * \param propertyName Name of the property 42 | * \param value Value 43 | * \return True if successful 44 | */ 45 | bool INextionWidget::setNumberProperty(char *propertyName, uint32_t value) 46 | { 47 | size_t commandLen = 8 + strlen(m_name) + strlen(propertyName); 48 | char commandBuffer[commandLen]; 49 | snprintf(commandBuffer, commandLen, "%s.%s=%ld", m_name, propertyName, value); 50 | return sendCommand(commandBuffer); 51 | } 52 | 53 | /*! 54 | * \brief Gets the value of a numerical property of this widget. 55 | * \param propertyName Name of the property 56 | * \return Value (may also return 0 in case of error) 57 | */ 58 | uint32_t INextionWidget::getNumberProperty(char *propertyName) 59 | { 60 | size_t commandLen = 7 + strlen(m_name) + strlen(propertyName); 61 | char commandBuffer[commandLen]; 62 | snprintf(commandBuffer, commandLen, "get %s.%s", m_name, propertyName); 63 | sendCommand(commandBuffer, false); 64 | uint32_t id; 65 | if (m_nextion.receiveNumber(&id)) 66 | return id; 67 | else 68 | return 0; 69 | } 70 | 71 | /*! 72 | * \brief Sets the value of a string property of this widget. 73 | * \param propertyName Name of the property 74 | * \param value Value 75 | * \return True if successful 76 | */ 77 | bool INextionWidget::setStringProperty(char *propertyName, char *value) 78 | { 79 | size_t commandLen = 7 + strlen(m_name) + strlen(propertyName) + strlen(value); 80 | char command[commandLen]; 81 | snprintf(command, commandLen, "%s.%s=\"%s\"", m_name, propertyName, value); 82 | return sendCommand(command); 83 | } 84 | 85 | /*! 86 | * \brief Gets the value of a string property of this widget. 87 | * \param propertyName Name of the property 88 | * \param value Pointer to char array to store result in 89 | * \param len Maximum length of value 90 | * \return Actual length of value 91 | */ 92 | size_t INextionWidget::getStringProperty(char *propertyName, char *value, 93 | size_t len) 94 | { 95 | size_t commandLen = 6 + strlen(m_name) + strlen(propertyName); 96 | char command[commandLen]; 97 | snprintf(command, commandLen, "get %s.%s", m_name, propertyName); 98 | sendCommand(command, false); 99 | return m_nextion.receiveString(value, len); 100 | } 101 | 102 | bool INextionWidget::sendCommand(char *commandStr, bool checkComplete) 103 | { 104 | m_nextion.sendCommand(commandStr); 105 | 106 | if (checkComplete) 107 | return m_nextion.checkCommandComplete(); 108 | else 109 | return true; 110 | } 111 | -------------------------------------------------------------------------------- /INextionFontStyleable.cpp: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #include "INextionFontStyleable.h" 4 | 5 | /*! 6 | * \copydoc INextionWidget::INextionWidget 7 | */ 8 | INextionFontStyleable::INextionFontStyleable(Nextion &nex, uint8_t page, 9 | uint8_t component, 10 | const char *name) 11 | : INextionWidget(nex, page, component, name) 12 | { 13 | } 14 | 15 | /*! 16 | * \brief Sets the active font for the text. 17 | * \param id Font ID 18 | * \param refresh If the widget should be refreshed 19 | * \return True if successful 20 | * \see INextionFontStyleable::getFont 21 | */ 22 | bool INextionFontStyleable::setFont(uint8_t id, bool refresh) 23 | { 24 | return afterSet(setNumberProperty("font", id), refresh); 25 | } 26 | 27 | /*! 28 | * \brief Gets the active font for the text. 29 | * \return Font ID (may return 0 in event of error) 30 | * \see INextionFontStyleable::setFont 31 | */ 32 | uint8_t INextionFontStyleable::getFont() 33 | { 34 | return getNumberProperty("font"); 35 | } 36 | 37 | /*! 38 | * \brief Sets the horizontal alignment of the text. 39 | * \param align Alignment 40 | * \param refresh If the widget should be refreshed 41 | * \return True if successful 42 | * \see INextionFontStyleable::getHAlignment 43 | */ 44 | bool INextionFontStyleable::setHAlignment(NextionFontAlignment align, 45 | bool refresh) 46 | { 47 | return afterSet(setNumberProperty("xcen", align), refresh); 48 | } 49 | 50 | /*! 51 | * \brief Gets the horizontal alignment of the text. 52 | * \return Alignment 53 | * \see INextionFontStyleable::setHAlignment 54 | */ 55 | NextionFontAlignment INextionFontStyleable::getHAlignment() 56 | { 57 | size_t commandLen = 10 + strlen(m_name); 58 | char commandBuffer[commandLen]; 59 | snprintf(commandBuffer, commandLen, "get %s.xcen", m_name); 60 | sendCommand(commandBuffer, false); 61 | uint32_t align; 62 | if (m_nextion.receiveNumber(&align)) 63 | return (NextionFontAlignment)align; 64 | else 65 | return NEX_FA_NONE; 66 | } 67 | 68 | /*! 69 | * \brief Sets the vertical alignment of the text. 70 | * \param align Alignment 71 | * \param refresh If the widget should be refreshed 72 | * \return True if successful 73 | * \see INextionFontStyleable::getVAlignment 74 | */ 75 | bool INextionFontStyleable::setVAlignment(NextionFontAlignment align, 76 | bool refresh) 77 | { 78 | return afterSet(setNumberProperty("ycen", align), refresh); 79 | } 80 | 81 | /*! 82 | * \brief Gets the vertical alignment of the text. 83 | * \return Alignment 84 | * \see INextionFontStyleable::setVAlignment 85 | */ 86 | NextionFontAlignment INextionFontStyleable::getVAlignment() 87 | { 88 | size_t commandLen = 10 + strlen(m_name); 89 | char commandBuffer[commandLen]; 90 | snprintf(commandBuffer, commandLen, "get %s.ycen", m_name); 91 | sendCommand(commandBuffer, false); 92 | uint32_t align; 93 | if (m_nextion.receiveNumber(&align)) 94 | return (NextionFontAlignment)align; 95 | else 96 | return NEX_FA_NONE; 97 | } 98 | 99 | /*! 100 | * \brief Handles refreshing the page after a style has been changed. 101 | * \param result Success of style change 102 | * \param refresh If the widget should be refreshed 103 | * \return True if successful 104 | */ 105 | bool INextionFontStyleable::afterSet(bool result, bool refresh) 106 | { 107 | if (result) 108 | { 109 | if (refresh) 110 | { 111 | m_nextion.refresh(m_name); 112 | return m_nextion.checkCommandComplete(); 113 | } 114 | else 115 | return true; 116 | } 117 | else 118 | return false; 119 | } 120 | -------------------------------------------------------------------------------- /INextionColourable.cpp: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #include "INextionColourable.h" 4 | 5 | /*! 6 | * \copydoc INextionWidget::INextionWidget 7 | */ 8 | INextionColourable::INextionColourable(Nextion &nex, uint8_t page, 9 | uint8_t component, const char *name) 10 | : INextionWidget(nex, page, component, name) 11 | { 12 | } 13 | 14 | /*! 15 | * \brief Sets the normal foreground colour. 16 | * \param colour Colour 17 | * \param refresh If the widget should be refreshed 18 | * \return True if successful 19 | * \see INextionColourable::getForegroundColour 20 | */ 21 | bool INextionColourable::setForegroundColour(uint32_t colour, bool refresh) 22 | { 23 | return setColour("pco", colour, refresh); 24 | } 25 | 26 | /*! 27 | * \brief Gets the normal foreground colour. 28 | * \return Colour (may also return 0 in case of error) 29 | * \see INextionColourable::setForegroundColour 30 | */ 31 | uint32_t INextionColourable::getForegroundColour() 32 | { 33 | return getColour("pco"); 34 | } 35 | 36 | /*! 37 | * \brief Sets the foreground colour when a touch event is active. 38 | * \param colour Colour 39 | * \param refresh If the widget should be refreshed 40 | * \return True if successful 41 | * \see INextionColourable::getEventForegroundColour 42 | */ 43 | bool INextionColourable::setEventForegroundColour(uint32_t colour, bool refresh) 44 | { 45 | return setColour("pco2", colour, refresh); 46 | } 47 | 48 | /*! 49 | * \brief Gets the foreground colour when a touch event is active. 50 | * \return Colour (may also return 0 in case of error) 51 | * \see INextionColourable::setEventForegroundColour 52 | */ 53 | uint32_t INextionColourable::getEventForegroundColour() 54 | { 55 | return getColour("pco2"); 56 | } 57 | 58 | /*! 59 | * \brief Sets the normal background colour. 60 | * \param colour Colour 61 | * \param refresh If the widget should be refreshed 62 | * \return True if successful 63 | * \see INextionColourable::getBackgroundColour 64 | */ 65 | bool INextionColourable::setBackgroundColour(uint32_t colour, bool refresh) 66 | { 67 | return setColour("bco", colour, refresh); 68 | } 69 | 70 | /*! 71 | * \brief Gets the normal background colour. 72 | * \return Colour (may also return 0 in case of error) 73 | * \see INextionColourable::setBackgroundColour 74 | */ 75 | uint32_t INextionColourable::getBackgroundColour() 76 | { 77 | return getColour("bco"); 78 | } 79 | 80 | /*! 81 | * \brief Sets the background colour when a touch event is active. 82 | * \param colour Colour 83 | * \param refresh If the widget should be refreshed 84 | * \return True if successful 85 | * \see INextionColourable::getEventBackgroundColour 86 | */ 87 | bool INextionColourable::setEventBackgroundColour(uint32_t colour, bool refresh) 88 | { 89 | return setColour("bco2", colour, refresh); 90 | } 91 | 92 | /*! 93 | * \brief Sets the background colour when a touch event is active. 94 | * \return Colour (may also return 0 in case of error) 95 | * \see INextionColourable::setEventBackgroundColour 96 | */ 97 | uint32_t INextionColourable::getEventBackgroundColour() 98 | { 99 | return getColour("bco2"); 100 | } 101 | 102 | /*! 103 | * \brief Sets a colour by its property name. 104 | * \param type Property name 105 | * \param colour Colour 106 | * \param refresh If the widget should be refreshed 107 | * \return True if successful 108 | */ 109 | bool INextionColourable::setColour(char *type, uint32_t colour, bool refresh) 110 | { 111 | return afterSet(setNumberProperty(type, colour), refresh); 112 | } 113 | 114 | /*! 115 | * \brief Gets a colour by its property name. 116 | * \param type Property name 117 | * \return Colour (may also return 0 in case of error) 118 | * \see INextionColourable::setColour 119 | */ 120 | uint32_t INextionColourable::getColour(char *type) 121 | { 122 | return getNumberProperty(type); 123 | } 124 | 125 | /*! 126 | * \brief Handles refreshing the page after a colour has been changed. 127 | * \param result Success of colour set 128 | * \param refresh If the widget should be refreshed 129 | * \return True if successful 130 | * \see INextionColourable::getColour 131 | */ 132 | bool INextionColourable::afterSet(bool result, bool refresh) 133 | { 134 | if (result) 135 | { 136 | if (refresh) 137 | { 138 | m_nextion.refresh(m_name); 139 | return m_nextion.checkCommandComplete(); 140 | } 141 | else 142 | return true; 143 | } 144 | else 145 | return false; 146 | } 147 | -------------------------------------------------------------------------------- /Nextion.cpp: -------------------------------------------------------------------------------- 1 | /*! \file */ 2 | 3 | #include "Nextion.h" 4 | #include "INextionTouchable.h" 5 | 6 | /*! 7 | * \brief Creates a new device driver. 8 | * \param stream Stream (serial port) the device is connected to 9 | * \param flushSerialBeforeTx If the serial port should be flushed before 10 | * transmission 11 | */ 12 | Nextion::Nextion(Stream &stream, bool flushSerialBeforeTx) 13 | : m_serialPort(stream) 14 | , m_timeout(500) 15 | , m_flushSerialBeforeTx(flushSerialBeforeTx) 16 | , m_touchableList(NULL) 17 | { 18 | } 19 | 20 | /*! 21 | * \brief Initialises the device. 22 | * \return True if initialisation was successful. 23 | */ 24 | bool Nextion::init() 25 | { 26 | sendCommand(""); 27 | 28 | sendCommand("bkcmd=1"); 29 | bool result1 = checkCommandComplete(); 30 | 31 | sendCommand("page 0"); 32 | bool result2 = checkCommandComplete(); 33 | 34 | return (result1 && result2); 35 | } 36 | 37 | /*! 38 | * \brief Polls for new messages and touch events. 39 | */ 40 | void Nextion::poll() 41 | { 42 | while (m_serialPort.available() > 0) 43 | { 44 | char c = m_serialPort.read(); 45 | 46 | if (c == NEX_RET_EVENT_TOUCH_HEAD) 47 | { 48 | delay(10); 49 | 50 | if (m_serialPort.available() >= 6) 51 | { 52 | static uint8_t buffer[8]; 53 | buffer[0] = c; 54 | 55 | uint8_t i; 56 | for (i = 1; i < 7; i++) 57 | buffer[i] = m_serialPort.read(); 58 | buffer[i] = 0x00; 59 | 60 | if (buffer[4] == 0xFF && buffer[5] == 0xFF && buffer[6] == 0xFF) 61 | { 62 | ITouchableListItem *item = m_touchableList; 63 | while (item != NULL) 64 | { 65 | item->item->processEvent(buffer[1], buffer[2], buffer[3]); 66 | item = item->next; 67 | } 68 | } 69 | } 70 | } 71 | } 72 | } 73 | 74 | /*! 75 | * \brief Refreshes the entire page. 76 | * \return True if successful 77 | */ 78 | bool Nextion::refresh() 79 | { 80 | sendCommand("ref 0"); 81 | return checkCommandComplete(); 82 | } 83 | 84 | /*! 85 | * \brief Refreshes a specific object. 86 | * \param objectName Name of the object to refresh 87 | * \return True if successful 88 | */ 89 | bool Nextion::refresh(const char *objectName) 90 | { 91 | size_t commandLen = 5 + strlen(objectName); 92 | char commandBuffer[commandLen]; 93 | snprintf(commandBuffer, commandLen, "ref %s", objectName); 94 | sendCommand(commandBuffer); 95 | return checkCommandComplete(); 96 | } 97 | 98 | /*! 99 | * \brief Puts the device into sleep mode. 100 | * \return True if successful 101 | */ 102 | bool Nextion::sleep() 103 | { 104 | sendCommand("sleep=1"); 105 | return checkCommandComplete(); 106 | } 107 | 108 | /*! 109 | * \brief Wakes the device from sleep mode. 110 | * \return True if successful 111 | */ 112 | bool Nextion::wake() 113 | { 114 | sendCommand("sleep=0"); 115 | return checkCommandComplete(); 116 | } 117 | 118 | /*! 119 | * \brief Gets the current backlight brightness. 120 | * \return Brightness 121 | */ 122 | uint16_t Nextion::getBrightness() 123 | { 124 | sendCommand("get dim"); 125 | uint32_t val; 126 | if (receiveNumber(&val)) 127 | return val; 128 | else 129 | return 0; 130 | } 131 | 132 | /*! 133 | * \brief Sets the backlight brightness. 134 | * \param val Brightness value (0-100) 135 | * \param persist If set to true value will be set as new power on default 136 | * \return True if successful 137 | */ 138 | bool Nextion::setBrightness(uint16_t val, bool persist) 139 | { 140 | size_t commandLen = 10; 141 | char commandBuffer[commandLen]; 142 | if (persist) 143 | snprintf(commandBuffer, commandLen, "dims=%d", val); 144 | else 145 | snprintf(commandBuffer, commandLen, "dim=%d", val); 146 | sendCommand(commandBuffer); 147 | return checkCommandComplete(); 148 | } 149 | 150 | /*! 151 | * \brief Gets the ID of the current displayed page. 152 | * \return Page ID 153 | */ 154 | uint8_t Nextion::getCurrentPage() 155 | { 156 | sendCommand("sendme"); 157 | 158 | uint8_t temp[5] = {0}; 159 | 160 | if (sizeof(temp) != m_serialPort.readBytes((char *)temp, sizeof(temp))) 161 | return 0; 162 | 163 | if (temp[0] == NEX_RET_CURRENT_PAGE_ID_HEAD && temp[2] == 0xFF && 164 | temp[3] == 0xFF && temp[4] == 0xFF) 165 | return temp[1]; 166 | 167 | return 0; 168 | } 169 | 170 | /*! 171 | * \brief Clears the current display. 172 | * \param colour Colour to set display to 173 | * \return True if successful 174 | */ 175 | bool Nextion::clear(uint32_t colour) 176 | { 177 | size_t commandLen = 9; 178 | char commandBuffer[commandLen]; 179 | snprintf(commandBuffer, commandLen, "cls %ld", colour); 180 | sendCommand(commandBuffer); 181 | return checkCommandComplete(); 182 | } 183 | 184 | /*! 185 | * \brief Draws a pre uploaded picture on the display. 186 | * \param x X position 187 | * \param y Y position 188 | * \param id ID of the picture to display 189 | * \return True if successful 190 | */ 191 | bool Nextion::drawPicture(uint16_t x, uint16_t y, uint8_t id) 192 | { 193 | size_t commandLen = 21; 194 | char commandBuffer[commandLen]; 195 | snprintf(commandBuffer, commandLen, "pic %d,%d,%d", x, y, id); 196 | sendCommand(commandBuffer); 197 | return checkCommandComplete(); 198 | } 199 | 200 | /*! 201 | * \brief Draws a cropped pre uplaoded picture on the display. 202 | * \param x X position 203 | * \param y Y position 204 | * \param w Width 205 | * \param h Height 206 | * \param id ID of the picture to display 207 | * \return True if successful 208 | */ 209 | bool Nextion::drawPicture(uint16_t x, uint16_t y, uint16_t w, uint16_t h, 210 | uint8_t id) 211 | { 212 | size_t commandLen = 35; 213 | char commandBuffer[commandLen]; 214 | snprintf(commandBuffer, commandLen, "picq %d,%d,%d,%d,%d", x, y, w, h, id); 215 | sendCommand(commandBuffer); 216 | return checkCommandComplete(); 217 | } 218 | 219 | /*! 220 | * \brief Draws a string on the display. 221 | * \param x X position 222 | * \param y Y position 223 | * \param w Width 224 | * \param h Height 225 | * \param fontID ID of the font to use 226 | * \param str String to draw 227 | * \param bgColour Colour of the background of the bounding box 228 | * \param fgColour Colour of the text 229 | * \param bgType Background type 230 | * \param xCentre X alignment 231 | * \param yCentre Y alignment 232 | * \return True if successful 233 | */ 234 | bool Nextion::drawStr(uint16_t x, uint16_t y, uint16_t w, uint16_t h, 235 | uint8_t fontID, char *str, uint32_t bgColour, 236 | uint32_t fgColour, uint8_t bgType, 237 | NextionFontAlignment xCentre, 238 | NextionFontAlignment yCentre) 239 | { 240 | size_t commandLen = 65 + strlen(str); 241 | char commandBuffer[commandLen]; 242 | snprintf(commandBuffer, commandLen, "xstr %d,%d,%d,%d,%d,%ld,%ld,%d,%d,%d,%s", 243 | x, y, w, h, fontID, fgColour, bgColour, xCentre, yCentre, bgType, 244 | str); 245 | sendCommand(commandBuffer); 246 | return checkCommandComplete(); 247 | } 248 | 249 | /*! 250 | * \brief Draws a line on the display. 251 | * \param x1 X position of first vertex 252 | * \param y1 Y position of first vertex 253 | * \param x2 X position of second vertex 254 | * \param y2 Y position of second vertex 255 | * \param colour Colour 256 | * \return True if successful 257 | */ 258 | bool Nextion::drawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, 259 | uint32_t colour) 260 | { 261 | size_t commandLen = 35; 262 | char commandBuffer[commandLen]; 263 | snprintf(commandBuffer, commandLen, "line %d,%d,%d,%d,%ld", x1, y1, x2, y2, 264 | colour); 265 | sendCommand(commandBuffer); 266 | return checkCommandComplete(); 267 | } 268 | 269 | /*! 270 | * \brief Draws a rectangle on the display. 271 | * \param x X position 272 | * \param y Y position 273 | * \param w Width 274 | * \param h Height 275 | * \param filled If the rectangle should be filled with a solid colour 276 | * \param colour Colour 277 | * \return True if successful 278 | */ 279 | bool Nextion::drawRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, 280 | bool filled, uint32_t colour) 281 | { 282 | size_t commandLen = 35; 283 | char commandBuffer[commandLen]; 284 | if (filled) 285 | snprintf(commandBuffer, commandLen, "draw %d,%d,%d,%d,%ld", x, y, x + w, 286 | y + h, colour); 287 | else 288 | snprintf(commandBuffer, commandLen, "fill %d,%d,%d,%d,%ld", x, y, w, h, 289 | colour); 290 | sendCommand(commandBuffer); 291 | return checkCommandComplete(); 292 | } 293 | 294 | /*! 295 | * \brief Draws a circle on the display. 296 | * \param x X position 297 | * \param y Y position 298 | * \param r Radius 299 | * \param colour Colour 300 | * \return True if successful 301 | */ 302 | bool Nextion::drawCircle(uint16_t x, uint16_t y, uint16_t r, uint32_t colour) 303 | { 304 | size_t commandLen = 27; 305 | char commandBuffer[commandLen]; 306 | snprintf(commandBuffer, commandLen, "cir %d,%d,%d,%ld", x, y, r, colour); 307 | sendCommand(commandBuffer); 308 | return checkCommandComplete(); 309 | } 310 | 311 | /*! 312 | * \brief Adds a INextionTouchable to the list of registered touchable 313 | * elements. 314 | * \param touchable Pointer to the INextionTouchable 315 | * 316 | * Required for touch events from an INextionTouchable to be polled. 317 | * 318 | * Should be called automatically by INextionTouchable::INextionTouchable. 319 | */ 320 | void Nextion::registerTouchable(INextionTouchable *touchable) 321 | { 322 | ITouchableListItem *newListItem = new ITouchableListItem; 323 | newListItem->item = touchable; 324 | newListItem->next = NULL; 325 | 326 | if (m_touchableList == NULL) 327 | m_touchableList = newListItem; 328 | else 329 | { 330 | ITouchableListItem *item = m_touchableList; 331 | while (item->next != NULL) 332 | item = item->next; 333 | item->next = newListItem; 334 | } 335 | } 336 | 337 | /*! 338 | * \brief Sends a command to the device. 339 | * \param command Command to send 340 | */ 341 | void Nextion::sendCommand(char *command) 342 | { 343 | if (m_flushSerialBeforeTx) 344 | m_serialPort.flush(); 345 | 346 | m_serialPort.print(command); 347 | m_serialPort.write(0xFF); 348 | m_serialPort.write(0xFF); 349 | m_serialPort.write(0xFF); 350 | } 351 | 352 | /*! 353 | * \brief Checks if the last command was successful. 354 | * \return True if command was successful 355 | */ 356 | bool Nextion::checkCommandComplete() 357 | { 358 | bool ret = false; 359 | uint8_t temp[4] = {0}; 360 | 361 | if (sizeof(temp) != m_serialPort.readBytes((char *)temp, sizeof(temp))) 362 | ret = false; 363 | 364 | if (temp[0] == NEX_RET_CMD_FINISHED && temp[1] == 0xFF && temp[2] == 0xFF && 365 | temp[3] == 0xFF) 366 | ret = true; 367 | 368 | return ret; 369 | } 370 | 371 | /*! 372 | * \brief Receive a number from the device. 373 | * \param number Pointer to the number to store received number in 374 | * \return True if receive was successful 375 | */ 376 | bool Nextion::receiveNumber(uint32_t *number) 377 | { 378 | uint8_t temp[8] = {0}; 379 | 380 | if (!number) 381 | return false; 382 | 383 | if (sizeof(temp) != m_serialPort.readBytes((char *)temp, sizeof(temp))) 384 | return false; 385 | 386 | if (temp[0] == NEX_RET_NUMBER_HEAD && temp[5] == 0xFF && temp[6] == 0xFF && 387 | temp[7] == 0xFF) 388 | { 389 | *number = (temp[4] << 24) | (temp[3] << 16) | (temp[2] << 8) | (temp[1]); 390 | return true; 391 | } 392 | 393 | return false; 394 | } 395 | 396 | /*! 397 | * \brief Receive a string from the device. 398 | * \param buffer Pointer to buffer to store string in 399 | * \param len Maximum length of data to receive 400 | * \return Actual length of string received 401 | */ 402 | size_t Nextion::receiveString(char *buffer, size_t len) 403 | { 404 | memset(buffer, 0, len); 405 | 406 | bool have_header_flag = false; 407 | uint8_t flag_count = 0; 408 | size_t pos = 0; 409 | 410 | if (!buffer || len == 0) 411 | return false; 412 | 413 | uint32_t start = millis(); 414 | while (millis() - start <= m_timeout) 415 | { 416 | while (m_serialPort.available()) 417 | { 418 | char c = m_serialPort.read(); 419 | if (have_header_flag) 420 | { 421 | if (c == 0xFF || c == 0xFFFFFFFF) 422 | { 423 | flag_count++; 424 | if (flag_count >= 3) 425 | break; 426 | } 427 | else 428 | { 429 | buffer[pos] = c; 430 | pos++; 431 | if (pos == len - 1) 432 | break; 433 | } 434 | } 435 | else if (c == NEX_RET_STRING_HEAD) 436 | have_header_flag = true; 437 | } 438 | 439 | if (flag_count >= 3) 440 | break; 441 | } 442 | 443 | pos++; 444 | buffer[pos] = '\0'; 445 | return pos; 446 | } 447 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | --------------------------------------------------------------------------------