mirror of
https://github.com/kidoman/embd
synced 2024-12-22 12:50:19 +01:00
pca9685: move pre scale calculation closer to usage
This commit is contained in:
parent
6da275f5b4
commit
a80a1701bf
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user