This shows you the differences between two versions of the page.
built_in:nxt_setonconnect [2015/03/11 17:22] madlyr [Example - Connect / Disconnect to NXT] |
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. Callback function returns success status of connection (true if connection is successful, and false, if connection failed) and caller nxt object.\\ Do not use SetOnConnected while using SetOnConnect. | ||
- | < | ||
- | Callback function myfunc. Function name changed to OnConnect. | ||
- | <code javacsript> | ||
- | </ | ||
- | |||
- | ====Example - Connect to NXT==== | ||
- | <code javascript> | ||
- | function OnStart() | ||
- | { | ||
- | nxt = app.CreateNxt(); | ||
- | nxt.SetOnConnect( OnConnect ); | ||
- | app.SetMenu( " | ||
- | } | ||
- | |||
- | function OnMenu( name ) | ||
- | { | ||
- | if( name == " | ||
- | nxt.ShowDevices(); | ||
- | } | ||
- | |||
- | function OnConnect( success, nxt ) | ||
- | { | ||
- | app.Alert( " | ||
- | } | ||
- | </ | ||
- | |||
- | ====Example - Connect / Disconnect to NXT==== | ||
- | <code javascript> | ||
- | var nxt; | ||
- | function OnStart() | ||
- | { | ||
- | nxt = app.CreateNxt(); | ||
- | nxt.SetOnConnect( OnConnect ); | ||
- | app.SetMenu( " | ||
- | app.ShowMenu( true ); | ||
- | } | ||
- | |||
- | function OnMenu( name ) | ||
- | { | ||
- | if( name == " | ||
- | nxt.ShowDevices(); | ||
- | } else if ( name == " | ||
- | nxt.Disconnect(); | ||
- | app.SetMenu( " | ||
- | app.ShowMenu( true ); | ||
- | } | ||
- | } | ||
- | |||
- | function OnConnect( success, nxt ) | ||
- | { | ||
- | if (success) { | ||
- | app.Alert( " | ||
- | app.SetMenu( " | ||
- | } else { | ||
- | app.Alert( " | ||
- | } | ||
- | app.ShowMenu( true ); | ||
- | } | ||
- | </ |