From 8c0e325447a7fd9772efb5ed8f137a0cd9f68f11 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Sat, 28 Mar 2020 18:04:53 -0500 Subject: [PATCH] parse comma separated RGB string --- cmd/util.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cmd/util.go b/cmd/util.go index 365d38e..04bde37 100644 --- a/cmd/util.go +++ b/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)) +}