diff options
-rw-r--r-- | light.go | 24 | ||||
-rw-r--r-- | light_test.go | 18 |
2 files changed, 42 insertions, 0 deletions
@@ -148,6 +148,30 @@ func (light *Light) ColorLoop(activate bool) error { return light.SetState(LightState{On: true, Effect: state}) } +// XY HSL colors used in `Light.SetColor` +var ( + RED = &[2]float32{0.6915, 0.3083} + YELLOW = &[2]float32{0.4023, 0.4725} + ORANGE = &[2]float32{0.4693, 0.4007} + GREEN = &[2]float32{0.1700, 0.7000} + CYAN = &[2]float32{0.1610, 0.3549} + BLUE = &[2]float32{0.1530, 0.0480} + PURPLE = &[2]float32{0.2363, 0.1154} + PINK = &[2]float32{0.3645, 0.1500} + WHITE = &[2]float32{0.3227, 0.3290} +) + +// Light.SetColor requires a selection from the above light +// color variable section and sets the light to that XY HSL color +func (light *Light) SetColor(color *[2]float32) error { + lightState := LightState{On: true, XY: color} + err := light.SetState(lightState) + if err != nil { + return err + } + return nil +} + // Light.SetState modifyies light attributes. See `LightState` struct for attributes. // Brightness must be between 1 and 254 (inclusive) // Hue must be between 0 and 65535 (inclusive) diff --git a/light_test.go b/light_test.go index 6fa1eb0..436d652 100644 --- a/light_test.go +++ b/light_test.go @@ -33,5 +33,23 @@ func TestSetLightState(t *testing.T) { selectedLight.Blink(3) + // selectedLight.SetColor(RED) + // time.Sleep(time.Second) + // selectedLight.SetColor(YELLOW) + // time.Sleep(time.Second) + // selectedLight.SetColor(ORANGE) + // time.Sleep(time.Second) + // selectedLight.SetColor(GREEN) + // time.Sleep(time.Second) + // selectedLight.SetColor(CYAN) + // time.Sleep(time.Second) + // selectedLight.SetColor(BLUE) + // time.Sleep(time.Second) + // selectedLight.SetColor(PURPLE) + // time.Sleep(time.Second) + // selectedLight.SetColor(PINK) + // time.Sleep(time.Second) + // selectedLight.SetColor(WHITE) + // _ := selectedLight.Delete() } |