From 49330d29b1d7fc9832e692c7b255b552d049f009 Mon Sep 17 00:00:00 2001 From: Ron Evans Date: Thu, 6 May 2021 17:53:54 +0200 Subject: [PATCH] cmd: improve dark and white correction subcommands --- cmd/kd6ctl/main.go | 59 ++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/cmd/kd6ctl/main.go b/cmd/kd6ctl/main.go index f31c7d1..3576f89 100644 --- a/cmd/kd6ctl/main.go +++ b/cmd/kd6ctl/main.go @@ -151,49 +151,62 @@ func main() { dark := &ffcli.Command{ Name: "dark", - ShortUsage: "kd6ctl dark ", - ShortHelp: "Dark correction on/off.", + ShortUsage: "kd6ctl dark ", + ShortHelp: "Dark correction on/off/adjust.", Exec: func(_ context.Context, args []string) error { - if n := len(args); n != 1 { - return fmt.Errorf("dark correction must be either 'on' or 'off'") + if n := len(args); n < 1 { + return fmt.Errorf("dark correction requires a subcommand: 'on', 'off', or 'adjust'") } - var on bool + cis := kd6rmx.Sensor{Port: *port} + switch args[0] { case "on": - on = true + return cis.DarkCorrectionEnabled(true) case "off": - on = false + return cis.DarkCorrectionEnabled(false) + case "adjust": + return cis.PerformDarkCorrection() default: - return fmt.Errorf("invalid dark correction, must be on or off") + return fmt.Errorf("invalid dark correction subcommand, must be 'on', 'off', or 'adjust'") } - - cis := kd6rmx.Sensor{Port: *port} - return cis.DarkCorrectionEnabled(on) }, } white := &ffcli.Command{ Name: "white", - ShortUsage: "kd6ctl white ", - ShortHelp: "White correction on/off.", + ShortUsage: "kd6ctl white ", + ShortHelp: "White correction on/off/adjust/target.", Exec: func(_ context.Context, args []string) error { - if n := len(args); n != 1 { - return fmt.Errorf("white correction must be either 'on' or 'off'") + if n := len(args); n < 1 { + return fmt.Errorf("white correction requires a subcommand: 'on', 'off', 'adjust', or 'target'") } - var on bool + cis := kd6rmx.Sensor{Port: *port} + switch args[0] { case "on": - on = true + return cis.WhiteCorrectionEnabled(true) case "off": - on = false + return cis.WhiteCorrectionEnabled(false) + case "adjust": + return cis.PerformWhiteCorrection() + case "target": + var target = 250 + if len(args) < 2 { + fmt.Printf("no white correction target provided, using factory default of %d\n", target) + } else { + var err error + target, err = strconv.Atoi(args[1]) + if err != nil { + return fmt.Errorf("invalid value for white correction target") + } + return cis.WhiteCorrectionTarget(target) + } + return cis.PerformWhiteCorrection() default: - return fmt.Errorf("invalid white correction, must be on or off") + return fmt.Errorf("invalid white correction subcommand, must be 'on', 'off', 'adjust', or 'target'") } - - cis := kd6rmx.Sensor{Port: *port} - return cis.WhiteCorrectionEnabled(on) }, } @@ -203,7 +216,7 @@ func main() { ShortHelp: "Sets LEDs on sensor on or off.", Exec: func(_ context.Context, args []string) error { if len(args) < 2 { - return fmt.Errorf("invalid led command params") + return fmt.Errorf("led command requires specific LEDs either 'a', 'b', 'ab'. You must also specify to set LEDs 'on' or 'off'") } leds := args[0]