From e6e6d55f800771c6c2de9a5bcbe8910610db0bbb Mon Sep 17 00:00:00 2001 From: viktor1970 Date: Mon, 20 Feb 2017 17:39:08 +0100 Subject: [PATCH 01/10] Update INextionWidget.cpp --- INextionWidget.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/INextionWidget.cpp b/INextionWidget.cpp index 9e077e8..a13cdfb 100644 --- a/INextionWidget.cpp +++ b/INextionWidget.cpp @@ -101,8 +101,9 @@ size_t INextionWidget::getStringProperty(char *propertyName, char *value, bool INextionWidget::sendCommand(char *commandStr, bool checkComplete) { - if (m_pageID != m_nextion.getCurrentPage()) - return false; + // Removed: this prevent to send commands to objects in other pages + //if (m_pageID != m_nextion.getCurrentPage()) + // return false; m_nextion.sendCommand(commandStr); From 3c18a2d0c5a33a20a6fc8a3ef2d868fb7dfb847f Mon Sep 17 00:00:00 2001 From: viktor1970 Date: Mon, 20 Feb 2017 17:44:19 +0100 Subject: [PATCH 02/10] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 9ae0744..cce96ff 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,11 @@ Avaliable through the library manager of the Arduio IDE as `NeoNextion`. ## New features +Added by Viktor1970: removed a check in sendMessage method, that prevents to control objects in other pages. + Now the page's show() method it's working. + + + I don't use Nextion displays in my projects anymore so this library may not allow all the features in the latest display firmware to be used. However I still own a few of them and am happy to work on adding new functionality From 11dd734b851f5dae3e35529df2e9469ee2db0739 Mon Sep 17 00:00:00 2001 From: Vittorio Date: Fri, 25 Aug 2017 15:33:05 +0200 Subject: [PATCH 03/10] Add files via upload --- INextionWidget.h | 7 ++++--- Nextion.cpp | 20 +++++++++++++++++--- NextionTypes.h | 5 +++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/INextionWidget.h b/INextionWidget.h index 0ad709f..fa609be 100644 --- a/INextionWidget.h +++ b/INextionWidget.h @@ -26,13 +26,14 @@ class INextionWidget bool setStringProperty(char *propertyName, char *value); size_t getStringProperty(char *propertyName, char *value, size_t len); -protected: + uint8_t m_componentID; //!< Component ID of this widget + uint8_t m_pageID; //!< ID of page this widget is on + + protected: bool sendCommand(char *commandStr, bool checkComplete = true); protected: Nextion &m_nextion; //!< Reference to the Nextion driver - uint8_t m_pageID; //!< ID of page this widget is on - uint8_t m_componentID; //!< Component ID of this widget const char *m_name; //!< Name of this widget }; diff --git a/Nextion.cpp b/Nextion.cpp index a5e3f29..aa9785f 100644 --- a/Nextion.cpp +++ b/Nextion.cpp @@ -43,7 +43,9 @@ void Nextion::poll() { char c = m_serialPort.read(); - if (c == NEX_RET_EVENT_TOUCH_HEAD) + //Serial.print("Ret:"); Serial.println((byte)c); + + if (c == NEX_RET_EVENT_TOUCH_HEAD ) { delay(10); @@ -56,7 +58,7 @@ void Nextion::poll() for (i = 1; i < 7; i++) buffer[i] = m_serialPort.read(); buffer[i] = 0x00; - + Serial.println(String(buffer[0])+" "+String(buffer[1])+" "+String(buffer[2])+" "+String(buffer[3])+" "+String(buffer[4])+" "+String(buffer[5])+" "+String(buffer[6])); if (buffer[4] == 0xFF && buffer[5] == 0xFF && buffer[6] == 0xFF) { ITouchableListItem *item = m_touchableList; @@ -68,6 +70,17 @@ void Nextion::poll() } } } + else if(c == NEX_RET_EVENT_SLEEP_POSITION_HEAD) + { + delay(10); + ITouchableListItem *item = m_touchableList; + while (item != NULL) + { + //item->item->processEvent(buffer[1], buffer[2], buffer[3]); + if(item->item->m_componentID==NEX_SS_COMP&&item->item->m_pageID==NEX_SS_PAGE) {item->item->processEvent(NEX_SS_PAGE,NEX_SS_COMP,NEX_EVENT_POP); break;} + else item = item->next; + } + } } } @@ -239,9 +252,10 @@ bool Nextion::drawStr(uint16_t x, uint16_t y, uint16_t w, uint16_t h, { size_t commandLen = 65 + strlen(str); char commandBuffer[commandLen]; - snprintf(commandBuffer, commandLen, "xstr %d,%d,%d,%d,%d,%ld,%ld,%d,%d,%d,%s", + snprintf(commandBuffer, commandLen, "xstr %d,%d,%d,%d,%d,%ld,%ld,%d,%d,%d,\"%s\"", x, y, w, h, fontID, fgColour, bgColour, xCentre, yCentre, bgType, str); + //Serial.println(commandBuffer); sendCommand(commandBuffer); return checkCommandComplete(); } diff --git a/NextionTypes.h b/NextionTypes.h index d6f8462..244b498 100644 --- a/NextionTypes.h +++ b/NextionTypes.h @@ -7,6 +7,11 @@ * \enum NextionValue * \brief Values used in messages. */ + + #define NEX_SS_PAGE 0 + #define NEX_SS_COMP 1 + + enum NextionValue { NEX_RET_CMD_FINISHED = (0x01), From 44cbbf768bc4d346a203a0de1af5dd8ef81675d0 Mon Sep 17 00:00:00 2001 From: Vittorio Date: Fri, 25 Aug 2017 16:05:23 +0200 Subject: [PATCH 04/10] Added exit sleep mode event support Sometimes can be useful put the display in sleep mode. Setting command "thup=1", the display is waked up by a touch event. The touch event is sent to microcontroller with X and Y coordinates, but the original poll() code does not manage that event. I added the capability of managing that event in a defined page and component ID, so a callback function can be called. This because microcontroller needs to know (or it should know!) if the display is in sleep mode or not. There are 3 new #define in NextionTypes.h: #define NEX_SS true/false : code supports Screen Saver (using sleep) mode? #define NEX_SS_COMP XX : touching component ID XX will activare event to exit Screen Saver mode (event attached will be called) #define NEX_SS_PAGE YY : the page YY in which component is Note: if no callback defined, the display exits sleep mode but, obviously, nothing is called. The most common use is to create an entire screen touch area and attach a callback. Whe --- Nextion.cpp | 2 ++ NextionTypes.h | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Nextion.cpp b/Nextion.cpp index aa9785f..977f96d 100644 --- a/Nextion.cpp +++ b/Nextion.cpp @@ -70,6 +70,7 @@ void Nextion::poll() } } } +#ifdef NEX_SS else if(c == NEX_RET_EVENT_SLEEP_POSITION_HEAD) { delay(10); @@ -81,6 +82,7 @@ void Nextion::poll() else item = item->next; } } +#endif } } diff --git a/NextionTypes.h b/NextionTypes.h index 244b498..ee94f72 100644 --- a/NextionTypes.h +++ b/NextionTypes.h @@ -3,15 +3,16 @@ #ifndef __NEONEXTION_NEXTIONTYPES #define __NEONEXTION_NEXTIONTYPES + +#define NEX_SS true //The code supports Screen Saver (using sleep) mode? +#define NEX_SS_COMP 1 //Touching that component ID will activare event to exit Screen Saver mode (event attached will be called) +#define NEX_SS_PAGE 0 //The page in which component is + + /*! * \enum NextionValue * \brief Values used in messages. */ - - #define NEX_SS_PAGE 0 - #define NEX_SS_COMP 1 - - enum NextionValue { NEX_RET_CMD_FINISHED = (0x01), From 99c7b9b1231f817b507ce0bd4401871b7e980f95 Mon Sep 17 00:00:00 2001 From: Vittorio Date: Fri, 25 Aug 2017 16:35:17 +0200 Subject: [PATCH 05/10] Update README.md --- README.md | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index cce96ff..e18e3e4 100644 --- a/README.md +++ b/README.md @@ -13,21 +13,13 @@ Avaliable through the library manager of the Arduio IDE as `NeoNextion`. ## New features -Added by Viktor1970: removed a check in sendMessage method, that prevents to control objects in other pages. - Now the page's show() method it's working. +Added by Viktor1970: +- added the capability of managing a wake event in a defined page and component ID, so a callback function can be called. +- removed a check in sendMessage method, that prevents to control objects in other pages. Now the page's show() method it's working. - -I don't use Nextion displays in my projects anymore so this library may not -allow all the features in the latest display firmware to be used. However -I still own a few of them and am happy to work on adding new functionality -if it is desired. - -If you find a feature that is missing that you want implemented let me know -and I'll look at adding it for you. - ## Links -- Repository: https://github.com/DanNixon/NeoNextion +- Original Repository: https://github.com/DanNixon/NeoNextion - Travis CI: https://travis-ci.org/DanNixon/NeoNextion - Documentation: https://dannixon.github.io/NeoNextion From d6155f50fc00eb5d0afc53f67c269b0f81c946d1 Mon Sep 17 00:00:00 2001 From: Vittorio Date: Fri, 25 Aug 2017 20:15:05 +0200 Subject: [PATCH 06/10] Add files via upload --- Nextion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nextion.cpp b/Nextion.cpp index 977f96d..6b93749 100644 --- a/Nextion.cpp +++ b/Nextion.cpp @@ -58,7 +58,7 @@ void Nextion::poll() for (i = 1; i < 7; i++) buffer[i] = m_serialPort.read(); buffer[i] = 0x00; - Serial.println(String(buffer[0])+" "+String(buffer[1])+" "+String(buffer[2])+" "+String(buffer[3])+" "+String(buffer[4])+" "+String(buffer[5])+" "+String(buffer[6])); + //Serial.println(String(buffer[0])+" "+String(buffer[1])+" "+String(buffer[2])+" "+String(buffer[3])+" "+String(buffer[4])+" "+String(buffer[5])+" "+String(buffer[6])); if (buffer[4] == 0xFF && buffer[5] == 0xFF && buffer[6] == 0xFF) { ITouchableListItem *item = m_touchableList; From 73fd915cac0aa7e3a931a9f9aeac70d332e91ee4 Mon Sep 17 00:00:00 2001 From: Vittorio Date: Fri, 25 Aug 2017 20:17:08 +0200 Subject: [PATCH 07/10] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index e18e3e4..f017dff 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,6 @@ Avaliable through the library manager of the Arduio IDE as `NeoNextion`. ## New features Added by Viktor1970: -- added the capability of managing a wake event in a defined page and component ID, so a callback function can be called. - removed a check in sendMessage method, that prevents to control objects in other pages. Now the page's show() method it's working. From e0d900e801e4debf5d8e64530c21103ef6c041be Mon Sep 17 00:00:00 2001 From: Vittorio Date: Fri, 25 Aug 2017 21:25:14 +0200 Subject: [PATCH 08/10] Add files via upload --- INextionWidget.h | 4 ++-- Nextion.cpp | 48 +++++++++++++++++++++++++++++++++++------------- Nextion.h | 5 +++++ NextionTypes.h | 4 ---- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/INextionWidget.h b/INextionWidget.h index fa609be..c7b8c40 100644 --- a/INextionWidget.h +++ b/INextionWidget.h @@ -26,8 +26,6 @@ class INextionWidget bool setStringProperty(char *propertyName, char *value); size_t getStringProperty(char *propertyName, char *value, size_t len); - uint8_t m_componentID; //!< Component ID of this widget - uint8_t m_pageID; //!< ID of page this widget is on protected: bool sendCommand(char *commandStr, bool checkComplete = true); @@ -35,6 +33,8 @@ class INextionWidget protected: Nextion &m_nextion; //!< Reference to the Nextion driver const char *m_name; //!< Name of this widget + uint8_t m_componentID; //!< Component ID of this widget + uint8_t m_pageID; //!< ID of page this widget is on }; #endif diff --git a/Nextion.cpp b/Nextion.cpp index 6b93749..d015e9a 100644 --- a/Nextion.cpp +++ b/Nextion.cpp @@ -23,6 +23,7 @@ Nextion::Nextion(Stream &stream, bool flushSerialBeforeTx) */ bool Nextion::init() { + WakeEvent=false; sendCommand(""); sendCommand("bkcmd=1"); @@ -70,22 +71,43 @@ void Nextion::poll() } } } -#ifdef NEX_SS - else if(c == NEX_RET_EVENT_SLEEP_POSITION_HEAD) - { - delay(10); - ITouchableListItem *item = m_touchableList; - while (item != NULL) - { - //item->item->processEvent(buffer[1], buffer[2], buffer[3]); - if(item->item->m_componentID==NEX_SS_COMP&&item->item->m_pageID==NEX_SS_PAGE) {item->item->processEvent(NEX_SS_PAGE,NEX_SS_COMP,NEX_EVENT_POP); break;} - else item = item->next; - } - } -#endif + + if(WakeEvent) + if(c == NEX_RET_EVENT_SLEEP_POSITION_HEAD) + { + delay(10); + ITouchableListItem *item = m_touchableList; + while (item != NULL) + { + // Serial.println(item->item->getComponentID()); + if(item->item->getComponentID()==WakeComponentID&&item->item->getPageID()==WakePageID) {item->item->processEvent(WakePageID, WakeComponentID, NEX_EVENT_POP); break;} + else item = item->next; + } + } + } } +/*! + * \brief Do not handle Wake event. + */ +void Nextion::DeActivateWakeEvent() +{ + WakeEvent=false; +} + +/*! + * \brief Set the callback to call when Wake event occours (the component needs a callback attached). + * \param page_id In which page the component is + * \param component_id The component ID + */ +void Nextion::ActivateWakeEvent(uint8_t page_id, uint8_t component_id) +{ + WakeEvent=true; + WakePageID=page_id; + WakeComponentID=component_id; +} + /*! * \brief Refreshes the entire page. * \return True if successful diff --git a/Nextion.h b/Nextion.h index 3fde709..cd61795 100644 --- a/Nextion.h +++ b/Nextion.h @@ -67,12 +67,17 @@ class Nextion bool checkCommandComplete(); bool receiveNumber(uint32_t *number); size_t receiveString(char *buffer, size_t len); + + void ActivateWakeEvent(uint8_t page_id, uint8_t component_id); + void DeActivateWakeEvent(); private: Stream &m_serialPort; //!< Serial port device is attached to uint32_t m_timeout; //!< Serial communication timeout in ms bool m_flushSerialBeforeTx; //!< Flush serial port before transmission ITouchableListItem *m_touchableList; //!< LInked list of INextionTouchable + bool WakeEvent; + uint8_t WakePageID, WakeComponentID; }; #endif diff --git a/NextionTypes.h b/NextionTypes.h index ee94f72..507438a 100644 --- a/NextionTypes.h +++ b/NextionTypes.h @@ -4,10 +4,6 @@ #define __NEONEXTION_NEXTIONTYPES -#define NEX_SS true //The code supports Screen Saver (using sleep) mode? -#define NEX_SS_COMP 1 //Touching that component ID will activare event to exit Screen Saver mode (event attached will be called) -#define NEX_SS_PAGE 0 //The page in which component is - /*! * \enum NextionValue From 7058454ac1bb41c6777c849cf102681923d4b77c Mon Sep 17 00:00:00 2001 From: Vittorio Date: Fri, 25 Aug 2017 21:51:57 +0200 Subject: [PATCH 09/10] Update README.md --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f017dff..3479b15 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,15 @@ Avaliable through the library manager of the Arduio IDE as `NeoNextion`. ## New features Added by Viktor1970: -- removed a check in sendMessage method, that prevents to control objects in other pages. Now the page's show() method it's working. +1. Removed a check in sendMessage method, that prevents to control objects in other pages. Now the page's show() method it's working. +2.I added 2 methods to Nextion.h/.cpp: + +`ActivateWakeEvent(uint8_t page_id, uint8_t component_id);` +This method permits to execute a callback handler attached to **component_id** in **page_id** when the display wakes up after sleep. + +`DeActivateWakeEvent();` +This method stops to execute callback described above (so wake-up after sleep send no event to code). ## Links From 5ebe6d8423f3ec84e77c754eb6efb4b27a947c26 Mon Sep 17 00:00:00 2001 From: Vittorio Date: Fri, 25 Aug 2017 21:52:33 +0200 Subject: [PATCH 10/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3479b15..e363ca8 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Avaliable through the library manager of the Arduio IDE as `NeoNextion`. Added by Viktor1970: 1. Removed a check in sendMessage method, that prevents to control objects in other pages. Now the page's show() method it's working. -2.I added 2 methods to Nextion.h/.cpp: +2. Added 2 methods to Nextion.h/.cpp: `ActivateWakeEvent(uint8_t page_id, uint8_t component_id);` This method permits to execute a callback handler attached to **component_id** in **page_id** when the display wakes up after sleep.