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
88 void setCallback(void (*callback)(int16_t))
89 {
90 changeCallback = callback;
91 }
92
93 void invokeCallback(int16_t valueIn)
94 {
95 this->value = valueIn;
96 if (changeCallback != nullptr)
97 {
98 changeCallback(valueIn);
99 }
100 }
101
111 uint16_t getBytes(uint8_t *out) override
112 {
113 offset = 0;
114 strLength = strlen(str);
115 if (strLength > MAX_STRING_LENGTH_TERMINAL)
116 {
117 strLength = MAX_STRING_LENGTH_TERMINAL;
118 }
119 copyAndOffset(out, &offset, &objID, sizeof(objID));
120 copyAndOffset(out, &offset, &x, sizeof(x));
121 copyAndOffset(out, &offset, &y, sizeof(y));
122 copyAndOffset(out, &offset, &tag, sizeof(tag));
123 copyAndOffset(out, &offset, &cmdId, sizeof(cmdId));
124 copyAndOffset(out, &offset, &dimSize, sizeof(dimSize));
125 copyAndOffset(out, &offset, &minValue, sizeof(minValue));
126 copyAndOffset(out, &offset, &maxValue, sizeof(maxValue));
127 copyAndOffset(out, &offset, &value, sizeof(value));
128 copyAndOffset(out, &offset, str, strLength);
129 return offset;
130 }
131
132 private:
133 uint8_t objID = BIND_ID_KNOB;
134 uint16_t offset = 0;
135 int strLength = 0;
136 const char *str;
137 static int16_t tagIndex;
138 void (*changeCallback)(int16_t) = nullptr;
139};
140#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:88
BindKnob::getBytes
uint16_t getBytes(uint8_t *out) override
Retrieves the bytes representing the knob for synchronization.
Definition BindKnob.hpp:111
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:22