Skip to content
This repository was archived by the owner on Dec 24, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions INextionWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ class INextionWidget
bool setStringProperty(char *propertyName, char *value);
size_t getStringProperty(char *propertyName, char *value, size_t len);

protected:

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
uint8_t m_componentID; //!< Component ID of this widget
uint8_t m_pageID; //!< ID of page this widget is on
};

#endif
44 changes: 41 additions & 3 deletions Nextion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Nextion::Nextion(Stream &stream, bool flushSerialBeforeTx)
*/
bool Nextion::init()
{
WakeEvent=false;
sendCommand("");

sendCommand("bkcmd=1");
Expand All @@ -43,7 +44,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);

Expand All @@ -56,7 +59,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;
Expand All @@ -68,9 +71,43 @@ void Nextion::poll()
}
}
}

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
Expand Down Expand Up @@ -239,9 +276,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();
}
Expand Down
5 changes: 5 additions & 0 deletions Nextion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions NextionTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#ifndef __NEONEXTION_NEXTIONTYPES
#define __NEONEXTION_NEXTIONTYPES



/*!
* \enum NextionValue
* \brief Values used in messages.
Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ Avaliable through the library manager of the Arduio IDE as `NeoNextion`.

## New features

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

If you find a feature that is missing that you want implemented let me know
and I'll look at adding it for you.
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.

`DeActivateWakeEvent();`
This method stops to execute callback described above (so wake-up after sleep send no event to code).

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