DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


Sidebar

Privacy Policy

News

Version1.42 is out since December 2nd 2016


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

built_in:nxt_isconnected

IsConnected

The IsConnected function returns true if the NXT brick is currently connected to the phone/tablet. Unlike CheckConnection method, it will not show a popup warning message and return false if no brick is currently connected.

connected = nxt.IsConnected();

Example - IsConnected Connect / Disconnect to NXT with FontAwesome icons

NxtConnect.js
var nxt, lay, btnConnect;
function OnStart()
{
  lay = app.CreateLayout( "Linear", "VCenter, FillXY" );
  //Create Connect button.
  btnConnect = app.CreateButton( "[fa-plug] Connect", 0.5, 0.08, "Gray,FontAwesome" );
  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("[fa-unlink] Disconnect");
        app.ShowPopup("Connected to Bluetooth device: "+nxt.GetBtName()+" : "+nxt.GetBtAddress());
    }
}
 
function btnConnect_OnTouch()
{        
	if (nxt.IsConnected()) {
	    app.ShowPopup( "Disconnectig from Bluetooth device: "+nxt.GetBtName() );
	    nxt.Disconnect();
	    btnConnect.SetText("[fa-plug] Connect");
	} else {
	    //Show list of NXT devices.
	    nxt.ShowDevices();
	}
}
built_in/nxt_isconnected.txt · Last modified: 2015/03/11 10:03 by madlyr