firmata

package module
v0.0.0-...-8d901bc Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2014 License: Apache-2.0 Imports: 7 Imported by: 0

README

go-firmata

Arduino Firmata client for golang

Documentation

Index

Constants

View Source
const (
	ProtocolMajorVersion = 2
	ProtocolMinorVersion = 3

	// max number of data bytes in non-Sysex messages
	MaxDataBytes = 32

	DigitalMessage     FirmataCommand = 0x90 // send data for a digital pin
	AnalogMessage      FirmataCommand = 0xE0 // send data for an analog pin (or PWM)
	EnableAnalogInput  FirmataCommand = 0xC0 // enable analog input by pin #
	EnableDigitalInput FirmataCommand = 0xD0 // enable digital input by port pair
	SetPinMode         FirmataCommand = 0xF4 // set a pin to INPUT/OUTPUT/PWM/etc
	ReportVersion      FirmataCommand = 0xF9 // report protocol version
	SystemReset        FirmataCommand = 0xFF // reset from MIDI
	StartSysEx         FirmataCommand = 0xF0 // start a MIDI Sysex message
	EndSysEx           FirmataCommand = 0xF7 // end a MIDI Sysex message

	// extended command set using sysex (0-127/0x00-0x7F)
	/* 0x00-0x0F reserved for user-defined commands */
	ServoConfig           SysExCommand = 0x70 // set max angle, minPulse, maxPulse, freq
	StringData            SysExCommand = 0x71 // a string message with 14-bits per char
	ShiftData             SysExCommand = 0x75 // a bitstream to/from a shift register
	I2CRequest            SysExCommand = 0x76 // send an I2C read/write request
	I2CReply              SysExCommand = 0x77 // a reply to an I2C read request
	I2CConfig             SysExCommand = 0x78 // config I2C settings such as delay times and power pins
	ExtendedAnalog        SysExCommand = 0x6F // analog write (PWM, Servo, etc) to any pin
	PinStateQuery         SysExCommand = 0x6D // ask for a pin's current mode and value
	PinStateResponse      SysExCommand = 0x6E // reply with pin's current mode and value
	CapabilityQuery       SysExCommand = 0x6B // ask for supported modes and resolution of all pins
	CapabilityResponse    SysExCommand = 0x6C // reply with supported modes and resolution
	AnalogMappingQuery    SysExCommand = 0x69 // ask for mapping of analog to pin numbers
	AnalogMappingResponse SysExCommand = 0x6A // reply with mapping info
	ReportFirmware        SysExCommand = 0x79 // report name and version of the firmware
	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
	Serial                SysExCommand = 0x60
	SysExSPI              SysExCommand = 0x80
	SysExOneWire          SysExCommand = 0x73 // Send a onewire request

	SerialConfig SerialSubCommand = 0x10
	SerialComm   SerialSubCommand = 0x20
	SerialFlush  SerialSubCommand = 0x30
	SerialClose  SerialSubCommand = 0x40

	SPIConfig SPISubCommand = 0x10
	SPIComm   SPISubCommand = 0x20

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

	OneWireConfig       OneWireSubCommand = 0x41
	OneWireSearch       OneWireSubCommand = 0x40
	OneWireSearchAlarms OneWireSubCommand = 0x44

	OneWirePowerNormal    = 0x0
	OneWirePowerParasitic = 0x1

	OW_RESET  = 0x1
	OW_SKIP   = 0x2
	OW_SELECT = 0x4
	OW_READ   = 0x8
	OW_DELAY  = 0x10
	OW_WRITE  = 0x20

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

	// pin modes
	Input  PinMode = 0x00
	Output PinMode = 0x01
	Analog PinMode = 0x02
	PWM    PinMode = 0x03
	Servo  PinMode = 0x04
	Shift  PinMode = 0x05
	I2C    PinMode = 0x06
	SPI    PinMode = 0x07
)

Variables

This section is empty.

Functions

func From7BitMulti

func From7BitMulti(data []byte) []byte

from7BitMulti converts 7 bit encoded data to 8 bit.

func OneWireCrc8

func OneWireCrc8(data []byte) byte

OneWireCrc8 calculates the 8 bit CRC of the data.

func To7BitMulti

func To7BitMulti(data []byte) []byte

to7BitMulti converts 8 bit encoded data to 7 bit.

Types

type Ds18x20

type Ds18x20 struct {
	// The client.
	Client *FirmataClient
	// The pin the bus is on.
	Pin byte
	// The address of the device on the bus.
	Address OneWireAddress

	// Latest temperature reading.
	Temperature float32
	// The TH register.
	RegisterTh byte
	// The TL register.
	RegisterTl byte
	// The config register.
	ConfigRegister byte
	// contains filtered or unexported fields
}

Ds18x20 is a Maxim DS1820 or DS18B20 device.

func (*Ds18x20) ConvertT

func (d *Ds18x20) ConvertT(all bool) error

ConvertT initiates a temperature conversion.

func (*Ds18x20) GetResolution

func (d *Ds18x20) GetResolution() byte

GetResolution gets the device temperature resolution in bits.

func (*Ds18x20) ReadScratchPad

func (d *Ds18x20) ReadScratchPad() error

ReadScratchPad reads the device scratchpad.

func (*Ds18x20) Resolution

func (d *Ds18x20) Resolution(r byte) error

Resolution sets the thermometer resolution, in bits.

type FirmataClient

type FirmataClient struct {
	Log *log4go.Logger
	// contains filtered or unexported fields
}

Arduino Firmata client for golang

func NewClient

func NewClient(dev string, baud int, ch chan FirmataValue) (client *FirmataClient, err error)

Creates a new FirmataClient object and connects to the Arduino board over specified serial port. This function blocks till a connection is succesfullt established and pin mappings are retrieved.

func (*FirmataClient) AnalogWrite

func (c *FirmataClient) AnalogWrite(pin uint, pinData byte) (err error)

Set the value of a analog pin

func (*FirmataClient) Close

func (c *FirmataClient) Close()

Close the serial connection to properly clean up after ourselves Usage: defer client.Close()

func (*FirmataClient) DigitalWrite

func (c *FirmataClient) DigitalWrite(pin uint, val bool) (err error)

Set the value of a digital pin

func (*FirmataClient) EnableAnalogInput

func (c *FirmataClient) EnableAnalogInput(pin uint, val bool) (err error)

Specified if a analog Pin should be watched for input. Values will be streamed back over a channel which can be retrieved by the GetValues() call

func (*FirmataClient) EnableDigitalInput

func (c *FirmataClient) EnableDigitalInput(pin uint, val bool) (err error)

Specified if a digital Pin should be watched for input. Values will be streamed back over a channel which can be retrieved by the GetValues() call

func (*FirmataClient) GetSerialData

func (c *FirmataClient) GetSerialData() <-chan string

Get channel for incoming serial data

func (*FirmataClient) GetValues

func (c *FirmataClient) GetValues() <-chan FirmataValue

Get the channel to retrieve analog and digital pin values

func (*FirmataClient) OneWireCommand

func (c *FirmataClient) OneWireCommand(csPin byte, request OneWireRequest) ([]byte, error)

OneWireCommand initiates a command on the OneWire bus.

func (*FirmataClient) OneWireConfig

func (c *FirmataClient) OneWireConfig(csPin byte, owPowerMode byte) (err error)

OneWireConfig configures a pin as a OneWire interface.

func (*FirmataClient) OneWireSearch

func (c *FirmataClient) OneWireSearch(csPin byte, owSearchMode OneWireSubCommand) (addresses []OneWireAddress, err error)

OneWireSearch initiates a search on the OneWire bus.

func (*FirmataClient) SPIConfig

func (c *FirmataClient) SPIConfig(csPin byte, spiMode byte) (err error)

Enable SPI communication for selected chip-select pin

func (*FirmataClient) SPIReadWrite

func (c *FirmataClient) SPIReadWrite(csPin byte, data []byte) (dataOut []byte, err error)

Read and write data to SPI device

func (*FirmataClient) SerialConfig

func (c *FirmataClient) SerialConfig(port SerialPort, baud int, txPin byte, rxPin byte) (err error)

Configure a builtin or soft serial port. This command must be called before sending serial data. Set txPin and rxPin to 0x00 for builtin serial ports.

func (*FirmataClient) ServoConfig

func (c *FirmataClient) ServoConfig(pin byte, minPulse int16, maxPulse int16) error

ServoConfig configures servo parameters for the given pin.

func (*FirmataClient) SetAnalogSamplingInterval

func (c *FirmataClient) SetAnalogSamplingInterval(ms byte) (err error)

Sets the polling interval in milliseconds for analog pin samples

func (*FirmataClient) SetPinMode

func (c *FirmataClient) SetPinMode(pin byte, mode PinMode) (err error)

Sets the Pin mode (input, output, etc.) for the Arduino pin

type FirmataCommand

type FirmataCommand byte

func (FirmataCommand) String

func (c FirmataCommand) String() string

type FirmataValue

type FirmataValue struct {
	// contains filtered or unexported fields
}

func (FirmataValue) GetAnalogValue

func (v FirmataValue) GetAnalogValue() (pin int, val int, err error)

func (FirmataValue) GetDigitalValue

func (v FirmataValue) GetDigitalValue() (port byte, val map[byte]interface{}, err error)

func (FirmataValue) IsAnalog

func (v FirmataValue) IsAnalog() bool

func (FirmataValue) String

func (v FirmataValue) String() string

type OneWireAddress

type OneWireAddress []byte

OneWireAddress is a ROM address.

type OneWireRequest

type OneWireRequest struct {
	// Command is the command to send to the Firmata firmware.
	Command OneWireSubCommand
	// Address is the ROM address for the 1wire device.
	Address OneWireAddress
	// ReadCount is the number of bytes to read from a device.
	ReadCount int32
	// CorrelationId is the unique ID for the request.
	CorrelationId int32
	// DelayMs is a delay to send prior to the command executing.
	DelayMs int32
	// Data is the data to send to the device.
	Data []byte
}

A OneWireRequest is a Firmata OneWire request.

func (*OneWireRequest) Encode

func (r *OneWireRequest) Encode() []byte

Encode encodes the request to 7 bit data ready to send on the wire.

type OneWireSubCommand

type OneWireSubCommand byte

OneWireSubCommand is the command to send to the device.

type PinMode

type PinMode byte

func (PinMode) String

func (m PinMode) String() string

type SPISubCommand

type SPISubCommand byte

type SerialPort

type SerialPort byte

type SerialSubCommand

type SerialSubCommand byte

type SysExCommand

type SysExCommand byte

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