fixed wrong led off/on register setting
This commit is contained in:
17
main.go
17
main.go
@@ -1,19 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"gen/ledd"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/op/go-logging"
|
||||
"golang.org/x/exp/io/i2c"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"encoding/binary"
|
||||
"gen/ledd"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
// CONSTANTS
|
||||
@@ -89,7 +88,7 @@ func (daemon *LedDaemon) receive() {
|
||||
switch msg := backendMsg.Msg.(type) {
|
||||
case *ledd.BackendWrapperMessage_MLedd:
|
||||
daemon.name = msg.MLedd.Name
|
||||
log.Infof("Connection with %s etablished; backend registered", msg.MLedd.Name)
|
||||
log.Infof("Connection with %s established; backend registered", msg.MLedd.Name)
|
||||
case *ledd.BackendWrapperMessage_MSetChannel:
|
||||
for c, v := range msg.MSetChannel.NewChannelValues {
|
||||
if c > CHANNEL {
|
||||
@@ -98,7 +97,7 @@ func (daemon *LedDaemon) receive() {
|
||||
}
|
||||
|
||||
vPerc := float64(v) / float64(RESOLUTION)
|
||||
vPerc = math.Pow(vPerc, 1/readConfig.Pca9685.Gamma)
|
||||
//vPerc = math.Pow(vPerc, 1/readConfig.Pca9685.Gamma)
|
||||
|
||||
if pwm, ok := pwmMap[c]; ok {
|
||||
pwm.setPercentage(float32(vPerc * 100))
|
||||
|
12
pca9685.go
12
pca9685.go
@@ -168,13 +168,11 @@ func (p *PCA9685) setAllPwm(on uint16, off uint16) {
|
||||
}
|
||||
|
||||
func (p *PCA9685) setPwm(pwm int, on uint16, off uint16) {
|
||||
onB := byte(on)
|
||||
offB := byte(off)
|
||||
|
||||
p.i2cBus.WriteReg(LED0_ON_L+byte(4)*byte(pwm), []byte{onB & 0xF0})
|
||||
p.i2cBus.WriteReg(LED0_ON_H+byte(4)*byte(pwm), []byte{onB & 0x0F})
|
||||
p.i2cBus.WriteReg(LED0_OFF_L+byte(4)*byte(pwm), []byte{offB & 0xF0})
|
||||
p.i2cBus.WriteReg(LED0_OFF_H+byte(4)*byte(pwm), []byte{offB & 0x0F})
|
||||
p.i2cBus.WriteReg(LED0_ON_H+byte(4)*byte(pwm), []byte{byte(on >> 8)})
|
||||
p.i2cBus.WriteReg(LED0_ON_L+byte(4)*byte(pwm), []byte{byte(on & 0x00FF)})
|
||||
p.i2cBus.WriteReg(LED0_OFF_H+byte(4)*byte(pwm), []byte{byte(off >> 8)})
|
||||
p.i2cBus.WriteReg(LED0_OFF_L+byte(4)*byte(pwm), []byte{byte(off & 0x00FF)})
|
||||
}
|
||||
|
||||
func (pwm *Pwm) setPercentage(percentage float32) error {
|
||||
@@ -183,7 +181,7 @@ func (pwm *Pwm) setPercentage(percentage float32) error {
|
||||
}
|
||||
|
||||
pwm.pca.log.Info(fmt.Sprintf("Setting pwm #%v to %v%% at \"%v\" device.", pwm.pin, percentage, pwm.pca.name))
|
||||
pwm.pca.setPwm(pwm.pin, 0, uint16(percentage*float32(pwm.pca.maxPulse)))
|
||||
pwm.pca.setPwm(pwm.pin, 0, uint16((percentage/100)*float32(pwm.pca.maxPulse)))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
2
proto
2
proto
Submodule proto updated: b0f65bb09a...3d37eb67b3
Reference in New Issue
Block a user