Treehopper C++ API
TreehopperUsb Class Reference

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

#include <TreehopperUsb.h>

Public Member Functions

 TreehopperUsb (UsbConnection &connection)
 ~TreehopperUsb ()
TreehopperUsboperator= (const TreehopperUsb &rhs)
 TreehopperUsb (const TreehopperUsb &rhs)
void reinitialize ()
 Reinitialize the board, setting all pins as high-impedance More...
bool connect ()
 Establish a connection with the board. More...
void disconnect ()
 Disconnect from the board. More...
wstring serialNumber ()
 Gets the serial number of the board. More...
wstring name ()
 Gets the name of the board. More...
void led (bool value)
 Sets the state of the LED. More...
bool led ()
 Gets the state of the LED. More...
wstring toString ()
 Gets a string representation of the board. More...

Public Attributes

bool isConnected
 Gets whether or not the board is connected. More...
vector< Pinpins
 Gets a collection of pins on the board. More...
const int numberOfPins = 20
 Gets the number of pins on the board (20) More...
HardwareI2c i2c
 Gets the HardwareI2c interface. More...
HardwareSpi spi
 Gets the HardwareSpi interface. More...
HardwarePwm pwm1
 Gets the HardwarePwm PWM1 pin. More...
HardwarePwm pwm2
 Gets the HardwarePwm PWM2 pin. More...
HardwarePwm pwm3
 Gets the HardwarePwm PWM3 pin. More...
HardwarePwmManager pwmManager
 Gets the HardwarePwmManager module. More...

Detailed Description

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::instance().getFirstDevice() method:

Or the ConnectionService::instance().boards vector.

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

Once a board is connected, other applications won't be able to use it. When your app is running in Windows or macOS, you can investigate the name or serialNumber properties before calling connect(). This will let you determine which board to connect to if you have multiple boards used by multiple applications.

Next steps

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

Constructor & Destructor Documentation

◆ TreehopperUsb() [1/2]

TreehopperUsb ( UsbConnection connection)

◆ ~TreehopperUsb()

◆ TreehopperUsb() [2/2]

TreehopperUsb ( const TreehopperUsb rhs)

Member Function Documentation

◆ connect()

bool connect ( )

◆ disconnect()

void disconnect ( )

◆ led() [1/2]

void led ( bool  value)

◆ led() [2/2]

bool led ( )

◆ name()

wstring name ( )

◆ operator=()

TreehopperUsb& operator= ( const TreehopperUsb rhs)

◆ reinitialize()

void reinitialize ( )

◆ serialNumber()

wstring serialNumber ( )

◆ toString()

wstring toString ( )

Member Data Documentation

◆ i2c

◆ isConnected

bool isConnected

◆ numberOfPins

const int numberOfPins = 20

◆ pins

vector<Pin> pins

◆ pwm1

◆ pwm2

◆ pwm3

◆ pwmManager

HardwarePwmManager pwmManager

◆ spi

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