36 lines
606 B
Go
36 lines
606 B
Go
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
|
|
}
|