This shows you the differences between two versions of the page.
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. | ||
- | < | + | < |
====Example - Connect to NXT==== | ====Example - Connect to NXT==== | ||
Line 18: | Line 18: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ====Example - IsConnected Connect / Disconnect to NXT with FontAwesome icons==== | ||
+ | <file javascript NxtConnect.js> | ||
+ | var nxt, lay; | ||
+ | function OnStart() | ||
+ | { | ||
+ | lay = app.CreateLayout( " | ||
+ | |||
+ | //Create Connect button. | ||
+ | btnConnect = app.CreateButton( " | ||
+ | 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(" | ||
+ | app.ShowPopup(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | function btnConnect_OnTouch() | ||
+ | { | ||
+ | if (nxt.IsConnected()) { | ||
+ | app.ShowPopup( " | ||
+ | nxt.Disconnect(); | ||
+ | btnConnect.SetText(" | ||
+ | } else { | ||
+ | //Show list of NXT devices. | ||
+ | nxt.ShowDevices(); | ||
+ | } | ||
+ | } | ||
+ | </ |