fixed gamma correction formula

This commit is contained in:
2018-06-29 09:59:48 +02:00
parent 5200fdb931
commit a37adc2a02

11
main.go
View File

@@ -46,8 +46,8 @@ type LedDaemon struct {
}
var log = logging.MustGetLogger("LedD")
var ledDaemon* LedDaemon
var pca9685* PCA9685
var ledDaemon *LedDaemon
var pca9685 *PCA9685
var pwmMap map[int32]*Pwm
var readConfig config
@@ -97,13 +97,14 @@ func (daemon *LedDaemon) receive() {
continue
}
v = int32(math.Min(math.Round(math.Pow(float64(v), readConfig.Pca9685.Gamma)), RESOLUTION))
vPerc := float64(v) / float64(RESOLUTION)
vPerc = math.Pow(vPerc, 1/readConfig.Pca9685.Gamma)
if pwm, ok := pwmMap[c]; ok {
pwm.setPercentage(float32(v) / RESOLUTION * 100)
pwm.setPercentage(float32(vPerc * 100))
} else {
pwmMap[c] = pca9685.NewPwm(int(c))
pwmMap[c].setPercentage(float32(v) / RESOLUTION * 100)
pwmMap[c].setPercentage(float32(vPerc * 100))
}
}
}