User Tools

Site Tools


built_in:nxt_isconnected

Differences

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

Link to this comparison view

Next revision
Previous revision
built_in:nxt_isconnected [2015/03/10 20:59]
madlyr created IsConnected
built_in:nxt_isconnected [2015/03/11 18:03] (current)
Line 1: Line 1:
 ====== IsConnected ====== ====== IsConnected ======
  
-The **IsConnected** function returns true if the NXT brick is currently connected to the phone/tablet. Unlike [[nxt_checkconnected|CheckConnected]] method, it will **not show a popup warning message** and return false if no brick is currently connected.+The **IsConnected** function returns true if the NXT brick is currently connected to the phone/tablet. Unlike [[nxt_checkconnection|CheckConnection]] method, it will **not show a popup warning message** and return false if no brick is currently connected.
 <code>connected = nxt.IsConnected();</code> <code>connected = nxt.IsConnected();</code>
  
 ====Example - IsConnected Connect / Disconnect to NXT with FontAwesome icons==== ====Example - IsConnected Connect / Disconnect to NXT with FontAwesome icons====
 <file javascript NxtConnect.js> <file javascript NxtConnect.js>
-var nxt, lay;+var nxt, lay, btnConnect;
 function OnStart() function OnStart()
 { {
   lay = app.CreateLayout( "Linear", "VCenter, FillXY" );   lay = app.CreateLayout( "Linear", "VCenter, FillXY" );
- 
   //Create Connect button.   //Create Connect button.
   btnConnect = app.CreateButton( "[fa-plug] Connect", 0.5, 0.08, "Gray,FontAwesome" );   btnConnect = app.CreateButton( "[fa-plug] Connect", 0.5, 0.08, "Gray,FontAwesome" );
Line 17: Line 16:
   btnConnect.SetOnTouch( btnConnect_OnTouch );     btnConnect.SetOnTouch( btnConnect_OnTouch );  
   lay.AddChild( btnConnect );   lay.AddChild( btnConnect );
- 
   app.AddLayout( lay );   app.AddLayout( lay );
  
Line 28: Line 26:
     if (nxt.IsConnected()) {     if (nxt.IsConnected()) {
         btnConnect.SetText("[fa-unlink] Disconnect");         btnConnect.SetText("[fa-unlink] Disconnect");
-        app.ShowPopup( "Connected to Bluetooth device: "+nxt.GetBtName() + " : " + nxt.GetBtAddress() );+        app.ShowPopup("Connected to Bluetooth device: "+nxt.GetBtName()+" : "+nxt.GetBtAddress());
     }     }
 } }
built_in/nxt_isconnected.1426021186.txt.gz ยท Last modified: 2015/03/11 04:59 (external edit)