From BlueMelon
The following code snippets can be found in the SDK's listDevices example.
Setup
Usually the application starts by allocating space for some tables:
// allocate memory for an interface table
bsDeviceInterface_registeredDeviceInterfaces_t registered =
bsDeviceInterface_allocInterfaceTable();
// allocate memory for a device table
bsDeviceTable_table_t devices = bsDeviceTable_allocDeviceTable();
// open a master device
bsMaster_device_t master = bsMaster_allocMaster(registered,devices,0);
Cleaning up
After you're done using BlueSense you should cleanup the allocated tables:
// clean up previously allocated memory
bsMaster_freeMaster(master);
bsDeviceTable_freeDeviceTable(devices);
bsDeviceInterface_freeInterfaceTable(registered);
Detecting devices
uint16_t newFound = 1;
while(newFound) {
// try to detect ten devices in 2 seconds
newFound = bsMaster_detectDevices(master,10,2*1000*1000);
}
Checking for error messages
After you have tried to detect devices it can be helpfull to check the message log (eg. to identify connection problems).
// check if there are connection problems
uint8_t msgCount = bsMaster_getMessageCount();
if (msgCount!=0) {
// print error messages
printf("Connection messages: \n");
uint8_t index;
for (index=0; index