Example #1
0
func (a *Agent) updateLeds(update *updateRequest) {

	logger.Debugf("update leds : %v", update)

	err, action := getLastToken(update.Topic)

	if err != nil {
		logger.Errorf("bad update request - %s", err)
	}

	if action == "reset" {
		a.leds.Reset()
		if leds.ValidBrightness(update.Brightness) {
			a.leds.SetPwmBrightness(update.Brightness)
		} else {
			logger.Warningf("bad brightness %d", update.Brightness)
		}
		return
	}

	if leds.ValidLedName(action) && leds.ValidColor(update.Color) {
		a.leds.SetColor(leds.LedNameIndex(action), update.Color, update.Flash)
	} else {
		logger.Warningf("bad SetColor params - %s %s %s", action, update.Color, update.Flash)
	}

}
Example #2
0
func (c *TesterCommand) Run(args []string) int {

	c.Ui = &cli.PrefixedUi{
		OutputPrefix: "==> ",
		InfoPrefix:   "    ",
		ErrorPrefix:  "==> ",
		Ui:           c.Ui,
	}

	var color string
	var ledName string

	cmdFlags := flag.NewFlagSet("agent", flag.ContinueOnError)
	cmdFlags.Usage = func() { c.Ui.Output(c.Help()) }
	cmdFlags.StringVar(&color, "color", "", "set the led to this color")
	cmdFlags.StringVar(&ledName, "ledname", "", "name of the led to set")

	if err := cmdFlags.Parse(args); err != nil {
		return 1
	}

	if color == "" {
		c.Ui.Error("color flag required")
		return 1
	}

	if leds.Colors[color] == nil {
		c.Ui.Error("Invalid color supplied")
		return 1
	}

	if !leds.ValidLedName(ledName) {
		c.Ui.Error("Invalid led name supplied")
		return 1
	}

	c.ledArray = leds.CreateLedArray()
	c.Ui.Output("Sphere LEDs tester")
	c.Ui.Info(fmt.Sprintf("Setting power %s to: %s", ledName, color))
	c.ledArray.SetColor(leds.LedNameIndex(ledName), color, true)
	c.ledArray.SetLEDs()

	return 0
}