Treehopper Java API
io.treehopper.ConnectionService Class Reference

Discovers Treehopper boards attached to your device. More...

Inheritance diagram for io.treehopper.ConnectionService:

Public Member Functions

Context getContext ()
 
void setContext (Context context)
 
 ConnectionService ()
 
HashMap< String, TreehopperUsbgetBoards ()
 (Android) Gets a HashMap of boards connected to this device More...
 
TreehopperUsb getFirstDevice ()
 Gets the first device attached. More...
 
void addEventsListener (TreehopperEventsHandler listener)
 
void removeEventsListener (TreehopperEventsHandler listener)
 
void deviceAdded (UsbDevice device)
 
void deviceRemoved (UsbDevice device)
 
void onReceive (Context context, Intent intent)
 
void scan ()
 
 ConnectionService ()
 
void updateBoards ()
 
List< TreehopperUsbgetBoards ()
 (Desktop) Gets a list of boards attached to this device More...
 
TreehopperUsb getFirstDevice ()
 

Static Public Member Functions

static ConnectionService getInstance ()
 Gets the ConnectionService instance for use. More...
 
static ConnectionService getInstance ()
 Gets the ConnectionService instance for use. More...
 

Static Public Attributes

static final String ActionUsbPermission = "io.treehopper.android.USB_PERMISSION"
 

Protected Member Functions

void finalize () throws Throwable
 

Detailed Description

Discovers Treehopper boards attached to your device.

This documentation set covers the ConnectionService class found in both Treehopper.Desktop, and Treehopper.Android packages.

Note
ConnectionService should always be accessed through its singleton property, getInstance(). Do not create instances of ConnectionService yourself.

Basic usage

There are two ways to access discovered boards. If you simply want to wait until the first Treehopper board is attached to the computer, the getFirstDevice() method will return an awaitable task with a result that contains the board:

TreehopperUsb board = ConnectionService.getInstance().getFirstDevice();

Advanced usage

For simple applications, you can retrieve a board instance with getFirstDevice(), however, if you'd like to present the user with a list of devices from which to choose, you can reference the getBoards() property.

Warning
Board discovery on Android is done asynchronously, so getBoards() will generally return an empty collection on application start-up. Inherit from TreehopperActivity or manually add the ConnectionService callback plumbing to receive boardAdded and boardRemoved callbacks.

Constructor & Destructor Documentation

◆ ConnectionService() [1/2]

io.treehopper.ConnectionService.ConnectionService ( )

◆ ConnectionService() [2/2]

io.treehopper.ConnectionService.ConnectionService ( )

Member Function Documentation

◆ addEventsListener()

void io.treehopper.ConnectionService.addEventsListener ( TreehopperEventsHandler  listener)

◆ deviceAdded()

void io.treehopper.ConnectionService.deviceAdded ( UsbDevice  device)

◆ deviceRemoved()

void io.treehopper.ConnectionService.deviceRemoved ( UsbDevice  device)

◆ finalize()

void io.treehopper.ConnectionService.finalize ( ) throws Throwable
protected

◆ getBoards() [1/2]

List<TreehopperUsb> io.treehopper.ConnectionService.getBoards ( )

(Desktop) Gets a list of boards attached to this device

Returns
a list of boards

◆ getBoards() [2/2]

HashMap<String, TreehopperUsb> io.treehopper.ConnectionService.getBoards ( )

(Android) Gets a HashMap of boards connected to this device

Returns
a HashMap of boards

◆ getContext()

Context io.treehopper.ConnectionService.getContext ( )

◆ getFirstDevice() [1/2]

TreehopperUsb io.treehopper.ConnectionService.getFirstDevice ( )

◆ getFirstDevice() [2/2]

TreehopperUsb io.treehopper.ConnectionService.getFirstDevice ( )

Gets the first device attached.

Returns
the first attached TreehopperUsb board

This function will block until a device is attached

◆ getInstance() [1/2]

static ConnectionService io.treehopper.ConnectionService.getInstance ( )
static

Gets the ConnectionService instance for use.

Returns
the ConnectionService instance to access

◆ getInstance() [2/2]

static ConnectionService io.treehopper.ConnectionService.getInstance ( )
static

Gets the ConnectionService instance for use.

Returns
the ConnectionService instance to access

◆ onReceive()

void io.treehopper.ConnectionService.onReceive ( Context  context,
Intent  intent 
)

◆ removeEventsListener()

void io.treehopper.ConnectionService.removeEventsListener ( TreehopperEventsHandler  listener)

◆ scan()

void io.treehopper.ConnectionService.scan ( )

◆ setContext()

void io.treehopper.ConnectionService.setContext ( Context  context)

◆ updateBoards()

void io.treehopper.ConnectionService.updateBoards ( )

Member Data Documentation

◆ ActionUsbPermission

final String io.treehopper.ConnectionService.ActionUsbPermission = "io.treehopper.android.USB_PERMISSION"
static

The documentation for this class was generated from the following file: