This repository has been archived by the owner on Dec 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
NextionSlidingText.cpp
100 lines (90 loc) · 2.75 KB
/
NextionSlidingText.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
95
96
97
98
99
100
/*! \file */
#include "NextionSlidingText.h"
/*!
* \copydoc INextionWidget::INextionWidget
*/
NextionSlidingText::NextionSlidingText(Nextion &nex, uint8_t page,
uint8_t component, const char *name)
: INextionWidget(nex, page, component, name)
, INextionTouchable(nex, page, component, name)
, INextionColourable(nex, page, component, name)
, INextionStringValued(nex, page, component, name)
, INextionFontStyleable(nex, page, component, name)
{
}
bool NextionSlidingText::setScrolling(bool scroll)
{
size_t commandLen = 10 + strlen(m_name);
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "%s.en=%d", m_name, scroll);
return sendCommand(commandBuffer);
}
bool NextionSlidingText::isScrolling()
{
size_t commandLen = 8 + strlen(m_name);
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "get %s.en", m_name);
sendCommand(commandBuffer, false);
uint32_t en;
if (m_nextion.receiveNumber(&en))
return (bool)en;
else
return 0;
}
bool NextionSlidingText::setScrollDirection(NextionScrollDirection direction)
{
size_t commandLen = 11 + strlen(m_name);
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "%s.dir=%d", m_name, direction);
return sendCommand(commandBuffer);
}
NextionScrollDirection NextionSlidingText::getScrollDirection()
{
size_t commandLen = 9 + strlen(m_name);
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "get %s.dir", m_name);
sendCommand(commandBuffer, false);
uint32_t val;
if (m_nextion.receiveNumber(&val))
return (NextionScrollDirection)val;
else
return NEX_SCROLL_NONE;
}
bool NextionSlidingText::setScrollDistance(uint32_t distance)
{
size_t commandLen = 11 + strlen(m_name);
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "%s.dis=%d", m_name, distance);
return sendCommand(commandBuffer);
}
uint32_t NextionSlidingText::getScrollDistance()
{
size_t commandLen = 9 + strlen(m_name);
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "get %s.dis", m_name);
sendCommand(commandBuffer, false);
uint32_t val;
if (m_nextion.receiveNumber(&val))
return val;
else
return 0;
}
bool NextionSlidingText::setScrollDelay(uint32_t delay)
{
size_t commandLen = 11 + strlen(m_name);
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "%s.tim=%d", m_name, delay);
return sendCommand(commandBuffer);
}
uint32_t NextionSlidingText::getScrollDelay()
{
size_t commandLen = 9 + strlen(m_name);
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "get %s.tim", m_name);
sendCommand(commandBuffer, false);
uint32_t val;
if (m_nextion.receiveNumber(&val))
return val;
else
return 0;
}