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 int16_t screenWidth = 0;
66 int16_t screenHeight = 0;
67
68 Bind()
69 {
70 setupCallback = NULL;
71 // Allocate memory for an array of pointers to Bind objects
72 switchObjects = new BindSwitch*[MAX_HANDLERS];
73 buttonObjects = new BindButton*[MAX_HANDLERS];
74 knobObjects = new BindKnob*[MAX_HANDLERS];
75 seekBarObjects = new BindSeekBar*[MAX_HANDLERS];
76 joystickObjects = new BindJoystick*[MAX_HANDLERS];
77 colorPickerObjects = new BindColorPicker*[MAX_HANDLERS];
78 textInputObjects = new BindTextInput*[MAX_HANDLERS];
79 dialogObjects = new BindDialog*[MAX_HANDLERS];
80
81 for (int i = 0; i < MAX_HANDLERS; ++i)
82 {
83 // Initialize each pointer to nullptr
84 switchObjects[i] = nullptr;
85 buttonObjects[i] = nullptr;
86 knobObjects[i] = nullptr;
87 seekBarObjects[i] = nullptr;
88 joystickObjects[i] = nullptr;
89 colorPickerObjects[i] = nullptr;
90 textInputObjects[i] = nullptr;
91 dialogObjects[i] = nullptr;
92 }
93 }
94
105 Bind(void (*_setupCallback)(int16_t, int16_t)) : Bind()
106 {
107 setupCallback = _setupCallback;
108 }
109
118 bool isReady()
119 {
120 return isInitialized;
121 }
122
145 bool init(Stream &stream, void (&setupCallback)(int16_t, int16_t));
146
147
152 void sync(BindView &obj);
153
167 void sync();
168
179 void sync(const uint8_t *buffer, size_t size);
180
192 void sync(float chartData, BindChart &obj);
193
208 void sync(const char *str, int32_t textColor, bool autoScroll, bool newLine, bool bold, bool italic, BindTerminal &obj);
209
222 void sync(const char *str, BindTerminal &obj);
223
232 void sync(BindSwitch &obj);
233
242 void sync(BindButton &obj);
243
252 void sync(BindKnob &obj);
253
262 void sync(BindSeekBar &obj);
263
272 void sync(BindJoystick &obj);
273
282 void sync(BindColorPicker &obj);
283
292 void sync(BindTextInput &obj);
293
307 void sync(BindDialog &obj);
308
309 private:
310 // Private member variables and functions...
311 uint8_t bufFrame[MAX_DATA_LENGHT];
312 uint8_t frameTXBuffer[MAX_DATA_LENGHT + 6];
313 int16_t valTmp1 = 0;
314 int16_t valTmp2 = 0;
315 int16_t valTmp3 = 0;
316 int dataLen = 0;
317 uint32_t lastMs = 0;
318 uint32_t deltaMs = 0;
319 BindSwitch** switchObjects;
320 BindButton** buttonObjects;
321 BindKnob** knobObjects;
322 BindSeekBar** seekBarObjects;
323 BindJoystick** joystickObjects;
324 BindColorPicker** colorPickerObjects;
325 BindTextInput** textInputObjects;
326 BindDialog** dialogObjects;
327 DataParser dataParser;
328 uint8_t buttonIndex = 1;
329 uint8_t dialKnobIndex = 1;
330 uint8_t switchIndex = 1;
331 uint8_t seekBarIndex = 1;
332 uint8_t joystickHandlerIndex = 1;
333 uint8_t colorPickerHandlerIndex = 1;
334 uint8_t textInputHandlerIndex = 1;
335 bool isInitialized = false;
336 void (*setupCallback)(int16_t, int16_t);
337 bool internalInit(Stream *stream, void (*setupCallback)(int16_t, int16_t));
338 void screenInit(int16_t w, int16_t h);
339 Stream *bindStream = NULL;
340 void updateScreen(uint8_t inp);
341 void updateScreen(Stream *stream);
342 void updateScreenInternal(uint8_t *dataFrame, uint16_t dataLen);
343 void updateJoystick(uint8_t tag, int16_t valX, int16_t valY);
344 void updateColorPicker(uint8_t tag, uint8_t r, uint8_t g, uint8_t b);
345 void updateSeekBar(uint8_t tag, int16_t val);
346 void knobChanged(int8_t tag, int val);
347 void clickButton(uint8_t tag);
348 void updateSwitch(uint8_t tag, bool val);
349 void updateTextInput(uint8_t tag, const char *val, uint8_t length);
350 void dialogResult(uint8_t tag, bool result, const char *text, uint8_t length);
351 void internalSync(BindView *obj);
352};
353
354#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:50
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:118
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:105
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:26
DataParser
Definition DataProtocol.h:18