@@ -118,54 +118,73 @@ def display(self):
118
118
"""show the contents of the display buffer"""
119
119
self .power_up ()
120
120
121
- while not self .spi_device .try_lock ():
122
- pass
123
- self .sram .cs_pin .value = False
124
- #send read command
125
- self .spi_device .write (bytearray ([Adafruit_MCP_SRAM .SRAM_READ ]))
126
- #send start address
127
- self .spi_device .write (bytearray ([0x00 , 0x00 ]))
128
- self .spi_device .unlock ()
129
-
130
- #first data byte from SRAM will be transfered in at the
131
- #same time as the EPD command is transferred out
132
- cmd = self .command (IL0373_DTM1 , end = False )
133
-
134
- while not self .spi_device .try_lock ():
135
- pass
136
- self ._dc .value = True
137
- xfer = bytearray ([cmd ])
138
- outbuf = bytearray (1 )
139
- for _ in range (self .bw_bufsize ):
140
- outbuf [0 ] = xfer [0 ]
141
- self .spi_device .write_readinto (outbuf , xfer )
142
- self ._cs .value = True
143
- self .sram .cs_pin .value = True
144
-
145
- time .sleep (.002 )
146
-
147
- self .sram .cs_pin .value = False
148
- #send read command
149
- self .spi_device .write (bytearray ([Adafruit_MCP_SRAM .SRAM_READ ]))
150
- #send start address
151
- self .spi_device .write (bytearray ([(self .bw_bufsize >> 8 ), (self .bw_bufsize & 0xFF )]))
152
- self .spi_device .unlock ()
153
-
154
- #first data byte from SRAM will be transfered in at the
155
- #same time as the EPD command is transferred out
156
- cmd = self .command (IL0373_DTM2 , end = False )
157
-
158
- while not self .spi_device .try_lock ():
159
- pass
160
- self ._dc .value = True
161
- xfer = bytearray ([cmd ])
162
- outbuf = bytearray (1 )
163
- for _ in range (self .bw_bufsize ):
164
- outbuf [0 ] = xfer [0 ]
165
- self .spi_device .write_readinto (outbuf , xfer )
166
- self ._cs .value = True
167
- self .sram .cs_pin .value = True
168
- self .spi_device .unlock ()
121
+ if self .sram :
122
+ while not self .spi_device .try_lock ():
123
+ pass
124
+ self .sram .cs_pin .value = False
125
+ #send read command
126
+ self .spi_device .write (bytearray ([Adafruit_MCP_SRAM .SRAM_READ ]))
127
+ #send start address
128
+ self .spi_device .write (bytearray ([0x00 , 0x00 ]))
129
+ self .spi_device .unlock ()
130
+
131
+ #first data byte from SRAM will be transfered in at the
132
+ #same time as the EPD command is transferred out
133
+ cmd = self .command (IL0373_DTM1 , end = False )
134
+
135
+ while not self .spi_device .try_lock ():
136
+ pass
137
+ self ._dc .value = True
138
+ xfer = bytearray ([cmd ])
139
+ outbuf = bytearray (1 )
140
+ for _ in range (self .bw_bufsize ):
141
+ outbuf [0 ] = xfer [0 ]
142
+ self .spi_device .write_readinto (outbuf , xfer )
143
+ self ._cs .value = True
144
+ self .sram .cs_pin .value = True
145
+
146
+ time .sleep (.002 )
147
+
148
+ self .sram .cs_pin .value = False
149
+ #send read command
150
+ self .spi_device .write (bytearray ([Adafruit_MCP_SRAM .SRAM_READ ]))
151
+ #send start address
152
+ self .spi_device .write (bytearray ([(self .bw_bufsize >> 8 ), (self .bw_bufsize & 0xFF )]))
153
+ self .spi_device .unlock ()
154
+
155
+ #first data byte from SRAM will be transfered in at the
156
+ #same time as the EPD command is transferred out
157
+ cmd = self .command (IL0373_DTM2 , end = False )
158
+
159
+ while not self .spi_device .try_lock ():
160
+ pass
161
+ self ._dc .value = True
162
+ xfer = bytearray ([cmd ])
163
+ outbuf = bytearray (1 )
164
+ for _ in range (self .bw_bufsize ):
165
+ outbuf [0 ] = xfer [0 ]
166
+ self .spi_device .write_readinto (outbuf , xfer )
167
+ self ._cs .value = True
168
+ self .sram .cs_pin .value = True
169
+ self .spi_device .unlock ()
170
+ else :
171
+ cmd = self .command (IL0373_DTM1 , end = False )
172
+ while not self .spi_device .try_lock ():
173
+ pass
174
+ self ._dc .value = True
175
+ self .spi_device .write (self .bw_buffer )
176
+ self ._cs .value = True
177
+ self .spi_device .unlock ()
178
+
179
+ time .sleep (.02 )
180
+
181
+ cmd = self .command (IL0373_DTM2 , end = False )
182
+ while not self .spi_device .try_lock ():
183
+ pass
184
+ self ._dc .value = True
185
+ self .spi_device .write (self .red_buffer )
186
+ self ._cs .value = True
187
+ self .spi_device .unlock ()
169
188
170
189
self .update ()
171
190
@@ -210,9 +229,17 @@ def draw_pixel(self, x, y, color):
210
229
x = 1
211
230
212
231
addr = ((self .width - x ) * self .height + y ) // 8
213
- if color == Adafruit_EPD .RED :
214
- addr = addr + self .bw_bufsize
215
- current = self .sram .read8 (addr )
232
+
233
+ if self .sram :
234
+ if color == Adafruit_EPD .RED :
235
+ current = self .sram .read8 (addr + self .bw_bufsize )
236
+ else :
237
+ current = self .sram .read8 (addr )
238
+ else :
239
+ if color == Adafruit_EPD .RED :
240
+ current = self .red_buffer [addr ]
241
+ else :
242
+ current = self .bw_buffer [addr ]
216
243
217
244
if color == Adafruit_EPD .WHITE :
218
245
current = current | (1 << (7 - y % 8 ))
@@ -221,7 +248,16 @@ def draw_pixel(self, x, y, color):
221
248
elif color == Adafruit_EPD .INVERSE :
222
249
current = current ^ (1 << (7 - y % 8 ))
223
250
224
- self .sram .write8 (addr , current )
251
+ if self .sram :
252
+ if color == Adafruit_EPD .RED :
253
+ current = self .sram .write8 (addr + self .bw_bufsize , current )
254
+ else :
255
+ current = self .sram .write8 (addr , current )
256
+ else :
257
+ if color == Adafruit_EPD .RED :
258
+ self .red_buffer [addr ] = current
259
+ else :
260
+ self .bw_buffer [addr ] = current
225
261
return
226
262
227
263
def fill (self , color ):
@@ -232,5 +268,10 @@ def fill(self, color):
232
268
black_fill = 0x00
233
269
if color == Adafruit_EPD .RED :
234
270
red_fill = 0x00
235
- self .sram .erase (0x00 , self .bw_bufsize , black_fill )
236
- self .sram .erase (self .bw_bufsize , self .red_bufsize , red_fill )
271
+ if self .sram :
272
+ self .sram .erase (0x00 , self .bw_bufsize , black_fill )
273
+ self .sram .erase (self .bw_bufsize , self .red_bufsize , red_fill )
274
+ else :
275
+ for i in range (len (self .bw_buffer )):
276
+ self .bw_buffer [i ] = black_fill
277
+ self .red_buffer [i ] = red_fill
0 commit comments