func (c *ChipAdaptor) I2cRead(address int, size int) (data []byte, err error) {
	if err = c.i2cDevice.SetAddress(address); err != nil {
		return
	}
	data = make([]byte, size)
	_, err = c.i2cDevice.Read(data)
	return
}
I2cRead returns value from i2c device using specified size
package chip
import (
	"errors"
	"github.com/hybridgroup/gobot/sysfs"
)
type ChipAdaptor struct {
	name        string
	digitalPins map[int]sysfs.DigitalPin
	i2cDevice   sysfs.I2cDevice
}
var pins = map[string]int{
	"XIO-P0": 408,
	"XIO-P1": 409,
	"XIO-P2": 410,
	"XIO-P3": 411,
	"XIO-P4": 412,
	"XIO-P5": 413,
	"XIO-P6": 414,
	"XIO-P7": 415,
}
func NewChipAdaptor(name string) *ChipAdaptor {
	c := &ChipAdaptor{
		name:        name,
		digitalPins: make(map[int]sysfs.DigitalPin),
	}
	return c
}
func (c *ChipAdaptor) Name() string { return c.name }
func (c *ChipAdaptor) Connect() (errs []error) {
	return
}
func (c *ChipAdaptor) Finalize() (errs []error) {
	for _, pin := range c.digitalPins {
		if pin != nil {
			if err := pin.Unexport(); err != nil {
				errs = append(errs, err)
			}
		}
	}
	if c.i2cDevice != nil {
		if err := c.i2cDevice.Close(); err != nil {
			errs = append(errs, err)
		}
	}
	return errs
}
func (c *ChipAdaptor) translatePin(pin string) (i int, err error) {
	if val, ok := pins[pin]; ok {
		i = val
	} else {
		err = errors.New("Not a valid pin")
	}
	return
}
func (c *ChipAdaptor) digitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPin, err error) {
	i, err := c.translatePin(pin)
	if err != nil {
		return
	}
	if c.digitalPins[i] == nil {
		c.digitalPins[i] = sysfs.NewDigitalPin(i)
		if err = c.digitalPins[i].Export(); err != nil {
			return
		}
	}
	if err = c.digitalPins[i].Direction(dir); err != nil {
		return
	}
	return c.digitalPins[i], nil
}
func (c *ChipAdaptor) DigitalRead(pin string) (val int, err error) {
	sysfsPin, err := c.digitalPin(pin, sysfs.IN)
	if err != nil {
		return
	}
	return sysfsPin.Read()
}
func (c *ChipAdaptor) DigitalWrite(pin string, val byte) (err error) {
	sysfsPin, err := c.digitalPin(pin, sysfs.OUT)
	if err != nil {
		return err
	}
	return sysfsPin.Write(int(val))
}
func (c *ChipAdaptor) I2cStart(address int) (err error) {
	if c.i2cDevice == nil {
		c.i2cDevice, err = sysfs.NewI2cDevice("/dev/i2c-1", address)
	}
	return err
}
func (c *ChipAdaptor) I2cWrite(address int, data []byte) (err error) {
	if err = c.i2cDevice.SetAddress(address); err != nil {
		return
	}
	_, err = c.i2cDevice.Write(data)
	return
}