feat: add UART reconnect and configurable channel logging
Build Ground Station / build (push) Successful in 23s
Build Ground Station / build (push) Successful in 23s
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user