client

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2018 License: Apache-2.0, Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package client provies a client for interacting with microcontrollers using the Firmata protocol https://github.com/firmata/protocol.

Index

Constants

View Source
const (
	Input  = 0x00
	Output = 0x01
	Analog = 0x02
	Pwm    = 0x03
	Servo  = 0x04
)

Pin Modes

View Source
const (
	ProtocolVersion          byte = 0xF9
	SystemReset              byte = 0xFF
	DigitalMessage           byte = 0x90
	DigitalMessageRangeStart byte = 0x90
	DigitalMessageRangeEnd   byte = 0x9F
	AnalogMessage            byte = 0xE0
	AnalogMessageRangeStart  byte = 0xE0
	AnalogMessageRangeEnd    byte = 0xEF
	ReportAnalog             byte = 0xC0
	ReportDigital            byte = 0xD0
	PinMode                  byte = 0xF4
	StartSysex               byte = 0xF0
	EndSysex                 byte = 0xF7
	CapabilityQuery          byte = 0x6B
	CapabilityResponse       byte = 0x6C
	PinStateQuery            byte = 0x6D
	PinStateResponse         byte = 0x6E
	AnalogMappingQuery       byte = 0x69
	AnalogMappingResponse    byte = 0x6A
	StringData               byte = 0x71
	I2CRequest               byte = 0x76
	I2CReply                 byte = 0x77
	I2CConfig                byte = 0x78
	FirmwareQuery            byte = 0x79
	I2CModeWrite             byte = 0x00
	I2CModeRead              byte = 0x01
	I2CModeContinuousRead    byte = 0x02
	I2CModeStopReading       byte = 0x03
	ServoConfig              byte = 0x70
)

Sysex Codes

Variables

View Source
var (
	ErrConnected = errors.New("client is already connected")
)

Errors

Functions

This section is empty.

Types

type Client

type Client struct {
	FirmwareName    string
	ProtocolVersion string

	ConnectTimeout time.Duration

	gobot.Eventer
	// contains filtered or unexported fields
}

Client represents a client connection to a firmata board

func New

func New() *Client

New returns a new Client

func (*Client) AnalogMappingQuery

func (b *Client) AnalogMappingQuery() error

AnalogMappingQuery sends the AnalogMappingQuery sysex code.

func (*Client) AnalogWrite

func (b *Client) AnalogWrite(pin int, value int) error

AnalogWrite writes value to pin.

func (*Client) CapabilitiesQuery

func (b *Client) CapabilitiesQuery() error

CapabilitiesQuery sends the CapabilityQuery sysex code.

func (*Client) Connect

func (b *Client) Connect(conn io.ReadWriteCloser) (err error)

Connect connects to the Client given conn. It first resets the firmata board then continuously polls the firmata board for new information when it's available.

func (*Client) Connected

func (b *Client) Connected() bool

Connected returns the current connection state of the Client

func (*Client) Connecting added in v1.6.0

func (b *Client) Connecting() bool

Connecting returns true when the client is connecting

func (*Client) DigitalWrite

func (b *Client) DigitalWrite(pin int, value int) error

DigitalWrite writes value to pin.

func (*Client) Disconnect

func (b *Client) Disconnect() (err error)

Disconnect disconnects the Client

func (*Client) FirmwareQuery

func (b *Client) FirmwareQuery() error

FirmwareQuery sends the FirmwareQuery sysex code.

func (*Client) I2cConfig

func (b *Client) I2cConfig(delay int) error

I2cConfig configures the delay in which a register can be read from after it has been written to.

func (*Client) I2cRead

func (b *Client) I2cRead(address int, numBytes int) error

I2cRead reads numBytes from address once.

func (*Client) I2cWrite

func (b *Client) I2cWrite(address int, data []byte) error

I2cWrite writes data to address.

func (*Client) PinStateQuery

func (b *Client) PinStateQuery(pin int) error

PinStateQuery sends a PinStateQuery for pin.

func (*Client) Pins

func (b *Client) Pins() []Pin

Pins returns all available pins

func (*Client) ProtocolVersionQuery

func (b *Client) ProtocolVersionQuery() error

ProtocolVersionQuery sends the ProtocolVersion sysex code.

func (*Client) ReportAnalog

func (b *Client) ReportAnalog(pin int, state int) error

ReportAnalog enables or disables analog reporting for pin, a non zero state enables reporting

func (*Client) ReportDigital

func (b *Client) ReportDigital(pin int, state int) error

ReportDigital enables or disables digital reporting for pin, a non zero state enables reporting

func (*Client) Reset

func (b *Client) Reset() error

Reset sends the SystemReset sysex code.

func (*Client) ServoConfig

func (b *Client) ServoConfig(pin int, max int, min int) error

ServoConfig sets the min and max pulse width for servo PWM range

func (*Client) SetPinMode

func (b *Client) SetPinMode(pin int, mode int) error

SetPinMode sets the pin to mode.

func (*Client) WriteSysex added in v1.6.0

func (b *Client) WriteSysex(data []byte) (err error)

WriteSysex writes an arbitrary Sysex command to the microcontroller.

type I2cReply

type I2cReply struct {
	Address  int
	Register int
	Data     []byte
}

I2cReply represents the response from an I2cReply message

type Pin

type Pin struct {
	SupportedModes []int
	Mode           int
	Value          int
	State          int
	AnalogChannel  int
}

Pin represents a pin on the firmata board

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL