]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
politely cope with strings of bytes
authorladyada <limor@ladyada.net>
Sat, 30 Jun 2018 22:12:20 +0000 (18:12 -0400)
committerYour Name <you@example.com>
Sun, 12 Aug 2018 02:58:26 +0000 (02:58 +0000)
src/busio.py

index 3523acd7289e172357725233f5a55439558f35a4..0d23b337f678a3765bf83cfac3fd08f4bf45c264 100755 (executable)
@@ -53,6 +53,8 @@ class I2C(Lockable):
         return self._i2c.readfrom_into(address, buffer, stop)
 
     def writeto(self, address, buffer, start=0, end=None, stop=True):
+        if isinstance(buffer, str):
+            buffer = bytes([ord(x) for x in buffer])
         if start is not 0 or end is not None:
             if end is None:
                 return self._i2c.writeto(address, memoryview(buffer)[start:], stop)