Treehopper Java API
io.treehopper.TreehopperUsb Class Reference

The core class for communicating with Treehopper USB boards. More...

Public Member Functions

 TreehopperUsb (Connection connection)
 Construct a Treehopper from a Connection. More...
 
boolean getConnected ()
 Get whether the board is connected. More...
 
boolean connect ()
 Connect to the board and reinitialize all peripherals. More...
 
void disconnect ()
 Disconnect from the board. More...
 
void reinitialize ()
 Reinitialize the board, setting all pins as digital inputs. More...
 
String getName ()
 
String getSerialNumber ()
 
boolean isLed ()
 
void setLed (boolean led)
 
Connection getConnection ()
 Get the connection associated with this Treehopper board. More...
 
void onPinReportReceived (byte[] pinReport)
 Internal event used by the Connection to report pin changes. More...
 
void sendPeripheralConfigPacket (byte[] dataToSend)
 send a peripheral configuration packet directly to the connection More...
 
byte [] receiveCommsResponsePacket (int numBytesToRead)
 receive a peripheral response packet from the connection More...
 

Public Attributes

Pin [] pins = new Pin[20]
 
I2c i2c
 
Spi spi
 
Pwm pwm1
 
Pwm pwm2
 
Pwm pwm3
 
HardwarePwmManager hardwarePwmManager
 
HardwareUart uart
 

Static Public Attributes

static Settings Settings = new Settings()
 

Detailed Description

The core class for communicating with Treehopper USB boards.

treehopper-hardware.svg
Treehopper pinout

Core Hardware

Treehopper is a USB 2.0 Full Speed device with 20 Pins — each of which can be used as an analog input, digital input, digital output, or soft-PWM output. Many of these pins also have dedicated peripheral functions for SPI, I2C, UART, and PWM.

You'll access all the pins, peripherals, and board functions through this class, which will automatically create all peripheral instances for you.

Getting a board reference

To obtain a reference to the board, use the ConnectionService.getInstance().getFirstDevice() method:

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

Or the ConnectionService.getInstance().getBoards() vector.

Warning
While you're free to create TreehopperUsb variables that reference boards, never call TreehopperUsb's constructor yourself.

Connect to the board

Before you use the board, you must explicitly connect to it by calling the ConnectAsync() method

TreehopperUsb board = ConnectionService.getInstance().getFirstDevice();
board.connect();
Note
Once a board is connected, other applications won't be able to use it.

Next steps

To learn about accessing different Treehopper peripherals, visit the doc links to the relevant classes:

Constructor & Destructor Documentation

◆ TreehopperUsb()

io.treehopper.TreehopperUsb.TreehopperUsb ( Connection  connection)

Construct a Treehopper from a Connection.

Parameters
connectionthe connection to use

Member Function Documentation

◆ connect()

boolean io.treehopper.TreehopperUsb.connect ( )

Connect to the board and reinitialize all peripherals.

Returns

◆ disconnect()

void io.treehopper.TreehopperUsb.disconnect ( )

Disconnect from the board.

◆ getConnected()

boolean io.treehopper.TreehopperUsb.getConnected ( )

Get whether the board is connected.

Returns
the connection state of the board

◆ getConnection()

Connection io.treehopper.TreehopperUsb.getConnection ( )

Get the connection associated with this Treehopper board.

Returns
the Connection associated with this board

◆ getName()

String io.treehopper.TreehopperUsb.getName ( )

◆ getSerialNumber()

String io.treehopper.TreehopperUsb.getSerialNumber ( )

◆ isLed()

boolean io.treehopper.TreehopperUsb.isLed ( )

◆ onPinReportReceived()

void io.treehopper.TreehopperUsb.onPinReportReceived ( byte []  pinReport)

Internal event used by the Connection to report pin changes.

Parameters
pinReportthe pin report received

◆ receiveCommsResponsePacket()

byte [] io.treehopper.TreehopperUsb.receiveCommsResponsePacket ( int  numBytesToRead)

receive a peripheral response packet from the connection

Parameters
numBytesToReadthe number of bytes to read
Returns
the data

◆ reinitialize()

void io.treehopper.TreehopperUsb.reinitialize ( )

Reinitialize the board, setting all pins as digital inputs.

◆ sendPeripheralConfigPacket()

void io.treehopper.TreehopperUsb.sendPeripheralConfigPacket ( byte []  dataToSend)

send a peripheral configuration packet directly to the connection

Parameters
dataToSendThe data to send

◆ setLed()

void io.treehopper.TreehopperUsb.setLed ( boolean  led)

Member Data Documentation

◆ hardwarePwmManager

HardwarePwmManager io.treehopper.TreehopperUsb.hardwarePwmManager

◆ i2c

I2c io.treehopper.TreehopperUsb.i2c

◆ pins

Pin [] io.treehopper.TreehopperUsb.pins = new Pin[20]

◆ pwm1

Pwm io.treehopper.TreehopperUsb.pwm1

◆ pwm2

Pwm io.treehopper.TreehopperUsb.pwm2

◆ pwm3

Pwm io.treehopper.TreehopperUsb.pwm3

◆ Settings

Settings io.treehopper.TreehopperUsb.Settings = new Settings()
static

◆ spi

Spi io.treehopper.TreehopperUsb.spi

◆ uart

HardwareUart io.treehopper.TreehopperUsb.uart

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