def draw_scanned(gateway_ip, linecount): if gateway_ip == '': return try: epd = epd2in7.EPD() # Init logging.info('init and Clear') epd.init() epd.Clear(0xFF) # Declaring Fonts font24 = ImageFont.truetype(os.path.join(resdir, 'consola.ttf'), 24) font12 = ImageFont.truetype(os.path.join(resdir, 'consola.ttf'), 12) font35 = ImageFont.truetype(os.path.join(resdir, 'consola.ttf'), 35) # Drawing logging.info('Drawing...') himage = Image.new('1', (epd.height, epd.width), 255) draw = ImageDraw.Draw(himage) # Title draw.text((10, 0), 'miezikatz', font=font24, fill=0) # Face draw.text((10, 40), faces.STARTUP_MIEZI1, font=font24, fill=0) draw.text((10, 65), faces.STARTUP_MIEZI2, font=font24, fill=0) draw.text((10, 90), faces.STARTUP_MIEZI3, font=font24, fill=0) # Explanation draw.text((10, 150), 'Finished! Maybe collected sth :3 ', font=font12, fill=0) # Gateway IP draw.text((130, 30), 'Default Gateway', font=font12, fill=0) draw.text((130, 40), gateway_ip, font=font12, fill=0) draw.rectangle((125, 25, 250, 55), outline = 0) # Linecount draw.text((130, 65), 'Wrote', font=font12, fill=0) draw.text((130, 75), str(linecount), font=font12, fill=0) draw.text((130, 85), 'lines to file', font=font12, fill=0) draw.rectangle((125, 60, 250, 100), outline = 0) epd.display(epd.getbuffer(himage)) except IOError as e: logging.info(e) except KeyboardInterrupt: logging.info('ctrl + c:') epd2in7.epdconfig.module_exit() exit()
def beanaproblem(message): # A visual cue that the wheels have fallen off thebean = Image.open(os.path.join(picdir, 'thebean.bmp')) epd = epd2in7.EPD() epd.Init_4Gray() image = Image.new('L', (epd.height, epd.width), 255) # 255: clear the image with white draw = ImageDraw.Draw(image) image.paste(thebean, (60, 15)) draw.text((15, 150), message, font=font_date, fill=0) image = ImageOps.mirror(image) epd.display_4Gray(epd.getbuffer_4Gray(image)) logging.info("epd2in7 BTC Frame") # Reload last good config.yaml with open(configfile) as f: config = yaml.load(f, Loader=yaml.FullLoader)
def main(): """Main function""" global g_image try: # *** PaPiRus ePaper / eInk Screen HAT for Raspberry Pi - 2.7" *** from papirus import Papirus papirus = Papirus(rotation=0) g_image = Image.new('1', papirus.size, WHITE) draw_image() g_image.save(image_filename) papirus.display(g_image) papirus.update() return except: logging.debug("Papirus failed.", exc_info=1) try: # *** Waveshare 2.7inch e-Paper HAT *** libdir = os.path.realpath( os.getenv('HOME') + '/e-Paper/RaspberryPi_JetsonNano/python/lib') if os.path.exists(libdir): sys.path.append(libdir) else: libdir = os.path.realpath( os.getenv('HOME') + '/e-Paper/RaspberryPi&JetsonNano/python/lib') if os.path.exists(libdir): sys.path.append(libdir) from waveshare_epd import epd2in7 epd = epd2in7.EPD() epd.init() g_image = Image.new('1', (epd.height, epd.width), 255) draw_image() g_image.save(image_filename) epd.display(epd.getbuffer(g_image)) epd.sleep() return except: logging.debug("Waveshare failed.", exc_info=1) # *** no known screen: just save the bmp logging.debug("No known screen.") g_image = Image.new('1', (264, 176), WHITE) draw_image() g_image.save(image_filename)
def draw_shutdown(): try: epd = epd2in7.EPD() # Init logging.info('init and Clear') epd.init() epd.Clear(0xFF) # Declaring Fonts font18 = ImageFont.truetype(os.path.join(resdir, 'consola.ttf'), 18) font10 = ImageFont.truetype(os.path.join(resdir, 'consola.ttf'), 10) ''' Himage2 = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame bmp = Image.open(os.path.join(picdir, '100x100.bmp')) Himage2.paste(bmp, (50,10)) epd.display(epd.getbuffer(Himage2)) ''' # Drawing logging.info('Drawing...') himage = Image.new('1', (epd.height, epd.width), 255) bmp = Image.open(os.path.join(resdir, 'sleeping_miezi.bmp')) draw = ImageDraw.Draw(himage) # Title draw.text((2, 2), 'Miezi tired. Zzzzz...', font=font18, fill=0) # Explanation draw.text((2, 18), '[ Don\'t wake her up :( ]', font=font10, fill=0) # Bitmap himage.paste(bmp, (25, 40)) epd.display(epd.getbuffer(himage)) except IOError as e: logging.info(e) except KeyboardInterrupt: logging.info('ctrl + c:') epd2in7.epdconfig.module_exit() exit()
def draw_startup(gateway_ip): try: epd = epd2in7.EPD() # Init logging.info('init and Clear') epd.init() epd.Clear(0xFF) # Declaring Fonts font24 = ImageFont.truetype(os.path.join(resdir, 'consola.ttf'), 24) font12 = ImageFont.truetype(os.path.join(resdir, 'consola.ttf'), 12) font35 = ImageFont.truetype(os.path.join(resdir, 'consola.ttf'), 35) # Drawing logging.info('Drawing...') himage = Image.new('1', (epd.height, epd.width), 255) draw = ImageDraw.Draw(himage) # Title draw.text((10, 0), 'miezikatz', font=font24, fill=0) # Face draw.text((10, 40), faces.STARTUP_MIEZI1, font=font24, fill=0) draw.text((10, 65), faces.STARTUP_MIEZI2, font=font24, fill=0) draw.text((10, 90), faces.STARTUP_MIEZI3, font=font24, fill=0) # Explanation draw.text((10, 150), 'Ready for meowing! Press Button...', font=font12, fill=0) # Gateway IP draw.text((130, 30), 'Default Gateway', font=font12, fill=0) draw.text((130, 40), gateway_ip, font=font12, fill=0) draw.rectangle((125, 25, 250, 55), outline = 0) epd.display(epd.getbuffer(himage)) except IOError as e: logging.info(e) except KeyboardInterrupt: logging.info('ctrl + c:') epd2in7.epdconfig.module_exit() exit()
def main(): logging.basicConfig(level=logging.DEBUG) # Initialise the display (once before loop) epd = epd2in7.EPD() epd.Init_4Gray() try: logging.info("epd2in7 BTC Frame") # Get the configuration from config.yaml with open(configfile) as f: config = yaml.load(f, Loader=yaml.FullLoader) logging.info(config) config['display']['orientation'] = int( config['display']['orientation']) key1 = 5 key2 = 6 key3 = 13 key4 = 19 # Note that there has been no data pull yet datapulled = False # Time of start lastcoinfetch = time.time() # Get the buttons for 2.7in EPD set up GPIO.setmode(GPIO.BCM) GPIO.setup(key1, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(key2, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(key3, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(key4, GPIO.IN, pull_up_down=GPIO.PUD_UP) while True: # Poll Keystates key1state = GPIO.input(key1) key2state = GPIO.input(key2) key3state = GPIO.input(key3) key4state = GPIO.input(key4) # If there is an internet connection, respond to the keypresses if internet(): if key1state == False: logging.info('Cycle currencies') crypto_list = currencycycle(config['ticker']['currency']) config['ticker']['currency'] = ",".join(crypto_list) lastcoinfetch = fullupdate(epd, config, lastcoinfetch) configwrite(config) if key2state == False: logging.info('Rotate - 90') config['display']['orientation'] = ( config['display']['orientation'] + 90) % 360 lastcoinfetch = fullupdate(epd, config, lastcoinfetch) configwrite(config) if key3state == False: logging.info('Invert Display') config['display'][ 'inverted'] = not config['display']['inverted'] lastcoinfetch = fullupdate(epd, config, lastcoinfetch) configwrite(config) if key4state == False: logging.info('Cycle fiat') fiat_list = currencycycle(config['ticker']['fiatcurrency']) config['ticker']['fiatcurrency'] = ",".join(fiat_list) lastcoinfetch = fullupdate(epd, config, lastcoinfetch) configwrite(config) if (time.time() - lastcoinfetch > float( config['ticker']['updatefrequency'])) or (datapulled == False): if config['display']['cycle'] == True: crypto_list = currencycycle( config['ticker']['currency']) config['ticker']['currency'] = ",".join(crypto_list) # configwrite(config) lastcoinfetch = fullupdate(epd, config, lastcoinfetch) datapulled = True except IOError as e: logging.info(e) image = beanaproblem(epd, str(e)) display_image(epd, image) except KeyboardInterrupt: logging.info("ctrl + c:") image = beanaproblem(epd, "Keyboard Interrupt") display_image(epd, image) epd2in7.epdconfig.module_exit() GPIO.cleanup() exit()
def __init__(self): self.epd = epd2in7.EPD() self.epd.init() inp = self.read_data() self.city = inp["city"] self.data = inp["one_call"]
def updateDisplay(config, pricestack, whichcoin, fiat): """ Takes the price data, the desired coin/fiat combo along with the config info for formatting if config is re-written following adustment we could avoid passing the last two arguments as they will just be the first two items of their string in config """ days_ago = int(config['ticker']['sparklinedays']) symbolstring = currency.symbol(fiat.upper()) if fiat == "jpy": symbolstring = "¥" pricenow = pricestack[-1] currencythumbnail = 'currency/' + whichcoin + '.bmp' tokenimage = Image.open(os.path.join(picdir, currencythumbnail)) sparkbitmap = Image.open(os.path.join(picdir, 'spark.bmp')) pricechange = str("%+d" % round( (pricestack[-1] - pricestack[0]) / pricestack[-1] * 100, 2)) + "%" if pricenow > 1000: pricenowstring = format(int(pricenow), ",") else: pricenowstring = str(float('%.5g' % pricenow)) if config['display']['orientation'] == 0 or config['display'][ 'orientation'] == 180: epd = epd2in7.EPD() epd.Init_4Gray() image = Image.new('L', (epd.width, epd.height), 255) # 255: clear the image with white draw = ImageDraw.Draw(image) draw.text((110, 80), str(days_ago) + "day :", font=font_date, fill=0) draw.text((110, 95), pricechange, font=font_date, fill=0) # Print price to 5 significant figures draw.text((15, 200), symbolstring + pricenowstring, font=font, fill=0) draw.text((10, 10), str(time.strftime("%H:%M %a %d %b %Y")), font=font_date, fill=0) image.paste(tokenimage, (10, 25)) image.paste(sparkbitmap, (10, 125)) if config['display']['orientation'] == 180: image = image.rotate(180, expand=True) if config['display']['orientation'] == 90 or config['display'][ 'orientation'] == 270: epd = epd2in7.EPD() epd.Init_4Gray() image = Image.new('L', (epd.height, epd.width), 255) # 255: clear the image with white draw = ImageDraw.Draw(image) draw.text((110, 90), str(days_ago) + "day : " + pricechange, font=font_date, fill=0) # Print price to 5 significant figures # draw.text((20,120),symbolstring,font =fonthiddenprice,fill = 0) draw.text((10, 120), symbolstring + pricenowstring, font=fontHorizontal, fill=0) image.paste(sparkbitmap, (80, 40)) image.paste(tokenimage, (0, 10)) draw.text((95, 15), str(time.strftime("%H:%M %a %d %b %Y")), font=font_date, fill=0) if config['display']['orientation'] == 270: image = image.rotate(180, expand=True) # This is a hack to deal with the mirroring that goes on in 4Gray Horizontal image = ImageOps.mirror(image) # If the display is inverted, invert the image usinng ImageOps if config['display']['inverted'] == True: image = ImageOps.invert(image) # Send the image to the screen epd.display_4Gray(epd.getbuffer_4Gray(image)) epd.sleep()
def main(): initial_screen = False info_status = False global photo_order photo_order = photo_list # Initialise the display (once before loop) epd = epd2in7.EPD() epd.Init_4Gray() # Initialize the keys key1, key2, key3, key4 = 5, 6, 13, 19 GPIO.setmode(GPIO.BCM) for key in (key1, key2, key3, key4): GPIO.setup(key, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Get the configuration from config.yaml with open(configfile) as f: config = yaml.load(f, Loader=yaml.FullLoader) config['display']['orientation'] = int(config['display']['orientation']) # Set time last_time = time.time() try: while True: # Detect button press if GPIO.input(key1) == False: # Show previous photo photo_order = photo_order[-1:] + photo_order[:-1] update_image(epd, config) info_status = False last_time = time.time() if GPIO.input(key2) == False: # Show next photo photo_order = photo_order[1:] + photo_order[:1] update_image(epd, config) info_status = False last_time = time.time() if GPIO.input(key3) == False: # Rotate 90 degrees config['display']['orientation'] = (config['display']['orientation']+90) % 360 update_image(epd, config) info_status = False last_time = time.time() # Overwrite config.yaml with open(configfile, 'w') as f: data = yaml.dump(config, f) if GPIO.input(key4) == False: # Display info if info_status == True: update_image(epd, config) info_status = False else: display_info(epd, config) info_status = True last_time = time.time() # Cycle photos if (time.time() - last_time > float(config['ticker']['updatefrequency'])) or (initial_screen == False): # Make first photo the last in the list if (config['display']['cycle'] == True) and (initial_screen == True): photo_order = photo_order[1:] + photo_order[:1] # Update image update_image(epd, config) # Update time keeper last_time = time.time() time.sleep(0.2) # Update initialization status initial_screen = True info_status = False except KeyboardInterrupt: print("ctrl + c: exiting") epd2in7.epdconfig.module_exit() GPIO.cleanup() exit()
def updateDisplay(config,pricestack,whichcoin): pricenow = pricestack[-1] currencythumbnail= 'currency/'+whichcoin+'.bmp' tokenimage = Image.open(os.path.join(picdir,currencythumbnail)) sparkbitmap = Image.open(os.path.join(picdir,'spark.bmp')) if config['ticker']['hidden'] == True: if config['display']['orientation'] == 0 or config['display']['orientation'] == 180 : epd = epd2in7.EPD() epd.Init_4Gray() image = Image.new('L', (epd.width, epd.height), 255) # 255: clear the image with white image.paste(tokenimage, (10,20)) draw = ImageDraw.Draw(image) draw.text((5,200),"1 "+ whichcoin,font =fonthiddenprice ,fill = 0) draw.text((0,10),str(time.strftime(" %a %b %d %I:%m%p")),font =font_date,fill = 0) if config['display']['orientation'] == 180 : image=image.rotate(180, expand=True) if config['display']['orientation'] == 90 or config['display']['orientation'] == 270 : epd = epd2in7.EPD() epd.Init_4Gray() image = Image.new('L', (epd.height, epd.width), 255) # 255: clear the image with white image.paste(tokenimage, (0,0)) draw = ImageDraw.Draw(image) draw.text((20,120),"1 "+ whichcoin,font =fontHorizontal,fill = 0) draw.text((85,5),str(time.strftime("%a %b %d %Y %n %t %I:%m %p")),font =font_date,fill = 0) if config['display']['orientation'] == 270 : image=image.rotate(180, expand=True) # This is a hack to deal with the mirroring that goes on in 4Gray Horizontal image = ImageOps.mirror(image) else: # Get the numbers pricechange = str("%+d" % round((pricestack[-1]-pricestack[0])/pricestack[-1]*100,2))+"%" if pricenow > 1000: pricenowstring =format(int(pricenow),",") else: pricenowstring =str(float('%.5g' % pricenow)) if config['display']['orientation'] == 0 or config['display']['orientation'] == 180 : epd = epd2in7.EPD() epd.Init_4Gray() image = Image.new('L', (epd.width, epd.height), 255) # 255: clear the image with white draw = ImageDraw.Draw(image) draw.text((110,80),"7day :",font =font_date,fill = 0) draw.text((110,95),pricechange,font =font_date,fill = 0) # Print price to 5 significant figures draw.text((5,200),"$"+pricenowstring,font =font,fill = 0) draw.text((0,10),str(time.strftime(" %a %b %d %I:%m%p")),font =font_date,fill = 0) image.paste(tokenimage, (10,25)) image.paste(sparkbitmap,(10,125)) if config['display']['orientation'] == 180 : image=image.rotate(180, expand=True) if config['display']['orientation'] == 90 or config['display']['orientation'] == 270 : epd = epd2in7.EPD() epd.Init_4Gray() image = Image.new('L', (epd.height, epd.width), 255) # 255: clear the image with white draw = ImageDraw.Draw(image) draw.text((100,100),"7day : "+pricechange,font =font_date,fill = 0) # Print price to 5 significant figures draw.text((20,120),"$"+pricenowstring,font =fontHorizontal,fill = 0) image.paste(sparkbitmap,(80,50)) image.paste(tokenimage, (0,0)) draw.text((85,5),str(time.strftime("%a %b %d %Y %n %t %I:%m %p")),font =font_date,fill = 0) if config['display']['orientation'] == 270 : image=image.rotate(180, expand=True) # This is a hack to deal with the mirroring that goes on in 4Gray Horizontal image = ImageOps.mirror(image) # If the display is inverted, invert the image usinng ImageOps if config['display']['inverted'] == True: image = ImageOps.invert(image) # Send the image to the screen epd.display_4Gray(epd.getbuffer_4Gray(image)) epd.sleep()
def main(): print("Weather station started") now = datetime.now() epd = epd2in7.EPD() epd.init() epd.Clear(0xFF) time.sleep(1) try: PaperImage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame draw = ImageDraw.Draw(PaperImage) draw.text((40, 40), 'HELLO.', font=helloFont, fill = 0) draw.text((40, 90), 'I AM WEATHER STATION.', font=helloFont, fill = 0) #draw.text((10,130), u'', font=iconFont, fill=0) draw.text((5, 165), 'V 1.0', font=hello8Font, fill = 0) draw.text((110, 165), 'RETRIEVING WEATHER INFORMATION...', font=hello8Font, fill = 0) epd.display(epd.getbuffer(PaperImage)) basedir = os.path.dirname(os.path.realpath(__file__)) icondir = os.path.join(basedir, 'icons') time.sleep(10) #epd.sleep() # better to do with this. started_time = time.time() - refresh_interval while True: print("loop start") elapsed_time = time.time() - started_time #epd = epd2in7.EPD() epd.init() #epd.Clear(0xFF) # if current time is 2AM or later, dim the screen. I have no idea it will burn or not. now = datetime.now() if((now.hour >= sleepStart) and (now.hour < sleepEnd)): print("sleep monitor") epd.Clear(0xFF) epd.sleep() # better to do with this. time.sleep(600) continue PaperImage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame draw = ImageDraw.Draw(PaperImage) basedir = os.path.dirname(os.path.realpath(__file__)) icondir = os.path.join(basedir, 'icons') if(elapsed_time >= refresh_interval): started_time = time.time() subprocess.check_output(os.path.join(basedir, 'download.sh'), shell=True) time.sleep(10) with open(os.path.join(basedir, 'current-data.json')) as conditions_data_file: conditions_data = json.load(conditions_data_file) with open(os.path.join(basedir, 'forecast-data.json')) as forecast_data_file: forecast_data = json.load(forecast_data_file) #city_name = conditions_data[u'name'] city_name = 'Toronto' temp_cur = conditions_data[u'main'][u'temp'] temp_cur_feels = conditions_data[u'main'][u'feels_like'] icon = str(conditions_data[u'weather'][0][u'icon']) description = conditions_data[u'weather'][0][u'description'] humidity = conditions_data[u'main'][u'humidity'] epoch = int(conditions_data[u'dt']) utime = time.strftime('%H:%M', time.localtime(epoch)) forecasts = [] finfo = forecastInfo() finfo.time = "Now" #city_name finfo.temp = temp_cur finfo.humidity = humidity finfo.timePfx = '' #finfo.bmp = logo finfo.icon = icon finfo.description = description forecasts.append(finfo) draw.text((5, 0), now.strftime("%B %-d"), font =font32, fill = 0) draw.text((210, 0), now.strftime("%a"), font =font32, fill = 0) # 04 font #draw.text((10, 0), now.strftime("%B %-d").upper(), font =hello32Font, fill = 0) #draw.text((210, 0), now.strftime("%a").upper(), font =hello32Font, fill = 0) # temp draw.text((5, 35), "TEMPERATURE", font =hello8Font, fill = 0) draw.text((10, 42), "%2.1fc" % temp_cur, font =font32, fill = 0) draw.text((5, 75), "FEELS LIKE", font =hello8Font, fill = 0) draw.text((10, 80), "%2.1fc" % temp_cur_feels, font =font32, fill = 0) # icon draw.text((140, 30), iconMap[icon], font =iconFontMid, fill = 0) # weather desc draw.text((110, 35), description.upper(), font =hello8Font, fill = 0) draw.line((95, 50, 95, 100), fill = 0) #draw.line((0, 125, 295, 125), fill = 0) # forecast draw : fi = forecast index (every 3 hours) for fi in range(4): finfo = forecastInfo() finfo.time_dt = forecast_data[u'list'][fi][u'dt'] finfo.time = time.strftime('%-I', time.localtime(finfo.time_dt)) finfo.ampm = time.strftime('%p', time.localtime(finfo.time_dt)) #finfo.time = time.strftime('%-I', time.localtime(finfo.time_dt)) finfo.timePfx = time.strftime('%p', time.localtime(finfo.time_dt)) finfo.temp = forecast_data[u'list'][fi][u'main'][u'temp'] finfo.humidity = forecast_data[u'list'][fi][u'main'][u'humidity'] finfo.icon = forecast_data[u'list'][fi][u'weather'][0][u'icon'] # show the first wether condition...? finfo.description = forecast_data[u'list'][fi][u'weather'][0][u'description'] # show the first wether condition...? #finfo.bmp = Image.open(os.path.join(icondir, finfo.icon[0:2] + ".bmp")) #forecasts.append(finfo) columnWidth = 65 if(fi > 0): draw.line(((fi * columnWidth), 145, (fi * columnWidth), 180), fill = 0) draw.text((3 + (fi * columnWidth), 130), finfo.time, font =helloFont, fill = 0) draw.text((8 + (fi * columnWidth), 145), finfo.ampm, font =hello8Font, fill = 0) draw.text((20 + (fi * columnWidth), 160), ("%2.1f" % finfo.temp), font=helloFont , fill = 0) draw.text((25 + (fi * columnWidth), 125), iconMap[finfo.icon], font =iconFontSmall, fill = 0) #draw.text((5 + (fi * columnWidth), 110), str(finfo.temp), font =font8, fill = 0) #draw.text((5 + (fi * columnWidth), 140), str(finfo.humidity) + '%', font =font8, fill = 0) #draw.text((160,8), "AS OF " + utime, font =hello8Font, fill = 0) epd.display(epd.getbuffer(PaperImage)) epd.sleep() # better to do with this. time.sleep(refresh_interval) except: PaperImage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame draw = ImageDraw.Draw(PaperImage) draw.text((10, 20), 'HMM... SOMETING WRONG.', font=helloFont, fill = 0) draw.text((10, 50), '1.CHECK INTERNET CONNECTION.', font=helloFont, fill = 0) draw.text((10, 75), '2.UPDATE DOWNLOAD.SH API KEY', font=helloFont, fill = 0) draw.text((10, 100), '3.CHECK FONTS FILES.', font=helloFont, fill = 0) draw.text((10, 130), 'IF ALL OKAY, ASK ME', font=helloFont, fill = 0) draw.text((20, 150), 'TWITTER @kota_morishita', font=helloFont, fill = 0) epd.display(epd.getbuffer(PaperImage))
TIME_AGO_INTERVAL = int(args.time_ago_interval) else: TIME_AGO_INTERVAL = 30 #sys.path.append("./lib") #This assumes you have placed the waveshare_epd libraries in ./lib (subdirectory of where this file is) log.debug("The path is: " + str(Path(__file__).parent.absolute()) + "/lib") sys.path.append(str(Path(__file__).parent.absolute()) + "/lib") font_file = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf" _font_s = 20 _font_m = 45 _font_l = 75 from waveshare_epd import epd2in7 from PIL import Image, ImageDraw, ImageFont epd = epd2in7.EPD() # get the display epd.init() # initialize the display epd.Clear(0xFF) # clear the display def printToDisplay(reading): now = datetime.datetime.utcnow() reading_time = datetime.datetime.utcfromtimestamp( reading["x"]) # Sugarmate puts the posix timstamp in the 'x' attribute difference = round((now - reading_time).total_seconds() / 60) if difference == 0: str_difference = "Just Now" elif difference == 1: str_difference = str(difference) + " Minute Ago" else:
if "papirus" in conf["atm"]["display"]: from papirus import Papirus PAPIRUS = Papirus(rotation=PAPIRUSROT) # Display - Waveshare 2.13 is 250 * 122 pixels if "waveshare" in conf["atm"]["display"]: from waveshare_epd import epd2in13_V2 WAVESHARE = epd2in13_V2.EPD() # Display - Waveshare 2.7 is 264 * 176 pixels if "waveshare2in7" in conf["atm"]["display"]: from waveshare_epd import epd2in7 WAVESHARE = epd2in7.EPD() # API URL for coingecko COINGECKO_URL_BASE = "https://api.coingecko.com/api/v3/" # Fiat and satoshi variables FIAT = 0 SATS = 0 SATSFEE = 0 INVOICE = "" # Set btc and sat price BTCPRICE = utils.get_btc_price(conf["atm"]["cur"]) SATPRICE = math.floor((1 / (BTCPRICE * 100)) * 100000000) # Button / Acceptor Pulses
def __init__(self): self.epd = epd2in7.EPD()
def updateDisplay(config, pricestack): BTC = pricestack[-1] bmp = Image.open(os.path.join(picdir, 'BTC.bmp')) bmp2 = Image.open(os.path.join(picdir, 'spark.bmp')) if config['ticker']['hidden'] == True: if config['display']['orientation'] == 0 or config['display'][ 'orientation'] == 180: epd = epd2in7.EPD() epd.Init_4Gray() image = Image.new('L', (epd.width, epd.height), 255) # 255: clear the image with white image.paste(bmp, (10, 20)) draw = ImageDraw.Draw(image) draw.text((5, 200), "1 BTC", font=font, fill=0) draw.text((0, 10), str(time.strftime("%c")), font=font_date, fill=0) if config['display']['orientation'] == 180: image = image.rotate(180, expand=True) if config['display']['orientation'] == 90 or config['display'][ 'orientation'] == 270: epd = epd2in7.EPD() epd.Init_4Gray() image = Image.new('L', (epd.height, epd.width), 255) # 255: clear the image with white image.paste(bmp, (0, 0)) draw = ImageDraw.Draw(image) draw.text((20, 120), "1 BTC", font=fontHorizontal, fill=0) draw.text((85, 5), str(time.strftime("%c")), font=font_date, fill=0) if config['display']['orientation'] == 270: image = image.rotate(180, expand=True) # This is a hack to deal with the mirroring that goes on in 4Gray Horizontal image = ImageOps.mirror(image) else: if config['display']['orientation'] == 0 or config['display'][ 'orientation'] == 180: epd = epd2in7.EPD() epd.Init_4Gray() image = Image.new('L', (epd.width, epd.height), 255) # 255: clear the image with white draw = ImageDraw.Draw(image) draw.text((110, 80), "7day :", font=font_date, fill=0) draw.text( (110, 95), str("%+d" % round( (pricestack[-1] - pricestack[1]) / pricestack[-1] * 100, 2)) + "%", font=font_date, fill=0) draw.text((5, 200), "$" + format(int(round(BTC)), ","), font=font, fill=0) draw.text((0, 10), str(time.strftime("%c")), font=font_date, fill=0) image.paste(bmp, (10, 20)) image.paste(bmp2, (10, 125)) if config['display']['orientation'] == 180: image = image.rotate(180, expand=True) if config['display']['orientation'] == 90 or config['display'][ 'orientation'] == 270: epd = epd2in7.EPD() epd.Init_4Gray() image = Image.new('L', (epd.height, epd.width), 255) # 255: clear the image with white draw = ImageDraw.Draw(image) draw.text( (100, 100), "7day : " + str("%+d" % round( (pricestack[-1] - pricestack[1]) / pricestack[-1] * 100, 2)) + "%", font=font_date, fill=0) draw.text((20, 120), "$" + format(int(round(BTC)), ","), font=fontHorizontal, fill=0) image.paste(bmp2, (80, 50)) image.paste(bmp, (0, 0)) draw.text((85, 5), str(time.strftime("%c")), font=font_date, fill=0) if config['display']['orientation'] == 270: image = image.rotate(180, expand=True) # This is a hack to deal with the mirroring that goes on in 4Gray Horizontal image = ImageOps.mirror(image) # If the display is inverted, invert the image usinng ImageOps if config['display']['inverted'] == True: image = ImageOps.invert(image) # Send the image to the screen epd.display_4Gray(epd.getbuffer_4Gray(image)) epd.sleep()
def updateDisplay(config, pricestack, whichcoin, fiat, other): """ Takes the price data, the desired coin/fiat combo along with the config info for formatting if config is re-written following adustment we could avoid passing the last two arguments as they will just be the first two items of their string in config """ days_ago = int(config['ticker']['sparklinedays']) symbolstring = currency.symbol(fiat.upper()) if fiat == "jpy" or fiat == "cny": symbolstring = "¥" pricenow = pricestack[-1] currencythumbnail = 'currency/' + whichcoin + '.bmp' tokenfilename = os.path.join(picdir, currencythumbnail) sparkbitmap = Image.open(os.path.join(picdir, 'spark.bmp')) ATHbitmap = Image.open(os.path.join(picdir, 'ATH.bmp')) # Check for token image, if there isn't one, get on off coingecko, resize it and pop it on a white background if os.path.isfile(tokenfilename): logging.info("Getting token Image from Image directory") tokenimage = Image.open(tokenfilename) else: logging.info("Getting token Image from Coingecko") tokenimageurl = "https://api.coingecko.com/api/v3/coins/" + whichcoin + "?tickers=false&market_data=false&community_data=false&developer_data=false&sparkline=false" rawimage = requests.get(tokenimageurl).json() tokenimage = Image.open( requests.get(rawimage['image']['large'], stream=True).raw) resize = 100, 100 tokenimage.thumbnail(resize, Image.ANTIALIAS) new_image = Image.new( "RGBA", (120, 120), "WHITE") # Create a white rgba background with a 10 pixel border new_image.paste(tokenimage, (10, 10), tokenimage) tokenimage = new_image tokenimage.thumbnail((100, 100), Image.ANTIALIAS) tokenimage.save(tokenfilename) pricechange = str("%+d" % round( (pricestack[-1] - pricestack[0]) / pricestack[-1] * 100, 2)) + "%" if pricenow > 1000: pricenowstring = format(int(pricenow), ",") else: pricenowstring = str(float('%.5g' % pricenow)) if config['display']['orientation'] == 0 or config['display'][ 'orientation'] == 180: epd = epd2in7.EPD() epd.Init_4Gray() image = Image.new('L', (epd.width, epd.height), 255) # 255: clear the image with white draw = ImageDraw.Draw(image) draw.text((110, 80), str(days_ago) + "day :", font=font_date, fill=0) draw.text((110, 95), pricechange, font=font_date, fill=0) # Print price to 5 significant figures draw.text((15, 200), symbolstring + pricenowstring, font=font, fill=0) draw.text((10, 10), str(time.strftime("%H:%M %a %d %b %Y")), font=font_date, fill=0) image.paste(tokenimage, (10, 25)) image.paste(sparkbitmap, (10, 125)) if config['display']['orientation'] == 180: image = image.rotate(180, expand=True) if config['display']['orientation'] == 90 or config['display'][ 'orientation'] == 270: epd = epd2in7.EPD() epd.Init_4Gray() image = Image.new('L', (epd.height, epd.width), 255) # 255: clear the image with white draw = ImageDraw.Draw(image) draw.text((110, 90), str(days_ago) + " day : " + pricechange, font=font_date, fill=0) #. uncomment the line below to show volume # draw.text((110,105),"24h vol : " + human_format(other['volume']),font =font_date,fill = 0) draw.text((10, 120), symbolstring + pricenowstring, font=fontHorizontal, fill=0) image.paste(sparkbitmap, (80, 40)) image.paste(tokenimage, (0, 10)) if other['ATH'] == True: image.paste(ATHbitmap, (190, 65)) draw.text((95, 15), str(time.strftime("%H:%M %a %d %b %Y")), font=font_date, fill=0) if config['display']['orientation'] == 270: image = image.rotate(180, expand=True) # This is a hack to deal with the mirroring that goes on in 4Gray Horizontal image = ImageOps.mirror(image) # If the display is inverted, invert the image usinng ImageOps if config['display']['inverted'] == True: image = ImageOps.invert(image) # Send the image to the screen epd.display_4Gray(epd.getbuffer_4Gray(image)) epd.sleep()
def count(): #Initiative Imports & Modules from waveshare_epd import epd2in7 from PIL import Image, ImageDraw, ImageFont import traceback datetimeFormat = '%Y-%m-%d %H:%M:%S' rad_Earth = 6378100 computer_time = strftime("%Y-%m-%d %H:%M:%S") #Gps Variables gps_time = gpsd.utc gps_altitude = gpsd.fix.altitude gps_latitude = gpsd.fix.latitude gps_longitude = gpsd.fix.longitude gps_on = gps() #Checking for Gps Signal f_mode = int(gpsd.fix.mode) #store number of sats has_fix = False if f_mode > 2: has_fix = True if has_fix == True and gps_on == 1: global lat1, lon1, rho1, z1, x1, y1, t1 lat1 = math.pi * gps_latitude / 180.0 lon1 = math.pi * gps_longitude / 180.0 rho1 = rad_Earth * math.cos(lat1) z1 = rad_Earth * math.sin(lat1) x1 = rho1 * math.cos(lon1) y1 = rho1 * math.sin(lon1) t1 = computer_time if has_fix == True and gps_on == 2: global lat2, lon2, rho2, z2, x2, y2, t2, dot, cos_theta, theta, dist, t2, vel lat2 = math.pi * gps_latitude / 180.0 lon2 = math.pi * gps_longitude / 180.0 rho2 = rad_Earth * math.cos(lat2) z2 = rad_Earth * math.sin(lat2) x2 = rho2 * math.cos(lon2) y2 = rho2 * math.sin(lon2) dot = (x1 * x2 + y1 * y2 + z1 * z2) cos_theta = dot / (rad_Earth * rad_Earth) theta = math.acos(cos_theta) dist = rad_Earth * theta t2 = computer_time diff = datetime.datetime.strptime( t2, datetimeFormat) - datetime.datetime.strptime( t1, datetimeFormat) print(diff.seconds) vel = dist / diff.seconds lat1 = lat2 lon1 = lon2 rho1 = rho2 z1 = z2 x1 = x2 y1 = y2 t1 = t2 gps() if recording == True: #cnt+1 counter() #Calculating Variables dht22_humidity, dht22_temperature = Adafruit_DHT.read_retry( dht22_sensor, dht22_pin) dht22_temperature_raw = round(dht22_temperature, 5) dht22_temperature_calib = round( dht22_temperature * temperature_cal_a1 + temperature_cal_a0, 3) dht22_temperature = dht22_temperature_calib saturation_vappress_ucalib = 0.6113 * numpy.exp( (2501000.0 / 461.5) * ((1.0 / 273.15) - (1.0 / (dht22_temperature_raw + 273.15)))) saturation_vappress_calib = 0.6113 * numpy.exp( (2501000.0 / 461.5) * ((1.0 / 273.15) - (1.0 / (dht22_temperature_calib + 273.15)))) dht22_vappress = (dht22_humidity / 100.0) * saturation_vappress_ucalib dht22_vappress_raw = round(dht22_vappress, 3) dht22_vappress_calib = round( dht22_vappress * vappress_cal_a1 + vappress_cal_a0, 3) dht22_vappress = dht22_vappress_calib dht22_humidity_raw = round(dht22_humidity, 5) dht22_humidity = round( 100 * (dht22_vappress_calib / saturation_vappress_calib), 5) if dht22_humidity > 100: dht22_humidity = 100 #ePaper Begins epd = epd2in7.EPD() epd.init() #Font Description font24 = ImageFont.truetype( os.path.join('/home/pi/Meteobike04', 'Font.ttc'), 24) font18 = ImageFont.truetype( os.path.join('/home/pi/Meteobike04', 'Font.ttc'), 18) font35 = ImageFont.truetype( os.path.join('/home/pi/Meteobike04', 'Font.ttc'), 35) font14 = ImageFont.truetype( os.path.join('/home/pi/Meteobike04', 'Font.ttc'), 14) #Descriptive image if cnt == 1: #1st run Himage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame draw = ImageDraw.Draw(Himage) draw.text((75, 2), ' Choices ', font=font24, fill=0) draw.text((2, 25), ' Key1: Start Recording ', font=font18, fill=0) draw.text((2, 45), ' Key2: Stop Recording ', font=font18, fill=0) draw.text((2, 65), ' Key3: Continue Recording', font=font18, fill=0) draw.text((2, 85), ' Key4: Exit Recording ', font=font18, fill=0) draw.text( (2, 105), 'If you do not make any choices the \nprogram continues with last preferences.\nEvery time you have five seconds to \ndecide. Press for two seconds.', font=font14, fill=0) epd.display(epd.getbuffer(Himage)) time.sleep(10) #Measurements Limage = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame draw = ImageDraw.Draw(Limage) draw.text((2, 0), ' Meteobike ' + raspberryid, font=font24, fill=0) draw.text((2, 35), 'Ta: ' + "{0:.1f} C".format(dht22_temperature), font=font18, fill=0) draw.text((2, 65), 'RH: ' + "{0:.1f} %".format(dht22_humidity), font=font18, fill=0) draw.text((2, 95), 'Vap_press: ' + "{0:.1f} kPa".format(dht22_vappress), font=font18, fill=0) draw.text((2, 125), 'Altitude: ' + "{0:.2f} m".format(gpsd.fix.altitude), font=font18, fill=0) draw.text((2, 155), 'Latitude: ' + "{0:.2f} N".format(gpsd.fix.latitude), font=font18, fill=0) draw.text((2, 185), 'Longitude: ' + "{0:.2f} E".format(gpsd.fix.longitude), font=font18, fill=0) if has_fix == True and gps_on == 2: #presents Velocity and gps time draw.text((2, 205), 'Velocity: ' + "{0:.2f} m/s".format(vel), font=font14, fill=0) draw.text((2, 235), 'Gps: ' + gpsd.utc + ' ', font=font14, fill=0) else: draw.text((2, 235), 'UTCI: ' + computer_time + ' ', font=font14, fill=0) draw.text((2, 220), 'Recording: ' + status_record + ' Counter: ' + str(cnt), font=font14, fill=0) draw.text((2, 250), 'name: ' + studentname, font=font14, fill=0) #draw.text((2,250), 'IP: ' +get_ip(), font = font14, fill = 0) epd.display(epd.getbuffer(Limage)) # Data Recording if recording: # and has_fix: it depends f0 = open(logfile, "a") f0.write(raspberryid + ",") f0.write(str(cnt) + ",") f0.write(computer_time + ",") if has_fix: f0.write(gps_time + ",") else: f0.write("nan,") f0.write("{0:.3f}".format(gps_altitude) + ",") f0.write("{0:.6f}".format(gps_latitude) + ",") f0.write("{0:.6f}".format(gps_longitude) + ",") f0.write(str(dht22_temperature) + ",") f0.write(str(dht22_temperature_raw) + ",") f0.write(str(dht22_humidity) + ",") f0.write(str(dht22_humidity_raw) + ",") f0.write(str(dht22_vappress) + ",") f0.write(str(dht22_vappress_raw) + ",") if has_fix and gps_on == 2: f0.write(vel + "\n") else: f0.write("nan\n") f0.close() #Decision Phase t = 0 while True: GPIO.setmode(GPIO.BCM) key1 = 5 key2 = 6 key3 = 16 key4 = 19 GPIO.setup(key1, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(key2, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(key3, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(key4, GPIO.IN, pull_up_down=GPIO.PUD_UP) '''2Gray(Black and white) display''' key1state = GPIO.input(key1) key2state = GPIO.input(key2) key3state = GPIO.input(key3) key4state = GPIO.input(key4) time.sleep(5) t += 1 if key1state == False: record_data() Himage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame draw = ImageDraw.Draw(Himage) draw.text((75, 2), ' Recording \n Started ', font=font24, fill=0) epd.display(epd.getbuffer(Himage)) print('Key1 Pressed') break if key2state == False: stop_data() Himage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame draw = ImageDraw.Draw(Himage) draw.text((75, 2), ' Recording \n Stopped', font=font24, fill=0) epd.display(epd.getbuffer(Himage)) print('Key2 Pressed') break if key3state == False: Himage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame draw = ImageDraw.Draw(Himage) draw.text((75, 2), ' Recording \n Continues', font=font24, fill=0) epd.display(epd.getbuffer(Himage)) print('Key3 Pressed') break if key4state == False: Himage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame draw = ImageDraw.Draw(Himage) draw.text((75, 2), ' EXIT', font=font35, fill=0) epd.display(epd.getbuffer(Himage)) exit_program() print('Key4 Pressed') break if t == 5: #Himage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame #draw = ImageDraw.Draw(Himage) #draw.text((75, 2), ' Recording \n Continues ' , font = font24, fill = 0) #epd.display(epd.getbuffer(Himage)) print("exit") break
sys.path.append(libdir) import logging from waveshare_epd import epd2in7 import time from PIL import Image, ImageDraw, ImageFont import traceback import qrcode import qrcode.image.pil logging.basicConfig(level=logging.DEBUG) try: epd = epd2in7.EPD() logging.info("init and Clear") epd.init() epd.Clear(0xFF) font24 = ImageFont.truetype(os.path.join(picdir, 'RobotoSlab-Regular.ttf'), 24) font18 = ImageFont.truetype(os.path.join(picdir, 'RobotoSlab-Regular.ttf'), 18) # Drawing on the Horizontal image logging.info("1.Drawing on the Horizontal image...") Himage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame draw = ImageDraw.Draw(Himage) draw.text((10, 50), 'Standby', font=font24, fill=0)
def render(buffer_img): epd = epd2in7.EPD() epd.init() epd.display(epd.getbuffer(buffer_img))