Bind
C++ UI toolkit for Arduino
 
Loading...
Searching...
No Matches
Bind Class Reference

The Bind class provides a framework for creating interactive applications with BindCanvas. More...

#include <Bind.hpp>

Public Member Functions

 Bind (void(*_setupCallback)(int16_t, int16_t))
 Constructs a Bind object with a setup callback function.
 
bool isReady ()
 Checks if the bind object is in a ready state.
 
void sync (BindView *obj)
 Synchronizes a BindView object with the BindCanvas screen.
 
void sync (BindView &obj)
 Synchronizes a BindView object with the BindCanvas screen. Same as sync(BindView *obj) but uses the object refrence to prevent common mistakes.
 
void sync ()
 Synchronizes the bind with the current state.
 
bool init (Stream *stream, void(*setupCallback)(int16_t, int16_t))
 Initializes the Bind framework with communication and screen setup.
 
bool init (Stream &stream, void(&setupCallback)(int16_t, int16_t))
 Initializes the Bind framework with communication and screen setup.
 
void join (BindButton *screenButton, void(*clickCallback)(void))
 Binds a Button object to a click callback function.
 
void join (BindButton &screenButton, void(&clickCallback)(void))
 Binds a Button object to a click callback function.
 
void join (BindKnob *screenKnob, void(*changeCallback)(int16_t))
 Binds a Dial Knob object to a change callback function.
 
void join (BindKnob &screenKnob, void(&changeCallback)(int16_t))
 Binds a Dial Knob object to a change callback function.
 
void join (BindSwitch *screenSwitch, void(*clickCallback)(bool))
 Binds a ON/OFF Switch object to a click callback function.
 
void join (BindSwitch &screenSwitch, void(&clickCallback)(bool))
 Binds a ON/OFF Switch object to a click callback function.
 
void join (BindSeekBar *screenSeekBar, void(*changeCallback)(int16_t))
 Binds a SeekBar object to a change callback function.
 
void join (BindSeekBar &screenSeekBar, void(&changeCallback)(int16_t))
 Binds a SeekBar object to a change callback function.
 
void join (BindJoystick *screenJoystick, void(*changeCallback)(int16_t, int16_t))
 Binds a Joystick object to a change callback function.
 
void join (BindJoystick &screenJoystick, void(&changeCallback)(int16_t, int16_t))
 Binds a Joystick object to a change callback function.
 
void join (BindColorPicker *screenColorPicker, void(*clickCallback)(uint8_t, uint8_t, uint8_t))
 Binds a Color Picker object to a click callback function.
 
void join (BindColorPicker &screenColorPicker, void(&clickCallback)(uint8_t, uint8_t, uint8_t))
 Binds a Color Picker object to a click callback function.
 
void sync (float chartData, BindChart &obj)
 Synchronizes chart data of a BindChart object.
 
void sync (const char *str, int32_t textColor, bool autoScroll, bool newLine, bool bold, bool italic, BindTerminal &obj)
 Prints terminal data in a BindTerminal object.
 
void sync (const char *str, BindTerminal &obj)
 Prints terminal data in a BindTerminal object.
 

Detailed Description

The Bind class provides a framework for creating interactive applications with BindCanvas.

Bind is a versatile class that enables you to build applications that interact with BindCanvas. It provides functions for binding and synchronizing various UI elements, including buttons, knobs, switches, seekbars, joysticks, color pickers, terminals, and many more. You can use Bind to connect your c++ programme to the BindCanvas screen, manage user interactions, and update UI elements in real time.

Sample app created by Bind
Sample app created by Bind

To use Bind effectively, you can define a setup callback function to configure the initial state of your application, including screen setup and object synchronization. Bind also allows you to set the communication device, such as a serial port, for data exchange with BindCanvas.

Note
To ensure smooth operation and responsiveness, regularly call the 'sync' function to synchronize your Bind objects with the current state of the BindCanvas screen. Failing to do so may result in missed events, such as button clicks or user interactions with your UI elements.

Constructor & Destructor Documentation

◆ Bind()

Bind::Bind ( void(*)(int16_t, int16_t)  _setupCallback)
inline

Constructs a Bind object with a setup callback function.

This constructor creates a Bind object and associates it with a setup callback function. The setup callback is in charge of configuring the initial state of the Bind object, which includes screen rotation and syncing all the objects. To put it simply, 'setupCallback' is where you construct the application view.

Parameters
_setupCallbackA pointer to the setup callback function that initializes the Bind screen.

Member Function Documentation

◆ init() [1/2]

bool Bind::init ( Stream &  stream,
void(&)(int16_t, int16_t)  setupCallback 
)

Initializes the Bind framework with communication and screen setup.

This function serves a dual purpose:

  1. It configures the communication device for the Bind framework using a 'Stream' object. The 'stream' can represent any serial port, including hardware, software serial, or Bluetooth classic serial.
  2. It sets the screen setup callback. This callback function is automatically invoked by BindCanvas upon establishing a connection. It plays a crucial role in configuring the screen and ensuring that all screen objects are synchronized properly. You will receive two parameters: 'w' for screen width and 'h' for screen height in density-independent pixels (dp). These values allow you to maintain consistent object positioning and size across various devices with different screen dimensions.
    Note
    For more information about density-independent pixels (dp) visit: http://en.wikipedia.org/wiki/Device-independent_pixel
    Parameters
    streamA reference to the 'Stream' object representing the communication device.
    setupCallbackA reference to the screen setup callback function. This function receives 'w' for width and 'h' for height. It ensures consistent object positioning and size across devices.
    Returns
    Returns 'true' if initialization is successful; otherwise, returns 'false'.

◆ init() [2/2]

bool Bind::init ( Stream *  stream,
void(*)(int16_t, int16_t)  setupCallback 
)

Initializes the Bind framework with communication and screen setup.

This function serves a dual purpose:

  1. It configures the communication device for the Bind framework using a 'Stream' object. The 'stream' can represent any serial port, including hardware, software serial, or Bluetooth classic serial.
  2. It sets the screen setup callback. This callback function is automatically invoked by BindCanvas upon establishing a connection. It plays a crucial role in configuring the screen and ensuring that all screen objects are synchronized properly. You will receive two parameters: 'w' for screen width and 'h' for screen height in density-independent pixels (dp). These values allow you to maintain consistent object positioning and size across various devices with different screen dimensions.
    Note
    For more information about density-independent pixels (dp) visit: http://en.wikipedia.org/wiki/Device-independent_pixel
    Parameters
    streamA pointer to the 'Stream' object representing the communication device.
    setupCallbackA pointer to the screen setup callback function. This function receives 'w' for width and 'h' for height. It ensures consistent object positioning and size across devices.
    Returns
    Returns 'true' if initialization is successful; otherwise, returns 'false'.

◆ isReady()

bool Bind::isReady ( )
inline

Checks if the bind object is in a ready state.

This function checks whether the Bind object is in a ready state, which indicates whether it is connected or not.

Returns
True if the object is ready; otherwise, false.

◆ join() [1/12]

void Bind::join ( BindButton screenButton,
void(&)(void)  clickCallback 
)

Binds a Button object to a click callback function.

This function establishes a connection between a Button object and a click callback function. It takes two parameters: a reference to the 'BindButton' object, 'screenButton,' and a reference to a callback function, 'clickCallback,' which handles button click events.

Parameters
screenButtonA reference to the 'BindButton' object to bind.
clickCallbackA reference to the callback function that responds to button clicks.

◆ join() [2/12]

void Bind::join ( BindButton screenButton,
void(*)(void)  clickCallback 
)

Binds a Button object to a click callback function.

This function establishes a connection between a Button object and a click callback function. It takes two parameters: a pointer to the 'BindButton' object, 'screenButton,' and a pointer to a callback function, 'clickCallback,' which handles button click events.

Parameters
screenButtonA pointer to the 'BindButton' object to bind.
clickCallbackA pointer to the callback function that responds to button clicks.

◆ join() [3/12]

void Bind::join ( BindColorPicker screenColorPicker,
void(&)(uint8_t, uint8_t, uint8_t)  clickCallback 
)

Binds a Color Picker object to a click callback function.

This function establishes a connection between a Color Picker object and a click callback function. It takes two parameters: a reference to the 'BindColorPicker' object, 'screenColorPicker,' and a reference to a callback function, 'clickCallback,' which handles color selection events.

Attention
The clickCallback receives three 8-bit integers (ranging from 0 to 255) that represent the Red, Green, and Blue elements of the selected color.
Parameters
screenColorPickerA reference to the 'BindColorPicker' object to bind.
clickCallbackA reference to the callback function that responds to color selection events.

◆ join() [4/12]

void Bind::join ( BindColorPicker screenColorPicker,
void(*)(uint8_t, uint8_t, uint8_t)  clickCallback 
)

Binds a Color Picker object to a click callback function.

This function establishes a connection between a Color Picker object and a click callback function. It takes two parameters: a pointer to the 'BindColorPicker' object, 'screenColorPicker,' and a pointer to a callback function, 'clickCallback,' which handles color selection events.

Attention
The clickCallback receives three 8-bit integers (ranging from 0 to 255) that represent the Red, Green, and Blue elements of the selected color.
Parameters
screenColorPickerA pointer to the 'BindColorPicker' object to bind.
clickCallbackA pointer to the callback function that responds to color selection events.

◆ join() [5/12]

void Bind::join ( BindJoystick screenJoystick,
void(&)(int16_t, int16_t)  changeCallback 
)

Binds a Joystick object to a change callback function.

This function establishes a connection between a Joystick object and a change callback function. It takes two parameters: a reference to the 'BindJoystick' object, 'screenJoystick,' and a reference to a callback function, 'changeCallback,' which handles changes in the joystick's position.

Attention
The clickCallback receives two 16-bit integers representing the X and Y axes of the joystick, with each axis ranging from -100 to 100.
Parameters
screenJoystickA reference to the 'BindJoystick' object to bind.
changeCallbackA reference to the callback function that responds to joystick position changes.

◆ join() [6/12]

void Bind::join ( BindJoystick screenJoystick,
void(*)(int16_t, int16_t)  changeCallback 
)

Binds a Joystick object to a change callback function.

This function establishes a connection between a Joystick object and a change callback function. It takes two parameters: a pointer to the 'BindJoystick' object, 'screenJoystick,' and a pointer to a callback function, 'changeCallback,' which handles changes in the joystick's position.

Attention
The clickCallback receives two 16-bit integers representing the X and Y axes of the joystick, with each axis ranging from -100 to 100.
Parameters
screenJoystickA pointer to the 'BindJoystick' object to bind.
changeCallbackA pointer to the callback function that responds to joystick position changes.

◆ join() [7/12]

void Bind::join ( BindKnob screenKnob,
void(&)(int16_t)  changeCallback 
)

Binds a Dial Knob object to a change callback function.

This function establishes a connection between a Dial Knob object and a change callback function. It takes two parameters: a reference to the 'BindKnob' object, 'screenKnob,' and a reference to a callback function, 'changeCallback,' which handles changes in the dial knob's value.

Attention
The changeCallback receives a 16-bit integer representing the knob angle, and the range of values depends on the user's configuration for that knob.
Parameters
screenKnobA reference to the 'BindKnob' object to bind.
changeCallbackA reference to the callback function that responds to dial knob value changes.

◆ join() [8/12]

void Bind::join ( BindKnob screenKnob,
void(*)(int16_t)  changeCallback 
)

Binds a Dial Knob object to a change callback function.

This function establishes a connection between a Dial Knob object and a change callback function. It takes two parameters: a pointer to the 'BindKnob' object, 'screenKnob,' and a pointer to a callback function, 'changeCallback,' which handles changes in the dial knob's value.

Attention
The changeCallback receives a 16-bit integer representing the knob angle, and the range of values depends on the user's configuration for that knob.
Parameters
screenKnobA pointer to the 'BindKnob' object to bind.
changeCallbackA pointer to the callback function that responds to dial knob value changes.

◆ join() [9/12]

void Bind::join ( BindSeekBar screenSeekBar,
void(&)(int16_t)  changeCallback 
)

Binds a SeekBar object to a change callback function.

This function establishes a connection between a SeekBar object and a change callback function. It takes two parameters: a reference to the 'BindSeekBar' object, 'screenSeekBar,' and a reference to a callback function, 'changeCallback,' which handles SeekBar value changes. The callback receives an integer parameter representing the new value of the seekbar.

Attention
The clickCallback receives a 16-bit integer representing the progress of the seekbar, and the range of values depends on the user's configuration for that seekbar.
Parameters
screenSeekBarA reference to the 'BindSeekBar' object to bind.
changeCallbackA reference to the callback function that responds to SeekBar changes.

◆ join() [10/12]

void Bind::join ( BindSeekBar screenSeekBar,
void(*)(int16_t)  changeCallback 
)

Binds a SeekBar object to a change callback function.

This function establishes a connection between a SeekBar object and a change callback function. It takes two parameters: a pointer to the 'BindSeekBar' object, 'screenSeekBar,' and a pointer to a callback function, 'changeCallback,' which handles SeekBar value changes. The callback receives an integer parameter representing the new value of the seekbar.

Attention
The clickCallback receives a 16-bit integer representing the progress of the seekbar, and the range of values depends on the user's configuration for that seekbar.
Parameters
screenSeekBarA pointer to the 'BindSeekBar' object to bind.
changeCallbackA pointer to the callback function that responds to SeekBar changes.

◆ join() [11/12]

void Bind::join ( BindSwitch screenSwitch,
void(&)(bool)  clickCallback 
)

Binds a ON/OFF Switch object to a click callback function.

This function establishes a connection between a Switch object and a click callback function. It takes two parameters: a reference to the 'BindSwitch' object, 'screenSwitch,' and a reference to a callback function, 'clickCallback,' which handles switch state changes.

Attention
The clickCallback receives a boolean representing the state of the switch.
Parameters
screenSwitchA reference to the 'BindSwitch' object to bind.
clickCallbackA reference to the callback function that responds to switch state changes.

◆ join() [12/12]

void Bind::join ( BindSwitch screenSwitch,
void(*)(bool)  clickCallback 
)

Binds a ON/OFF Switch object to a click callback function.

This function establishes a connection between a Switch object and a click callback function. It takes two parameters: a pointer to the 'BindSwitch' object, 'screenSwitch,' and a pointer to a callback function, 'clickCallback,' which handles switch state changes.

Attention
The clickCallback receives a boolean representing the state of the switch.
Parameters
screenSwitchA pointer to the 'BindSwitch' object to bind.
clickCallbackA pointer to the callback function that responds to switch state changes.

◆ sync() [1/5]

void Bind::sync ( )

Synchronizes the bind with the current state.

This function synchronizes the Bind object with the current state by reading data from the canvas and managing user interactions with Bind views, such as button presses or connection requests. In simpler terms, it reads the screen.

Attention
: To ensure smooth operation and prevent data loss or lag, regularly run the following line of code. It's recommended to execute it a few times per second, and faster is even better! Try to achieve a rate more than 10Hz for optimal performance."

◆ sync() [2/5]

void Bind::sync ( BindView obj)

Synchronizes a BindView object with the BindCanvas screen.

This function synchronizes a 'BindView' object, 'obj,' with the BindCanvas screen, ensuring that the object reflects the most up-to-date data and appearance as intended.

Parameters
objA pointer to the 'BindView' object (e.g. BindButton, BindSeekbar) to synchronize.

◆ sync() [3/5]

void Bind::sync ( const char *  str,
BindTerminal obj 
)

Prints terminal data in a BindTerminal object.

This function prints terminal data with this simple format: textColor is white autoScroll is enable always adds a new line No bold, no italic

Parameters
strThe text data to be printed in the 'BindTerminal' object.
objA pointer to the 'BindTerminal' object for data synchronization.

◆ sync() [4/5]

void Bind::sync ( const char *  str,
int32_t  textColor,
bool  autoScroll,
bool  newLine,
bool  bold,
bool  italic,
BindTerminal obj 
)

Prints terminal data in a BindTerminal object.

This function synchronizes terminal data, including text, text color, formatting options, and terminal behavior, with a 'BindTerminal' object.

Parameters
strThe text data to be printed in the 'BindTerminal' object.
textColorThe color of the text.
autoScrollDetermines whether auto-scrolling is enabled.
newLineDetermines whether a new line is added after the text.
boldIndicates whether the text should be bold.
italicIndicates whether the text should be italic.
objA reference to the 'BindTerminal' object for data synchronization.

◆ sync() [5/5]

void Bind::sync ( float  chartData,
BindChart obj 
)

Synchronizes chart data of a BindChart object.

This function synchronizes the chart data represented by a float value with a 'BindChart' object. It takes two parameters: the 'chartData' to be synchronized and a pointer to the 'BindChart' object, 'obj' so that it knows the data blong to which chart. This function updates the chart data on the screen immediately.

Parameters
chartDataThe data to be synchronized with the 'BindChart' object.
objA reference to the 'BindChart' object for data synchronization.

The documentation for this class was generated from the following files: