Files
groundstation/internal/config/config.go
T
piotr bb178eff6d
Build Ground Station / build (push) Successful in 23s
feat: add UART reconnect and configurable channel logging
2026-09-30 10:30:01 +02:00

50 lines
946 B
Go

package config
import (
"os"
"gopkg.in/yaml.v3"
)
type Config struct {
Serial struct {
Path string `yaml:"path"`
} `yaml:"serial"`
Video struct {
Enabled bool `yaml:"enabled"`
AuxIndex int `yaml:"aux_index"`
Threshold int16 `yaml:"threshold"`
Command string `yaml:"command"`
} `yaml:"video"`
Logging struct {
Enabled bool `yaml:"enabled"`
Path string `yaml:"path"`
} `yaml:"logging"`
}
func Default() Config {
var c Config
c.Serial.Path = "/dev/ttyS0"
c.Video.Enabled = true
c.Video.AuxIndex = 5 // AUX2, zero-based
c.Video.Threshold = -512
c.Video.Command = "fpv-video"
c.Logging.Enabled = true
return c
}
func Load(path string) (Config, error) {
config := Default()
data, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
return config, nil
}
return config, err
}
if err := yaml.Unmarshal(data, &config); err != nil {
return config, err
}
return config, nil
}