Skip to content

Commit

Permalink
Fixing the magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Suderman committed Jan 19, 2020
1 parent a8397dd commit 503673f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion control.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ var offCmd = &cobra.Command{
}
defer led.ws.Fini()

_ = led.fade(off, 0)
_ = led.fade(off, minBrightness)
},
}
6 changes: 3 additions & 3 deletions homekit.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func startHomekit() {
ac.Lightbulb.On.OnValueRemoteUpdate(func(on bool) {
if on {
klog.Infof("Switch is on")
err = led.fade(colors["white"], 150)
err = led.fade(colors["white"], maxBrightness)
if err != nil {
klog.Error(err)
}
} else {
klog.Infof("Switch is off")
err = led.fade(off, 0)
err = led.fade(off, minBrightness)
if err != nil {
klog.Error(err)
}
Expand All @@ -80,7 +80,7 @@ func startHomekit() {

hc.OnTermination(func() {
klog.Info("terminated. turning off lights")
err = led.fade(off, 0)
err = led.fade(off, minBrightness)
if err != nil {
klog.Error(err)
}
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func init() {
// Flags
rootCmd.PersistentFlags().IntVarP(&ledCount, "led-count", "l", 12, "The number of LEDs in the array.")
rootCmd.PersistentFlags().IntVar(&maxBrightness, "max-brightness", 200, "The maximum brightness that will work within the 0-250 range.")
rootCmd.PersistentFlags().IntVar(&minBrightness, "min-brightness", 30, "The minimum brightness that will work within the 0-250 range.")
rootCmd.PersistentFlags().IntVarP(&fadeDuration, "fade-duration", "f", 30, "The duration of fade-ins and fade-outs in ms.")
rootCmd.PersistentFlags().IntVar(&minBrightness, "min-brightness", 25, "The minimum brightness that will work within the 0-250 range.")
rootCmd.PersistentFlags().IntVarP(&fadeDuration, "fade-duration", "f", 100, "The duration of fade-ins and fade-outs in ms.")

//Commands
rootCmd.AddCommand(versionCmd)
Expand Down
6 changes: 3 additions & 3 deletions neopixel.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func newLEDArray() (*LEDArray, error) {
return nil, err
}
// Start off
led.brightness = 0
led.brightness = minBrightness
led.color = off
return led, nil
}
Expand Down Expand Up @@ -143,13 +143,13 @@ func (led *LEDArray) fade(color uint32, target int) error {
// stepRamp returns a list of steps in a brightness ramp up
func stepRamp(start float64, stop float64, duration float64) []int {
slope := (stop - start) / duration
klog.V(10).Infof("slope of ramp: %f", slope)
klog.V(7).Infof("slope of ramp: %f", slope)

var ramp []int
for i := 0; i < int(duration); i++ {
point := start + (slope * float64(i))
ramp = append(ramp, int(point))
}
klog.V(10).Infof("calculated ramp: %v", ramp)
klog.V(7).Infof("calculated ramp: %v", ramp)
return ramp
}

0 comments on commit 503673f

Please sign in to comment.