Skip to content

Commit 8feaafa

Browse files
mrmcwethytannewt
authored andcommitted
changed import ustruct to struct (#4)
changed import ustruct to struct
1 parent 7061bb0 commit 8feaafa

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

adafruit_rgb_display/ili9341.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import ustruct
1+
try:
2+
import struct
3+
except ImportError:
4+
import ustruct as struct
5+
26
from adafruit_rgb_display.rgb import DisplaySPI
37

48

@@ -60,4 +64,4 @@ def scroll(self, dy=None):
6064
if dy is None:
6165
return self._scroll
6266
self._scroll = (self._scroll + dy) % self.height
63-
self._write(0x37, ustruct.pack('>H', self._scroll))
67+
self._write(0x37, struct.pack('>H', self._scroll))

adafruit_rgb_display/rgb.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import time
2-
import ustruct
2+
try:
3+
import struct
4+
except ImportError:
5+
import ustruct as struct
36

47
import adafruit_bus_device.spi_device as spi_device
58

@@ -45,22 +48,22 @@ def _block(self, x0, y0, x1, y1, data=None):
4548
self._write(self._COLUMN_SET, self._encode_pos(x0, x1))
4649
self._write(self._PAGE_SET, self._encode_pos(y0, y1))
4750
if data is None:
48-
size = ustruct.calcsize(self._DECODE_PIXEL)
51+
size = struct.calcsize(self._DECODE_PIXEL)
4952
return self._read(self._RAM_READ,
5053
(x1 - x0 + 1) * (y1 - y0 + 1) * size)
5154
self._write(self._RAM_WRITE, data)
5255

5356
def _encode_pos(self, a, b):
5457
"""Encode a postion into bytes."""
55-
return ustruct.pack(self._ENCODE_POS, a, b)
58+
return struct.pack(self._ENCODE_POS, a, b)
5659

5760
def _encode_pixel(self, color):
5861
"""Encode a pixel color into bytes."""
59-
return ustruct.pack(self._ENCODE_PIXEL, color)
62+
return struct.pack(self._ENCODE_PIXEL, color)
6063

6164
def _decode_pixel(self, data):
6265
"""Decode bytes into a pixel color."""
63-
return color565(*ustruct.unpack(self._DECODE_PIXEL, data))
66+
return color565(*struct.unpack(self._DECODE_PIXEL, data))
6467

6568
def pixel(self, x, y, color=None):
6669
"""Read or write a pixel."""

adafruit_rgb_display/st7735.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from adafruit_rgb_display.rgb import DisplaySPI
2-
import ustruct
2+
try:
3+
import struct
4+
except ImportError:
5+
import ustruct as struct
36

47

58
_NOP=const(0x00)
@@ -132,8 +135,8 @@ def __init__(self, spi, dc, cs, rst=None, width=128, height=160):
132135

133136
def init(self):
134137
super().init()
135-
cols = ustruct.pack('>HH', 0, self.width - 1)
136-
rows = ustruct.pack('>HH', 0, self.height - 1)
138+
cols = struct.pack('>HH', 0, self.width - 1)
139+
rows = struct.pack('>HH', 0, self.height - 1)
137140
for command, data in (
138141
(_CASET, cols),
139142
(_RASET, rows),

0 commit comments

Comments
 (0)