2019-06-16 11:00:50 +00:00
|
|
|
package types
|
|
|
|
|
2019-06-16 18:11:10 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
2019-06-16 11:00:50 +00:00
|
|
|
|
|
|
|
type LED struct {
|
2019-06-19 17:18:01 +00:00
|
|
|
LEDID string `json:"led_id" xml:"led_id"`
|
|
|
|
LEDName string `json:"led_name" xml:"led_name"`
|
|
|
|
LEDLocation string `json:"led_location" xml:"led_location"`
|
|
|
|
GPIONumber *GPIO `json:"gpio_number" xml:"gpio_number"`
|
|
|
|
LEDEnabled bool `json:"led_enabled" xml:"led_enabled"`
|
|
|
|
LEDColor *LEDColor `json:"led_color" xml:"led_color"`
|
|
|
|
DeviceID string `json:"device_id" xml:"device_id"`
|
|
|
|
CreationDate time.Time `json:"creation_date" xml:"creation_date"`
|
2019-06-16 11:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type RGBLED struct {
|
2019-06-19 17:18:01 +00:00
|
|
|
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:"color_to_gpio" xml:"color_to_gpio"`
|
|
|
|
ActionMapping map[LEDOption]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 11:00:50 +00:00
|
|
|
}
|
|
|
|
|
2019-06-16 18:11:10 +00:00
|
|
|
type BaseColor string
|
2019-06-16 11:00:50 +00:00
|
|
|
|
|
|
|
const (
|
2019-06-16 18:11:10 +00:00
|
|
|
BaseColorBlue BaseColor = "blue"
|
|
|
|
BaseColorRed BaseColor = "red"
|
|
|
|
BaseColorGreen BaseColor = "green"
|
2019-06-16 11:00:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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"
|
2019-06-16 11:00:50 +00:00
|
|
|
)
|
|
|
|
|
2019-06-16 18:11:10 +00:00
|
|
|
func StrintToLEDColor(color string) (LEDColor, error) {
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-16 11:00:50 +00:00
|
|
|
type LEDOption string
|
|
|
|
|
|
|
|
const (
|
2019-06-16 18:11:10 +00:00
|
|
|
LEDError LEDOption = "error"
|
|
|
|
LEDWarn = "warn"
|
|
|
|
LEDOk = "ok"
|
|
|
|
LEDSync = "sync"
|
|
|
|
LEDLogfile = "logfile"
|
2019-06-16 11:00:50 +00:00
|
|
|
)
|
2019-06-16 18:11:10 +00:00
|
|
|
|
|
|
|
var DefaultActionMapping = map[LEDOption]LEDColor{
|
|
|
|
LEDError: LEDColorRed,
|
|
|
|
LEDWarn: LEDColorYellow,
|
|
|
|
LEDOk: LEDColorGreen,
|
|
|
|
LEDSync: LEDColorTurquoise,
|
|
|
|
LEDLogfile: LEDColorBlue,
|
|
|
|
}
|