Browse Source

changed default values to match testign env for now; added gamma correction

master
Giovanni Harting 1 year ago
parent
commit
5200fdb931
2 changed files with 16 additions and 11 deletions
  1. +3
    -2
      config.yaml
  2. +13
    -9
      main.go

+ 3
- 2
config.yaml View File

@@ -3,7 +3,8 @@ ledd:
host: "127.0.0.1"
port: 5640
pca9685:
device: "dev/i2c-2"
address: 0x40
device: "/dev/i2c-1"
address: 0x44
minpulse: 0
maxpulse: 4095
gamma: 2.2

+ 13
- 9
main.go View File

@@ -13,6 +13,7 @@ import (
"gen/ledd"
"github.com/golang/protobuf/proto"
"fmt"
"math"
)

// CONSTANTS
@@ -34,6 +35,7 @@ type config struct {
Address int
MinPulse uint16
MaxPulse uint16
Gamma float64
}
}

@@ -44,9 +46,10 @@ type LedDaemon struct {
}

var log = logging.MustGetLogger("LedD")
var ledDaemon = &LedDaemon{}
var pca9685 = &PCA9685{}
var pwmMap = map[int32]*Pwm{}
var ledDaemon* LedDaemon
var pca9685* PCA9685
var pwmMap map[int32]*Pwm
var readConfig config

func check(e error) {
if e != nil {
@@ -94,6 +97,8 @@ func (daemon *LedDaemon) receive() {
continue
}

v = int32(math.Min(math.Round(math.Pow(float64(v), readConfig.Pca9685.Gamma)), RESOLUTION))

if pwm, ok := pwmMap[c]; ok {
pwm.setPercentage(float32(v) / RESOLUTION * 100)
} else {
@@ -131,24 +136,23 @@ func main() {
signal.Notify(killSignals, syscall.SIGINT, syscall.SIGTERM)

log.Info("LedD PCA9685 backend", VERSION)
config := config{}

content, err := ioutil.ReadFile("config.yaml")
check(err)

err = yaml.Unmarshal(content, &config)
err = yaml.Unmarshal(content, &readConfig)
check(err)

i2cDevice, err := i2c.Open(&i2c.Devfs{Dev: config.Pca9685.Device}, config.Pca9685.Address)
i2cDevice, err := i2c.Open(&i2c.Devfs{Dev: readConfig.Pca9685.Device}, readConfig.Pca9685.Address)
check(err)
defer i2cDevice.Close()

pca9685 = createPCA9685(i2cDevice, config.Name, config.Pca9685.MinPulse, config.Pca9685.MaxPulse, logging.MustGetLogger("PCA9685"))
pca9685 = createPCA9685(i2cDevice, readConfig.Name, readConfig.Pca9685.MinPulse, readConfig.Pca9685.MaxPulse, logging.MustGetLogger("PCA9685"))
pca9685.Init()

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", readConfig.Ledd.Host, readConfig.Ledd.Port))
check(err)

ledDaemon = &LedDaemon{
@@ -163,7 +167,7 @@ func main() {
wrapperMsg := &ledd.BackendWrapperMessage{
Msg: &ledd.BackendWrapperMessage_MBackend{
MBackend: &ledd.Backend{
Name: config.Name,
Name: readConfig.Name,
Channel: CHANNEL,
Type: "PCA9685",
Resolution: RESOLUTION,


Loading…
Cancel
Save