forked from DanNixon/NeoNextion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINextionStringValued.h
83 lines (75 loc) · 1.84 KB
/
INextionStringValued.h
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
/*! \file */
#ifndef __NEONEXTION_INEXTIONSTRINGVALUED
#define __NEONEXTION_INEXTIONSTRINGVALUED
#include "Nextion.h"
#include "INextionWidget.h"
#include "NextionTypes.h"
/*!
* \class INextionStringValued
* \brief Interface for widgets that hold a string value.
*
* Assumes that the string value is a property named "txt".
*/
class INextionStringValued : public virtual INextionWidget
{
public:
/*!
* \copydoc INextionWidget::INextionWidget
*/
INextionStringValued(Nextion &nex, uint8_t page, uint8_t component,
const char *name)
: INextionWidget(nex, page, component, name)
{
}
/*!
* \brief Gets the value of the string.
* \param buffer Pointer to storage to strore string in
* \param len Maximum length of string
* \return Actual length of string
* \see INextionStringValued::setText
*/
size_t getText(char *buffer, size_t len)
{
return getStringProperty("txt", buffer, len);
}
/*!
* \brief Sets the value of the string.
* \param buffer Value
* \return True if successful
* \see INextionStringValued::getText
*/
bool setText(char *buffer)
{
return setStringProperty("txt", buffer);
}
/*!
* \brief Sets the text by a numercal value.
* \param value Numerical value
* \return True if successful
* \see INextionStringValued::getTextAsNumber
*/
bool setTextAsNumber(uint32_t value)
{
char buffer[8];
snprintf(buffer, 8, "%ld", value);
return setStringProperty("txt", buffer);
}
/*!
* \brief Gets the text parsed as a number.
* \return Numerical value
* \see INextionStringValued::setTextAsNumber
*/
uint32_t getTextAsNumber()
{
char buffer[8];
if (getStringProperty("txt", buffer, 8))
{
uint32_t value;
sscanf(buffer, "%ld", &value);
return value;
}
else
return 0;
}
};
#endif