This repository has been archived by the owner on Sep 15, 2023. It is now read-only.
forked from DanNixon/NeoNextion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NextionTimer.cpp
70 lines (63 loc) · 1.62 KB
/
NextionTimer.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
/*! \file */
#include "NextionTimer.h"
/*!
* \copydoc INextionWidget::INextionWidget
*/
NextionTimer::NextionTimer(Nextion &nex, uint8_t page, uint8_t component,
const char *name)
: INextionWidget(nex, page, component, name)
, INextionTouchable(nex, page, component, name)
{
}
/*!
* \brief Gets the cycle time of the timer.
* \return Time in ms (may also return 0 in case of error)
*/
uint32_t NextionTimer::getCycle()
{
size_t commandLen = 9 + strlen(m_name);
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "get %s.tim", m_name);
sendCommand(commandBuffer, false);
uint32_t id;
if (m_nextion.receiveNumber(&id))
return id;
else
return 0;
}
/*!
* \brief Sets the cycle time of the timer.
* \param cycle Time in ms
* \return True if successful
*/
bool NextionTimer::setCycle(uint32_t cycle)
{
if (cycle < 50)
return false;
size_t commandLen = 11 + strlen(m_name);
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "%s.tim=%d", m_name, cycle);
return sendCommand(commandBuffer);
}
/*!
* \brief Enable/start the timer.
* \return True if successful
*/
bool NextionTimer::enable()
{
size_t commandLen = 6 + strlen(m_name);
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "%s.en=1", m_name);
return sendCommand(commandBuffer);
}
/*!
* \brief Disable/stop the timer.
* \return True if successful
*/
bool NextionTimer::disable()
{
size_t commandLen = 6 + strlen(m_name);
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "%s.en=0", m_name);
return sendCommand(commandBuffer);
}