fixed gamma correction formula

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

13
main.go
View File

@@ -35,7 +35,7 @@ type config struct {
Address int Address int
MinPulse uint16 MinPulse uint16
MaxPulse uint16 MaxPulse uint16
Gamma float64 Gamma float64
} }
} }
@@ -46,8 +46,8 @@ type LedDaemon struct {
} }
var log = logging.MustGetLogger("LedD") var log = logging.MustGetLogger("LedD")
var ledDaemon* LedDaemon var ledDaemon *LedDaemon
var pca9685* PCA9685 var pca9685 *PCA9685
var pwmMap map[int32]*Pwm var pwmMap map[int32]*Pwm
var readConfig config var readConfig config
@@ -97,13 +97,14 @@ func (daemon *LedDaemon) receive() {
continue 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 { if pwm, ok := pwmMap[c]; ok {
pwm.setPercentage(float32(v) / RESOLUTION * 100) pwm.setPercentage(float32(vPerc * 100))
} else { } else {
pwmMap[c] = pca9685.NewPwm(int(c)) pwmMap[c] = pca9685.NewPwm(int(c))
pwmMap[c].setPercentage(float32(v) / RESOLUTION * 100) pwmMap[c].setPercentage(float32(vPerc * 100))
} }
} }
} }