@@ -42,6 +42,7 @@ def read_buttons():
4242 if reading > 0.13 :
4343 return 2
4444 return 1
45+ return None
4546
4647# display bitmap file
4748def display_bitmap (epd , filename ):
@@ -108,9 +109,8 @@ def display_bitmap(epd, filename):
108109 for col in range (bmpWidth ):
109110 for b in range (8 ):
110111 if (rowdata [col ] & (0x80 >> b ) != 0 and blkpixel == 0 ) or (
111- rowdata [col ] & (0x80 >> b ) == 0 and blkpixel == 1
112- ):
113- epd .pixel (col * 8 + b , row , Adafruit_EPD .BLACK )
112+ rowdata [col ] & (0x80 >> b ) == 0 and blkpixel == 1 ):
113+ epd .pixel (col * 8 + b , row , Adafruit_EPD .BLACK )
114114 except OSError :
115115 display_message ("Error: couldn't read file " + filename )
116116 except BMPError :
@@ -248,75 +248,74 @@ def run_job(jobfile):
248248 out .write (bytearray ([0xFF , 0xFF , 0xFF , 0 , 0 , 0 , 0 , 0 ]))
249249 with open (
250250 config ["bkfolder" ] + "/background-" + str (whitepct )
251- + "-" + str (pixelsize ) + ".dat" , "rb" ) as fp :
252- bkdata = fp .read ()
253- canvas = list (bkdata )
254- for y in range (0 , display .height ):
255- # blink the LED
256- if y % 2 == 0 :
257- led .value = True
258- else :
259- led .value = False
260- tcanvas = [0 for i in range (display .width + panelwidth )]
261- tpanel = [0 for i in range (panelwidth )]
262- for x in range (panelwidth ):
263- bytepos = ((x % panelwidth ) // 8 ) + (
264- y // pixelsize * (panelwidth + 7 ) // 8
265- )
266- bitpos = x % 8
267- pixel = canvas [bytepos ] & 1 << (bitpos )
268- if pixel != 0 :
269- tpanel [x ] = 1
270- for x in range (display .width + panelwidth ):
271- pixel = tpanel [x % panelwidth ]
272- if pixel != 0 :
273- tcanvas [x ] = 1
274- for x in range (0 , display .width ):
275- if (x % panelwidth ) == 0 and x > 0 :
276- for x2 in range (x , x + panelwidth ):
277- tcanvas [x2 ] = tcanvas [x2 - panelwidth ]
278- for x2 in range (panelwidth ):
279- tpanel [x2 ] = tcanvas [x + x2 - panelwidth ]
280- offset = 0
281- print ("debug" )
282- if x >= 22 and (
283- x < (image .width + panelwidth // 2 )
284- and y < image .height
285- and (
286- (image [x - panelwidth // 2 , y ] != 0 and not inv )
287- or (image [x - panelwidth // 2 , y ] == 0 and inv )
251+ + "-" + str (pixelsize ) + ".dat" , "rb" ) as fp :
252+ bkdata = fp .read ()
253+ canvas = list (bkdata )
254+ for y in range (0 , display .height ):
255+ # blink the LED
256+ if y % 2 == 0 :
257+ led .value = True
258+ else :
259+ led .value = False
260+ tcanvas = [0 for i in range (display .width + panelwidth )]
261+ tpanel = [0 for i in range (panelwidth )]
262+ for x in range (panelwidth ):
263+ bytepos = ((x % panelwidth ) // 8 ) + (
264+ y // pixelsize * (panelwidth + 7 ) // 8
288265 )
289- ):
290- # offset = 4
291- if job ["imagegrayscale" ] == 0 :
292- offset = job ["imageheight" ]
293- else :
294- offset = (
295- image [x - panelwidth // 2 , y ]
296- * job ["grayscalecolors" ]
297- // 255
298- )
299- if offset != 0 :
300- for x2 in range (x , display .width , panelwidth ):
301- tcanvas [x2 ] = tcanvas [x2 + offset ]
302- for x in range (0 , display .width ):
303- # write line to eink display
304- if tcanvas [x ] != 0 :
305- display .pixel (x , y , Adafruit_EPD .BLACK )
306- # else:
307- # display.pixel(x,y,Adafruit_EPD.WHITE)
308- if createfile :
309- count = 0
310- for x in range (0 , display .width + 7 , 8 ):
311- value = 0
312- for b in range (8 ):
313- value |= (tcanvas [x + b ] << 7 ) >> b
314- out .write (bytes ([value ]))
315- count += 1
316- # add padding to end of line
317- padding = (4 - (count % 4 )) % 4
318- for x in range (padding ):
319- out .write (bytes ([0 ]))
266+ bitpos = x % 8
267+ pixel = canvas [bytepos ] & 1 << (bitpos )
268+ if pixel != 0 :
269+ tpanel [x ] = 1
270+ for x in range (display .width + panelwidth ):
271+ pixel = tpanel [x % panelwidth ]
272+ if pixel != 0 :
273+ tcanvas [x ] = 1
274+ for x in range (0 , display .width ):
275+ if (x % panelwidth ) == 0 and x > 0 :
276+ for x2 in range (x , x + panelwidth ):
277+ tcanvas [x2 ] = tcanvas [x2 - panelwidth ]
278+ for x2 in range (panelwidth ):
279+ tpanel [x2 ] = tcanvas [x + x2 - panelwidth ]
280+ offset = 0
281+ if x >= 22 and (
282+ x < (image .width + panelwidth // 2 )
283+ and y < image .height
284+ and (
285+ (image [x - panelwidth // 2 , y ] != 0 and not inv
286+ ) or (
287+ image [x - panelwidth // 2 , y ] == 0 and inv )
288+ )):
289+ # offset = 4
290+ if job ["imagegrayscale" ] == 0 :
291+ offset = job ["imageheight" ]
292+ else :
293+ offset = (
294+ image [x - panelwidth // 2 , y ]
295+ * job ["grayscalecolors" ]
296+ // 255
297+ )
298+ if offset != 0 :
299+ for x2 in range (x , display .width , panelwidth ):
300+ tcanvas [x2 ] = tcanvas [x2 + offset ]
301+ for x in range (0 , display .width ):
302+ # write line to eink display
303+ if tcanvas [x ] != 0 :
304+ display .pixel (x , y , Adafruit_EPD .BLACK )
305+ # else:
306+ # display.pixel(x,y,Adafruit_EPD.WHITE)
307+ if createfile :
308+ count = 0
309+ for x in range (0 , display .width + 7 , 8 ):
310+ value = 0
311+ for b in range (8 ):
312+ value |= (tcanvas [x + b ] << 7 ) >> b
313+ out .write (bytes ([value ]))
314+ count += 1
315+ # add padding to end of line
316+ padding = (4 - (count % 4 )) % 4
317+ for x in range (padding ):
318+ out .write (bytes ([0 ]))
320319 if createfile :
321320 out .close ()
322321 endtime = time .monotonic ()
@@ -347,8 +346,8 @@ def run_job(jobfile):
347346 continue
348347 print ("Button #%d pressed" % button )
349348 if button == 1 :
350- for jobfile in config ["jobs" ]:
351- run_job (jobfile )
349+ for job in config ["jobs" ]:
350+ run_job (job )
352351 if button == 2 :
353352 show_files ()
354353 time .sleep (0.01 )
0 commit comments