@@ -32,6 +32,16 @@ def __init__(self):
3232 self .__last_rfid_successful_read_time = 0
3333 self .__rfid_read_delay = Config .RFID .READ_DELAY
3434
35+ def handle_error (self , exception : Exception ) -> None :
36+ self .__display .clear ()
37+ self .__display .print_centered ("Exception" , line = 1 )
38+ self .__display .print_centered ("occurred" , line = 2 )
39+ self .__buzzer .play_failure ()
40+
41+ time .sleep (2 )
42+
43+ self .__display .print_scroll_text (f"{ type (exception ).__name__ } :{ str (exception )} " , line = 2 )
44+
3545 def run (self ) -> None :
3646 self .__display .print_centered (f"{ chr (Symbols .NOTE .index )} Music Box { chr (Symbols .NOTE .index )} " , line = 1 )
3747 self .__display .print_centered ("Initializing..." , line = 2 )
@@ -41,7 +51,7 @@ def run(self) -> None:
4151 return
4252
4353 self .__display .print ("Devices:" , line = 1 , clear_full = True )
44- self .__display_current_device ()
54+ self .__display_current_device (reset = True )
4555
4656 while True :
4757 self .__check_buttons_press ()
@@ -67,9 +77,9 @@ def __check_api_health(self) -> bool:
6777 self .__buzzer .play_success ()
6878 return True
6979
70- def __display_current_device (self ) -> None :
80+ def __display_current_device (self , reset : bool = False ) -> None :
7181 self .__display .print ("Loading..." , line = 2 , clear_line = True )
72- current_device_data = self .__api .get_current_device (reset = True )
82+ current_device_data = self .__api .get_current_device (reset = reset )
7383 self .__display_device (current_device_data )
7484
7585 def __display_device (self , device_data : dict ) -> None :
@@ -93,6 +103,8 @@ def __check_buttons_press(self) -> None:
93103 current_device_data = self .__api .previous_device ()
94104 elif was_right_button_pressed :
95105 current_device_data = self .__api .next_device ()
106+ else :
107+ return
96108
97109 self .__display_device (current_device_data )
98110 self .__buttons .reset ()
@@ -125,4 +137,8 @@ def __check_rfid_read(self) -> None:
125137
126138if __name__ == "__main__" :
127139 app = App ()
128- app .run ()
140+
141+ try :
142+ app .run ()
143+ except Exception as e :
144+ app .handle_error (e )
0 commit comments