Loading...
Searching...
No Matches
Bind.h
1#ifndef __BIND_H
2#define __BIND_H
3#include <stdint.h>
4#include "Stream.h"
5#include "SLPacker.hpp"
6#include "DataProtocol.h"
7#include "BindUtils.hpp"
8#include "BindWidgets.hpp"
9
11#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32)
12#define MAX_HANDLERS 32
13#else
14#define MAX_HANDLERS 16
15#endif
16
18#define BIND_ADD_OR_REFRESH_CMD 0
19
21#define BIND_DATA_ONLY_CMD 6
22
24#define BIND_REMOVE_CMD 1
25
27#define BIND_DISABLE_CMD 2
28
30#define BIND_ENABLE_CMD 3
31
33#define BIND_HIDE_CMD 4
34
36#define BIND_VISIBLE_CMD 5
37
61 class Bind
62{
63 public:
64 // Constructors and setup functions...
65
66 Bind()
67 {
68 setupCallback = NULL;
69 // Allocate memory for an array of pointers to Bind objects
70 switchObjects = new BindSwitch*[MAX_HANDLERS];
71 buttonObjects = new BindButton*[MAX_HANDLERS];
72 knobObjects = new BindKnob*[MAX_HANDLERS];
73 seekBarObjects = new BindSeekBar*[MAX_HANDLERS];
74 joystickObjects = new BindJoystick*[MAX_HANDLERS];
75 colorPickerObjects = new BindColorPicker*[MAX_HANDLERS];
76 textInputObjects = new BindTextInput*[MAX_HANDLERS];
77 dialogObjects = new BindDialog*[MAX_HANDLERS];
78
79 for (int i = 0; i < MAX_HANDLERS; ++i)
80 {
81 // Initialize each pointer to nullptr
82 switchObjects[i] = nullptr;
83 buttonObjects[i] = nullptr;
84 knobObjects[i] = nullptr;
85 seekBarObjects[i] = nullptr;
86 joystickObjects[i] = nullptr;
87 colorPickerObjects[i] = nullptr;
88 textInputObjects[i] = nullptr;
89 dialogObjects[i] = nullptr;
90 }
91 }
92
103 Bind(void (*_setupCallback)(int16_t, int16_t)) : Bind()
104 {
105 setupCallback = _setupCallback;
106 }
107
116 bool isReady()
117 {
118 return isInitialized;
119 }
120
143 bool init(Stream &stream, void (&setupCallback)(int16_t, int16_t));
144
145
150 void sync(BindView &obj);
151
165 void sync();
166
177 void sync(const uint8_t *buffer, size_t size);
178
190 void sync(float chartData, BindChart &obj);
191
206 void sync(const char *str, int32_t textColor, bool autoScroll, bool newLine, bool bold, bool italic, BindTerminal &obj);
207
220 void sync(const char *str, BindTerminal &obj);
221
230 void sync(BindSwitch &obj);
231
240 void sync(BindButton &obj);
241
250 void sync(BindKnob &obj);
251
260 void sync(BindSeekBar &obj);
261
270 void sync(BindJoystick &obj);
271
280 void sync(BindColorPicker &obj);
281
290 void sync(BindTextInput &obj);
291
305 void sync(BindDialog &obj);
306
307 private:
308 // Private member variables and functions...
309 uint8_t bufFrame[MAX_DATA_LENGHT];
310 uint8_t frameTXBuffer[MAX_DATA_LENGHT + 6];
311 int16_t valTmp1 = 0;
312 int16_t valTmp2 = 0;
313 int16_t valTmp3 = 0;
314 int dataLen = 0;
315 uint32_t lastMs = 0;
316 uint32_t deltaMs = 0;
317 BindSwitch** switchObjects;
318 BindButton** buttonObjects;
319 BindKnob** knobObjects;
320 BindSeekBar** seekBarObjects;
321 BindJoystick** joystickObjects;
322 BindColorPicker** colorPickerObjects;
323 BindTextInput** textInputObjects;
324 BindDialog** dialogObjects;
325 DataParser dataParser;
326 uint8_t buttonIndex = 1;
327 uint8_t dialKnobIndex = 1;
328 uint8_t switchIndex = 1;
329 uint8_t seekBarIndex = 1;
330 uint8_t joystickHandlerIndex = 1;
331 uint8_t colorPickerHandlerIndex = 1;
332 uint8_t textInputHandlerIndex = 1;
333 bool isInitialized = false;
334 void (*setupCallback)(int16_t, int16_t);
335 bool internalInit(Stream *stream, void (*setupCallback)(int16_t, int16_t));
336 void screenInit(int16_t w, int16_t h);
337 Stream *bindStream = NULL;
338 int updateScreen(uint8_t inp);
339 void updateScreen(Stream *stream);
340 int updateScreenInternal(uint8_t *dataFrame);
341 void updateJoystick(uint8_t tag, int16_t valX, int16_t valY);
342 void updateColorPicker(uint8_t tag, uint8_t r, uint8_t g, uint8_t b);
343 void updateSeekBar(uint8_t tag, int16_t val);
344 void knobChanged(int8_t tag, int val);
345 void clickButton(uint8_t tag);
346 void updateSwitch(uint8_t tag, bool val);
347 void updateTextInput(uint8_t tag, const char *val, uint8_t length);
348 void dialogResult(uint8_t tag, bool result, const char *text, uint8_t length);
349 void internalSync(BindView *obj);
350};
351
352#endif /* __BIND_H */
BindButton
The BindButton class represents a button UI element for use with BindCanvas.
Definition BindButton.hpp:27
BindChart
Represents a customizable chart element for BindCanvas.
Definition BindChart.hpp:32
BindColorPicker
BindColorPicker Class.
Definition BindColorPicker.hpp:56
BindDialog
BindDialog class represents a dialog box for use with BindCanvas app.
Definition BindDialog.hpp:38
Bind
The Bind class provides a framework for creating interactive applications with BindCanvas.
Definition Bind.h:62
Bind::init
bool init(Stream &stream, void(&setupCallback)(int16_t, int16_t))
Initializes the Bind framework with communication and screen setup.
Definition Bind.cpp:23
Bind::isReady
bool isReady()
Checks if the bind object is in a ready state.
Definition Bind.h:116
Bind::sync
void sync()
Synchronizes the bind with the current state.
Definition Bind.cpp:137
Bind::Bind
Bind(void(*_setupCallback)(int16_t, int16_t))
Constructs a Bind object with a setup callback function.
Definition Bind.h:103
BindJoystick
BindJoystick Class.
Definition BindJoystick.hpp:58
BindKnob
The BindKnob class represents a knob UI element for use with BindCanvas.
Definition BindKnob.hpp:30
BindSeekBar
Represents a SeekBar object in the Bind framework.
Definition BindSeekBar.hpp:24
BindSwitch
Represents a toggle switch UI element in the Bind framework.
Definition BindSwitch.hpp:33
BindTerminal
Represents a terminal display for BindCanvas.
Definition BindTerminal.hpp:26
BindTextInput
The BindTextInput class represents a text input UI element for use with BindCanvas.
Definition BindTextInput.hpp:16
BindView
Definition BindView.hpp:22
DataParser
Definition DataProtocol.h:18