PKGBUILD/pkg/types/led.go

80 lines
2.1 KiB
Go
Raw Normal View History

package types
2019-06-16 18:11:10 +00:00
import (
"fmt"
"time"
)
type RGBLED struct {
RGBLEDID string `json:"rgbled_id" xml:"rgbled_id"`
RGBLEDName string `json:"rgbled_name" xml:"rgbled_name"`
RGBLEDLocation string `json:"rgbled_location" xml:"rgb_location"`
BaseColorsToGPIO map[BaseColor]*GPIO `json:"base_colors_to_gpio" xml:"base_colors_to_gpio"`
ActionMapping map[LEDAction]LEDColor `json:"action_mapping" xml:"action_mapping"`
RGBLEDEnabled bool `json:"rgbled_enabled" xml:"rgb_enabled"`
DeviceID string `json:"device_id" xml:"device_id"`
CreationDate time.Time `json:"creation_date" xml:"creation_date"`
}
2019-06-16 18:11:10 +00:00
type BaseColor string
const (
2019-06-16 18:11:10 +00:00
BaseColorBlue BaseColor = "blue"
BaseColorRed BaseColor = "red"
BaseColorGreen BaseColor = "green"
)
type LEDColor string
const (
2019-06-16 18:11:10 +00:00
LEDColorBlue LEDColor = "blue"
LEDColorGreen LEDColor = "green"
LEDColorNone LEDColor = "none"
LEDColorPurple LEDColor = "purple"
LEDColorRed LEDColor = "red"
LEDColorTurquoise LEDColor = "turquoise"
LEDColorYellow LEDColor = "yellow"
LEDColorWhite LEDColor = "white"
)
func StringToLEDColor(color string) (LEDColor, error) {
2019-06-16 18:11:10 +00:00
switch color {
case "blue":
return LEDColorBlue, nil
case "red":
return LEDColorRed, nil
case "green":
return LEDColorGreen, nil
case "none":
return LEDColorNone, nil
case "purple":
return LEDColorPurple, nil
case "turquoise":
return LEDColorTurquoise, nil
case "yellow":
return LEDColorYellow, nil
case "white":
return LEDColorWhite, nil
default:
return LEDColorNone, fmt.Errorf("Can not convert color to const")
}
}
type LEDAction string
const (
LEDActionError LEDAction = "error"
LEDActionWarn = "warn"
LEDActionRun = "run"
LEDActionSync = "sync"
LEDActionLogfile = "logfile"
)
2019-06-16 18:11:10 +00:00
var DefaultActionMapping = map[LEDAction]LEDColor{
LEDActionError: LEDColorRed,
LEDActionWarn: LEDColorYellow,
LEDActionRun: LEDColorGreen,
LEDActionSync: LEDColorTurquoise,
LEDActionLogfile: LEDColorBlue,
2019-06-16 18:11:10 +00:00
}