added more debug out and channel max logic

This commit is contained in:
2018-06-29 08:04:27 +02:00
parent 1cd57c829e
commit 7732a05cac

10
main.go
View File

@@ -18,7 +18,7 @@ import (
// CONSTANTS // CONSTANTS
const VERSION = "0.1" const VERSION = "0.1"
const RESOLUTION = 4096 const RESOLUTION = 4095
const CHANNEL = 16 const CHANNEL = 16
// STRUCTS // STRUCTS
@@ -88,7 +88,13 @@ func (daemon *LedDaemon) receive() {
daemon.name = msg.MLedd.Name daemon.name = msg.MLedd.Name
log.Infof("Connection with %s etablished; backend registered", msg.MLedd.Name) log.Infof("Connection with %s etablished; backend registered", msg.MLedd.Name)
case *ledd.BackendWrapperMessage_MSetChannel: case *ledd.BackendWrapperMessage_MSetChannel:
log.Debug(msg.MSetChannel.NewChannelValues)
for c, v := range msg.MSetChannel.NewChannelValues { for c, v := range msg.MSetChannel.NewChannelValues {
if c > CHANNEL {
log.Warningf("[%s] Channel index %d is higher then this device's max channel index %d. Skipping.", daemon.name, c, CHANNEL)
continue
}
if pwm, ok := pwmMap[c]; ok { if pwm, ok := pwmMap[c]; ok {
pwm.setPercentage(float32(v) / RESOLUTION * 100) pwm.setPercentage(float32(v) / RESOLUTION * 100)
} else { } else {
@@ -141,7 +147,7 @@ func main() {
pca9685 = createPCA9685(i2cDevice, config.Name, config.Pca9685.MinPulse, config.Pca9685.MaxPulse, logging.MustGetLogger("PCA9685")) pca9685 = createPCA9685(i2cDevice, config.Name, config.Pca9685.MinPulse, config.Pca9685.MaxPulse, logging.MustGetLogger("PCA9685"))
pca9685.Init() pca9685.Init()
pwmMap = make(map[int32]*Pwm, 1) pwmMap = make(map[int32]*Pwm, 0)
conn, err := net.Dial("tcp4", fmt.Sprintf("%s:%d", config.Ledd.Host, config.Ledd.Port)) conn, err := net.Dial("tcp4", fmt.Sprintf("%s:%d", config.Ledd.Host, config.Ledd.Port))
check(err) check(err)