Version: v0.0.0-...-95c2dcd Latest Latest

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

Go to latest
Published: Nov 23, 2020 License: Apache-2.0 Imports: 9 Imported by: 0




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

	SPI_MODE0 = 0x00
	SPI_MODE1 = 0x04
	SPI_MODE2 = 0x08
	SPI_MODE3 = 0x0C

	SoftSerial  SerialPort = 0x00
	HardSerial1 SerialPort = 0x01
	HardSerial2 SerialPort = 0x02
	HardSerial3 SerialPort = 0x03

	I2CModeWrite          byte = 0x00
	I2CModeRead           byte = 0x01
	I2CModeContinuousRead byte = 0x02
	I2CModeStopReading    byte = 0x03

Pin Modes


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



This section is empty.


type Firmata

type Firmata struct {
	FirmwareName    string
	ProtocolVersion string
	// contains filtered or unexported fields

Firmata represents a client connection to a firmata board

func New

func New() *Firmata

New returns a new Firmata

func (*Firmata) AnalogMappingQuery

func (f *Firmata) AnalogMappingQuery() error

AnalogMappingQuery sends the AnalogMappingQuery sysex code.

func (*Firmata) AnalogWrite

func (f *Firmata) AnalogWrite(pin int, value int) error

AnalogWrite writes value to pin.

func (*Firmata) CapabilitiesQuery

func (f *Firmata) CapabilitiesQuery() error

CapabilitiesQuery sends the CapabilityQuery sysex code.

func (*Firmata) Connect

func (f *Firmata) Connect(conn io.ReadWriteCloser) (err error)

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

func (*Firmata) Connected

func (f *Firmata) Connected() bool

Connected returns the current connection state of the Firmata

func (*Firmata) DigitalWrite

func (f *Firmata) DigitalWrite(pin int, value int) error

DigitalWrite writes value to pin.

func (*Firmata) Disconnect

func (f *Firmata) Disconnect() (err error)

Disconnect disconnects the Firmata

func (*Firmata) FirmwareQuery

func (f *Firmata) FirmwareQuery() error

FirmwareQuery sends the FirmwareQuery sysex code.

func (*Firmata) I2cConfig

func (f *Firmata) I2cConfig(delay int) error

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

func (*Firmata) I2cRead

func (f *Firmata) I2cRead(address int, numBytes int) error

I2cRead reads numBytes from address once.

func (*Firmata) I2cWrite

func (f *Firmata) I2cWrite(address int, data []byte) error

I2cWrite writes data to address.

func (*Firmata) PinStateQuery

func (f *Firmata) PinStateQuery(pin int) error

PinStateQuery sends a PinStateQuery for pin.

func (*Firmata) Pins

func (f *Firmata) Pins() []Pin

Pins returns all available pins

func (*Firmata) ProtocolVersionQuery

func (f *Firmata) ProtocolVersionQuery() error

ProtocolVersionQuery sends the ProtocolVersion sysex code.

func (*Firmata) ReadString

func (f *Firmata) ReadString() <-chan string

func (*Firmata) ReportAnalog

func (f *Firmata) ReportAnalog(pin int, state int) error

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

func (*Firmata) ReportDigital

func (f *Firmata) ReportDigital(pin int, state int) error

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

func (*Firmata) Reset

func (f *Firmata) Reset() error

Reset sends the SystemReset sysex code.

func (*Firmata) SendString

func (f *Firmata) SendString(str string) error

func (*Firmata) ServoConfig

func (f *Firmata) ServoConfig(pin int, max int, min int) error

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

func (*Firmata) SetPinMode

func (f *Firmata) SetPinMode(pin int, mode int) error

SetPinMode sets the pin to mode.

type FirmataCommand

type FirmataCommand byte
const (
	DigitalMessage           FirmataCommand = 0x90
	DigitalMessageRangeStart FirmataCommand = 0x90
	DigitalMessageRangeEnd   FirmataCommand = 0x9F
	ReportAnalog             FirmataCommand = 0xC0
	ReportDigital            FirmataCommand = 0xD0
	AnalogMessage            FirmataCommand = 0xE0
	AnalogMessageRangeStart  FirmataCommand = 0xE0
	AnalogMessageRangeEnd    FirmataCommand = 0xEF
	StartSysex               FirmataCommand = 0xF0
	PinMode                  FirmataCommand = 0xF4
	EndSysex                 FirmataCommand = 0xF7
	ProtocolVersion          FirmataCommand = 0xF9
	SystemReset              FirmataCommand = 0xFF

Firmata commands

func (FirmataCommand) String

func (c FirmataCommand) String() string

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

type SerialPort

type SerialPort byte

type SysExCommand

type SysExCommand byte
const (
	Serial                SysExCommand = 0x60
	AnalogMappingQuery    SysExCommand = 0x69
	AnalogMappingResponse SysExCommand = 0x6A
	CapabilityQuery       SysExCommand = 0x6B
	CapabilityResponse    SysExCommand = 0x6C
	PinStateQuery         SysExCommand = 0x6D
	PinStateResponse      SysExCommand = 0x6E
	ServoConfig           SysExCommand = 0x70
	StringData            SysExCommand = 0x71
	ShiftData             SysExCommand = 0x75 // a bitstream to/from a shift register
	I2CRequest            SysExCommand = 0x76
	I2CReply              SysExCommand = 0x77
	I2CConfig             SysExCommand = 0x78
	FirmwareQuery         SysExCommand = 0x79
	SamplingInterval      SysExCommand = 0x7A // set the poll rate of the main loop
	SysExNonRealtime      SysExCommand = 0x7E // MIDI Reserved for non-realtime messages
	SysExRealtime         SysExCommand = 0x7F // MIDI Reserved for realtime messages
	SysExSPI              SysExCommand = 0x80

SysEx Commands

func (SysExCommand) String

func (c SysExCommand) String() string

Jump to

Keyboard shortcuts

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