Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
BindJoystick Class Reference

BindJoystick Class. More...

`#include <BindJoystick.hpp>`

Inheritance diagram for BindJoystick:

## Public Member Functions
void | setCallback (void(*callback)(int16_t, int16_t))
| Set the Callback function for the joystick.
void | invokeCallback (int16_t xIn, int16_t yIn)
uint16_t | getBytes (uint8_t *out) override
| Serialize the joystick object into bytes.

## Public Attributes
int16_t | x = 0
| The x-coordinate position of the joystick on the screen.
int16_t | y = 0
| The y-coordinate position of the joystick on the screen.
uint8_t | cmdId = 0
| Command identifier to add or refresh the joystick. See the notes for possible cmdId values.
int16_t | dimSize = 200
| The dimensions (size) of the joystick.
int16_t | sX = 0
| The joystick's current X-axis position (internal).
int16_t | sY = 0
| The joystick's current Y-axis position (internal).
bool | springed = true
| Indicates whether the joystick returns to the center automatically when released.
Public Attributes inherited from BindView
int16_t | tag

## Detailed Description

BindJoystick Class.

BindJoystick

The `BindJoystick` class is a part of the Bind framework for Arduino, designed to creat a joystick element that can be displayed and controlled on the BindCanvas Android app interface.

Note
  The joystick ranges from -100 to 100 on both the X and Y axes.
  Possible cmdId values for a BindView and corresponding effects:
  - BIND_ADD_OR_REFRESH_CMD: Adds the object to the canvas (screen) or refreshes the existing one.
  - BIND_DATA_ONLY_CMD: Refreshes the existing object without moving or resizing; updates data, such as text.
  - BIND_REMOVE_CMD: Removes the object from the canvas (screen).
  - BIND_DISABLE_CMD: Disables the object.
  - BIND_ENABLE_CMD: Enables the object.
  - BIND_HIDE_CMD: Hides the object.
  - BIND_VISIBLE_CMD: Restores the object's visibility.

This class allows you to define the properties of a joystick, including its position, size, spring behavior, and more. You can synchronize these properties with BindCanvas to provide joystick controls in your Arduino projects.

Note
  To receive touch events and user interactions, you must regularly call `bind.sync()` in your main loop.

To use the `BindJoystick` class effectively, you can create an instance, set the callback function, set its attributes, and call `bind.sync(your_joystick)` to synchronize it with BindCanvas.

Example usage:

BindJoystick joystick;
...
joystick.x = 30;
joystick.y = 100;
joystick.dimSize = 200;
joystick.springed = true;
joystick.cmdId = BIND_ADD_OR_REFRESH_CMD;
joystick.setCallback(joystick1_onChange);
bind.sync(joystick);
...
void joystick1_onChange(int16_t x, int16_t y) {
Serial.print("joystick1 has been changed, x:");
Serial.print(x);
Serial.print(" y:");
Serial.println(y);
}
BindJoystick
BindJoystick Class.
Definition BindJoystick.hpp:58
BindJoystick::y
int16_t y
The y-coordinate position of the joystick on the screen.
Definition BindJoystick.hpp:67
BindJoystick::x
int16_t x
The x-coordinate position of the joystick on the screen.
Definition BindJoystick.hpp:66
BindJoystick::dimSize
int16_t dimSize
The dimensions (size) of the joystick.
Definition BindJoystick.hpp:69
BindJoystick::cmdId
uint8_t cmdId
Command identifier to add or refresh the joystick. See the notes for possible cmdId values.
Definition BindJoystick.hpp:68
BindJoystick::springed
bool springed
Indicates whether the joystick returns to the center automatically when released.
Definition BindJoystick.hpp:72
BindJoystick::setCallback
void setCallback(void(*callback)(int16_t, int16_t))
Set the Callback function for the joystick.
Definition BindJoystick.hpp:85

Note
  check the examples for more information.

## Member Function Documentation

## ◆ getBytes()

uint16_t BindJoystick::getBytes | ( | uint8_t * | out | ) |
| inline override virtual

Serialize the joystick object into bytes.

This function serializes the joystick object into a byte array, allowing it to be sent and displayed on BindCanvas.

Parameters

  out | A pointer to the byte array where the serialized data will be stored.

Returns
  The offset representing the length of the serialized data.

Reimplemented from BindView.

## ◆ setCallback()

void BindJoystick::setCallback | ( | void(*)(int16_t, int16_t) | callback | ) |
| inline

Set the Callback function for the joystick.

This callback function is called when the joystick is moved. The signature of the callback function should be like:

void callback(int16_t x, int16_t y)

Parameters

  callback |

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

- BindJoystick.hpp
- Bind.cpp