NeoNextion
Arduino library for the Nextion displays.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator
INextionStringValued.h
Go to the documentation of this file.
1 
3 #ifndef __NEONEXTION_INEXTIONSTRINGVALUED
4 #define __NEONEXTION_INEXTIONSTRINGVALUED
5 
6 #include "Nextion.h"
7 #include "INextionWidget.h"
8 #include "NextionTypes.h"
9 
16 class INextionStringValued : public virtual INextionWidget
17 {
18 public:
22  INextionStringValued(Nextion &nex, uint8_t page, uint8_t component,
23  const char *name)
24  : INextionWidget(nex, page, component, name)
25  {
26  }
27 
35  size_t getText(char *buffer, size_t len)
36  {
37  return getStringProperty("txt", buffer, len);
38  }
39 
46  bool setText(char *buffer)
47  {
48  return setStringProperty("txt", buffer);
49  }
50 
57  bool setTextAsNumber(uint32_t value)
58  {
59  char buffer[8];
60  snprintf(buffer, 8, "%ld", value);
61  return setStringProperty("txt", buffer);
62  }
63 
69  uint32_t getTextAsNumber()
70  {
71  char buffer[8];
72  if (getStringProperty("txt", buffer, 8))
73  {
74  uint32_t value;
75  sscanf(buffer, "%ld", &value);
76  return value;
77  }
78  else
79  return 0;
80  }
81 };
82 
83 #endif
bool setText(char *buffer)
Sets the value of the string.
Definition: INextionStringValued.h:46
bool setStringProperty(char *propertyName, char *value)
Sets the value of a string property of this widget.
Definition: INextionWidget.cpp:77
size_t getText(char *buffer, size_t len)
Gets the value of the string.
Definition: INextionStringValued.h:35
Interface for widgets that hold a string value.
Definition: INextionStringValued.h:16
size_t getStringProperty(char *propertyName, char *value, size_t len)
Gets the value of a string property of this widget.
Definition: INextionWidget.cpp:92
Abstract class for all UI widgets.
Definition: INextionWidget.h:15
uint32_t getTextAsNumber()
Gets the text parsed as a number.
Definition: INextionStringValued.h:69
INextionStringValued(Nextion &nex, uint8_t page, uint8_t component, const char *name)
Create a new widget adapter.
Definition: INextionStringValued.h:22
Driver for a physical Nextion device.
Definition: Nextion.h:31
bool setTextAsNumber(uint32_t value)
Sets the text by a numercal value.
Definition: INextionStringValued.h:57