]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Fix some pylint errors
authorFrancis Guevarra <francis@binho.io>
Tue, 3 Dec 2019 01:16:04 +0000 (17:16 -0800)
committerFrancis Guevarra <francis@binho.io>
Tue, 3 Dec 2019 02:10:43 +0000 (18:10 -0800)
src/adafruit_blinka/microcontroller/nova/__init__.py
src/adafruit_blinka/microcontroller/nova/pin.py
src/adafruit_blinka/microcontroller/nova/pwmout.py
src/adafruit_blinka/microcontroller/nova/spi.py
src/adafruit_blinka/microcontroller/nova/uart.py

index 6c1d4460b5212be24bb92eaa58f5213910a47327..12ccf0c1c6f6a6696ead21d161e22d75dcedf6be 100644 (file)
@@ -3,22 +3,22 @@ class Connection:
     @staticmethod
     def getInstance():
         """ Static access method. """
     @staticmethod
     def getInstance():
         """ Static access method. """
-        if Connection.__instance == None:
+        if Connection.__instance is None:
             Connection()
         return Connection.__instance
 
     def __init__(self):
         """ Virtually private constructor. """
             Connection()
         return Connection.__instance
 
     def __init__(self):
         """ Virtually private constructor. """
-        if Connection.__instance != None:
+        if Connection.__instance is not None:
             raise Exception("This class is a singleton!")
             raise Exception("This class is a singleton!")
-        else:
-            from binhoHostAdapter import binhoHostAdapter
-            from binhoHostAdapter import binhoUtilities
 
 
-            utilities = binhoUtilities.binhoUtilities()
-            devices = utilities.listAvailableDevices()
+        from binhoHostAdapter import binhoHostAdapter
+        from binhoHostAdapter import binhoUtilities
+
+        utilities = binhoUtilities.binhoUtilities()
+        devices = utilities.listAvailableDevices()
 
 
-            if len(devices) > 0:
-                Connection.__instance = binhoHostAdapter.binhoHostAdapter(devices[0])
-            else:
-                raise RuntimeError('No Binho Nova found!')
+        if len(devices) > 0:
+            Connection.__instance = binhoHostAdapter.binhoHostAdapter(devices[0])
+        else:
+            raise RuntimeError('No Binho Nova found!')
index 966599cbb6ab26aa577b78121e4e6246a81a50e7..6b5a61636734998fd34132ca70cbb2c3b92c652e 100644 (file)
@@ -36,7 +36,7 @@ class Pin:
         if val is None:
             return int(Pin._nova.getIOpinValue(self.id).split('VALUE ')[1])
         # write
         if val is None:
             return int(Pin._nova.getIOpinValue(self.id).split('VALUE ')[1])
         # write
-        elif val in (self.LOW, self.HIGH):
+        if val in (self.LOW, self.HIGH):
             Pin._nova.setIOpinValue(self.id, val)
         else:
             raise RuntimeError("Invalid value for pin")
             Pin._nova.setIOpinValue(self.id, val)
         else:
             raise RuntimeError("Invalid value for pin")
@@ -54,8 +54,8 @@ SDA = IO0
 SCK = SCLK = IO3
 MOSI = IO4
 MISO = IO2
 SCK = SCLK = IO3
 MOSI = IO4
 MISO = IO2
-SS0  = IO0
-SS1  = IO1
+SS0 = IO0
+SS1 = IO1
 
 PWM0 = IO0
 # No PWM support on IO1
 
 PWM0 = IO0
 # No PWM support on IO1
@@ -64,10 +64,10 @@ PWM3 = IO3
 PWM4 = IO4
 
 # orderd as (channel, pin), id
 PWM4 = IO4
 
 # orderd as (channel, pin), id
-pwmOuts = ( ((1, 0), PWM0), ((1, 2), PWM2), ((1, 3), PWM3), ((1, 4), PWM4) )
+pwmOuts = (((1, 0), PWM0), ((1, 2), PWM2), ((1, 3), PWM3), ((1, 4), PWM4))
 
 UART1_TX = IO4
 UART1_RX = IO3
 
 # ordered as uartId, txId, rxId
 
 UART1_TX = IO4
 UART1_RX = IO3
 
 # ordered as uartId, txId, rxId
-uartPorts = ( (0, UART1_TX, UART1_RX), )
+uartPorts = ((0, UART1_TX, UART1_RX), )
index 2f4e4b563672578ac050f9159d69e56e5cd8ddd3..6af2de87e9bfffffa2b2ca800f1395803e7a3906 100644 (file)
@@ -1,5 +1,3 @@
-import os
-import digitalio
 
 try:
     from microcontroller.pin import pwmOuts
 
 try:
     from microcontroller.pin import pwmOuts
@@ -41,6 +39,7 @@ class PWMOut(object):
             from adafruit_blinka.microcontroller.nova import Connection
             PWMOut._nova = Connection.getInstance()
 
             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)
 
         self._pwmpin = None
         self._open(pin, duty_cycle, frequency, variable_frequency)
 
@@ -77,20 +76,20 @@ class PWMOut(object):
         self._set_enabled(True)
 
     def deinit(self):
         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
-
-      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:
 
     def _is_deinited(self):
         if self._pwmpin is None:
index 2e16c490ec0e25c3c82321294fe87bbd16e44c3a..39269229db72879e7546cd6a268a9bf9bc66499a 100644 (file)
@@ -21,14 +21,14 @@ class SPI:
         #  3     1    1
 
     def init(self, baudrate=100000, polarity=0, phase=0, bits=8,
         #  3     1    1
 
     def init(self, baudrate=100000, polarity=0, phase=0, bits=8,
-                  firstbit=MSB, sck=None, mosi=None, miso=None):
+             firstbit=MSB, sck=None, mosi=None, miso=None):
         #print("baudrate: " + str(baudrate))
         #print("mode: " + str((polarity<<1) | (phase)))
         self._nova.setClockSPI(0, baudrate)
         self._nova.setModeSPI(0, (polarity<<1) | (phase))
 
     @staticmethod
         #print("baudrate: " + str(baudrate))
         #print("mode: " + str((polarity<<1) | (phase)))
         self._nova.setClockSPI(0, baudrate)
         self._nova.setModeSPI(0, (polarity<<1) | (phase))
 
     @staticmethod
-    def getSpiReceivedData(lineOutput):
+    def get_received_data(lineOutput):
         return (lineOutput.split('RXD ')[1])
 
     @property
         return (lineOutput.split('RXD ')[1])
 
     @property
@@ -54,9 +54,9 @@ class SPI:
     def readinto(self, buf, start=0, end=None, write_value=0):
         end = end if end else len(buf)
         for i in range(start, end):
     def readinto(self, buf, start=0, end=None, write_value=0):
         end = end if end else len(buf)
         for i in range(start, end):
-            buf[start+i] = int(self.getSpiReceivedData(self._nova.transferSPI(0, write_value)))
+            buf[start+i] = int(self.get_received_data(self._nova.transferSPI(0, write_value)))
 
 
-    def write_readinto(self, buffer_out, buffer_in,  out_start=0, out_end=None, in_start=0, in_end=None):
+    def write_readinto(self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None):
         out_end = out_end if out_end else len(buffer_out)
         in_end = in_end if in_end else len(buffer_in)
         readlen = in_end-in_start
         out_end = out_end if out_end else len(buffer_out)
         in_end = in_end if in_end else len(buffer_in)
         readlen = in_end-in_start
@@ -68,7 +68,7 @@ class SPI:
             buffer_out = tmp
         i = 0
         for data_out in buffer_out:
             buffer_out = tmp
         i = 0
         for data_out in buffer_out:
-            data_in = int(self.getSpiReceivedData(self._nova.transferSPI(0, data_out)))
+            data_in = int(self.get_received_data(self._nova.transferSPI(0, data_out)))
             if i < readlen:
                 buffer_in[in_start+i] = data_in
             i += 1
             if i < readlen:
                 buffer_in[in_start+i] = data_in
             i += 1
index 3bb471aac239a6942546ef952216701be6a2acf8..253d7a7198bb6bcdc901f5ee8b13c8d96c4dd924 100644 (file)
@@ -62,4 +62,4 @@ class UART():
         return line
 
     def write(self, buf):
         return line
 
     def write(self, buf):
-        return self._nova.writeBridgeUART(buf)
\ No newline at end of file
+        return self._nova.writeBridgeUART(buf)