Compare commits

..

No commits in common. "1b054466cf0efa363bd967b2dbbaf94ad172ae0a" and "67cd97e2d8fc3a96a54cb1fdb9825bb2ba030775" have entirely different histories.

4 changed files with 3 additions and 141 deletions

View File

@ -36,20 +36,12 @@ var (
defaultFast bool = false defaultFast bool = false
defaultWhiteKelvin string = "" defaultWhiteKelvin string = ""
defaultWhiteName string = "" defaultWhiteName string = ""
defaultHue string = ""
defaultSaturation string = ""
defaultRGB string = ""
) )
func (f Flags) String(name string) string { func (f Flags) String(name string) string {
return f.FlagSet.Lookup(name).Value.String() return f.FlagSet.Lookup(name).Value.String()
} }
func (f Flags) Float32(name string) float32 {
val, _ := strconv.ParseFloat(f.String(name), 32)
return float32(val)
}
func (f Flags) Float64(name string) float64 { func (f Flags) Float64(name string) float64 {
val, _ := strconv.ParseFloat(f.String(name), 64) val, _ := strconv.ParseFloat(f.String(name), 64)
return val return val

View File

@ -1,105 +0,0 @@
package lumecmd
import (
"flag"
"fmt"
"git.kill0.net/chill9/lume"
)
func init() {
var cmdName string = "set-color"
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
selector := fs.String("selector", "all", "the selector")
fs.StringVar(selector, "s", "all", "the selector")
power := fs.String("power", defaultPower, "power state")
fs.StringVar(power, "p", defaultPower, "power state")
hue := fs.String("hue", defaultHue, "hue level")
fs.StringVar(hue, "H", defaultHue, "hue level")
saturation := fs.String("saturation", defaultSaturation, "saturation level")
fs.StringVar(saturation, "S", defaultSaturation, "saturation level")
rgb := fs.String("rgb", defaultRGB, "RGB value")
fs.StringVar(rgb, "r", defaultRGB, "RGB value")
brightness := fs.String("brightness", defaultBrightness, "brightness state")
fs.StringVar(brightness, "b", defaultBrightness, "brightness state")
duration := fs.Float64("duration", defaultDuration, "duration state")
fs.Float64Var(duration, "d", defaultDuration, "duration state")
fast := fs.Bool("fast", defaultFast, "fast state")
fs.BoolVar(fast, "f", defaultFast, "fast state")
RegisterCommand(cmdName, Command{
Func: SetColorCmd,
Flags: fs,
})
}
func SetColorCmd(args CmdArgs) int {
c := args.Client
state := lifx.State{}
selector := args.Flags.String("selector")
power := args.Flags.String("power")
if power != "" {
state.Power = power
}
hueFlag := args.Flags.String("hue")
saturationFlag := args.Flags.String("saturation")
rgbFlag := args.Flags.String("rgb")
if hueFlag != "" || saturationFlag != "" {
color := lifx.HSBKColor{}
if hueFlag != "" {
hue := args.Flags.Float32("hue")
color.H = lifx.Float32Ptr(hue)
}
if saturationFlag != "" {
saturation := args.Flags.Float32("saturation")
color.S = lifx.Float32Ptr(saturation)
}
state.Color = color
} else if rgbFlag != "" {
color, err := parseRGB(rgbFlag)
if err != nil {
fmt.Printf("fatal: %s\n", err)
return 1
}
state.Color = color
}
brightnessFlag := args.Flags.String("brightness")
if brightnessFlag != "" {
brightness := args.Flags.Float64("brightness")
state.Brightness = brightness
}
duration := args.Flags.Float64("duration")
state.Duration = duration
fast := args.Flags.Bool("fast")
state.Fast = fast
r, err := c.SetState(selector, state)
if err != nil {
fmt.Printf("fatal: %s\n", err)
return 1
}
if !fast {
PrintResults(r.Results)
}
return 0
}

View File

@ -2,8 +2,6 @@ package lumecmd
import ( import (
"fmt" "fmt"
"strconv"
"strings"
"time" "time"
"git.kill0.net/chill9/lume" "git.kill0.net/chill9/lume"
@ -103,21 +101,3 @@ func PrintLights(lights []lifx.Light) {
) )
} }
} }
func parseRGB(s string) (lifx.RGBColor, error) {
var c lifx.RGBColor
rgb := strings.SplitN(s, ",", 3)
r, err := strconv.ParseUint(rgb[0], 10, 8)
if err != nil {
return c, err
}
g, err := strconv.ParseUint(rgb[1], 10, 8)
if err != nil {
return c, err
}
b, err := strconv.ParseUint(rgb[2], 10, 8)
if err != nil {
return c, err
}
return lifx.NewRGBColor(uint8(r), uint8(g), uint8(b))
}

View File

@ -77,13 +77,12 @@ var (
} }
) )
func NewRGBColor(r, g, b uint8) (RGBColor, error) { func NewRGBColor(r, g, b uint8) (*RGBColor, error) {
var c RGBColor
if (r < 0 || r > 255) && (g < 0 || r > 255) && (b < 0 || b > 255) { if (r < 0 || r > 255) && (g < 0 || r > 255) && (b < 0 || b > 255) {
return c, errors.New("values must be between 0-255") return nil, errors.New("values must be between 0-255")
} }
return RGBColor{R: r, G: g, B: b}, nil return &RGBColor{R: r, G: g, B: b}, nil
} }
func NewHSColor(h, s float32) (HSBKColor, error) { func NewHSColor(h, s float32) (HSBKColor, error) {
@ -189,10 +188,6 @@ func (c HSBKColor) MarshalText() ([]byte, error) {
return []byte(c.ColorString()), nil return []byte(c.ColorString()), nil
} }
func (c RGBColor) MarshalText() ([]byte, error) {
return []byte(c.ColorString()), nil
}
func (c NamedColor) ColorString() string { func (c NamedColor) ColorString() string {
return string(c) return string(c)
} }