feat(ezcoo): serial driver for EZCOO HDMI matrix
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package ezcoo
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Port string `yaml:"port"`
|
||||
Baud int `yaml:"baud"`
|
||||
PollInterval time.Duration `yaml:"poll_interval"`
|
||||
}
|
||||
|
||||
func (c *Config) SetDefaults() {
|
||||
if c.Port == "" {
|
||||
c.Port = "/dev/ttyACM0"
|
||||
}
|
||||
if c.Baud == 0 {
|
||||
c.Baud = 57600
|
||||
}
|
||||
if c.PollInterval == 0 {
|
||||
c.PollInterval = 15 * time.Second
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Config) Validate() error {
|
||||
if c.Port == "" {
|
||||
return errors.New("device.port is required")
|
||||
}
|
||||
if c.Baud <= 0 {
|
||||
return fmt.Errorf("device.baud must be positive, got %d", c.Baud)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user