func (i2c *I2C) ReadUint8() (result uint8, err error) {
	_, err = i2c.smbusAccess(C.I2C_SMBUS_READ, 0, C.I2C_SMBUS_BYTE, unsafe.Pointer(&result))
	if err != nil {
		return 0, wrapErr("ReadUint8", err)
	}
	return 0xFF & result, nil
}
ReadUint8 reads a single byte from a device, without specifying a device
register. Some devices are so simple that this interface is enough; for
others, it is a shorthand if you want to read the same register as in
the previous SMBus command.
package i2c
import "C"
import (
	"fmt"
	"os"
	"syscall"
	"unsafe"
)
func SwapBytes(word uint16) uint16 {
	return word<<8 | word>>8
}
type Err struct {
	method string
	cause  error
}
func (err Err) Error() string {
	return fmt.Sprintf("I2C.%s error: %s", err.method, err.cause)
}
func wrapErr(method string, err error) error {
	if err == nil {
		return nil
	}
	if e, ok := err.(Err); ok {
		e.method = method
		return e
	}
	return Err{method, err}
}
type I2C struct {
	file    *os.File
	address int
}
func NewI2C(bus, address int) (*I2C, error) {
	filename := fmt.Sprintf("/dev/i2c-%d", bus)
	file, err := os.OpenFile(filename, os.O_RDWR, 0)
	if err != nil {
		return nil, err
	}
	i2c := &I2C{file: file, address: -1}
	err = i2c.SetAddress(address)
	if err != nil {
		file.Close()
		return nil, err
	}
	return i2c, nil
}
func (i2c *I2C) Close() error {
	return wrapErr("Close", i2c.file.Close())
}
func (i2c *I2C) Address() int {
	return i2c.address
}
func (i2c *I2C) SetAddress(address int) error {
	if address != i2c.address {
		result, _, errno := syscall.Syscall(syscall.SYS_IOCTL, i2c.file.Fd(), C.I2C_SLAVE, uintptr(address))
		if result != 0 {
			return Err{"SetAddress", errno}
		}
		i2c.address = address
	}
	return nil
}
func (i2c *I2C) smbusAccess(readWrite, register uint8, size int, data unsafe.Pointer) (uintptr, error) {
	args := C.struct_i2c_smbus_ioctl_data{
		read_write: C.char(readWrite),
		command:    C.__u8(register),
		size:       C.int(size),
		data:       (*C.union_i2c_smbus_data)(data),
	}
	result, _, errno := syscall.Syscall(syscall.SYS_IOCTL, i2c.file.Fd(), C.I2C_SMBUS, uintptr(unsafe.Pointer(&args)))
	if int(result) == -1 {
		return 0, errno
	}
	return result, nil
}
func (i2c *I2C) WriteQuick(value uint8) error {
	_, err := i2c.smbusAccess(value, 0, C.I2C_SMBUS_QUICK, nil)
	return wrapErr("SetAddress", err)
}