forked from DanNixon/NeoNextion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
INextionTouchable.cpp
94 lines (80 loc) · 2.05 KB
/
INextionTouchable.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*! \file */
#include "INextionTouchable.h"
/*!
* \copydoc INextionWidget::INextionWidget
*/
INextionTouchable::INextionTouchable(Nextion &nex, uint8_t page,
uint8_t component, const char *name)
: INextionWidget(nex, page, component, name)
, m_callback(NULL)
{
nex.registerTouchable(this);
}
/*!
* \brief Processes a touch event.
* \param pageID Page ID of touch event
* \param componentID Component ID of touch event
* \param eventType Type of touch event
* \return True if the event effects this widget
*/
bool INextionTouchable::processEvent(uint8_t pageID, uint8_t componentID,
uint8_t eventType)
{
if (pageID != m_pageID)
return false;
if (componentID != m_componentID)
return false;
switch (eventType)
{
case NEX_EVENT_PUSH:
if (m_callback)
m_callback->handleNextionEvent((NextionEventType)eventType, this);
return true;
case NEX_EVENT_POP:
if (m_callback)
m_callback->handleNextionEvent((NextionEventType)eventType, this);
return true;
default:
return false;
}
}
/*!
* \brief Attaches a callback function to this widget.
* \param function Pointer to callback function
* \return True if successful
* \see INextionTouchable::detachCallback
*/
bool INextionTouchable::attachCallback(
NextionCallbackFunctionHandler::NextionFunction function)
{
if (!function)
return false;
if (m_callback != NULL)
detachCallback();
m_callback = new NextionCallbackFunctionHandler(function);
return true;
}
/*!
* \brief Attaches a callback handler to this widget.
* \param handler Pointer to handler
* \return True if successful
* \see INextionTouchable::detachCallback
*/
bool INextionTouchable::attachCallback(INextionCallback *handler)
{
if (!handler)
return false;
if (m_callback != NULL)
detachCallback();
m_callback = handler;
return true;
}
/*!
* \brief Removes the callback handler from this widget
*
* Memory is not freed.
*/
void INextionTouchable::detachCallback()
{
m_callback = NULL;
}