def draw_screen(battery_percent, sd_free_percent, photo_count): try: logging.debug("Loading fonts") font_file = os.path.join(resources_dir, 'OCRA.ttf') font_small = ImageFont.truetype(font_file, 12) font_medium = ImageFont.truetype(font_file, 16) font_large = ImageFont.truetype(font_file, 40) logging.info("Initializing screen") epd = epd2in13bc.EPD() epd.init() time.sleep(1) logging.debug("Preparing image") black_image = Image.new('1', (epd.height, epd.width), 255) # 212*104 red_image = Image.new('1', (epd.height, epd.width), 255) # 212*104 black_draw = ImageDraw.Draw(black_image) red_draw = ImageDraw.Draw(red_image) if battery_percent <= 25: bat_end = draw_gauge('Batt.', battery_percent, epd.height, red_draw, font_medium, 0) else: bat_end = draw_gauge('Batt.', battery_percent, epd.height, black_draw, font_medium, 0) if sd_free_percent <= 15: sd_end = draw_gauge('SD', sd_free_percent, epd.height, red_draw, font_medium, bat_end + 5) else: sd_end = draw_gauge('SD', sd_free_percent, epd.height, black_draw, font_medium, bat_end + 5) draw_counter(str(photo_count), epd.height, black_draw, font_large, sd_end + 1, epd.width - 1) black_image = black_image.transpose(Image.ROTATE_180) red_image = red_image.transpose(Image.ROTATE_180) logging.info("Updating screen") epd.display(epd.getbuffer(black_image), epd.getbuffer(red_image)) time.sleep(2) logging.info("Sleep mode") epd.sleep() except IOError as e: logging.info(e) except KeyboardInterrupt: logging.info("ctrl + c:") epd2in13bc.epdconfig.module_exit() exit()
os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib') if os.path.exists(libdir): sys.path.append(libdir) import logging from waveshare_epd import epd2in13bc import time from PIL import Image, ImageDraw, ImageFont import traceback logging.basicConfig(level=logging.DEBUG) try: logging.info("epd2in13bc Demo") epd = epd2in13bc.EPD() logging.info("init and Clear") epd.init() epd.Clear() time.sleep(1) # Drawing on the image logging.info("Drawing") font20 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 20) font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18) logging.info("3.read bmp file") HBlackimage = Image.open(os.path.join(picdir, '213_ad_tag-b.bmp')) HRYimage = Image.open(os.path.join(picdir, '213_ad_tag-ry.bmp')) epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRYimage)) time.sleep(2)
def main(): counterChecks = 0 counter = 0 try: logging.info("Skimbuster v1.0 Demo") epd = epd2in13bc.EPD() logging.info("init and Clear") epd.init() time.sleep(1) font16 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 16) font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18) HBlackimage = Image.new('1', (epd.height, epd.width), 255) # 298*126 HRYimage = Image.new('1', (epd.height, epd.width), 255) # 298*126 ryimage: red or yellow image drawblack = ImageDraw.Draw(HBlackimage) drawry = ImageDraw.Draw(HRYimage) drawry.text((2, 0), 'Skimbuster', font=font18, fill=0) drawblack.text((175, 1), 'v1.0', font=font18, fill=0) drawblack.text((35, 85), 'stutm @ SensePost', font=font16, fill=0) drawblack.line((0, 20, 298, 20), fill=0) drawblack.line((0, 85, 298, 85), fill=0) nearby_devices = discover_devices(lookup_names=True, lookup_class=True) for addr, name, cod in nearby_devices: counter = counter + 1 if name in listOfNames: deviceName = name counterChecks = counterChecks + 1 if (hex(cod) == '0x1f00'): deviceCod = hex(cod) counterChecks = counterChecks + 1 if addr[:8] in listOfPrefix: deviceMac = addr counterChecks = counterChecks + 1 drawblack.text((2, 20), 'Scanned devices:' + str(counter), font=font18, fill=0) if (counterChecks <= 3 and counterChecks != 0): drawblack.text((2, 42), 'Skimmer found: ' + deviceName, font=font18, fill=0) drawblack.text((2, 65), 'MAC: ' + deviceMac, font=font18, fill=0) else: drawblack.text((2, 42), 'No skimmer found. :)', font=font18, fill=0) epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRYimage)) time.sleep(20) logging.info("Clear...") epd.Clear() epd.sleep() command = "/usr/bin/sudo /sbin/shutdown -r now" process = subprocess.Popen(command.split(), stdout=subprocess.PIPE) output = process.communicate()[0] except IOError as e: logging.info(e) except KeyboardInterrupt: logging.info("ctrl + c:") epd2in13bc.epdconfig.module_exit() exit()