This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
built_in:nxt_showdevices [2015/03/10 07:45] madlyr [ShowDevices] Corrected arguments. ShowDevices has no arguments file and repeat. |
built_in:nxt_showdevices [2015/03/11 05:07] (current) |
||
---|---|---|---|
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(); | ||
+ | } | ||
+ | } | ||
+ | </ |