parse comma separated RGB string

This commit is contained in:
Ryan Cavicchioni 2020-03-28 18:04:53 -05:00
parent fce5ff9667
commit 8c0e325447
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D

View File

@ -2,6 +2,8 @@ package lumecmd
import ( import (
"fmt" "fmt"
"strconv"
"strings"
"time" "time"
"git.kill0.net/chill9/lume" "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))
}