Skip to content

Commit 642cb0d

Browse files
committed
width/height change with rotation
1 parent cf49a1d commit 642cb0d

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

adafruit_epd/epd.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class Adafruit_EPD:
4444
# pylint: disable=too-many-arguments
4545
def __init__(self, width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin):
4646
# pylint: enable=too-many-arguments
47-
self.width = width
48-
self.height = height
47+
self._width = width
48+
self._height = height
4949

5050
# Setup reset pin, if we have one
5151
self._rst = rst_pin
@@ -145,6 +145,18 @@ def text(self, string, x, y, color, *, font_name="font5x8.bin"):
145145
self._bw_framebuf.text(string, x, y, (color == Adafruit_EPD.BLACK) != self.black_invert, font_name=font_name)
146146
self._red_framebuf.text(string, x, y, (color == Adafruit_EPD.RED) != self.red_invert, font_name=font_name)
147147

148+
@property
149+
def width(self):
150+
if self.rotation in (0, 2):
151+
return self._width
152+
return self._height
153+
154+
@property
155+
def height(self):
156+
if self.rotation in (0, 2):
157+
return self._height
158+
return self._width
159+
148160
@property
149161
def rotation(self):
150162
return self._bw_framebuf._rotation

adafruit_epd/il0373.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ def power_up(self):
109109
self.command(_IL0373_PANEL_SETTING, bytearray([0xCF]))
110110
self.command(_IL0373_CDI, bytearray([0x37]))
111111
self.command(_IL0373_PLL, bytearray([0x29]))
112-
_b1 = self.width & 0xFF
113-
_b2 = (self.width >> 8) & 0xFF
114-
_b3 = self.height & 0xFF
115-
_b4 = (self.height >> 8) & 0xFF
112+
_b1 = self._width & 0xFF
113+
_b2 = (self._width >> 8) & 0xFF
114+
_b3 = self._height & 0xFF
115+
_b4 = (self._height >> 8) & 0xFF
116116
self.command(_IL0373_RESOLUTION, bytearray([_b1, _b2, _b3, _b4]))
117117
self.command(_IL0373_VCM_DC_SETTING, bytearray([0x0A]))
118118

@@ -210,7 +210,7 @@ def image(self, image):
210210
x = 1
211211
pixel = pix[x, y]
212212

213-
addr = int(((self.width - x) * self.height + y)/8)
213+
addr = int(((self._width - x) * self._height + y)/8)
214214

215215
if pixel == (0xFF, 0, 0):
216216
addr = addr + self.bw_bufsize
@@ -226,11 +226,11 @@ def image(self, image):
226226
def pixel(self, x, y, color):
227227
"""draw a single pixel in the display buffer"""
228228
if self.sram:
229-
if (x < 0) or (x >= self.width) or (y < 0) or (y >= self.height):
229+
if (x < 0) or (x >= self._width) or (y < 0) or (y >= self._height):
230230
return
231231
if x == 0:
232232
x = 1
233-
addr = ((self.width - x) * self.height + y) // 8
233+
addr = ((self._width - x) * self._height + y) // 8
234234
if color == Adafruit_EPD.RED:
235235
current = self.sram.read8(addr + self.bw_bufsize)
236236
else:

0 commit comments

Comments
 (0)