This shows you the differences between two versions of the page.
built_in:nxt_setonconnect [2015/03/11 07:49] madlyr [SetOnConnect] |
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.\\ This function returns status of connection in callback method, true if connection is successful, and false, if connection failed.\\ Do not use SetOnConnected while using SetOnConnect. | ||
- | < | ||
- | |||
- | ====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( status ) | ||
- | { | ||
- | 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( status ) | ||
- | { | ||
- | if (status) { | ||
- | app.Alert( " | ||
- | app.SetMenu( " | ||
- | } else { | ||
- | app.Alert( " | ||
- | } | ||
- | app.ShowMenu( true ); | ||
- | } | ||
- | </ | ||