parse comma separated RGB string
This commit is contained in:
parent
fce5ff9667
commit
8c0e325447
20
cmd/util.go
20
cmd/util.go
@ -2,6 +2,8 @@ package lumecmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.kill0.net/chill9/lume"
|
||||
@ -101,3 +103,21 @@ 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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user