Skip to content

Commit 4ab1359

Browse files
committed
mod: improve ArduinoAlvik Error handling
mod: removed sys module dependency fix: lab for micropython crashes after sys.exit(-2) on Win & MP1.24
1 parent 670385b commit 4ab1359

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

arduino_alvik/arduino_alvik.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
import struct
32
from machine import I2C
43
import _thread
@@ -231,12 +230,15 @@ def _idle(self, delay_=1, check_on_thread=False, blocking=False) -> None:
231230
self.i2c.set_single_thread(False)
232231
if self.is_on():
233232
print("\n********** Alvik is on **********")
234-
except KeyboardInterrupt:
233+
except KeyboardInterrupt as e:
235234
self.stop()
236-
sys.exit()
237-
except Exception as e:
238-
pass
235+
raise e
236+
except OSError as e:
239237
print(f'\nUnable to read SOC: {e}')
238+
raise e
239+
except Exception as e:
240+
print(f'\nUnhandled exception: {e} {type(e)}')
241+
raise e
240242
finally:
241243
LEDR.value(1)
242244
LEDG.value(1)
@@ -285,8 +287,8 @@ def begin(self) -> int:
285287
self._snake_robot(1000)
286288
self._wait_for_ack()
287289
if not self._wait_for_fw_check():
288-
print('\n********** PLEASE UPDATE ALVIK FIRMWARE (required: '+'.'.join(map(str,self._required_fw_version))+')! Check documentation **********\n')
289-
sys.exit(-2)
290+
self.stop()
291+
raise Exception('\n********** PLEASE UPDATE ALVIK FIRMWARE (required: '+'.'.join(map(str,self._required_fw_version))+')! Check documentation **********\n')
290292
self._snake_robot(2000)
291293
self.set_illuminator(True)
292294
self.set_behaviour(1)

examples/communication/modulino.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
pixels = ModulinoPixels(alvik.i2c)
1515

1616
if not pixels.connected:
17-
print("🤷 No pixel modulino found")
18-
sys.exit(-2)
17+
raise Exception("🤷 No pixel modulino found")
1918

2019
while True:
2120
try:

0 commit comments

Comments
 (0)