diff --git a/leads_vec/cli.py b/leads_vec/cli.py index 11616c6f..5909b2dc 100644 --- a/leads_vec/cli.py +++ b/leads_vec/cli.py @@ -14,8 +14,7 @@ from leads_audio import DIRECTION_INDICATOR_ON, DIRECTION_INDICATOR_OFF, WARNING, CONFIRM from leads_gui import RuntimeData, Window, GForceVar, FrequencyGenerator, Left, Color, Right, ContextManager, \ Typography, Speedometer, ProxyCanvas, SpeedTrendMeter, GForceMeter, Stopwatch, Hazard, initialize, Battery, Brake, \ - ESC, Satellite, Motor, Speed, Base64Photo -from leads_raspberry_pi import LEDGroupCommand, LEDCommand, Transition, Entire + ESC, Satellite, Motor, Speed, Base64Photo, Light from leads_vec.__version__ import __version__ @@ -248,16 +247,12 @@ def post_suspend(self, e: SuspensionEvent) -> None: @_override def brake_indicator(self, event: Event, state: bool) -> None: if has_device(BRAKE_INDICATOR): - get_device(BRAKE_INDICATOR).write(LEDGroupCommand( - LEDCommand.ON, Entire() - ) if state else LEDGroupCommand(LEDCommand.OFF, Entire())) + get_device(BRAKE_INDICATOR).write(state) @_override def left_indicator(self, e: Event, state: bool) -> None: if has_device(LEFT_INDICATOR): - get_device(LEFT_INDICATOR).write(LEDGroupCommand( - LEDCommand.BLINK, Transition("left2right", 100) - ) if state else LEDGroupCommand(LEDCommand.OFF, Entire())) + get_device(LEFT_INDICATOR).write(state) if state: w.add_frequency_generator("left_indicator", LeftIndicator(500)) w.add_frequency_generator("direction_indicator_sound", DirectionIndicatorSound(500)) @@ -269,9 +264,7 @@ def left_indicator(self, e: Event, state: bool) -> None: @_override def right_indicator(self, e: Event, state: bool) -> None: if has_device(RIGHT_INDICATOR): - get_device(RIGHT_INDICATOR).write(LEDGroupCommand( - LEDCommand.BLINK, Transition("right2left", 100) - ) if state else LEDGroupCommand(LEDCommand.OFF, Entire())) + get_device(RIGHT_INDICATOR).write(state) if state: w.add_frequency_generator("right_indicator", RightIndicator(500)) w.add_frequency_generator("direction_indicator_sound", DirectionIndicatorSound(500)) @@ -290,6 +283,7 @@ def hazard(self, e: Event, state: bool) -> None: uim["brake_fault"] = _Label(root, text="") uim["esc_fault"] = _Label(root, text="") uim["gps_fault"] = _Label(root, text="") + uim["light_fault"] = _Label(root, text="") uim["motor_fault"] = _Label(root, text="") uim["wsc_fault"] = _Label(root, text="") @@ -303,6 +297,8 @@ def on_fail(e: SuspensionEvent) -> None: uim["esc_fault"].configure(image=ESC(color=Color.RED)) case "GPS": uim["gps_fault"].configure(image=Satellite(color=Color.RED)) + case "LIGHT": + uim["light_fault"].configure(image=Light(color=Color.RED)) case "MOTOR": uim["motor_fault"].configure(image=Motor(color=Color.RED)) case "WSC": @@ -320,6 +316,8 @@ def on_recover(e: SuspensionEvent) -> None: uim["esc_fault"].configure(image=None) case "GPS": uim["gps_fault"].configure(image=None) + case "LIGHT": + uim["light_fault"].configure(image=None) case "MOTOR": uim["motor_fault"].configure(image=None) case "WSC": diff --git a/leads_vec/devices.py b/leads_vec/devices.py index 00b4e51d..1d637fb4 100644 --- a/leads_vec/devices.py +++ b/leads_vec/devices.py @@ -6,7 +6,7 @@ FRONT_VIEW_CAMERA, LEFT_VIEW_CAMERA, RIGHT_VIEW_CAMERA, REAR_VIEW_CAMERA, VisualDataContainer, BRAKE_INDICATOR from leads_arduino import ArduinoMicro, WheelSpeedSensor, VoltageSensor from leads_gui import Config -from leads_raspberry_pi import NMEAGPSReceiver, LEDGroup, LED, LEDGroupCommand, LEDCommand, Entire +from leads_raspberry_pi import NMEAGPSReceiver, LEDGroup, LED, LEDGroupCommand, LEDCommand, Entire, Transition config: Config = require_config() GPS_ONLY: int = config.get("gps_only", False) @@ -112,14 +112,40 @@ def initialize(self, *parent_tags: str) -> None: super().initialize(*parent_tags) -@device((BRAKE_INDICATOR, LEFT_INDICATOR, RIGHT_INDICATOR), MAIN_CONTROLLER, [ - (LED(23), LED(24)), - (LED(5, .5, .5), LED(6, .5, .5), LED(26, .5, .5)), - (LED(17, .5, .5), LED(27, .5, .5), LED(22, .5, .5)) -]) -class DirectionIndicators(LEDGroup): +class Indicator(LEDGroup): @override def initialize(self, *parent_tags: str) -> None: - mark_device(self, "DI") + mark_device(self, "LIGHT") super().initialize(*parent_tags) - self.write(LEDGroupCommand(LEDCommand.BLINK_ONCE, Entire())) + + +@device(BRAKE_INDICATOR, MAIN_CONTROLLER, (LED(23), LED(24))) +class BrakeIndicator(Indicator): + @override + def initialize(self, *parent_tags: str) -> None: + super().initialize(*parent_tags) + super().write(LEDGroupCommand(LEDCommand.BLINK_ONCE, Entire())) + + @override + def write(self, payload: bool) -> None: + super().write(LEDGroupCommand( + LEDCommand.OFF, Entire() + ) if payload else LEDGroupCommand(LEDCommand.OFF, Entire())) + + +@device(LEFT_INDICATOR, MAIN_CONTROLLER, (LED(5, .5, .5), LED(6, .5, .5), LED(26, .5, .5))) +class LeftIndicator(Indicator): + @override + def write(self, payload: bool) -> None: + super().write(LEDGroupCommand( + LEDCommand.BLINK, Transition("left2right", 100) + ) if payload else LEDGroupCommand(LEDCommand.OFF, Entire())) + + +@device(RIGHT_INDICATOR, MAIN_CONTROLLER, (LED(17, .5, .5), LED(27, .5, .5), LED(22, .5, .5))) +class RightIndicator(Indicator): + @override + def write(self, payload: bool) -> None: + super().write(LEDGroupCommand( + LEDCommand.BLINK, Transition("right2left", 100) + ) if payload else LEDGroupCommand(LEDCommand.OFF, Entire()))