Example #1
0
File: gy520.go Project: FyIoT/hwio
func (g *GY520) GetGyro() (gyroX int, gyroY int, gyroZ int, e error) {
	buffer, e := g.device.Read(REG_GYRO_XOUT_H, 6)
	if e != nil {
		return 0, 0, 0, e
	}

	gyroX = int(int16(hwio.UInt16FromUInt8(buffer[0], buffer[1])))
	gyroY = int(int16(hwio.UInt16FromUInt8(buffer[2], buffer[3])))
	gyroZ = int(int16(hwio.UInt16FromUInt8(buffer[4], buffer[5])))

	return gyroX, gyroY, gyroZ, nil
}
Example #2
0
File: gy520.go Project: FyIoT/hwio
func (g *GY520) GetAccel() (accelX int, accelY int, accelZ int, e error) {
	buffer, e := g.device.Read(REG_ACCEL_XOUT_H, 6)
	if e != nil {
		return 0, 0, 0, e
	}

	accelX = int(int16(hwio.UInt16FromUInt8(buffer[0], buffer[1])))
	accelY = int(int16(hwio.UInt16FromUInt8(buffer[2], buffer[3])))
	accelZ = int(int16(hwio.UInt16FromUInt8(buffer[4], buffer[5])))

	return accelX, accelY, accelZ, nil
}
Example #3
0
File: gy520.go Project: FyIoT/hwio
func (g *GY520) GetTemp() (int, error) {
	buffer, e := g.device.Read(REG_TEMP_OUT_H, 2)
	if e != nil {
		return 0, e
	}

	return int(int16(hwio.UInt16FromUInt8(buffer[0], buffer[1]))), nil
}