|
1 | 1 | import time |
2 | | -import ustruct |
| 2 | +try: |
| 3 | + import struct |
| 4 | +except ImportError: |
| 5 | + import ustruct as struct |
3 | 6 |
|
4 | 7 | import adafruit_bus_device.spi_device as spi_device |
5 | 8 |
|
@@ -45,22 +48,22 @@ def _block(self, x0, y0, x1, y1, data=None): |
45 | 48 | self._write(self._COLUMN_SET, self._encode_pos(x0, x1)) |
46 | 49 | self._write(self._PAGE_SET, self._encode_pos(y0, y1)) |
47 | 50 | if data is None: |
48 | | - size = ustruct.calcsize(self._DECODE_PIXEL) |
| 51 | + size = struct.calcsize(self._DECODE_PIXEL) |
49 | 52 | return self._read(self._RAM_READ, |
50 | 53 | (x1 - x0 + 1) * (y1 - y0 + 1) * size) |
51 | 54 | self._write(self._RAM_WRITE, data) |
52 | 55 |
|
53 | 56 | def _encode_pos(self, a, b): |
54 | 57 | """Encode a postion into bytes.""" |
55 | | - return ustruct.pack(self._ENCODE_POS, a, b) |
| 58 | + return struct.pack(self._ENCODE_POS, a, b) |
56 | 59 |
|
57 | 60 | def _encode_pixel(self, color): |
58 | 61 | """Encode a pixel color into bytes.""" |
59 | | - return ustruct.pack(self._ENCODE_PIXEL, color) |
| 62 | + return struct.pack(self._ENCODE_PIXEL, color) |
60 | 63 |
|
61 | 64 | def _decode_pixel(self, data): |
62 | 65 | """Decode bytes into a pixel color.""" |
63 | | - return color565(*ustruct.unpack(self._DECODE_PIXEL, data)) |
| 66 | + return color565(*struct.unpack(self._DECODE_PIXEL, data)) |
64 | 67 |
|
65 | 68 | def pixel(self, x, y, color=None): |
66 | 69 | """Read or write a pixel.""" |
|
0 commit comments