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