User Tools

Site Tools


built_in:bluetoothserial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
built_in:bluetoothserial [2015/03/21 16:28]
84.181.9.122 [Methods] sorted
built_in:bluetoothserial [2015/03/22 13:49]
octazid completed
Line 2: Line 2:
  
 ===== Methods ===== ===== Methods =====
-^Method ^Description ^ +^ Method                                    ^ Description  
-|BluetoothSerial.Clear() | | +| BluetoothSerial.Clear()                                
-|BluetoothSerial.Connect( name,channel ) | | +| BluetoothSerial.Connect( name,channel )                
-|BluetoothSerial.Disconnect() | | +| BluetoothSerial.Disconnect()                           
-|BluetoothSerial.IsBluetoothEnabled() | | +| BluetoothSerial.IsBluetoothEnabled()                   
-|BluetoothSerial.IsConnected() | | +| BluetoothSerial.IsConnected()                          
-|BluetoothSerial.IsPaired( p1 ) | | +| BluetoothSerial.IsPaired( p1 )                         
-|BluetoothSerial.RequestEnable() | | +| BluetoothSerial.RequestEnable()                        
-|BluetoothSerial.SetOnConnect( p1 ) | | +| BluetoothSerial.SetOnConnect( callback               
-|BluetoothSerial.SetOnReceive( p1 ) | | +| BluetoothSerial.SetOnReceive( callback               
-|BluetoothSerial.SetSplitMode( p1,p2,p3 ) | | +| BluetoothSerial.SetSplitMode( p1,p2,p3 )               
-|BluetoothSerial.SetTimeout( p1 ) | | +| BluetoothSerial.SetTimeout( p1 )                       
-|BluetoothSerial.Write( p1 ) | |+| BluetoothSerial.Write( p1 )                            | 
 + 
 +=====Example===== 
 +//(Example taken from the DroidScript sample section)// 
 + 
 +<code javascript> 
 +//Called when application is started.  
 +function OnStart()  
 +{  
 + //Create a layout with objects vertically centered.  
 + lay = app.CreateLayout( "linear", "VCenter,FillXY" );  
 + 
 + //Create a button 1/3 of screen width and 1/4 screen height.  
 + btn = app.CreateButton( "Connect", 0.4, 0.15 );  
 + btn.SetOnTouch( btn_OnTouch );  
 + lay.AddChild( btn );  
 + app.AddLayout( lay );  
 +  
 + //Create Bluetooth serial object.  
 + bt = app.CreateBluetoothSerial();  
 + bt.SetOnConnect( bt_OnConnect )  
 + bt.SetOnReceive( bt_OnReceive );  
 + bt.SetSplitMode( "End", "\n" );  
 +}  
 + 
 +//Called when user touches the button.  
 +function btn_OnTouch()   
 +{  
 +    bt.Connect( "HC-05" );  
 +}  
 + 
 +//Called when we are connected.  
 +function bt_OnConnect( ok )  
 +{  
 +    if( ok ) bt.Write( "digitalWrite(LED1,1);\n" );  
 +    else app.ShowPopup( "Failed to connect!" );  
 +}  
 + 
 +//Called when we get data from device.  
 +function bt_OnReceive( data )  
 +{  
 +    app.ShowPopup( data );  
 +}  
 +</code>
built_in/bluetoothserial.txt · Last modified: 2019/02/25 14:32 (external edit)