fix(pkg/rgb-led): complete rgb-led pkg
This commit is contained in:
		| @@ -1,6 +1,9 @@ | ||||
| package types | ||||
|  | ||||
| import "time" | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| type LED struct { | ||||
| 	LEDID        string    `json:"led_id"` | ||||
| @@ -14,39 +17,74 @@ type LED struct { | ||||
| } | ||||
|  | ||||
| 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"` | ||||
| 	RGBLEDID         string                 `json:"rgbled_id"` | ||||
| 	RGBLEDName       string                 `json:"rgbled_name"` | ||||
| 	RGBLEDLocation   string                 `json:"rgbled_location"` | ||||
| 	BaseColorsToGPIO map[BaseColor]*GPIO    `json:"color_to_gpio"` | ||||
| 	ActionMapping    map[LEDOption]LEDColor `json:"action_mapping"` | ||||
| 	RGBLEDEnabled    bool                   `json:"rgbled_enabled"` | ||||
| 	DeviceID         string                 `json:"device_id"` | ||||
| 	CreationDate     time.Time              `json:"creation_date"` | ||||
| } | ||||
|  | ||||
| type RGBColor string | ||||
| type BaseColor string | ||||
|  | ||||
| const ( | ||||
| 	RGBLEDBlue  RGBColor = "blue" | ||||
| 	RGBLEDRed            = "red" | ||||
| 	RGBLEDGreen          = "green" | ||||
| 	BaseColorBlue  BaseColor = "blue" | ||||
| 	BaseColorRed   BaseColor = "red" | ||||
| 	BaseColorGreen BaseColor = "green" | ||||
| ) | ||||
|  | ||||
| type LEDColor string | ||||
|  | ||||
| const ( | ||||
| 	LEDBlue            LEDColor = "blue" | ||||
| 	LEDRed                      = "red" | ||||
| 	LEDGreen                    = "green" | ||||
| 	LEDPurple                   = "purple" | ||||
| 	LEDTurquoiseGravel          = "turquoise gravel" | ||||
| 	LEDYellow                   = "yellow" | ||||
| 	LEDWhite                    = "white" | ||||
| 	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 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") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| type LEDOption string | ||||
|  | ||||
| const ( | ||||
| 	LEDError LEDOption = "error" | ||||
| 	LEDWarn            = "warn" | ||||
| 	LEDOk              = "ok" | ||||
| 	LEDError   LEDOption = "error" | ||||
| 	LEDWarn              = "warn" | ||||
| 	LEDOk                = "ok" | ||||
| 	LEDSync              = "sync" | ||||
| 	LEDLogfile           = "logfile" | ||||
| ) | ||||
|  | ||||
| var DefaultActionMapping = map[LEDOption]LEDColor{ | ||||
| 	LEDError:   LEDColorRed, | ||||
| 	LEDWarn:    LEDColorYellow, | ||||
| 	LEDOk:      LEDColorGreen, | ||||
| 	LEDSync:    LEDColorTurquoise, | ||||
| 	LEDLogfile: LEDColorBlue, | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user