diff --git a/pkg/led/led.go b/pkg/led/led.go index 63e4d3b..2264b6c 100644 --- a/pkg/led/led.go +++ b/pkg/led/led.go @@ -21,6 +21,7 @@ func init() { var ( ColorBlack = Color{0, 0, 0} ColorRed = Color{255, 0, 0} + ColorPurple = Color{255, 0, 255} ColorYellow = Color{255, 255, 0} ColorGreen = Color{0, 255, 0} ColorBlue = Color{0, 0, 255} @@ -145,6 +146,7 @@ func (l *PiColorLed) blink(freq float64) { var setLed = func(v int, led gpio.PinIO, mutex *sync.Mutex) { mutex.Lock() defer mutex.Unlock() + lvl := gpio.High if v == 0 { lvl = gpio.Low diff --git a/pkg/part/part.go b/pkg/part/part.go index 4d76d30..23549bd 100644 --- a/pkg/part/part.go +++ b/pkg/part/part.go @@ -161,7 +161,17 @@ func (p *LedPart) updateColor() { defer p.muThrottle.Unlock() if p.throttle <= -0.05 { - p.led.SetColor(led.Color{Red: int(p.throttle * -255)}) + col := led.ColorWhite + if p.throttle <= -0.25 { + col = led.ColorYellow + if p.throttle <= -0.5 { + col = led.ColorRed + if p.throttle <= -0.75 { + col = led.ColorPurple + } + } + } + p.led.SetColor(col) return } diff --git a/pkg/part/part_test.go b/pkg/part/part_test.go index eaf5774..45f20e5 100644 --- a/pkg/part/part_test.go +++ b/pkg/part/part_test.go @@ -138,17 +138,22 @@ func TestLedPart_OnThrottle(t *testing.T) { { "slow brake", testtools.NewFakeMessageFromProtobuf("throttle", &events.ThrottleMessage{Throttle: -0.06}), - led.Color{Red: 15}, + led.ColorWhite, }, { "normal brake", - testtools.NewFakeMessageFromProtobuf("throttle", &events.ThrottleMessage{Throttle: -0.5}), - led.Color{Red: 127}, + testtools.NewFakeMessageFromProtobuf("throttle", &events.ThrottleMessage{Throttle: -0.4}), + led.ColorYellow, + }, + { + "normal high brake", + testtools.NewFakeMessageFromProtobuf("throttle", &events.ThrottleMessage{Throttle: -0.6}), + led.ColorRed, }, { "high brake", testtools.NewFakeMessageFromProtobuf("throttle", &events.ThrottleMessage{Throttle: -1.}), - led.ColorRed, + led.ColorPurple, }, }