This shows you the differences between two versions of the page.
built_in:nxt_setonconnect [2015/03/10 16:29] madlyr created |
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. This function has in callback method parameter with 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 ); | ||
- | } | ||
- | </ | ||