28 #ifndef NeosensoryBluefruit_h 29 #define NeosensoryBluefruit_h 32 #include <bluefruit.h> 40 typedef void (*ConnectedCallback)(bool);
41 typedef void (*DisconnectedCallback)(uint16_t, uint8_t);
42 typedef void (*ReadNotifyCallback)(BLEClientCharacteristic*, uint8_t*, uint16_t);
52 uint8_t initial_min_vibration=30, uint8_t initial_max_vibration=255);
257 bool checkAddressMatches(uint8_t foundAddress[]);
258 bool checkDevice(ble_gap_evt_adv_report_t* report);
259 bool checkIsNeosensory(ble_gap_evt_adv_report_t* report);
260 bool connect_to_any_neo_device_;
262 uint8_t device_address_[BLE_GAP_ADDR_LEN];
263 void setDeviceAddress(
char device_id[]);
266 uint8_t *previous_motor_array_;
267 uint8_t firmware_frame_duration_;
268 uint8_t max_frames_per_bt_package_;
270 void getMotorIntensitiesFromLinArray(
271 float lin_array[], uint8_t motor_space_array[],
size_t array_size);
272 void sendMotorCommand(uint8_t motor_intensities[],
size_t num_frames=1);
277 void handleCliJson(String jsonMessage);
278 void parseCliData(uint8_t* data, uint16_t len);
281 ConnectedCallback externalConnectedCallback;
282 DisconnectedCallback externalDisconnectedCallback;
283 ReadNotifyCallback externalReadNotifyCallback;
286 uint8_t wb_service_uuid_[16];
287 uint8_t wb_write_char_uuid_[16];
288 uint8_t wb_read_char_uuid_[16];
291 BLEClientService wb_service_;
292 BLEClientCharacteristic wb_write_characteristic_;
293 BLEClientCharacteristic wb_read_characteristic_;
296 void connectCallbackWrapper(uint16_t conn_handle);
297 void disconnectCallbackWrapper(uint16_t conn_handle, uint8_t reason);
298 void readNotifyCallbackWrapper(BLEClientCharacteristic* chr, uint8_t* data, uint16_t len);
299 void scanCallbackWrapper(ble_gap_evt_adv_report_t* report);
void vibrateMotor(uint8_t motor, float intensity)
Turn on a single motor at an intensity.
Definition: neosensory_bluefruit.cpp:386
void setDeviceId(char new_device_id[])
Sets new device ID for central to search for.
Definition: neosensory_bluefruit.cpp:107
uint8_t min_vibration
Definition: neosensory_bluefruit.h:213
void motorsStart(void)
Initialize and start the motors interface.
Definition: neosensory_bluefruit.cpp:197
void deviceInfo(void)
Get information about the connected Neosensory device.
Definition: neosensory_bluefruit.cpp:193
uint8_t firmware_frame_duration(void)
Get firmware frame duration in milliseconds.
Definition: neosensory_bluefruit.cpp:257
void audioStart(void)
Starts the audio task processing.
Definition: neosensory_bluefruit.cpp:213
void setDisconnectedCallback(DisconnectedCallback)
Sets a callback that gets called when NeoBluefruit disconnects from a device.
Definition: neosensory_bluefruit.cpp:441
void turnOffAllMotors(void)
Turn off all the motors.
Definition: neosensory_bluefruit.cpp:380
uint8_t max_frames_per_bt_package(void)
Get maximum number of frames allowed in a Bluetooth packet.
Definition: neosensory_bluefruit.cpp:261
void stopAlgorithm(void)
Stops the sound-to-touch algorithm that runs on the wristband.
Definition: neosensory_bluefruit.cpp:188
void begin(void)
Begins Bluetooth components of NeosensoryBluefruit.
Definition: neosensory_bluefruit.cpp:70
void scanCallback(ble_gap_evt_adv_report_t *report)
Callback when a device is found during scan.
Definition: neosensory_bluefruit.cpp:396
void readNotifyCallback(BLEClientCharacteristic *chr, uint8_t *data, uint16_t len)
Callback when read characteristic has data to be read.
Definition: neosensory_bluefruit.cpp:430
void authorizeDeveloper(void)
Send a command to the wristband to authorize developer options.
Definition: neosensory_bluefruit.cpp:180
static NeosensoryBluefruit * NeoBluefruit
Definition: neosensory_bluefruit.h:54
void disconnectCallback(uint16_t conn_handle, uint8_t reason)
Callback when central disconnects.
Definition: neosensory_bluefruit.cpp:424
bool isAuthorized(void)
Returns true if connected device has authorized developer options.
Definition: neosensory_bluefruit.cpp:172
void connectCallback(uint16_t conn_handle)
Callback when central connects.
Definition: neosensory_bluefruit.cpp:405
void setConnectedCallback(ConnectedCallback)
Sets a callback that gets called when NeoBluefruit connects to a device.
Definition: neosensory_bluefruit.cpp:436
void acceptTermsAndConditions(void)
Send a command to the wristband to accept developer terms and conditions.
Definition: neosensory_bluefruit.cpp:184
uint8_t * getDeviceAddress(void)
Get address of device to connect to.
Definition: neosensory_bluefruit.cpp:114
void deviceBattery(void)
Get the amount of charge left on the device battery in percentage.
Definition: neosensory_bluefruit.cpp:209
bool startScan(void)
Start scanning for desired device.
Definition: neosensory_bluefruit.cpp:120
void sendCommand(char cmd[])
Send a command to the wristband.
Definition: neosensory_bluefruit.cpp:176
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.
Definition: neosensory_bluefruit.cpp:33
void motorsClearQueue(void)
Clears the motor command queue.
Definition: neosensory_bluefruit.cpp:205
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.
Definition: neosensory_bluefruit.h:38
void setReadNotifyCallback(ReadNotifyCallback)
Sets a callback that gets called when read characteristic has data.
Definition: neosensory_bluefruit.cpp:446
void vibrateMotors(float *intensities[], int num_frames)
Cause the wristband to vibrate at the given intensities, for multiple frames.
Definition: neosensory_bluefruit.cpp:364
void audioStop(void)
Stops the current audio task processing and hence any motor outputs from the algorithm.
Definition: neosensory_bluefruit.cpp:217
void motorsStop(void)
Clears the motor queue and stops the motors interface.
Definition: neosensory_bluefruit.cpp:201
uint8_t num_motors(void)
Get number of motors.
Definition: neosensory_bluefruit.cpp:253
uint8_t max_vibration
Definition: neosensory_bluefruit.h:211
bool isConnected(void)
Returns true if NeosensoryBluefruit has connected to a device.
Definition: neosensory_bluefruit.cpp:125