1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 04:40:04 +01:00

pca9685: move pre scale calculation closer to usage

This commit is contained in:
Karan Misra 2014-01-10 07:35:21 +05:30
parent 6da275f5b4
commit a80a1701bf

View File

@ -60,11 +60,6 @@ func (d *PCA9685) setup() (err error) {
d.mu.Lock()
defer d.mu.Unlock()
preScaleValue := byte(math.Floor(float64(clockFreq/(pwmControlPoints*d.Freq))+float64(0.5)) - 1)
if d.Debug {
log.Printf("pca9685: calculated prescale value = %#02x", preScaleValue)
}
mode1Reg, err := d.mode1Reg()
if err != nil {
return
@ -77,6 +72,10 @@ func (d *PCA9685) setup() (err error) {
return
}
preScaleValue := byte(math.Floor(float64(clockFreq/(pwmControlPoints*d.Freq))+float64(0.5)) - 1)
if d.Debug {
log.Printf("pca9685: calculated prescale value = %#02x", preScaleValue)
}
if err = d.Bus.WriteByteToReg(d.Addr, preScaleRegAddr, byte(preScaleValue)); err != nil {
return
}