feat(brake): display brake power with 4 colors
This commit is contained in:
parent
8b67d8a434
commit
f4f83af3c5
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user