X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/9584ded68bb4b291c0c7aaa99a15b61962f265f3..94b8f61cb28cb7cab038744ebc60d0dcbbb9e4e5:/src/adafruit_blinka/microcontroller/nova/pwmout.py diff --git a/src/adafruit_blinka/microcontroller/nova/pwmout.py b/src/adafruit_blinka/microcontroller/nova/pwmout.py index 57aa0e5..6af2de8 100644 --- a/src/adafruit_blinka/microcontroller/nova/pwmout.py +++ b/src/adafruit_blinka/microcontroller/nova/pwmout.py @@ -1,5 +1,3 @@ -import os -import digitalio try: from microcontroller.pin import pwmOuts @@ -38,21 +36,10 @@ class PWMOut(object): """ if PWMOut._nova is None: - if Pin._nova is not None: - # check if Pin already connected to Binho Nova - PWMOut._nova = Pin._nova - else: - from binhoHostAdapter import binhoHostAdapter - from binhoHostAdapter import binhoUtilities - - utilities = binhoUtilities.binhoUtilities() - devices = utilities.listAvailableDevices() - - if len(devices) > 0: - PWMOut._nova = binhoHostAdapter.binhoHostAdapter(devices[0]) - else: - raise RuntimeError('No Binho Host Adapter found!') + from adafruit_blinka.microcontroller.nova import Connection + PWMOut._nova = Connection.getInstance() + PWMOut._nova.setOperationMode(0, 'IO') self._pwmpin = None self._open(pin, duty_cycle, frequency, variable_frequency) @@ -80,7 +67,6 @@ class PWMOut(object): # set frequency self.frequency = freq - PWMOut._nova.setIOpinPWMFreq(self._pwmpin, self.frequency) # set period self._period = self._get_period() @@ -90,27 +76,20 @@ class PWMOut(object): self._set_enabled(True) def deinit(self): - try: - """Deinit the Nova PWM.""" - if self._channel is not None: - #self.duty_cycle = 0 - self._set_enabled(False) # make to disable before unexport - """ - try: - #unexport_path = os.path.join(channel_path, self._unexport_path) - with open(os.path.join(channel_path, self._unexport_path), "w") as f_unexport: - f_unexport.write("%d\n" % self._pwmpin) - except IOError as e: - raise PWMError(e.errno, "Unexporting PWM pin: " + e.strerror) - """ - except Exception as e: - # due to a race condition for which I have not yet been - # able to find the root cause, deinit() often fails - # but it does not effect future usage of the pwm pin - print("warning: failed to deinitialize pwm pin {0}:{1} due to: {2}\n".format(self._channel, self._pwmpin, type(e).__name__)) - finally: - self._channel = None - self._pwmpin = None + try: + """Deinit the Nova PWM.""" + if self._channel is not None: + #self.duty_cycle = 0 + self._set_enabled(False) # make to disable before unexport + + except Exception as e: + # due to a race condition for which I have not yet been + # able to find the root cause, deinit() often fails + # but it does not effect future usage of the pwm pin + print("warning: failed to deinitialize pwm pin {0}:{1} due to: {2}\n".format(self._channel, self._pwmpin, type(e).__name__)) + finally: + self._channel = None + self._pwmpin = None def _is_deinited(self): if self._pwmpin is None: