Bind
C++ UI framework for Arduino
 
Loading...
Searching...
No Matches
BindGauge.hpp
1#ifndef __BINDGAUGE_HPP
2#define __BINDGAUGE_HPP
3#include "BindView.hpp"
4#include "BindUtils.hpp"
5
6// TODO: Extract each class to a serprate .h and .c file! Now!
30class BindGauge : public BindView
31{
32public:
41 BindGauge(const char *cstr);
42
49 BindGauge() : BindGauge("Gauge"){};
50
51 int16_t x;
52 int16_t y;
53 uint8_t cmdId = 0;
54 int16_t dimSize = 100;
55 float value = 0;
56 float maxValue = 100.0f;
57 uint8_t drawArc = 0;
58 float arcGreenMaxVal = 0;
59 float arcYellowMaxVal = 0;
60 float arcRedMaxVal = 0;
61
70 void setLabel(const char *cstr)
71 {
72 str = cstr;
73 }
74
75 [[deprecated("Use setLabel instead")]]
76 void setlabel(const char *cstr)
77 {
78 setLabel(cstr);
79 }
80
91 uint16_t getBytes(uint8_t *out) override
92 {
93 offset = 0;
94 strLength = strlen(str);
95 if (strLength > MAX_STRING_LENGTH_TERMINAL)
96 {
97 strLength = MAX_STRING_LENGTH_TERMINAL;
98 }
99 copyAndOffset(out, &offset, &objID, 1);
100 copyAndOffset(out, &offset, &x, sizeof(x));
101 copyAndOffset(out, &offset, &y, sizeof(y));
102 copyAndOffset(out, &offset, &tag, sizeof(tag));
103 copyAndOffset(out, &offset, &cmdId, sizeof(cmdId));
104 copyAndOffset(out, &offset, &dimSize, sizeof(dimSize));
105 copyAndOffset(out, &offset, &value, sizeof(value));
106 copyAndOffset(out, &offset, &maxValue, sizeof(maxValue));
107 copyAndOffset(out, &offset, &drawArc, sizeof(drawArc));
108 copyAndOffset(out, &offset, &arcGreenMaxVal, sizeof(arcGreenMaxVal));
109 copyAndOffset(out, &offset, &arcYellowMaxVal, sizeof(arcYellowMaxVal));
110 copyAndOffset(out, &offset, &arcRedMaxVal, sizeof(arcRedMaxVal));
111 copyAndOffset(out, &offset, str, strLength);
112 return offset;
113 }
114
115private:
116 uint8_t objID = BIND_ID_GAUGE1;
117 uint16_t offset = 0;
118 int strLength = 0;
119 const char *str;
120 static int16_t tagIndex;
121};
122
123#endif /* __BINDGAUGE_HPP */
The BindGauge class represents a gauge UI element for use with BindCanvas.
Definition BindGauge.hpp:31
void setLabel(const char *cstr)
Sets the label text for the gauge.
Definition BindGauge.hpp:70
uint16_t getBytes(uint8_t *out) override
Serializes gauge properties into a byte array for synchronization.
Definition BindGauge.hpp:91
float maxValue
Maximum value of the gauge.
Definition BindGauge.hpp:56
uint8_t cmdId
Command ID for the gauge. See the notes for possible cmdId values.
Definition BindGauge.hpp:53
int16_t dimSize
Size of the gauge (Width = height)
Definition BindGauge.hpp:54
float arcRedMaxVal
Maximum value for the red arc section.
Definition BindGauge.hpp:60
float value
Current value of the gauge.
Definition BindGauge.hpp:55
BindGauge()
Constructs a BindGauge with a default label.
Definition BindGauge.hpp:49
uint8_t drawArc
Indicates whether to draw the gauge arc.
Definition BindGauge.hpp:57
float arcYellowMaxVal
Maximum value for the yellow arc section.
Definition BindGauge.hpp:59
int16_t y
Y-coordinate position of the gauge.
Definition BindGauge.hpp:52
float arcGreenMaxVal
Maximum value for the green arc section.
Definition BindGauge.hpp:58
int16_t x
X-coordinate position of the gauge.
Definition BindGauge.hpp:51
Definition BindView.hpp:26