Skip to content

Commit

Permalink
adding illumination period setting and reading
Browse files Browse the repository at this point in the history
  • Loading branch information
julian59189 authored and deadprogram committed Apr 1, 2022
1 parent bbff56e commit 6f26733
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ SUBCOMMANDS
white White correction on/off/adjust/target.
led Turn sensor LEDs on or off.
duty Set LED duty illumination period register value. Valid range 0 to 4095.
illum Set effective LED illumination period register value. Valid range 0 to 4095.
cmd Sends the specified command to sensor

FLAGS
Expand Down
22 changes: 21 additions & 1 deletion cmd/kd6ctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,25 @@ func main() {
},
}

illum := &ffcli.Command{
Name: "illum",
ShortUsage: "kd6ctl illum <period>",
ShortHelp: "Set effective LED illumination period register value. Valid range 0 to 4095.",
Exec: func(_ context.Context, args []string) error {
if len(args) < 1 {
return fmt.Errorf("adjust the effective illumination period number")
}

period, err := strconv.Atoi(args[0])
if err != nil {
return err
}

cis := kd6rmx.Sensor{Port: *port, Logging: *logging, FileLogging: *logFile}
return cis.LEDIlluminationPeriod(period)
},
}

gain := &ffcli.Command{
Name: "gain",
ShortUsage: "kd6ctl gain <value/on/off>",
Expand Down Expand Up @@ -357,6 +376,7 @@ func main() {
cis.ReadRegister("LC")
cis.ReadRegisterWithVal("LC", "A0")
cis.ReadRegisterWithVal("LC", "C0")
cis.ReadRegisterWithVal("LC", "E0")
cis.ReadRegister("WC")
// cis.ReadRegister("PG")
// cis.ReadRegister("GC")
Expand Down Expand Up @@ -390,7 +410,7 @@ func main() {
ShortUsage: "kd6ctl [flags] <subcommand>",
ShortHelp: "kd6ctl is a command line utility to change config on the KD6RMX contact image sensor.",
FlagSet: rootFlagSet,
Subcommands: []*ffcli.Command{version, dumpreg, gain, load, save, pattern, outputfreq, outputfmt, interp, dark, white, leds, duty, cmd},
Subcommands: []*ffcli.Command{version, dumpreg, gain, load, save, pattern, outputfreq, outputfmt, interp, dark, white, leds, duty, illum, cmd},
Exec: func(context.Context, []string) error {
return flag.ErrHelp
},
Expand Down
30 changes: 19 additions & 11 deletions kd6rmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ func (cis Sensor) LEDDutyCycle(led string, duty int) error {
return errors.New("invalid LED for duty cycle")
}

if duty <= 0 || duty >= 4096 {
dutyMax := 4096
if duty <= 0 || duty >= dutyMax {
return errors.New("invalid duty cycle register value")
}
param := fmt.Sprintf("%s%04X", ls, duty)
Expand All @@ -413,6 +414,20 @@ func (cis Sensor) LEDDutyCycle(led string, duty int) error {
return checkError("LEDDutyCycle", result)
}

func (cis Sensor) LEDIlluminationPeriod(period int) error {
periodMax := 4095
if period > periodMax {
return errors.New("invalid illumination period")
}
param := fmt.Sprintf("60%04X", period)

result, err := cis.SendCommand("LC", param)
if err != nil {
return err
}
return checkError("LEDIlluminationPeriod", result)
}

func (cis Sensor) DarkCorrectionEnabled(on bool) error {
var param = "00"
if on {
Expand Down Expand Up @@ -913,16 +928,9 @@ func parseLED(short_res, result, val string) error {
value, _ := strconv.ParseInt(hex, 16, 64)
fmt.Printf("(LED Period B: %d)\n", value)
case "E0":
// var val string
// switch short_res {
// case "40":
// val = "Interpolation function Off"
// case "41":
// val = "Interpolation function On"
// default:
// return errors.New("invalid interpolation output")
// }
fmt.Printf("(period setting %s)\n", short_res)
hex := result[4:8]
value, _ := strconv.ParseInt(hex, 16, 64)
fmt.Printf("(LED Illumination period setting %d)\n", value)
default:
return errors.New("LED control setting")
}
Expand Down

0 comments on commit 6f26733

Please sign in to comment.