feat(brake): display brake power with 4 colors

This commit is contained in:
2023-05-11 20:02:19 +02:00
parent 8b67d8a434
commit f4f83af3c5
3 changed files with 22 additions and 5 deletions

View File

@ -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
}

View File

@ -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,
},
}