Loading...
Searching...
No Matches
BindKnob.hpp
1#ifndef __BINDKNOB_H
2#define __BINDKNOB_H
3#include "BindView.hpp"
4#include "BindUtils.hpp"
5// TODO: Extract the class to a serprate .h and .c file! Now!
29 class BindKnob : public BindView
30{
31
32 public:
41 BindKnob(const char *cstr)
42 {
43 this->tag = tagIndex++;
44 setLabel(cstr);
45 }
46
53 BindKnob() : BindKnob("Knob"){}
54
55 int16_t x;
56 int16_t y;
57 uint8_t cmdId = 0;
58 int16_t dimSize;
59 int16_t minValue;
60 int16_t maxValue;
61 int16_t value;
62
72 void setLabel(const char *cstr)
73 {
74 str = cstr;
75 }
76
77 [[deprecated("Use setLabel instead")]]
78 void setlabel(const char *cstr)
79 {
80 setLabel(cstr);
81 }
82
94 void setCallback(void (*callback)(int16_t))
95 {
96 changeCallback = callback;
97 }
98
99 void invokeCallback(int16_t valueIn)
100 {
101 this->value = valueIn;
102 if (changeCallback != nullptr)
103 {
104 changeCallback(valueIn);
105 }
106 }
107
117 uint16_t getBytes(uint8_t *out) override
118 {
119 offset = 0;
120 strLength = strlen(str);
121 if (strLength > MAX_STRING_LENGTH_TERMINAL)
122 {
123 strLength = MAX_STRING_LENGTH_TERMINAL;
124 }
125 copyAndOffset(out, &offset, &objID, sizeof(objID));
126 copyAndOffset(out, &offset, &x, sizeof(x));
127 copyAndOffset(out, &offset, &y, sizeof(y));
128 copyAndOffset(out, &offset, &tag, sizeof(tag));
129 copyAndOffset(out, &offset, &cmdId, sizeof(cmdId));
130 copyAndOffset(out, &offset, &dimSize, sizeof(dimSize));
131 copyAndOffset(out, &offset, &minValue, sizeof(minValue));
132 copyAndOffset(out, &offset, &maxValue, sizeof(maxValue));
133 copyAndOffset(out, &offset, &value, sizeof(value));
134 copyAndOffset(out, &offset, str, strLength);
135 return offset;
136 }
137
138 private:
139 uint8_t objID = BIND_ID_KNOB;
140 uint16_t offset = 0;
141 int strLength = 0;
142 const char *str;
143 static int16_t tagIndex;
144 void (*changeCallback)(int16_t) = nullptr;
145};
146#endif /* __BINDKNOB_H */
BindKnob
The BindKnob class represents a knob UI element for use with BindCanvas.
Definition BindKnob.hpp:30
BindKnob::y
int16_t y
Y-coordinate position of the knob.
Definition BindKnob.hpp:56
BindKnob::setLabel
void setLabel(const char *cstr)
Sets the label text for the knob.
Definition BindKnob.hpp:72
BindKnob::minValue
int16_t minValue
Minimum value of the knob's range.
Definition BindKnob.hpp:59
BindKnob::setCallback
void setCallback(void(*callback)(int16_t))
Set the Callback function for the knob.
Definition BindKnob.hpp:94
BindKnob::getBytes
uint16_t getBytes(uint8_t *out) override
Retrieves the bytes representing the knob for synchronization.
Definition BindKnob.hpp:117
BindKnob::dimSize
int16_t dimSize
Dimensions or size of the knob.
Definition BindKnob.hpp:58
BindKnob::value
int16_t value
Current value of the knob.
Definition BindKnob.hpp:61
BindKnob::maxValue
int16_t maxValue
Maximum value of the knob's range.
Definition BindKnob.hpp:60
BindKnob::x
int16_t x
X-coordinate position of the knob.
Definition BindKnob.hpp:55
BindKnob::cmdId
uint8_t cmdId
Command ID for the knob. See the notes for possible cmdId values.
Definition BindKnob.hpp:57
BindKnob::BindKnob
BindKnob(const char *cstr)
Constructs a BindKnob with a custom label.
Definition BindKnob.hpp:41
BindKnob::BindKnob
BindKnob()
Constructs a BindKnob with a default label.
Definition BindKnob.hpp:53
BindView
Definition BindView.hpp:26