コード例 #1
0
ファイル: nunchuck.go プロジェクト: FyIoT/hwio
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)

	// instead of the common 0x40 -> 0x00 initialization, we
	// use 0xF0 -> 0x55 followed by 0xFB -> 0x00.
	// this lets us use 3rd party nunchucks (like cheap $4 ebay ones)
	// while still letting us use official oness.
	// see http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1264805255

	e := device.WriteByte(0xF0, 0x55) // first config register
	if e != nil {
		return nil, e
	}

	hwio.Delay(1)

	e = device.WriteByte(0xFB, 0x00) // second config register
	if e != nil {
		return nil, e
	}

	return n, nil
}
コード例 #2
0
ファイル: hd44780_i2c.go プロジェクト: FyIoT/hwio
func NewHD44780Extended(module hwio.I2CModule, address int, en int, rw int, rs int, d4 int, d5 int, d6 int, d7 int, bl int, polarity int) *HD44780 {
	device := module.GetDevice(address)
	result := &HD44780{
		device:     device,
		d7:         1 << uint16(d7),
		d6:         1 << uint16(d6),
		d5:         1 << uint16(d5),
		d4:         1 << uint16(d4),
		bl:         1 << uint16(bl),
		en:         1 << uint16(en),
		rs:         1 << uint16(rs),
		rw:         1 << uint16(rw),
		blPolarity: polarity}

	return result
}
コード例 #3
0
ファイル: mcp23017.go プロジェクト: FyIoT/hwio
// Create a new isntance, and set it to use Bank 0. The address can either be what is wired on
// (A2,A1,A0) of the physical device, in which case this is added to the base address for the device
// (0x20). Otherwise, you can use 0x20-0x27. Anything else will return an error.
func NewMCP23017(module hwio.I2CModule, address int) (*MCP23017, error) {
	if address < 8 {
		address += DEFAULT_BASE_ADDRESS
	}

	if address < 0x20 || address > 0x27 {
		return nil, fmt.Errorf("Device address %d is invalid for an MCP23017. It must be in the range 0x20-0x27", address)
	}

	device := module.GetDevice(address)
	result := &MCP23017{device: device}

	// set config reg, force BANK=0, SEQOP=0. Note that this only works if already in BANK0, which is default on power-up
	device.WriteByte(REG_IOCON, 0)

	return result, nil
}
コード例 #4
0
ファイル: gy520.go プロジェクト: FyIoT/hwio
func NewGY520(module hwio.I2CModule) *GY520 {
	device := module.GetDevice(DEVICE_ADDRESS)
	result := &GY520{device: device}

	return result
}
コード例 #5
0
ファイル: bh1750fvi.go プロジェクト: FyIoT/hwio
// Create a new device, with i2c address specified. This can be used to access the device
// on a non-standard address, since it has an address bit.
func NewBH1750FVIAddr(module hwio.I2CModule, address int) *BH1750FVI {
	device := module.GetDevice(address)
	result := &BH1750FVI{device: device}

	return result
}
コード例 #6
0
ファイル: tmp102.go プロジェクト: vonwenm/hwio
func NewTMP102(module hwio.I2CModule) *TMP102 {
	device := module.GetDevice(DEVICE_ADDRESS)
	result := &TMP102{device: device}

	return result
}