Neosensory SDK for Bluefruit
|
Class that handles connecting to and communicating with a Neosensory device over BLE. Relies heavily on Adafruit's Bluefruit library for BLE. Opens all developer accessible CLI commands with Neosensory hardware. Also offers some higher level motor vibration functions. More...
#include <neosensory_bluefruit.h>
Public Member Functions | |
NeosensoryBluefruit (char device_id[]="", uint8_t num_motors=4, uint8_t initial_min_vibration=30, uint8_t initial_max_vibration=255) | |
Constructor for new NeosensoryBluefruit object. More... | |
bool | isConnected (void) |
Returns true if NeosensoryBluefruit has connected to a device. More... | |
bool | startScan (void) |
Start scanning for desired device. More... | |
uint8_t * | getDeviceAddress (void) |
Get address of device to connect to. More... | |
void | begin (void) |
Begins Bluetooth components of NeosensoryBluefruit. | |
void | setDeviceId (char new_device_id[]) |
Sets new device ID for central to search for. More... | |
bool | isAuthorized (void) |
Returns true if connected device has authorized developer options. More... | |
void | acceptTermsAndConditions (void) |
Send a command to the wristband to accept developer terms and conditions. | |
void | audioStart (void) |
Starts the audio task processing. More... | |
void | audioStop (void) |
Stops the current audio task processing and hence any motor outputs from the algorithm. More... | |
void | authorizeDeveloper (void) |
Send a command to the wristband to authorize developer options. More... | |
void | deviceBattery (void) |
Get the amount of charge left on the device battery in percentage. | |
void | deviceInfo (void) |
Get information about the connected Neosensory device. More... | |
void | motorsClearQueue (void) |
Clears the motor command queue. | |
void | motorsStart (void) |
Initialize and start the motors interface. More... | |
void | motorsStop (void) |
Clears the motor queue and stops the motors interface. More... | |
void | sendCommand (char cmd[]) |
Send a command to the wristband. More... | |
void | stopAlgorithm (void) |
Stops the sound-to-touch algorithm that runs on the wristband. More... | |
void | connectCallback (uint16_t conn_handle) |
Callback when central connects. More... | |
void | disconnectCallback (uint16_t conn_handle, uint8_t reason) |
Callback when central disconnects. More... | |
void | readNotifyCallback (BLEClientCharacteristic *chr, uint8_t *data, uint16_t len) |
Callback when read characteristic has data to be read. More... | |
void | scanCallback (ble_gap_evt_adv_report_t *report) |
Callback when a device is found during scan. More... | |
void | setConnectedCallback (ConnectedCallback) |
Sets a callback that gets called when NeoBluefruit connects to a device. More... | |
void | setDisconnectedCallback (DisconnectedCallback) |
Sets a callback that gets called when NeoBluefruit disconnects from a device. More... | |
void | setReadNotifyCallback (ReadNotifyCallback) |
Sets a callback that gets called when read characteristic has data. More... | |
uint8_t | firmware_frame_duration (void) |
Get firmware frame duration in milliseconds. More... | |
uint8_t | max_frames_per_bt_package (void) |
Get maximum number of frames allowed in a Bluetooth packet. More... | |
uint8_t | num_motors (void) |
Get number of motors. More... | |
void | turnOffAllMotors (void) |
Turn off all the motors. | |
void | vibrateMotor (uint8_t motor, float intensity) |
Turn on a single motor at an intensity. More... | |
void | vibrateMotors (float *intensities[], int num_frames) |
Cause the wristband to vibrate at the given intensities, for multiple frames. More... | |
void | vibrateMotors (float intensities[]) |
Cause the wristband to vibrate at the given intensities. More... | |
Public Attributes | |
uint8_t | max_vibration |
uint8_t | min_vibration |
Static Public Attributes | |
static NeosensoryBluefruit * | NeoBluefruit = 0 |
Class that handles connecting to and communicating with a Neosensory device over BLE. Relies heavily on Adafruit's Bluefruit library for BLE. Opens all developer accessible CLI commands with Neosensory hardware. Also offers some higher level motor vibration functions.
NeosensoryBluefruit::NeosensoryBluefruit | ( | char | device_id[] = "" , |
uint8_t | num_motors = 4 , |
||
uint8_t | initial_min_vibration = 30 , |
||
uint8_t | initial_max_vibration = 255 |
||
) |
Constructor for new NeosensoryBluefruit object.
[in] | device_id | The device_id of the hardware to connect to. Leave blank to connect to any Neosensory device. |
[in] | num_motors | The number of vibrating motors this device has. |
[in] | initial_min_vibration | The mininum vibration intensity, between 0 and 255. Should be less than initial_max_vibration. |
[in] | initial_max_vibration | The maximum vibration intensity, between 0 and 255. Should be greater than initial_min_vibration. |
bool NeosensoryBluefruit::isConnected | ( | void | ) |
Returns true if NeosensoryBluefruit has connected to a device.
bool NeosensoryBluefruit::startScan | ( | void | ) |
Start scanning for desired device.
uint8_t * NeosensoryBluefruit::getDeviceAddress | ( | void | ) |
Get address of device to connect to.
void NeosensoryBluefruit::setDeviceId | ( | char | new_device_id[] | ) |
Sets new device ID for central to search for.
[in] | new_device_id | New device id to search for. If is an empty array, NeosensoryBluefruit will connect to any Neosensory device. |
bool NeosensoryBluefruit::isAuthorized | ( | void | ) |
Returns true if connected device has authorized developer options.
void NeosensoryBluefruit::audioStart | ( | void | ) |
Starts the audio task processing.
void NeosensoryBluefruit::audioStop | ( | void | ) |
Stops the current audio task processing and hence any motor outputs from the algorithm.
void NeosensoryBluefruit::authorizeDeveloper | ( | void | ) |
Send a command to the wristband to authorize developer options.
void NeosensoryBluefruit::deviceInfo | ( | void | ) |
Get information about the connected Neosensory device.
void NeosensoryBluefruit::motorsStart | ( | void | ) |
Initialize and start the motors interface.
void NeosensoryBluefruit::motorsStop | ( | void | ) |
Clears the motor queue and stops the motors interface.
void NeosensoryBluefruit::sendCommand | ( | char | cmd[] | ) |
Send a command to the wristband.
[in] | cmd | Command to send |
void NeosensoryBluefruit::stopAlgorithm | ( | void | ) |
Stops the sound-to-touch algorithm that runs on the wristband.
void NeosensoryBluefruit::connectCallback | ( | uint16_t | conn_handle | ) |
Callback when central connects.
conn_handle | Connection Handle that central connected to |
void NeosensoryBluefruit::disconnectCallback | ( | uint16_t | conn_handle, |
uint8_t | reason | ||
) |
Callback when central disconnects.
[in] | conn_handle | Connection handle that central is disconnecting from. |
[in] | reason | Reason for disconnect. |
void NeosensoryBluefruit::readNotifyCallback | ( | BLEClientCharacteristic * | chr, |
uint8_t * | data, | ||
uint16_t | len | ||
) |
Callback when read characteristic has data to be read.
[in] | chr | Characteristic that read data. |
[in] | data | Data read. |
[in] | len | Length of data array. |
void NeosensoryBluefruit::scanCallback | ( | ble_gap_evt_adv_report_t * | report | ) |
Callback when a device is found during scan.
[in] | report | Report of device that scan found. |
void NeosensoryBluefruit::setConnectedCallback | ( | ConnectedCallback | connectedCallback | ) |
Sets a callback that gets called when NeoBluefruit connects to a device.
[in] | connectedCallback | The function to call. Takes a bool argument, which will be true if connection resulted in successfully finding all services and characteristics, else false. |
void NeosensoryBluefruit::setDisconnectedCallback | ( | DisconnectedCallback | disconnectedCallback | ) |
Sets a callback that gets called when NeoBluefruit disconnects from a device.
[in] | disconnectedCallback | The function to call. |
void NeosensoryBluefruit::setReadNotifyCallback | ( | ReadNotifyCallback | readNotifyCallback | ) |
Sets a callback that gets called when read characteristic has data.
[in] | readNotifyCallback | The function to call. |
uint8_t NeosensoryBluefruit::firmware_frame_duration | ( | void | ) |
Get firmware frame duration in milliseconds.
uint8_t NeosensoryBluefruit::max_frames_per_bt_package | ( | void | ) |
Get maximum number of frames allowed in a Bluetooth packet.
uint8_t NeosensoryBluefruit::num_motors | ( | void | ) |
Get number of motors.
void NeosensoryBluefruit::vibrateMotor | ( | uint8_t | motor, |
float | intensity | ||
) |
Turn on a single motor at an intensity.
[in] | motor | Index of motor to vibrate |
[in] | intensity | Intensity to vibrate motor at, between 0 and 1 |
void NeosensoryBluefruit::vibrateMotors | ( | float * | intensities[], |
int | num_frames | ||
) |
Cause the wristband to vibrate at the given intensities, for multiple frames.
[in] | intensities | A nested array of float values that denote the linear intensity values, between 0 and 1. Each index in the inner arrays corresponds to a motor. The value at that index corresponds to the intensity that motor will play at. A value of 0 is off, a value of 1 is max_vibration, and any value between is a linearly perceived value between min_vibration and max_vibration. The outer indices correspond to individual frames. Each frame is played by the firmware at firmware_frame_duration intervals. |
[in] | num_frames | The number of frames. Cannot be more than max_frames_per_bt_package_. |
void NeosensoryBluefruit::vibrateMotors | ( | float | intensities[] | ) |
Cause the wristband to vibrate at the given intensities.
[in] | intensities | An array of float values that denote the linear intensity values, between 0 and 1. Each index in this array corresponds to a motor. The value at that index corresponds to the intensity that motor will play at. A value of 0 is off, a value of 1 is max_vibration, and any value between is a linearly perceived value between min_vibration and max_vibration. |
|
static |
Static, singleton instance of NeosensoryBluefruit. Used for setting callbacks.
uint8_t NeosensoryBluefruit::max_vibration |
Maximum vibration intensity, between 0 and 255.
uint8_t NeosensoryBluefruit::min_vibration |
Minimum vibration intensity, between 0 and 255.