Exemple #1
0
// Close stops the controller and resets mode and pwm controller registers.
func (d *PCA9685) Close() error {
	if err := d.setup(); err != nil {
		return err
	}

	if err := d.sleep(); err != nil {
		return err
	}

	glog.V(1).Infof("pca9685: reset request received")

	if err := d.Bus.WriteByteToReg(d.Addr, mode1RegAddr, 0x00); err != nil {
		return err
	}

	glog.V(1).Infof("pca9685: cleaning up all PWM control registers")

	for regAddr := 0x06; regAddr <= 0x45; regAddr++ {
		if err := d.Bus.WriteByteToReg(d.Addr, byte(regAddr), 0x00); err != nil {
			return err
		}
	}

	if glog.V(1) {
		glog.Infof("pca9685: done Cleaning up all PWM control registers")
		glog.Infof("pca9685: controller reset")
	}

	return nil
}
Exemple #2
0
func (d *PCA9685) sleep() error {
	glog.V(1).Infof("pca9685: sleep request received")

	mode1Reg, err := d.mode1Reg()
	if err != nil {
		return err
	}
	sleepmode := (mode1Reg & 0x7F) | 0x10
	if err := d.Bus.WriteByteToReg(d.Addr, mode1RegAddr, sleepmode); err != nil {
		return err
	}
	if glog.V(1) {
		glog.Infof("pca9685: sleep mode [%#02x] written to MODE1 Reg [regAddr: %#02x]", sleepmode, mode1RegAddr)
		glog.Infoln("pca9685: controller set to Sleep mode")
	}

	return nil
}
Exemple #3
0
func (d *BMP085) calibrate() error {
	d.cmu.RLock()
	if d.calibrated {
		d.cmu.RUnlock()
		return nil
	}
	d.cmu.RUnlock()

	d.cmu.Lock()
	defer d.cmu.Unlock()

	readInt16 := func(reg byte) (int16, error) {
		v, err := d.Bus.ReadWordFromReg(address, reg)
		if err != nil {
			return 0, err
		}
		return int16(v), nil
	}

	readUInt16 := func(reg byte) (uint16, error) {
		v, err := d.Bus.ReadWordFromReg(address, reg)
		if err != nil {
			return 0, err
		}
		return uint16(v), nil
	}

	var err error
	d.ac1, err = readInt16(calAc1)
	if err != nil {
		return err
	}
	d.ac2, err = readInt16(calAc2)
	if err != nil {
		return err
	}
	d.ac3, err = readInt16(calAc3)
	if err != nil {
		return err
	}
	d.ac4, err = readUInt16(calAc4)
	if err != nil {
		return err
	}
	d.ac5, err = readUInt16(calAc5)
	if err != nil {
		return err
	}
	d.ac6, err = readUInt16(calAc6)
	if err != nil {
		return err
	}
	d.b1, err = readInt16(calB1)
	if err != nil {
		return err
	}
	d.b2, err = readInt16(calB2)
	if err != nil {
		return err
	}
	d.mb, err = readInt16(calMB)
	if err != nil {
		return err
	}
	d.mc, err = readInt16(calMC)
	if err != nil {
		return err
	}
	d.md, err = readInt16(calMD)
	if err != nil {
		return err
	}

	d.calibrated = true

	if glog.V(1) {
		glog.Info("bmp085: calibration data retrieved")
		glog.Infof("bmp085: param AC1 = %v", d.ac1)
		glog.Infof("bmp085: param AC2 = %v", d.ac2)
		glog.Infof("bmp085: param AC3 = %v", d.ac3)
		glog.Infof("bmp085: param AC4 = %v", d.ac4)
		glog.Infof("bmp085: param AC5 = %v", d.ac5)
		glog.Infof("bmp085: param AC6 = %v", d.ac6)
		glog.Infof("bmp085: param B1 = %v", d.b1)
		glog.Infof("bmp085: param B2 = %v", d.b2)
		glog.Infof("bmp085: param MB = %v", d.mb)
		glog.Infof("bmp085: param MC = %v", d.mc)
		glog.Infof("bmp085: param MD = %v", d.md)
	}

	return nil
}