Neosensory SDK for Bluefruit
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
NeosensoryBluefruit Class Reference

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 NeosensoryBluefruitNeoBluefruit = 0
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Parameters
[in]device_idThe device_id of the hardware to connect to. Leave blank to connect to any Neosensory device.
[in]num_motorsThe number of vibrating motors this device has.
[in]initial_min_vibrationThe mininum vibration intensity, between 0 and 255. Should be less than initial_max_vibration.
[in]initial_max_vibrationThe maximum vibration intensity, between 0 and 255. Should be greater than initial_min_vibration.

Member Function Documentation

bool NeosensoryBluefruit::isConnected ( void  )

Returns true if NeosensoryBluefruit has connected to a device.

Returns
True if NeosensoryBluefruit has connected to a device.
bool NeosensoryBluefruit::startScan ( void  )

Start scanning for desired device.

Returns
True if able to start scan, else False
Note
Will automatically connect to device if it is found in scan
uint8_t * NeosensoryBluefruit::getDeviceAddress ( void  )

Get address of device to connect to.

Returns
Byte array of address to connect to, or 0 if not set.
void NeosensoryBluefruit::setDeviceId ( char  new_device_id[])

Sets new device ID for central to search for.

Parameters
[in]new_device_idNew device id to search for. If is an empty array, NeosensoryBluefruit will connect to any Neosensory device.
Note
Does not restart scan, just sets device id for use in next scan.
bool NeosensoryBluefruit::isAuthorized ( void  )

Returns true if connected device has authorized developer options.

Returns
True if the connected device has authorized developer options.
void NeosensoryBluefruit::audioStart ( void  )

Starts the audio task processing.

Note
This will start microphone audio acquisition and pipe the audio to the current audio sink.
void NeosensoryBluefruit::audioStop ( void  )

Stops the current audio task processing and hence any motor outputs from the algorithm.

Note
This stops the actual audio acquisition from the microphone.
void NeosensoryBluefruit::authorizeDeveloper ( void  )

Send a command to the wristband to authorize developer options.

Note
Authorization will only happen if this command is followed by acceptTermsAndConditions().
void NeosensoryBluefruit::deviceInfo ( void  )

Get information about the connected Neosensory device.

Note
This can be called without authorizing developer options.
void NeosensoryBluefruit::motorsStart ( void  )

Initialize and start the motors interface.

Note
The device will now respond to motor vibrate commands.
void NeosensoryBluefruit::motorsStop ( void  )

Clears the motor queue and stops the motors interface.

Note
The device will no longer respond to motor vibrate commands.
void NeosensoryBluefruit::sendCommand ( char  cmd[])

Send a command to the wristband.

Parameters
[in]cmdCommand to send
void NeosensoryBluefruit::stopAlgorithm ( void  )

Stops the sound-to-touch algorithm that runs on the wristband.

Note
Stops audio and restarts the motors, which stop when audio is stopped.
void NeosensoryBluefruit::connectCallback ( uint16_t  conn_handle)

Callback when central connects.

Parameters
conn_handleConnection Handle that central connected to
Note
Checks that wristband services and characteristics are present, enables notification callbacks from read characteristic, and pairs to connected wristband. If not, disconnects. Also calls externalConnectedCallback.
void NeosensoryBluefruit::disconnectCallback ( uint16_t  conn_handle,
uint8_t  reason 
)

Callback when central disconnects.

Parameters
[in]conn_handleConnection handle that central is disconnecting from.
[in]reasonReason for disconnect.
void NeosensoryBluefruit::readNotifyCallback ( BLEClientCharacteristic *  chr,
uint8_t *  data,
uint16_t  len 
)

Callback when read characteristic has data to be read.

Parameters
[in]chrCharacteristic that read data.
[in]dataData read.
[in]lenLength of data array.
void NeosensoryBluefruit::scanCallback ( ble_gap_evt_adv_report_t *  report)

Callback when a device is found during scan.

Parameters
[in]reportReport of device that scan found.
Note
This is set to automatically connect to a found device if its address matches our desired device address. Otherwise, the scanner resumes scanning.
void NeosensoryBluefruit::setConnectedCallback ( ConnectedCallback  connectedCallback)

Sets a callback that gets called when NeoBluefruit connects to a device.

Parameters
[in]connectedCallbackThe 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.

Parameters
[in]disconnectedCallbackThe function to call.
void NeosensoryBluefruit::setReadNotifyCallback ( ReadNotifyCallback  readNotifyCallback)

Sets a callback that gets called when read characteristic has data.

Parameters
[in]readNotifyCallbackThe function to call.
uint8_t NeosensoryBluefruit::firmware_frame_duration ( void  )

Get firmware frame duration in milliseconds.

Returns
Frame duration of the firmware in milliseconds.
Note
When multiple motor frames are sent to the wristband, they will each play for this duration (or longer, if no subsequent motor frame has been sent).
uint8_t NeosensoryBluefruit::max_frames_per_bt_package ( void  )

Get maximum number of frames allowed in a Bluetooth packet.

Returns
Max frames allowed in a Bluetooth packet.
uint8_t NeosensoryBluefruit::num_motors ( void  )

Get number of motors.

Returns
The number of motors this instance of NeosensoryBluetooth expects in the target device.
void NeosensoryBluefruit::vibrateMotor ( uint8_t  motor,
float  intensity 
)

Turn on a single motor at an intensity.

Parameters
[in]motorIndex of motor to vibrate
[in]intensityIntensity 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.

Parameters
[in]intensitiesA 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_framesThe number of frames. Cannot be more than max_frames_per_bt_package_.
Note
This will send all frames, even if any or all are identical to each other.
void NeosensoryBluefruit::vibrateMotors ( float  intensities[])

Cause the wristband to vibrate at the given intensities.

Parameters
[in]intensitiesAn 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.
Note
This will not send a new command if the last sent array is identical to the new array of intensities.

Member Data Documentation

NeosensoryBluefruit * NeosensoryBluefruit::NeoBluefruit = 0
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.


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