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