2019-06-16 18:11:10 +00:00
|
|
|
package rgbled
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/go-flucky/flucky/pkg/config"
|
|
|
|
"github.com/go-flucky/flucky/pkg/rgbled"
|
|
|
|
"github.com/go-flucky/flucky/pkg/types"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var onRgbLedCmd = &cobra.Command{
|
|
|
|
Use: "on",
|
|
|
|
Short: "Turn a RGB-LED color on",
|
|
|
|
Example: `flucky rgb-led on <names/uuids> <blue/green/purple/red/turquoise/white/yellow>
|
|
|
|
flucky rgb-led on my-led blue
|
|
|
|
flucky rgb-led on my-led my-sweet-led white
|
|
|
|
flucky rgb-led on 1c5b9424-f6e9-4a37-be5c-77e531e94aab red`,
|
|
|
|
Args: cobra.MinimumNArgs(1),
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
|
|
// read configuration
|
|
|
|
cnf, err := config.Read(configFile)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
rgbLEDs := make([]rgbled.RGBLED, 0)
|
|
|
|
if len(args) > 1 {
|
|
|
|
rgbLEDs = cnf.GetRGBLEDsByName(args[0 : len(args)-1])
|
|
|
|
} else {
|
|
|
|
rgbLEDs = cnf.GetRGBLEDs(config.ENABLED)
|
|
|
|
}
|
|
|
|
|
2019-06-24 20:57:29 +00:00
|
|
|
color, err := types.StringToLEDColor(args[len(args)-1])
|
2019-06-16 18:11:10 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = rgbled.CustomColor(rgbLEDs, color)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rgbLedCmd.AddCommand(onRgbLedCmd)
|
|
|
|
}
|