User Tools

Site Tools


built_in:nxt_showdevices

Differences

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

Link to this comparison view

Next revision
Previous revision
built_in:nxt_showdevices [2015/03/09 16:23]
octazid created
built_in:nxt_showdevices [2015/03/11 05:07] (current)
Line 2: Line 2:
  
 The **ShowDevices** function shows the user a dialog box that contains a list of NXT bricks which are paired with the phone. The user can then select the brick to connect to via Bluetooth. The **ShowDevices** function shows the user a dialog box that contains a list of NXT bricks which are paired with the phone. The user can then select the brick to connect to via Bluetooth.
-<code>nxt.ShowDevices( file, repeat );</code>+<code>nxt.ShowDevices();</code>
  
 ====Example - Connect to NXT==== ====Example - Connect to NXT====
Line 18: Line 18:
 } }
 </code> </code>
 +
 +====Example - IsConnected Connect / Disconnect to NXT with FontAwesome icons====
 +<file javascript NxtConnect.js>
 +var nxt, lay;
 +function OnStart()
 +{
 +  lay = app.CreateLayout( "Linear", "VCenter, FillXY" );
 +
 +  //Create Connect button.
 +  btnConnect = app.CreateButton( "[fa-plug] Connect", 0.5, 0.08, "Gray,FontAwesome" );
 +  btnConnect.SetMargins( 0.1, 0.01, 0.1, 0.01 );
 +  btnConnect.SetTextSize( 24 );
 +  btnConnect.SetOnTouch( btnConnect_OnTouch );  
 +  lay.AddChild( btnConnect );
 +
 +  app.AddLayout( lay );
 +
 +  nxt = app.CreateNxt();
 +  nxt.SetOnConnected(onNXTConnected);
 +}
 +
 +function onNXTConnected() 
 +{
 +    if (nxt.IsConnected()) {
 +        btnConnect.SetText("[fa-unlink] Disconnect");
 +        app.ShowPopup("Connected to Bluetooth device: "+nxt.GetBtName()+" : "+nxt.GetBtAddress());
 +    }
 +}
 +
 +function btnConnect_OnTouch()
 +{        
 + if (nxt.IsConnected()) {
 +     app.ShowPopup( "Disconnectig from Bluetooth device: "+nxt.GetBtName() );
 +     nxt.Disconnect();
 +     btnConnect.SetText("[fa-plug] Connect");
 + } else {
 +     //Show list of NXT devices.
 +     nxt.ShowDevices();
 + }
 +}
 +</file>
built_in/nxt_showdevices.1425918229.txt.gz ยท Last modified: 2015/03/10 00:23 (external edit)