diff --git a/cmd/kd6ctl/main.go b/cmd/kd6ctl/main.go index 3576f89..2ef8a37 100644 --- a/cmd/kd6ctl/main.go +++ b/cmd/kd6ctl/main.go @@ -213,7 +213,7 @@ func main() { leds := &ffcli.Command{ Name: "led", ShortUsage: "kd6ctl led [pulse]", - ShortHelp: "Sets LEDs on sensor on or off.", + ShortHelp: "Turn sensor LEDs on or off.", Exec: func(_ context.Context, args []string) error { if len(args) < 2 { return fmt.Errorf("led command requires specific LEDs either 'a', 'b', 'ab'. You must also specify to set LEDs 'on' or 'off'") @@ -250,11 +250,35 @@ func main() { }, } + duty := &ffcli.Command{ + Name: "duty", + ShortUsage: "kd6ctl duty ", + ShortHelp: "Set LED duty illumination period (in microseconds).", + Exec: func(_ context.Context, args []string) error { + if len(args) < 2 { + return fmt.Errorf("duty command requires specific LEDs either 'a' or 'b'. You must also specify the duty to set LEDs to") + } + + led := args[0] + if led != "a" && led != "b" { + return fmt.Errorf("invalid led value. must be 'a' or 'b'") + } + + duty, err := strconv.ParseFloat(args[1], 32) + if err != nil { + return err + } + + cis := kd6rmx.Sensor{Port: *port} + return cis.LEDDutyCycle(led, float32(duty)) + }, + } + root := &ffcli.Command{ ShortUsage: "kd6ctl [flags] ", ShortHelp: "kd6ctl is a command line utility to change config on the KD6RMX contact image sensor.", FlagSet: rootFlagSet, - Subcommands: []*ffcli.Command{load, save, outputfreq, outputfmt, interp, dark, white, leds}, + Subcommands: []*ffcli.Command{load, save, outputfreq, outputfmt, interp, dark, white, leds, duty}, Exec: func(context.Context, []string) error { return flag.ErrHelp }, diff --git a/kd6rmx.go b/kd6rmx.go index 97c6f04..feafa56 100644 --- a/kd6rmx.go +++ b/kd6rmx.go @@ -383,7 +383,9 @@ func (cis Sensor) LEDControl(leds string, on bool, pulsedivider int) error { return checkError("LEDControl", result) } -func (cis Sensor) LEDDutyCycle(led string, duty int) error { +// LEDDutyCycle sets the duty cycle for each LED separately. +// The value for duty represents the number of microseconds. +func (cis Sensor) LEDDutyCycle(led string, duty float32) error { var ls string switch led { case "a", "A": @@ -394,10 +396,10 @@ func (cis Sensor) LEDDutyCycle(led string, duty int) error { return errors.New("invalid LED for duty cycle") } - if duty < 0 || duty > 0xFFFF { + if duty <= 0 || duty >= 4096 { return errors.New("invalid duty cycle value") } - param := fmt.Sprintf("%s%04X", ls, duty) + param := fmt.Sprintf("%s%04X", ls, duty*16) result, err := cis.sendCommand("LC", param) if err != nil {