Set command was realised

This commit is contained in:
2016-06-27 00:29:32 +05:00
parent dcec154ed6
commit 9e1fecd513

View File

@@ -2,18 +2,18 @@ package main
import (
"flag"
"fmt"
"github.com/dedkovd/noolite"
)
func main() {
channel := flag.Int("channel", -1, "Noolite adapter channel")
command := flag.String("command", "", "Command")
value := flag.Int("val", 0, "Set value")
red := flag.Int("r", 0, "Red channel")
green := flag.Int("g", 0, "Green channel")
blue := flag.Int("b", 0, "Blue channel")
flag.Parse()
fmt.Println(*channel)
fmt.Println(*command)
if *channel == -1 {
panic("Channel was not set")
}
@@ -24,25 +24,35 @@ func main() {
n, err := noolite.DefaultNooliteAdapter()
commands := map[string]func(int) error{
"on": n.On,
"off": n.Off,
"switch": n.Switch,
}
if err != nil {
panic(err)
}
defer n.Close()
if *command == "set" {
if *value != 0 {
err = n.SetBrightnesValue(*channel, *value)
} else if *red != 0 || *green != 0 || *blue != 0 {
err = n.SetBrightnesValues(*channel, *red, *green, *blue)
} else {
panic("Need some value")
}
} else {
commands := map[string]func(int) error{
"on": n.On,
"off": n.Off,
"switch": n.Switch,
}
cmd, ok := commands[*command]
if !ok {
panic("Command not found")
}
cmd(*channel)
err = cmd(*channel)
}
if err != nil {
panic(err)