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
/
NextionWaveform.cpp
122 lines (109 loc) · 2.86 KB
/
NextionWaveform.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*! \file */
#include "NextionWaveform.h"
#include "INextionWidget.h"
/*!
* \copydoc INextionWidget::INextionWidget
*/
NextionWaveform::NextionWaveform(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)
{
}
/*!
* \brief Adds a value to the waveform display.
* \param channel Channel number
* \param value Value
* \return True if successful
*/
bool NextionWaveform::addValue(uint8_t channel, uint8_t value)
{
if (channel > 3)
return false;
size_t commandLen = 22;
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "add %d,%d,%d", m_componentID, channel,
value);
sendCommand(commandBuffer, false);
/* TODO: this check still fails but the command does actually work */
/* return m_nextion.checkCommandComplete(); */
return true;
}
/*!
* \brief Sets the colour of a channel.
* \param channel Channel number
* \param colour Colour
* \param refresh If the widget should be refreshed
* \return True if successful
*/
bool NextionWaveform::setChannelColour(uint8_t channel, uint32_t colour,
bool refresh)
{
char buffer[5];
snprintf(buffer, 5, "pco%d", channel);
return setColour(buffer, colour, refresh);
}
/*!
* \brief Gets the colour of a channel.
* \param channel Channel number
* \return Colour (may return 0 in case of error)
*/
uint32_t NextionWaveform::getChannelColour(uint8_t channel)
{
char buffer[5];
snprintf(buffer, 5, "pco%d", channel);
return getColour(buffer);
}
/*!
* \brief Sets the colour of the grid lines.
* \param colour Colour
* \param refresh If the widget should be refreshed
* \return True if successful
*/
bool NextionWaveform::setGridColour(uint32_t colour, bool refresh)
{
return setColour("gdc", colour, refresh);
}
/*!
* \brief Gets the colour of the grid lines.
* \return Colour (may return 0 in case of error)
*/
uint32_t NextionWaveform::getGridColour()
{
return getColour("gdc");
}
/*!
* \brief Sets the width of the grid squares.
* \param width Width
* \return True if successful
*/
bool NextionWaveform::setGridWidth(uint16_t width)
{
return setNumberProperty("gdw", width);
}
/*!
* \brief Gets the width of the grid squares.
* \return Width (may return 0 in case of error)
*/
uint16_t NextionWaveform::getGridWidth()
{
return getNumberProperty("gdw");
}
/*!
* \brief Sets the height of the grid squares.
* \param height Height
* \return True if successful
*/
bool NextionWaveform::setGridHeight(uint16_t height)
{
return setNumberProperty("gdh", height);
}
/*!
* \brief Gets the height of the grid squares.
* \return Height (may return 0 in case of error)
*/
uint16_t NextionWaveform::getGridHeight()
{
return getNumberProperty("gdh");
}