User Tools

Site Tools


built_in:nxt_setonconnect

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

built_in:nxt_setonconnect [2015/03/11 07:49]
madlyr [SetOnConnect]
built_in:nxt_setonconnect [2015/03/12 01:26]
Line 1: Line 1:
-====== SetOnConnect ====== 
- 
-The **SetOnConnect** function allows you to set the name of a function that you would like to be called when the NXT has been successfully connected via Bluetooth. The **SetOnConnect** function allows you to set the name of a function that you would like to be called when the NXT has been successfully connected via Bluetooth.\\ This function returns status of connection in callback method, true if connection is successful, and false, if connection failed.\\ Do not use SetOnConnected while using SetOnConnect. 
-<code>nxt.SetOnConnect( myfunc );</code> 
- 
-====Example - Connect to NXT==== 
-<code javascript> 
-function OnStart() 
-{ 
-  nxt = app.CreateNxt(); 
-  nxt.SetOnConnect( OnConnect ); 
-  app.SetMenu( "Connect" ); 
-} 
- 
-function OnMenu( name ) 
-{ 
-  if( name == "Connect" ) 
-    nxt.ShowDevices(); 
-} 
- 
-function OnConnect( status ) 
-{ 
-  app.Alert( "Connected = " + status, "OnConnect" ); 
-} 
-</code> 
- 
-====Example - Connect / Disconnect to NXT==== 
-<code javascript> 
-var nxt; 
-function OnStart() 
-{ 
-  nxt = app.CreateNxt(); 
-  nxt.SetOnConnect( OnConnect ); 
-  app.SetMenu( "Connect" ); 
-  app.ShowMenu( true ); 
-} 
-  
-function OnMenu( name ) 
-{ 
-  if( name == "Connect" ) { 
-    nxt.ShowDevices(); 
-  } else if ( name == "Disconnect" )  { 
-    nxt.Disconnect(); 
-    app.SetMenu( "Connect" ); 
-    app.ShowMenu( true ); 
-  } 
-} 
-  
-function OnConnect( status ) 
-{ 
-  if (status) { 
-    app.Alert( "Connected to: " + nxt.GetBtName(), "OnConnect" ); 
-    app.SetMenu( "Disconnect" ); 
-  } else { 
-    app.Alert( "Connection to NXT failed", "OnConnect" ); 
-  } 
-  app.ShowMenu( true ); 
-} 
-</code> 
  
built_in/nxt_setonconnect.txt ยท Last modified: 2015/03/12 01:26 (external edit)