func (n *Nunchuck) CalibrateJoystick() {
	n.SetJoystickZero(n.lastJoyX, n.lastJoyY)
}
Calibrate the joystick to the most recently read values.
package nunchuck
import (
	"fmt"
	"github.com/mrmorphic/hwio"
	"math"
)
const (
	DEVICE_ADDRESS = 0x52
	DEFAULT_JOYSTICK_ZERO_X = 124
	DEFAULT_JOYSTICK_ZERO_Y = 132
	DEFAULT_ACCEL_ZEROX = 0.0
	DEFAULT_ACCEL_ZEROY = 0.0
	DEFAULT_ACCEL_ZEROZ = 0.0
	RADIUS = 210
)
type Nunchuck struct {
	device     hwio.I2CDevice
	zeroJoyX   int
	zeroJoyY   int
	zeroAccelX float32
	zeroAccelY float32
	zeroAccelZ float32
	lastJoyX     int
	lastJoyY     int
	lastAccelX   float32
	lastAccelY   float32
	lastAccelZ   float32
	lastZPressed bool
	lastCPressed bool
}
func NewNunchuck(module hwio.I2CModule) (*Nunchuck, error) {
	device := module.GetDevice(DEVICE_ADDRESS)
	n := &Nunchuck{device: device}
	n.SetJoystickZero(DEFAULT_JOYSTICK_ZERO_X, DEFAULT_JOYSTICK_ZERO_Y)
	n.SetAccelZero(DEFAULT_ACCEL_ZEROX, DEFAULT_ACCEL_ZEROY, DEFAULT_ACCEL_ZEROZ)
	e := device.WriteByte(0xF0, 0x55)  
	if e != nil {
		return nil, e
	}
	hwio.Delay(1)
	e = device.WriteByte(0xFB, 0x00)  
	if e != nil {
		return nil, e
	}
	return n, nil
}
func (n *Nunchuck) ReadSensors() error {
	bytes, e := n.device.Read(0, 6)
	if e != nil {
		return e
	}
	if len(bytes) < 6 {
		return fmt.Errorf("Error getting nunchuck data, expected 6 bytes but got %d", len(bytes))
	}
	n.lastJoyX = int(bytes[0])
	n.lastJoyY = int(bytes[1])
	ax := int(int8(bytes[2]<<2)) | int((bytes[5]>>2)&3)
	ay := int(int8(bytes[3]<<2)) | int((bytes[5]>>4)&3)
	az := int(int8(bytes[4]<<2)) | int((bytes[5]>>6)&3)
	n.lastAccelX = float32(ax) - n.zeroAccelX
	n.lastAccelY = float32(ay) - n.zeroAccelY
	n.lastAccelZ = float32(az) - n.zeroAccelZ
	n.lastZPressed = true
	if bytes[5]&1 > 0 {
		n.lastZPressed = false
	}
	n.lastCPressed = true
	if bytes[5]&2 > 0 {
		n.lastCPressed = false
	}
	return nil
}