Compare commits
No commits in common. "1b054466cf0efa363bd967b2dbbaf94ad172ae0a" and "67cd97e2d8fc3a96a54cb1fdb9825bb2ba030775" have entirely different histories.
1b054466cf
...
67cd97e2d8
@ -36,20 +36,12 @@ var (
|
||||
defaultFast bool = false
|
||||
defaultWhiteKelvin string = ""
|
||||
defaultWhiteName string = ""
|
||||
defaultHue string = ""
|
||||
defaultSaturation string = ""
|
||||
defaultRGB string = ""
|
||||
)
|
||||
|
||||
func (f Flags) String(name string) 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 {
|
||||
val, _ := strconv.ParseFloat(f.String(name), 64)
|
||||
return val
|
||||
|
105
cmd/setcolor.go
105
cmd/setcolor.go
@ -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
|
||||
}
|
20
cmd/util.go
20
cmd/util.go
@ -2,8 +2,6 @@ package lumecmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"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))
|
||||
}
|
||||
|
11
color.go
11
color.go
@ -77,13 +77,12 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func NewRGBColor(r, g, b uint8) (RGBColor, error) {
|
||||
var c RGBColor
|
||||
func NewRGBColor(r, g, b uint8) (*RGBColor, error) {
|
||||
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) {
|
||||
@ -189,10 +188,6 @@ func (c HSBKColor) MarshalText() ([]byte, error) {
|
||||
return []byte(c.ColorString()), nil
|
||||
}
|
||||
|
||||
func (c RGBColor) MarshalText() ([]byte, error) {
|
||||
return []byte(c.ColorString()), nil
|
||||
}
|
||||
|
||||
func (c NamedColor) ColorString() string {
|
||||
return string(c)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user