feat(cmd/rgb-led): add subcommands to operate with rgb-leds

This commit is contained in:
2019-06-16 13:00:50 +02:00
parent c81cd2d21c
commit 49d66cfcbb
27 changed files with 713 additions and 40 deletions

View File

@ -91,6 +91,63 @@ func GPIOToString(gpio GPIO) (string, error) {
}
}
func GPIOToInt(gpio GPIO) (int, error) {
switch gpio {
case GPIO02:
return 2, nil
case GPIO03:
return 3, nil
case GPIO04:
return 4, nil
case GPIO05:
return 5, nil
case GPIO06:
return 6, nil
case GPIO07:
return 7, nil
case GPIO08:
return 8, nil
case GPIO10:
return 10, nil
case GPIO11:
return 11, nil
case GPIO12:
return 12, nil
case GPIO13:
return 13, nil
case GPIO14:
return 14, nil
case GPIO15:
return 15, nil
case GPIO16:
return 16, nil
case GPIO17:
return 17, nil
case GPIO18:
return 18, nil
case GPIO19:
return 19, nil
case GPIO20:
return 20, nil
case GPIO21:
return 21, nil
case GPIO22:
return 22, nil
case GPIO23:
return 23, nil
case GPIO24:
return 24, nil
case GPIO25:
return 25, nil
case GPIO26:
return 26, nil
case GPIO27:
return 27, nil
default:
return 0, fmt.Errorf("Can not determine gpio %v", gpio)
}
}
func StringToGPIO(gpio string) (GPIO, error) {
switch gpio {
case "GPIO02":

52
pkg/types/led.go Normal file
View File

@ -0,0 +1,52 @@
package types
import "time"
type LED struct {
LEDID string `json:"led_id"`
LEDName string `json:"led_name"`
LEDLocation string `json:"led_location"`
GPIONumber *GPIO `json:"gpio_number"`
LEDEnabled bool `json:"led_enabled"`
LEDColor *LEDColor `json:"led_color"`
DeviceID string `json:"device_id"`
CreationDate time.Time `json:"creation_date"`
}
type RGBLED struct {
RGBLEDID string `json:"rgbled_id"`
RGBLEDName string `json:"rgbled_name"`
RGBLEDLocation string `json:"rgbled_location"`
RGBLEDColorToGPIO map[RGBColor]*GPIO `json:"color_to_gpio"`
RGBLEDEnabled bool `json:"rgbled_enabled"`
DeviceID string `json:"device_id"`
CreationDate time.Time `json:"creation_date"`
}
type RGBColor string
const (
RGBLEDBlue RGBColor = "blue"
RGBLEDRed = "red"
RGBLEDGreen = "green"
)
type LEDColor string
const (
LEDBlue LEDColor = "blue"
LEDRed = "red"
LEDGreen = "green"
LEDPurple = "purple"
LEDTurquoiseGravel = "turquoise gravel"
LEDYellow = "yellow"
LEDWhite = "white"
)
type LEDOption string
const (
LEDError LEDOption = "error"
LEDWarn = "warn"
LEDOk = "ok"
)