# GPIO setup GPIO.setmode(GPIO.BOARD) GPIO.setup(SHOT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(PRINT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(NEXT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(PREV_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(HALT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # add edge detection on a channel GPIO.add_event_detect(SHOT_PIN, GPIO.FALLING, bouncetime=1000) GPIO.add_event_detect(PRINT_PIN, GPIO.FALLING, bouncetime=1000) GPIO.add_event_detect(NEXT_PIN, GPIO.FALLING, bouncetime=400) GPIO.add_event_detect(PREV_PIN, GPIO.FALLING, bouncetime=400) # Create Sharp mempry LCD lcd = SMemLCD('/dev/spidev0.0') # Create Printer printer = Adafruit_Thermal("/dev/ttyAMA0", 115200, timeout=0, rtscts=True) # Create camera and in-memory stream stream = BytesIO() camera = PiCamera() camera.rotation = 180 camera.resolution = F_SIZE camera.framerate = 20 camera.contrast = 50 camera.exposure_mode = 'night' camera.start_preview() sleep(1)
img.paste(0) center(draw, 60, 'smemlcd library demo', font) s = 'closing in {:02d}...'.format(i) center(draw, 100, s, font) draw.rectangle((5, 120, 395, 140), outline='white') draw.rectangle((6, 121, 6 + 393 * (60 - i) / 60, 139), outline='white', fill='white') sw = time.monotonic() await lcd.write_async(img.tobytes()) end = time.monotonic() print('time: process={:.4f}, write={:.4f}'.format(end - start, end - sw)) await asyncio.sleep(0.2) loop = asyncio.get_event_loop() lcd = SMemLCD(args.device, loop=loop) lcd.width = 50 lcd.reversed = False try: loop.run_until_complete(run(lcd)) finally: loop.close() lcd.close() # vim: sw=4:et:ai
parser = argparse.ArgumentParser(description='smemlcd library example') parser.add_argument('-f', dest='font', nargs=1, help='TrueType font filename') parser.add_argument('device', help='SPI device filename, i.e. /dev/spi') args = parser.parse_args() WIDTH, HEIGHT = 400, 240 def center(draw, y, txt, font): w, h = draw.textsize(txt, font=font) x = int((WIDTH - w) / 2) draw.text((x, y), txt, fill='white', font=font) lcd = SMemLCD(args.device) img = PIL.Image.new('1', (WIDTH, HEIGHT)) draw = PIL.ImageDraw.Draw(img) if args.font: font = PIL.ImageFont.truetype(args.font[0], size=30) else: font = PIL.ImageFont.load_default() for i in range(60, -1, -1): img.paste(0) center(draw, 60, 'smemlcd library demo', font) s = 'closing in {:02d}...'.format(i) center(draw, 100, s, font)
from smemlcd import SMemLCD GPIO.setmode(GPIO.BOARD) GPIO.setup(22, GPIO.OUT, initial=GPIO.LOW) WIDTH, HEIGHT = 400, 240 # Create the in-memory stream stream = BytesIO() camera = PiCamera() camera.resolution = (864, 576) camera.start_preview() camera.contrast = 25 time.sleep(2) lcd = SMemLCD('/dev/spidev0.0') for i in range(100, -1, -1): t1 = time.time() camera.capture(stream, format='jpeg', use_video_port=True, resize=(WIDTH, HEIGHT)) stream.seek( 0) # "Rewind" the stream to the beginning so we can read its content image = Image.open(stream) image = image.convert('L') # convert image to black and white image = PIL.ImageOps.invert(image) image = image.convert('1') # convert image to black and white GPIO.output(22, 1)
# GPIO setup GPIO.setmode(GPIO.BOARD) GPIO.setup(SHOT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(PRINT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(NEXT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(PREV_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(HALT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # add edge detection on a channel GPIO.add_event_detect(SHOT_PIN, GPIO.FALLING, bouncetime=250) GPIO.add_event_detect(PRINT_PIN, GPIO.FALLING, bouncetime=250) GPIO.add_event_detect(NEXT_PIN, GPIO.FALLING, bouncetime=250) GPIO.add_event_detect(PREV_PIN, GPIO.FALLING, bouncetime=250) # Create Sharp mempry LCD lcd = SMemLCD('/dev/spidev0.0') # Create Printer printer = Adafruit_Thermal("/dev/ttyAMA0", 115200, timeout=0, rtscts=True) # Create camera and in-memory stream stream = BytesIO() camera = PiCamera() camera.rotation = 180 camera.resolution = (F_WIDTH, F_HEIGHT) camera.framerate = 8 camera.contrast = 50 camera.start_preview() sleep(1) #Printer resolution camera Thread to minimize shot delay liveViewThread = CameraThread()
parser = argparse.ArgumentParser(description='smemlcd library example') parser.add_argument('-f', dest='font', nargs=1, help='TrueType font filename') parser.add_argument('device', help='SPI device filename, i.e. /dev/spi') args = parser.parse_args() WIDTH, HEIGHT = 400, 240 def center(draw, y, txt, font): w, h = draw.textsize(txt, font=font) x = int((WIDTH - w) / 2) draw.text((x, y), txt, fill='white', font=font) lcd = SMemLCD(args.device) lcd.width = 50 lcd.reversed = False img = PIL.Image.new('1', (WIDTH, HEIGHT)) draw = PIL.ImageDraw.Draw(img) if args.font: font = PIL.ImageFont.truetype(args.font[0], size=30) else: font = PIL.ImageFont.load_default() for i in range(60, -1, -1): start = time.monotonic() img.paste(0) center(draw, 60, 'smemlcd library demo', font)
center(cr, 60, 'smemlcd library demo') s = 'closing in {:02d}...'.format(i) center(cr, 100, s) cr.rectangle(5, 120, 390, 20) cr.stroke() cr.rectangle(6, 121, 388 * (60 - i) / 60, 18) cr.fill() sw = time.monotonic() await lcd.write_async(img_data) end = time.monotonic() print('time: process={:.4f}, write={:.4f}'.format( end - start, end - sw)) await asyncio.sleep(0.2) loop = asyncio.get_event_loop() lcd = SMemLCD(args.device, loop=loop) try: loop.run_until_complete(run(lcd)) finally: loop.close() lcd.close() # vim: sw=4:et:ai
from smemlcd import SMemLCD import PIL.Image, PIL.ImageDraw, PIL.ImageFont parser = argparse.ArgumentParser(description='smemlcd library example') parser.add_argument('-f', dest='font', nargs=1, help='TrueType font filename') parser.add_argument('device', help='SPI device filename, i.e. /dev/spi') args = parser.parse_args() WIDTH, HEIGHT = 400, 240 def center(draw, y, txt, font): w, h = draw.textsize(txt, font=font) x = int((WIDTH - w) / 2) draw.text((x, y), txt, fill='white', font=font) lcd = SMemLCD(args.device) lcd.width = 50 lcd.reversed = False img = PIL.Image.new('1', (WIDTH, HEIGHT)) draw = PIL.ImageDraw.Draw(img) if args.font: font = PIL.ImageFont.truetype(args.font[0], size=30) else: font = PIL.ImageFont.load_default() for i in range(60, -1, -1): start = time.monotonic() img.paste(0) center(draw, 60, 'smemlcd library demo', font)
s = 'closing in {:02d}...'.format(i) center(draw, 100, s, font) draw.rectangle((5, 120, 395, 140), outline='white') draw.rectangle((6, 121, 6 + 393 * (60 - i) / 60, 139), outline='white', fill='white') sw = time.monotonic() await lcd.write_async(img.tobytes()) end = time.monotonic() print('time: process={:.4f}, write={:.4f}'.format( end - start, end - sw)) await asyncio.sleep(0.2) loop = asyncio.get_event_loop() lcd = SMemLCD(args.device, loop=loop) lcd.width = 50 lcd.reversed = False try: loop.run_until_complete(run(lcd)) finally: loop.close() lcd.close() # vim: sw=4:et:ai
cr.set_operator(cairo.OPERATOR_OVER) center(cr, 60, 'smemlcd library demo') s = 'closing in {:02d}...'.format(i) center(cr, 100, s) cr.rectangle(5, 120, 390, 20) cr.stroke() cr.rectangle(6, 121, 388 * (60 - i) / 60, 18) cr.fill() sw = time.monotonic() await lcd.write_async(img_data) end = time.monotonic() print('time: process={:.4f}, write={:.4f}'.format(end - start, end - sw)) await asyncio.sleep(0.2) loop = asyncio.get_event_loop() lcd = SMemLCD(args.device, loop=loop) try: loop.run_until_complete(run(lcd)) finally: loop.close() lcd.close() # vim: sw=4:et:ai