@@ -117,9 +117,12 @@ class Display: #pylint: disable-msg=no-member
117117 _ENCODE_POS = ">HH"
118118 _DECODE_PIXEL = ">BBB"
119119
120- def __init__ (self , width , height ):
120+ def __init__ (self , width , height , rotation ):
121121 self .width = width
122122 self .height = height
123+ if rotation not in (0 , 90 , 180 , 270 ):
124+ raise ValueError ('Rotation must be 0/90/180/270' )
125+ self ._rotation = rotation
123126 self .init ()
124127
125128 def init (self ):
@@ -161,9 +164,11 @@ def pixel(self, x, y, color=None):
161164 self ._block (x , y , x , y , self ._encode_pixel (color ))
162165 return None
163166
164- def image (self , img , rotation = 0 ):
167+ def image (self , img , rotation = None ):
165168 """Set buffer to value of Python Imaging Library image. The image should
166169 be in 1 bit mode and a size equal to the display size."""
170+ if rotation is None :
171+ rotation = self .rotation
167172 if not img .mode in ('RGB' , 'RGBA' ):
168173 raise ValueError ('Image must be in mode RGB or RGBA' )
169174 if rotation not in (0 , 90 , 180 , 270 ):
@@ -215,13 +220,23 @@ def vline(self, x, y, height, color):
215220 """Draw a vertical line."""
216221 self .fill_rectangle (x , y , 1 , height , color )
217222
223+ @property
224+ def rotation (self ):
225+ """Set the default rotation"""
226+ return self ._rotation
227+
228+ @rotation .setter
229+ def rotation (self , val ):
230+ if val not in (0 , 90 , 180 , 270 ):
231+ raise ValueError ('Rotation must be 0/90/180/270' )
232+ self ._rotation = val
218233
219234class DisplaySPI (Display ):
220235 """Base class for SPI type devices"""
221236 #pylint: disable-msg=too-many-arguments
222237 def __init__ (self , spi , dc , cs , rst = None , width = 1 , height = 1 ,
223238 baudrate = 12000000 , polarity = 0 , phase = 0 , * ,
224- x_offset = 0 , y_offset = 0 ):
239+ x_offset = 0 , y_offset = 0 , rotation = 0 ):
225240 self .spi_device = spi_device .SPIDevice (spi , cs , baudrate = baudrate ,
226241 polarity = polarity , phase = phase )
227242 self .dc_pin = dc
@@ -232,7 +247,7 @@ def __init__(self, spi, dc, cs, rst=None, width=1, height=1,
232247 self .reset ()
233248 self ._X_START = x_offset # pylint: disable=invalid-name
234249 self ._Y_START = y_offset # pylint: disable=invalid-name
235- super ().__init__ (width , height )
250+ super ().__init__ (width , height , rotation )
236251 #pylint: enable-msg=too-many-arguments
237252
238253 def reset (self ):
0 commit comments