feat: render minimal flight OSD from supervisor snapshots (#3)
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.piksar.eu/piotr/groundstation/internal/osd"
|
||||
"git.piksar.eu/piotr/groundstation/internal/protocol"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -15,6 +18,16 @@ type DisplayConfig struct {
|
||||
Xauthority string `yaml:"xauthority"`
|
||||
}
|
||||
|
||||
// OSDConfig configures the supervisor's flight OSD snapshot publication.
|
||||
type OSDConfig struct {
|
||||
// StatePath is the snapshot state file the display process reads.
|
||||
StatePath string `yaml:"state_path"`
|
||||
// ArmIndex and ArmedThreshold derive the arm state from the final RC
|
||||
// channels: armed while that channel stays above the threshold.
|
||||
ArmIndex int `yaml:"arm_index"`
|
||||
ArmedThreshold int16 `yaml:"armed_threshold"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Display DisplayConfig `yaml:"display"`
|
||||
Serial struct {
|
||||
@@ -26,6 +39,7 @@ type Config struct {
|
||||
Threshold int16 `yaml:"threshold"`
|
||||
Command string `yaml:"command"`
|
||||
} `yaml:"video"`
|
||||
OSD OSDConfig `yaml:"osd"`
|
||||
Logging struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Path string `yaml:"path"`
|
||||
@@ -40,6 +54,7 @@ func Default() Config {
|
||||
c.Video.AuxIndex = 5 // AUX2, zero-based
|
||||
c.Video.Threshold = -512
|
||||
c.Video.Command = "fpv-video"
|
||||
c.OSD = DefaultOSD()
|
||||
c.Logging.Enabled = true
|
||||
return c
|
||||
}
|
||||
@@ -56,17 +71,41 @@ func DefaultDisplay() DisplayConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultOSD publishes snapshots to the default tmpfs path and derives the
|
||||
// arm state from CH5/AUX1, armed above the midpoint.
|
||||
func DefaultOSD() OSDConfig {
|
||||
return OSDConfig{
|
||||
StatePath: osd.DefaultStatePath,
|
||||
ArmIndex: 4,
|
||||
ArmedThreshold: 0,
|
||||
}
|
||||
}
|
||||
|
||||
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, config.validate()
|
||||
}
|
||||
return config, err
|
||||
}
|
||||
if err := yaml.Unmarshal(data, &config); err != nil {
|
||||
return config, err
|
||||
}
|
||||
return config, nil
|
||||
return config, config.validate()
|
||||
}
|
||||
|
||||
// validate rejects channel indexes outside the final RC channel range: an
|
||||
// out-of-range index would panic on the first decoded frame.
|
||||
func (c Config) validate() error {
|
||||
for name, index := range map[string]int{
|
||||
"video.aux_index": c.Video.AuxIndex,
|
||||
"osd.arm_index": c.OSD.ArmIndex,
|
||||
} {
|
||||
if index < 0 || index >= protocol.Channels {
|
||||
return fmt.Errorf("%s %d outside the RC channel range 0..%d", name, index, protocol.Channels-1)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user