Bind
C++ UI toolkit 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!
29class BindGauge : public BindView
30{
31public:
40 BindGauge(const char *cstr);
41
48 BindGauge() : BindGauge("Gauge"){};
49
50 int16_t x;
51 int16_t y;
52 uint8_t cmdId = 0;
53 int16_t dimSize = 100;
54 float value = 0;
55 float maxValue = 100.0f;
56 uint8_t drawArc = 0;
57 float arcGreenMaxVal = 0;
58 float arcYellowMaxVal = 0;
59 float arcRedMaxVal = 0;
60
69 void setlabel(const char *cstr)
70 {
71 str = cstr;
72 }
73
84 uint16_t getBytes(uint8_t *out) override
85 {
86 offset = 0;
87 strLength = strlen(str);
88 if (strLength > MAX_STRING_LENGTH_TERMINAL)
89 {
90 strLength = MAX_STRING_LENGTH_TERMINAL;
91 }
92 copyAndOffset(out, &offset, &objID, 1);
93 copyAndOffset(out, &offset, &x, sizeof(x));
94 copyAndOffset(out, &offset, &y, sizeof(y));
95 copyAndOffset(out, &offset, &tag, sizeof(tag));
96 copyAndOffset(out, &offset, &cmdId, sizeof(cmdId));
97 copyAndOffset(out, &offset, &dimSize, sizeof(dimSize));
98 copyAndOffset(out, &offset, &value, sizeof(value));
99 copyAndOffset(out, &offset, &maxValue, sizeof(maxValue));
100 copyAndOffset(out, &offset, &drawArc, sizeof(drawArc));
101 copyAndOffset(out, &offset, &arcGreenMaxVal, sizeof(arcGreenMaxVal));
102 copyAndOffset(out, &offset, &arcYellowMaxVal, sizeof(arcYellowMaxVal));
103 copyAndOffset(out, &offset, &arcRedMaxVal, sizeof(arcRedMaxVal));
104 copyAndOffset(out, &offset, str, strLength);
105 return offset;
106 }
107
108private:
109 uint8_t objID = BIND_ID_GAUGE1;
110 uint16_t offset = 0;
111 int strLength = 0;
112 const char *str;
113 static int16_t tagIndex;
114};
115
116#endif /* __BINDGAUGE_HPP */
The BindGauge class represents a gauge UI element for use with BindCanvas.
Definition BindGauge.hpp:30
void setlabel(const char *cstr)
Sets the label text for the gauge.
Definition BindGauge.hpp:69
uint16_t getBytes(uint8_t *out) override
Serializes gauge properties into a byte array for synchronization.
Definition BindGauge.hpp:84
float maxValue
Maximum value of the gauge.
Definition BindGauge.hpp:55
uint8_t cmdId
Command ID for the gauge. See the notes for possible cmdId values.
Definition BindGauge.hpp:52
int16_t dimSize
Size of the gauge (Width = height)
Definition BindGauge.hpp:53
float arcRedMaxVal
Maximum value for the red arc section.
Definition BindGauge.hpp:59
float value
Current value of the gauge.
Definition BindGauge.hpp:54
BindGauge()
Constructs a BindGauge with a default label.
Definition BindGauge.hpp:48
uint8_t drawArc
Indicates whether to draw the gauge arc.
Definition BindGauge.hpp:56
float arcYellowMaxVal
Maximum value for the yellow arc section.
Definition BindGauge.hpp:58
int16_t y
Y-coordinate position of the gauge.
Definition BindGauge.hpp:51
float arcGreenMaxVal
Maximum value for the green arc section.
Definition BindGauge.hpp:57
int16_t x
X-coordinate position of the gauge.
Definition BindGauge.hpp:50
Definition BindView.hpp:22