Page 1 of 1

[NXC][BT] Finding BlueTooth Devices

Posted: 17 Oct 2010, 23:04
by muntoo
Is there any function that allows you find BlueTooth Devices?
Here's what I got so far:

Code: Select all

/*
byte BTDevicesEnum(string &devnames[])
Lists the names of the devices in devnames.
Returns the array length of devnames.
*/
byte BTDevicesEnum(string &devnames[])
{
	byte btdc = BTDeviceCount();

	ArrayInit(devnames, "", btdc);

	for(/*unsigned int*/ byte devidx = 0; devidx < btdc; devidx++)
		devnames[devidx] = BTDeviceName(devidx);

	return(btdc);
}

Re: NXC: Finding BlueTooth Devices

Posted: 18 Oct 2010, 02:02
by afanofosc
I'm not sure what you mean by "allows you to find BlueTooth Devices". I would not copy the names from the Comm module's IOMap structure into a separate array since that just puts the data in two places. Are you wanting to just list the names of known devices from the BTDevice table? Or are you wanting to programmatically connect to a known device?

John Hansen

Re: NXC: Finding BlueTooth Devices

Posted: 18 Oct 2010, 02:24
by muntoo
Yeah, I'm trying to connect BT devices inside the program. I just realized that those BTDevice() functions are listing the devices in the table...
Know anything equivalent to doing NXT->Bluetooth->Search, but in a program, of course?

Re: NXC: Finding BlueTooth Devices

Posted: 18 Oct 2010, 02:32
by afanofosc
Maybe using CommExecuteFunction but in theory you would just get all the devices you may need in your device table before you start running your program and then you can connect/disconnect to one of those devices from within your program.

Code: Select all


          VarsUi.BTCommand  = (UBYTE)SEARCH;
          VarsUi.BTPar1     = (UBYTE)1;
          VarsUi.BTPar2     = (UBYTE)0;
          if (pMapComm->pFunc(VarsUi.BTCommand,VarsUi.BTPar1,VarsUi.BTPar2,0,NULL,&(VarsUi.BTResult)) == SUCCESS)
You can do that same kind of thing, iirc, using SysCommExecuteFunction with the CommExecuteFunctionType structure.

John Hansen

Re: NXC: Finding BlueTooth Devices

Posted: 18 Oct 2010, 05:15
by muntoo
Still can't figure it out.

Code: Select all

/*
byte BTDevicesEnum(string &devnames[])
Lists the names of the devices in devnames.
Returns the array length of devnames.
*/
byte BTDevicesEnum(string &devnames[])
{
	CommExecuteFunctionType ceftArgs;
	ceftArgs.Cmd = INTF_SEARCH;
	for(ceftArgs.RetVal = LDR_BTBUSY; ceftArgs.RetVal != LDR_SUCCESS; SysCommExecuteFunction(ceftArgs))
	{
		NumOut(0, LCD_LINE7, ceftArgs.RetVal, 1);
		Wait(1000);
	}

	Wait(2000);

/*
	Wait(1000);

	ceftArgs.Cmd = INTF_STOPSEARCH;
	SysCommExecuteFunction(ceftArgs);
	Wait(1000);
*/
	byte btdc = BTDeviceCount();

	ArrayInit(devnames, "", btdc);

	for(/*unsigned int*/ byte devidx = 0; devidx < btdc; devidx++)
		devnames[devidx] = BTDeviceName(devidx);

	return(btdc);
}
Is the "table" supposed to be "My Contacts"?

Re: NXC: Finding BlueTooth Devices

Posted: 23 Oct 2010, 18:54
by muntoo
*bump*

[Isn't there supposed to be a "bump" button on these forums?]

Re: NXC: Finding BlueTooth Devices

Posted: 31 Oct 2010, 00:27
by muntoo
How can I search for, and add devices to the BlueTooth device table?

Here's what I got so far:

Code: Select all

/*
byte BTDevicesEnum(string &devnames[])
Lists the names of the devices in devnames.
Returns the array length of devnames.
*/
byte BTDevicesEnum(string &devnames[])
{
// INTF_STOPSEARCH INTF_CONNECT INTF_CONNECTBYNAME INTF_REMOVEDEVICE INTF_SETCMDMODE
// LDR_INPROGRESS == 0x0001 == 1
// LDR_BTBUSY == 0x9400 == 37888
//BTDataMode()
//BTDeviceStatus()

	unsigned long timer = 0;
	CommExecuteFunctionType ceftArgs;


	ceftArgs.Cmd = INTF_SEARCH;
	SysCommExecuteFunction(ceftArgs);
	timer = CurrentTick();
	while(((timer + 20000) > CurrentTick()) && (!ButtonPressed(BTNCENTER, 0)))
	{
		ClearLine(LCD_LINE4);
		ClearLine(LCD_LINE5);
		NumOut(0, LCD_LINE4, ceftArgs.RetVal, 0);
		NumOut(0, LCD_LINE5, ceftArgs.Result, 0);
	}
	while(ButtonPressed(BTNCENTER, 0));

	ceftArgs.Cmd = INTF_STOPSEARCH;
	SysCommExecuteFunction(ceftArgs);
	timer = CurrentTick();
	while(((timer + 20000) > CurrentTick()) && (!ButtonPressed(BTNCENTER, 0)))
	{
		ClearLine(LCD_LINE6);
		ClearLine(LCD_LINE7);	
		NumOut(0, LCD_LINE6, ceftArgs.RetVal, 0);
		NumOut(0, LCD_LINE7, ceftArgs.Result, 0);
	}
	while(ButtonPressed(BTNCENTER, 0));

	byte btdc = BTDeviceCount();

	ArrayInit(devnames, "", btdc);

	for(/*unsigned int*/ byte devidx = 0; devidx < btdc; devidx++)
		devnames[devidx] = BTDeviceName(devidx);

	return(btdc);
}

Re: NXC: Finding BlueTooth Devices

Posted: 31 Oct 2010, 19:28
by afanofosc
As I mentioned already, I just don't see the point to searching for other bluetooth devices while your program is running. Just get all the devices you want/need into the device table before you start your program by using the NXT menu system.

John Hansen