]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Merge pull request #20 from brentru/write_readinto_patches 0.1.10
authorLimor "Ladyada" Fried <limor@ladyada.net>
Wed, 25 Jul 2018 15:43:48 +0000 (08:43 -0700)
committerGitHub <noreply@github.com>
Wed, 25 Jul 2018 15:43:48 +0000 (08:43 -0700)
Write_ReadInto PR Review Changes

.travis.yml
src/adafruit_blinka/microcontroller/raspi_23/spi.py

index 7c83742379aa87df8133277028b1ddee366572a6..58f60ffa7cd2eaf6e56128c2ae151823d9a4d3ea 100755 (executable)
@@ -17,7 +17,8 @@ deploy:
 
 install:
   - pip install -r requirements.txt
-  - pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme
+  - pip install --force-reinstall pylint==1.9.2
+  - pip install circuitpython-build-tools Sphinx sphinx-rtd-theme
 
 script:
   - pylint src/**/*.py
index d862e018c73167d641efff8728c6248c1dce3137..27ead42ebc5eb9ca2f11e58031f0be3b4f43e816 100755 (executable)
@@ -68,11 +68,16 @@ class SPI:
             print("Could not open SPI device - check if SPI is enabled in kernel!")
             raise
 
-    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):
         if not buffer_out or not buffer_in:
             return
+        if out_end is None:
+            out_end = len(buffer_out)        
+        if in_end is None:
+            in_end = len(buffer_in)
         if out_end - out_start != in_end - in_start:
-            raise RuntimeError
+            raise RuntimeError('Buffer slices must be of equal length.')
         try:
             self._spi.open(self._port, 0)
             try:
@@ -82,10 +87,10 @@ class SPI:
             self._spi.max_speed_hz = self.baudrate
             self._spi.mode = self.mode
             self._spi.bits_per_word = self.bits
-            data = self._spi.xfer(list(buffer_out))
-            for i in range(len(buffer_in)): # 'readinto' the given buffer
-                buffer_in[i] = data[i]
+            data = self._spi.xfer(list(buffer_out[out_start:out_end+1]))
+            for i in range((in_end - in_start)):
+                buffer_in[i+in_start] = data[i]
             self._spi.close()
         except FileNotFoundError as not_found:
             print("Could not open SPI device - check if SPI is enabled in kernel!")
-            raise
\ No newline at end of file
+            raise