Skip to content

Commit 00c835f

Browse files
committed
Better cleanup
1 parent 7e83c5e commit 00c835f

1 file changed

Lines changed: 2 additions & 11 deletions

File tree

library/inventorhatmini/__init__.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22

33
import time
4-
import atexit
54
import RPi.GPIO as GPIO
65
from ioexpander import SuperIOE, ADC
76
from ioexpander.motor import Motor, MotorState
@@ -112,8 +111,6 @@ def __init__(self, address=IOE_ADDRESS, motor_gear_ratio=50, init_motors=True, i
112111
# Setup a dummy Plasma class, so examples don't need to check LED presence
113112
self.leds = DummyPlasma()
114113

115-
atexit.register(self.__cleanup)
116-
117114
def reinit(self):
118115
try:
119116
self.__ioe = SuperIOE(i2c_addr=self.address, perform_reset=True)
@@ -139,15 +136,9 @@ def reinit(self):
139136
self.__ioe.set_mode(self.IOE_CURRENT_SENSES[0], ADC)
140137
self.__ioe.set_mode(self.IOE_CURRENT_SENSES[1], ADC)
141138

142-
def __cleanup(self):
143-
for motor in self.motors:
144-
motor.coast()
145-
146-
for servo in self.servos:
147-
servo.disable()
148-
139+
def __del__(self):
140+
self.__ioe.reset()
149141
self.leds.clear()
150-
151142
GPIO.cleanup()
152143

153144
def switch_pressed(self):

0 commit comments

Comments
 (0)