func (f *FirmataAdaptor) I2cRead(address int, size int) (data []byte, err error) {
	ret := make(chan []byte)
	if err = f.board.I2cRead(address, size); err != nil {
		return
	}
	f.Once(f.board.Event("I2cReply"), func(data interface{}) {
		ret <- data.(client.I2cReply).Data
	})
	data = <-ret
	return
}
I2cRead returns size bytes from the i2c device
Returns an empty array if the response from the board has timed out
package firmata
import (
	"io"
	"strconv"
	"time"
	"github.com/hybridgroup/gobot"
	"github.com/hybridgroup/gobot/platforms/firmata/client"
	"github.com/tarm/goserial"
)
type firmataBoard interface {
	Connect(io.ReadWriteCloser) error
	Disconnect() error
	Pins() []client.Pin
	AnalogWrite(int, int) error
	SetPinMode(int, int) error
	ReportAnalog(int, int) error
	ReportDigital(int, int) error
	DigitalWrite(int, int) error
	I2cRead(int, int) error
	I2cWrite(int, []byte) error
	I2cConfig(int) error
	ServoConfig(int, int, int) error
	Event(string) string
}
type FirmataAdaptor struct {
	name   string
	port   string
	board  firmataBoard
	conn   io.ReadWriteCloser
	openSP func(port string) (io.ReadWriteCloser, error)
	gobot.Eventer
}
func NewFirmataAdaptor(name string, args ...interface{}) *FirmataAdaptor {
	f := &FirmataAdaptor{
		name:  name,
		port:  "",
		conn:  nil,
		board: client.New(),
		openSP: func(port string) (io.ReadWriteCloser, error) {
			return serial.OpenPort(&serial.Config{Name: port, Baud: 57600})
		},
		Eventer: gobot.NewEventer(),
	}
	for _, arg := range args {
		switch arg.(type) {
		case string:
			f.port = arg.(string)
		case io.ReadWriteCloser:
			f.conn = arg.(io.ReadWriteCloser)
		}
	}
	return f
}
func (f *FirmataAdaptor) Connect() (errs []error) {
	if f.conn == nil {
		sp, err := f.openSP(f.Port())
		if err != nil {
			return []error{err}
		}
		f.conn = sp
	}
	if err := f.board.Connect(f.conn); err != nil {
		return []error{err}
	}
	return
}
func (f *FirmataAdaptor) Disconnect() (err error) {
	if f.board != nil {
		return f.board.Disconnect()
	}
	return nil
}
func (f *FirmataAdaptor) Finalize() (errs []error) {
	if err := f.Disconnect(); err != nil {
		return []error{err}
	}
	return
}
func (f *FirmataAdaptor) Port() string { return f.port }
func (f *FirmataAdaptor) Name() string { return f.name }
func (f *FirmataAdaptor) ServoConfig(pin string, min, max int) error {
	p, err := strconv.Atoi(pin)
	if err != nil {
		return err
	}
	return f.board.ServoConfig(p, max, min)
}
func (f *FirmataAdaptor) ServoWrite(pin string, angle byte) (err error) {
	p, err := strconv.Atoi(pin)
	if err != nil {
		return err
	}
	if f.board.Pins()[p].Mode != client.Servo {
		err = f.board.SetPinMode(p, client.Servo)
		if err != nil {
			return err
		}
	}
	err = f.board.AnalogWrite(p, int(angle))
	return
}
func (f *FirmataAdaptor) PwmWrite(pin string, level byte) (err error) {
	p, err := strconv.Atoi(pin)
	if err != nil {
		return err
	}
	if f.board.Pins()[p].Mode != client.Pwm {
		err = f.board.SetPinMode(p, client.Pwm)
		if err != nil {
			return err
		}
	}
	err = f.board.AnalogWrite(p, int(level))
	return
}
func (f *FirmataAdaptor) DigitalWrite(pin string, level byte) (err error) {
	p, err := strconv.Atoi(pin)
	if err != nil {
		return
	}
	if f.board.Pins()[p].Mode != client.Output {
		err = f.board.SetPinMode(p, client.Output)
		if err != nil {
			return
		}
	}
	err = f.board.DigitalWrite(p, int(level))
	return
}
func (f *FirmataAdaptor) DigitalRead(pin string) (val int, err error) {
	p, err := strconv.Atoi(pin)
	if err != nil {
		return
	}
	if f.board.Pins()[p].Mode != client.Input {
		if err = f.board.SetPinMode(p, client.Input); err != nil {
			return
		}
		if err = f.board.ReportDigital(p, 1); err != nil {
			return
		}
		<-time.After(10 * time.Millisecond)
	}
	return f.board.Pins()[p].Value, nil
}
func (f *FirmataAdaptor) AnalogRead(pin string) (val int, err error) {
	p, err := strconv.Atoi(pin)
	if err != nil {
		return
	}
	p = f.digitalPin(p)
	if f.board.Pins()[p].Mode != client.Analog {
		if err = f.board.SetPinMode(p, client.Analog); err != nil {
			return
		}
		if err = f.board.ReportAnalog(p, 1); err != nil {
			return
		}
		<-time.After(10 * time.Millisecond)
	}
	return f.board.Pins()[p].Value, nil
}
func (f *FirmataAdaptor) digitalPin(pin int) int {
	return pin + 14
}
func (f *FirmataAdaptor) I2cStart(address int) (err error) {
	return f.board.I2cConfig(0)
}