Initial commit: Go driver for the Lian Li Galahad II LCD
Streams H.264 to the Galahad II LCD via USB (gousb) with: - ffmpeg CLI transcoding (no fragile FFmpeg C-ABI bindings) - pure-Go Annex-B access-unit splitting - framerate pacing with graceful shutdown and USB reconnect - TOML config, cobra CLI, structured slog logging, unit tests
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"galahad2lcd/internal/config"
|
||||
"galahad2lcd/internal/service"
|
||||
)
|
||||
|
||||
func newSetCmd() *cobra.Command {
|
||||
var (
|
||||
configPath string
|
||||
input string
|
||||
rotate int
|
||||
speed float64
|
||||
fps float64
|
||||
noRestart bool
|
||||
)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "set",
|
||||
Short: "Update display settings and restart the service",
|
||||
Long: `Update the galahad2lcd configuration file and restart the systemd
|
||||
service. Provide at least one flag to change a setting. Writing the default
|
||||
configuration path requires root.`,
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
if !cmd.Flags().Changed("input") &&
|
||||
!cmd.Flags().Changed("rotate") &&
|
||||
!cmd.Flags().Changed("speed") &&
|
||||
!cmd.Flags().Changed("fps") {
|
||||
return fmt.Errorf("nothing to set; provide at least one of --input, --rotate, --speed, --fps")
|
||||
}
|
||||
|
||||
cfg, err := config.Load(configPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := applyOverrides(cmd, &cfg, input, rotate, speed, fps); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cfg.Validate(); err != nil {
|
||||
return fmt.Errorf("invalid configuration: %w", err)
|
||||
}
|
||||
|
||||
if configPath == config.DefaultConfigPath && os.Geteuid() != 0 {
|
||||
return fmt.Errorf("writing %s requires root (run with sudo)", configPath)
|
||||
}
|
||||
if err := cfg.Save(configPath); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("configuration saved to %s\n", configPath)
|
||||
|
||||
if noRestart {
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx, stop := newSignalContext()
|
||||
defer stop()
|
||||
if err := service.New(config.ServiceName).Restart(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("service restarted")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringVar(&configPath, "config", config.DefaultConfigPath, "path to the configuration file")
|
||||
cmd.Flags().StringVar(&input, "input", "", "path to the media file")
|
||||
cmd.Flags().IntVar(&rotate, "rotate", 0, "rotation in degrees (0, 90, 180, 270)")
|
||||
cmd.Flags().Float64Var(&speed, "speed", 0, "playback speed (>1 slower, <1 faster)")
|
||||
cmd.Flags().Float64Var(&fps, "fps", 0, "output framerate (0 = auto)")
|
||||
cmd.Flags().BoolVar(&noRestart, "no-restart", false, "do not restart the service after saving")
|
||||
return cmd
|
||||
}
|
||||
Reference in New Issue
Block a user