C Language Development Kit/Functions/BltDiscovery

From OptiWiki

Jump to: navigation, search
Description Discovers up to 10 available bluetooth devices in the neighbourhood.
Syntax
int blt_discovery(struct device_info * dev_inf, int abortkey);
Arguments
struct device_info * dev_inf
After a successful dicovery the dev_info structure contains the discovered bluetooth devices.

The device_info structure is defined as follows:

int abortkey
The key to abort the discovery. When abortkey = 0 no abort key is used
Returns
> 0 The number of devices discovered.
-3 User aborted the discovery.
< -10 Discovery failure.
Remarks blt_discovery() function can find upto 10 bluetooth devices during the discovery. If more devices are available in the neighbourhood these devices will be ignored.

To prevent stack problems make sure that the device_info input parameter is defined as static.

Example
#include "lib.h"
#include <stdio.h>
 
void main( void )
{
    int x, ret;
    // make sure this array can contain 10 objects 
    // bluetooth discovery can discover 10 bluetooth items
    static device_info blt_dev_info[ 10 ];
 
    cursor( NOWRAP );
    setfont( MEDIUM_FONT, NULL );
    for(;;)
    {
        printf("\f\tr   BT Discovery    \tr\n" );
        gotoxy( 0, 4 );
        printf(  "\tr                   \tr");
 
        gotoxy(0,1);
        printf("Searching..         ");
 
        // Do a discovery with the Trigger key to abort
        if((ret = blt_discovery( blt_dev_info, TRIGGER_KEY)) <= 0)
        {
            gotoxy(0,2);
            if( ret == 0 )
                printf("No device found!!!\nPress any key");
            else if( ret == ERR_USER_BREAK )
                printf("Abort key pressed\nPress any key");
            else
                printf("Discovery Failure!\nPress any key");
            while( getchar() == EOF)
                idle();
            continue;
        }
 
        x=0;
        for(;;)
        {
            printf("\f\trSelect address %i/%i\tr\n",x+1,ret);
            gotoxy( 0, 4 );
            printf(  "\tr1=up        2=down \tr");
            gotoxy(0,1);
            printf("%s        \n",blt_dev_info[x].bd_address);
            printf("%s        \n",blt_dev_info[x].name);
 
            resetkey();
            while( !kbhit() )
                idle();
            switch(getchar())
            {
                case UP_KEY:
                    x++;
                    if( x == ret )
                        x = 0;
                    break;
                case DOWN_KEY:
                    if( x == 0 )
                        x = ret-1;
                    else
                        x\-\-;
                    break;
                case TRIGGER_KEY:
                    ret = TRIGGER_KEY;
                    break;
            }
 
            if( ret == TRIGGER_KEY )
                break;
        }
    }
}


Views
Personal tools