def display_ssid_and_key(ssid, key): epd = epd2in7b.EPD() epd.init() epd.set_rotate(epd2in7b.ROTATE_90) frame_black = [0] * (epd.width * epd.height / 8) frame_red = [0] * (epd.width * epd.height / 8) font_height = 16 font = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', font_height) line_height = font_height + 2 y = 2 epd.draw_string_at(frame_black, 2, y, "SSID:", font, COLORED) y = y + line_height epd.draw_string_at(frame_black, 2, y, "{}".format(ssid), font, COLORED) y = y + line_height epd.draw_string_at(frame_black, 2, y, "Key:", font, COLORED) y = y + line_height epd.draw_string_at(frame_black, 2, y, "{}".format(" ".join(textwrap.wrap(key, 4))), font, COLORED) epd.display_frame(frame_black, frame_red) # You can get frame buffer from an image or import the buffer directly: #epd.display_frame(imagedata.IMAGE_BLACK, imagedata.IMAGE_RED) epd.sleep()
def main(): epd = epd2in7b.EPD() epd.init() imagefile = raw_input( "Please name the file you want to draw to screen (for a list of files in the current directory enter bmplist): " ) while imagefile == "bmplist": bmpfiles = os.listdir('.') pattern = "*.bmp" for entry in bmpfiles: if fnmatch.fnmatch(entry, pattern): print(entry) imagefile = raw_input( "Please name the file you want to draw to screen (for a list of files in the current directory enter bmplist): " ) # For simplicity, the arguments are explicit numerical coordinates image = Image.new('1', (epd2in7b.EPD_WIDTH, epd2in7b.EPD_HEIGHT), 255) # 255: clear the image with white draw = ImageDraw.Draw(image) epd.display_frame(epd.get_frame_buffer(image)) # display images epd.display_frame(epd.get_frame_buffer(Image.open(imagefile)))
def eink_img(text1, text2): EPD_WIDTH = 176 EPD_HEIGHT = 264 epd = epd2in7b.EPD() epd.init() print("Clear...") epd.Clear(0xFF) HBlackimage = Image.new('1', (EPD_HEIGHT, EPD_WIDTH), 255) img = Image.open('covid.png').transpose(PIL.Image.FLIP_LEFT_RIGHT) imgmask = img.copy() HRedimage = Image.new('1', (EPD_HEIGHT, EPD_WIDTH), 255) # 298*126 font1 = ImageFont.truetype('Candy Beans.otf', 14) offset = (105, 10) HRedimage.paste(img, offset, imgmask) drawblack = ImageDraw.Draw(HBlackimage) #drawred = ImageDraw.Draw(HRedimage) drawblack.text((2, 10), text1, font=font1) drawblack.text((2, 105), text2, font=font1) epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRedimage))
def main(): epd = epd2in7b.EPD() epd.init() # clear the frame buffer frame_black = [0] * (epd.width * epd.height / 8) frame_red = [0] * (epd.width * epd.height / 8) # For simplicity, the arguments are explicit numerical coordinates epd.draw_rectangle(frame_black, 10, 130, 50, 180, COLORED); epd.draw_line(frame_black, 10, 130, 50, 180, COLORED); epd.draw_line(frame_black, 50, 130, 10, 180, COLORED); epd.draw_circle(frame_black, 120, 150, 30, COLORED); epd.draw_filled_rectangle(frame_red, 10, 200, 50, 250, COLORED); epd.draw_filled_rectangle(frame_red, 0, 76, 176, 96, COLORED); epd.draw_filled_circle(frame_red, 120, 220, 30, COLORED); # draw strings to the buffer font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 18) epd.draw_string_at(frame_black, 4, 50, "e-Paper Demo", font, COLORED) epd.draw_string_at(frame_red, 18, 80, "Hello world!", font, UNCOLORED) # display the frames epd.display_frame(frame_black, frame_red) # display images frame_black = epd.get_frame_buffer(Image.open('black.bmp')) frame_red = epd.get_frame_buffer(Image.open('red.bmp')) epd.display_frame(frame_black, frame_red)
def show_image(black_image, red_image): epd = epd2in7b.EPD() epd.init() frame_black = epd.get_frame_buffer(black_image) frame_red = epd.get_frame_buffer(red_image) epd.display_frame(frame_black, frame_red)
def main(): requests.post('http://192.168.1.139/gift/0') epd = epd2in7b.EPD() # get the display object and assing to epd epd.init() # initialize the display f1 = 'intro_b.png' f2 = 'intro_red.png' #f1 = '/home/pi/Desktop/pi/code/2dot7_eink_python3/Tom_eink_1_red.bmp' #f2 = '/home/pi/Desktop/pi/code/2dot7_eink_python3/Tom_eink_1_black.bmp' #f1 = 'off_b.png' #f2 = 'off_r.png' disp_gift(epd, f1, f2) #time.sleep(2) #print('sleep') while True: key1state = GPIO.input(key1) key2state = GPIO.input(key2) key3state = GPIO.input(key3) key4state = GPIO.input(key4) if key1state == False: print('Key1 Pressed') f1 = 'pain_black.png' f2 = 'pain_red.png' disp_gift(epd, f1, f2) requests.post('http://192.168.1.139/gift/1') #time.sleep(2) if key2state == False: print('Key2 Pressed') f1 = 'dust_black2.png' f2 = 'dust_red.png' disp_gift(epd, f1, f2) requests.post('http://192.168.1.139/gift/2') #time.sleep(2) if key3state == False: print('Key3 Pressed') f1 = 'gift_black.png' f2 = 'gift_red.png' disp_gift(epd, f1, f2) requests.post('http://192.168.1.139/gift/3') #time.sleep(2) if key4state == False: #start = time.time() print('Key4 Pressed') f1 = 'puter_black.png' f2 = 'puter_red.png' disp_gift(epd, f1, f2) requests.post('http://192.168.1.139/gift/4')
def main(): epd = epd2in7b.EPD() epd.init() # clear the frame buffer frame_black = [0] * (epd.width * epd.height / 8) frame_red = [0] * (epd.width * epd.height / 8) epd.display_frame(frame_black, frame_red)
def main(): locale.setlocale(locale.LC_ALL, LOCALE) epd = epd2in7b.EPD() epd.init() epd.set_rotate(epd2in7b.ROTATE_270) fonts = Fonts(timefont_size=75, datefont_size=30) read_button4_for_shutdown() clock_loop(epd, fonts)
def main(): #locale.setlocale(locale.LC_ALL, LOCALE) locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') epd = epd2in7b.EPD() epd.init() epd.set_rotate(epd2in7b.ROTATE_270) fonts = Fonts(timefont_size=40, datefont_size=20, datafont_size=20) read_button4_for_shutdown() clock_loop(epd, fonts)
def main(): # Initialize and clear the 2in7b (tri-color) display epd = epd2in7b.EPD() epd.init() epd.Clear() display = Display(epd2in7b.EPD_WIDTH, epd2in7b.EPD_HEIGHT) while (True): epd.init() # check time. # You can specify "hour minute second" as command-line arguments # to be in "test-mode". It will run once in test mode with the # time specified and then quit hour = None minute = None second = None if (len(sys.argv) > 1): hour = int(sys.argv[1]) minute = int(sys.argv[2]) second = int(sys.argv[3]) else: now = datetime.now() hour = now.hour minute = now.minute second = now.second print("Time is {}:{}:{}".format(hour, minute, second)) (imageHighlight, imageGray) = display.drawClock(hour, minute) # We're mapping the highlighted text to black and the gray text to red epd.display(epd.getbuffer(imageHighlight), epd.getbuffer(imageGray)) sleep(2) epd.sleep() if (len(sys.argv) > 1): # If we are running with command line arguments, we are in "test-mode" # We run with the time specified on the command line and then just # exit exit( ) #debugging with command line arguments, so just exit after one run else: # Go to sleep until the next time to wake up and display the time again # Since the word clock has a granularity of 5 minutes or greater, we can # go to sleep for 5 minutes sleep( 300 ) # sleep for 5 minutes because that is the granularity of the word clock!
def main(): #requests.post('http://192.168.1.139/gift/5') epd = epd2in7b.EPD() # get the display object and assing to epd epd.init() # initialize the display f1 = 'intro_b.png' f2 = 'intro_red.png' #f1 = '/home/pi/Desktop/pi/code/2dot7_eink_python3/Tom_eink_1_red.bmp' #f2 = '/home/pi/Desktop/pi/code/2dot7_eink_python3/Tom_eink_1_black.bmp' f1 = 'off_b.png' f2 = 'off_r.png' disp_gift(epd, f1, f2)
def clear_display(epd): ''' Clear display to prevent burn-in / ghosting. ''' try: epd = epd2in7b.EPD() epd.init() print("Clear...") epd.Clear() epd.sleep() except: print('traceback.format_exc():\n%s', traceback.format_exc()) exit()
def display_Charts(): epd = epd2in7b.EPD() epd.init() epd.set_rotate(3) # Rotate the Display by 270 degree from coinmarketcap import Market coinmarketcap = Market() CurrencyData = coinmarketcap.ticker(start=0, limit=5, convert='EUR') # clear the frame buffer frame_black = [0] * (epd.width * epd.height / 8) frame_red = [0] * (epd.width * epd.height / 8) LINEHEIGHT = 20 price = 0 currency_symbol = '€' # For simplicity, the arguments are explicit numerical coordinates epd.draw_filled_rectangle(frame_black, 0, 0, 264, 28, COLORED) epd.draw_filled_rectangle(frame_black, 0, 160, 264, 176, COLORED) epd.draw_filled_rectangle(frame_red, 0, 28, 264, 50, COLORED) # draw strings to the buffer font = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 12) font_table_title = ImageFont.truetype('fonts/Grand9KPixel.ttf', 10) font_titles = ImageFont.truetype('fonts/slkscr.ttf', 16) font_num = ImageFont.truetype('fonts/PixelSplitter-Bold.ttf', 14) font_date = ImageFont.truetype('fonts/PixelSplitter-Bold.ttf', 12) epd.draw_string_at(frame_black, 2, 8, " Cryptocurrency Market ", font_titles, UNCOLORED) epd.draw_string_at( frame_red, 5, 32, "NAME PRICE CHANGE(24h)", font_table_title, UNCOLORED) print(CurrencyData[0]['id']) for item in CurrencyData: #price=round(float(),4) epd.draw_string_at(frame_black, 5, 40 + LINEHEIGHT, item['symbol'], font_titles, COLORED) epd.draw_string_at(frame_black, 60, 40 + LINEHEIGHT, "€" + item['price_eur'], font_num, COLORED) epd.draw_string_at(frame_black, 200, 40 + LINEHEIGHT, item['percent_change_24h'] + "%", font_num, COLORED) LINEHEIGHT += 20 epd.draw_string_at(frame_black, 0, 160, str(" UPDATED ON:" + time.strftime("%c")), font_date, UNCOLORED) # display the frames epd.display_frame(frame_black, frame_red)
def display_qr_code(ssid, key): epd = epd2in7b.EPD() epd.init() epd.set_rotate(epd2in7b.ROTATE_0) frame_black = [0] * (epd.width * epd.height / 8) frame_red = [0] * (epd.width * epd.height / 8) qr_image = generate_qr_image(ssid, key) width, height = qr_image.size image_padding = max(0, (epd.width - width) // 2) epd.draw_image(frame_black, max(0, (epd.width - width) // 2), max(0, (epd.height - height) // 2), qr_image) epd.display_frame(frame_black, frame_red) epd.sleep()
def main(): # API to get ISS Current Location URL = 'http://api.open-notify.org/iss-now.json' # Initialize and clear the 2in7b (tri-color) display epd = epd2in7b.EPD() display = Display(epd2in7b.EPD_HEIGHT, epd2in7b.EPD_WIDTH) positions = [] while (True): t0 = time.time() try: r = requests.get(url=URL) data = r.json() lat = float(data['iss_position']['latitude']) lon = float(data['iss_position']['longitude']) positions.append((lat, lon)) myPrint("Fetched new coordinates: " + str(positions[len(positions) - 1])) except: myPrint("Problem while fetching new coordinates!") if (len(positions) > 0): myPrint("Appending last position: " + str(positions[len(positions) - 1])) # Appending last positon so logic based on len(positions) (display refresh, marker positon) isn't affected by a few fails positions.append(positions[len(positions) - 1]) # Refresh the display on the first fetch and then on every DISPLAY_REFRESH_INTERVAL fetch if (DISPLAY_REFRESH_INTERVAL == 1 or len(positions) % DISPLAY_REFRESH_INTERVAL == 1): myPrint("Updating screen ...") t2 = time.time() epd.init() (imageBlack, imageRed) = display.drawISS(positions) epd.display(epd.getbuffer(imageBlack), epd.getbuffer(imageRed)) time.sleep(2) epd.sleep() myPrint("Updated screen in " + str(round(time.time() - t2)) + "s.") t1 = time.time() sleepTime = max(DATA_INTERVAL - (t1 - t0), 0) time.sleep( sleepTime ) # Try to keep a data refresh interval of DATA_INTERVAL seconds
def update_2in7epd(text_string,image_path=None, sleep_sec=1): epd = epd2in7b.EPD() epd.init() # clear the frame buffer frame_black = [0] * int((epd.width * epd.height / 8)) frame_red = [0] * int((epd.width * epd.height / 8)) font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMono.ttf', 14) print(text_string) if image_path: frame_black = epd.get_frame_buffer(Image.open(image_path)) if text_string: epd.draw_string_at(frame_black, 4, 4, text_string, font, COLORED) epd.display_frame(frame_black, frame_red) sleep(sleep_sec)
def main(): try: epd = epd2in7b.EPD() epd.init() # is this necessary? # epd.Clear() # time.sleep(1) data = apis.getOpenWeatherOneCall() if data != None: now = datetime.fromtimestamp(data['current']['dt']) sunrise = datetime.fromtimestamp(data['current']['sunrise']) sunset = datetime.fromtimestamp(data['current']['sunset']) temp = str(int(data['current']['temp'])) + '°c' weather = data['current']['weather'][0]['description'] icon = data['current']['weather'][0]['icon'] blackImage, redImage = images.getImages(now=now, sunrise=sunrise, sunset=sunset, temp=temp, weather=weather, icon=icon) else: blackImage, redImage = images.getImages(now=datetime.now(), sunrise=None, sunset=None, temp='...', weather='...', icon="unknown") epd.display(epd.getbuffer(blackImage), epd.getbuffer(redImage)) epd.sleep() except IOError as e: print(e) except KeyboardInterrupt: print("ctrl + c:") epd2in7b.epdconfig.module_exit() exit()
def updateWeather(writeToFile=None): location = "orlando" units = "imperial" url = "https://api.openweathermap.org/data/2.5/weather?q=" + location + "&units=" + units + "&appid=" + getAppKey( ) result = requests.get(url) weatherData = result.json() if writeToFile is not None: # Write json data to file with open('data/' + location + '.json', 'w') as outfile: json.dump(weatherData, outfile) print("Temperature is:") print(weatherData['main']['temp']) print(weatherData['weather'][0]['description']) DayL = ['Mon', 'Tues', 'Wednes', 'Thurs', 'Fri', 'Satur', 'Sun'] dayOfWeek = DayL[date.today().weekday()] + 'day' print(dayOfWeek) epd = epd2in7b.EPD() epd.init() # clear the frame buffer frame_black = [0] * (epd.width * epd.height / 8) frame_red = [0] * (epd.width * epd.height / 8) COLORED = 1 UNCOLORED = 0 # draw strings to the buffer font = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 18) epd.draw_string_at(frame_black, 10, 20, time.strftime("%m/%d/%Y"), font, COLORED) epd.draw_string_at(frame_black, 10, 50, dayOfWeek, font, COLORED) epd.draw_string_at(frame_black, 10, 80, str(weatherData['main']['temp']) + u"\u00b0" + "F", font, COLORED) epd.draw_string_at(frame_red, 10, 110, weatherData['weather'][0]['description'], font, COLORED) # display the frames epd.display_frame(frame_black, frame_red)
def ctrl_c_handler(signal, frame): print('Goodbye!') # To preserve the life of the ePaper display, it is best not to keep it powered up - # instead putting it to sleep when done displaying, or cutting off power to it altogether when # quitting. We'll also make sure to clear the screen when exiting. If you are powering down your # Raspberry Pi and storing it and the ePaper display, it is recommended # that the display be cleared prior to storage, to prevent any burn-in. # # I have modified epdconfig.py to initialize SPI handle in module_init() (vs. at the global scope) # because slepe/module_exit closes the SPI handle, which wasn't getting initialized in module_init. # I've also added a module_sleep (which epd.sleep calls) which does not call GPIO.cleanup, and # made module_exit call both module_sleep and GPIO.cleanup epd = epd2in7b.EPD() print("Clearing screen before exiting ... Please wait!") epd.init() epd.Clear() epd.exit() exit(0)
def main(): # API to get ISS Current Location URL = 'http://api.open-notify.org/iss-now.json' # Initialize and clear the 2in7b (tri-color) display epd = epd2in7b.EPD() display = Display(epd2in7b.EPD_HEIGHT, epd2in7b.EPD_WIDTH) # Store positions in list positions = [] while (True): t0 = time() r = requests.get(url=URL) # extracting data in json format data = r.json() print(data) lat = float(data['iss_position']['latitude']) lon = float(data['iss_position']['longitude']) positions.append((lat, lon)) print(positions) # Refresh the display on the first fetch and then on every DISPLAY_REFRESH_INTERVAL fetch if ((len(positions) >= 1) and ((len(positions) - 1) % DISPLAY_REFRESH_INTERVAL)): epd.init() (imageBlack, imageRed) = display.drawISS(positions) # We're drawing the map in black and the ISS location and trajectory in red # Swap it around if you'd like the inverse color scheme epd.display(epd.getbuffer(imageBlack), epd.getbuffer(imageRed)) sleep(2) epd.sleep() t1 = time() sleepTime = max(DATA_INTERVAL - (t1 - t0), 0) sleep( sleepTime ) # sleep for 30 seconds minus duration of get request and display refresh
def __init__(self): # EPD self.epd = epd2in7b.EPD() self.epd.init() self.last_drawn = None self.big_change = False self._status = None self._status_text = None self._progress = None self._extruder = None self.bed = None self.last_connection_try = None # Fonts self.fporc = ImageFont.truetype('fonts/UbuntuMono-B.ttf', 26) self.fporc2 = ImageFont.truetype('fonts/Ubuntu-B.ttf', 10) self.fval = ImageFont.truetype('fonts/UbuntuMono-R.ttf', 11) self.fvalsm = ImageFont.truetype('fonts/UbuntuMono-R.ttf', 10) self.fcapt = ImageFont.truetype('fonts/Ubuntu-B.ttf', 8)
def main(): epd = epd2in7b.EPD() epd.init() #clear the frame buffer frame_black = [0] * (epd.width * epd.height / 8) frame_red = [0] * (epd.width * epd.height / 8) #draw a rectangle #epd.draw_rectangle(frame_black, 165, 30, 30, 30, COLORED) #draw a string font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 18) epd.draw_string_at(frame_black, 20, 20, "Temperature:", font, COLORED) epd.draw_string_at(frame_red, 20, 40, temperature+"F", font, COLORED) epd.draw_string_at(frame_black, 20, 60, "Weather:", font, COLORED) epd.draw_string_at(frame_red, 20, 80, weather, font, COLORED) epd.draw_string_at(frame_black, 20, 100, "High:", font, COLORED) epd.draw_string_at(frame_red, 20, 120, maximum+"F", font, COLORED) epd.draw_string_at(frame_black, 20, 140, "Low", font, COLORED) epd.draw_string_at(frame_red, 20, 160, minimum+"F", font, COLORED) # bison = epd.get_frame_buffer(Image.open('bison.png')) epd.display_frame(frame_black, frame_red)
def main(): # API to get ISS Current Location URL = 'http://api.open-notify.org/iss-now.json' # Initialize and clear the 2in7b (tri-color) display epd = epd2in7b.EPD() display = Display(epd2in7b.EPD_HEIGHT, epd2in7b.EPD_WIDTH) # Store positions in list positions = [] while (True): epd.init() r = requests.get(url=URL) # extracting data in json format data = r.json() print(data) lat = float(data['iss_position']['latitude']) lon = float(data['iss_position']['longitude']) positions.append((lat, lon)) print(positions) (imageBlack, imageRed) = display.drawISS(positions) # We're drawing the map in black and the ISS location and trajectory in red # Swap it around if you'd like the inverse color scheme epd.display(epd.getbuffer(imageBlack), epd.getbuffer(imageRed)) sleep(2) epd.sleep() sleep(INTERVAL) # sleep for 30 seconds
# https://gist.github.com/RaneWallin/fd73ddbffdabea23358f722adb9f4075#file-hello_epaper3-py import sys # import sys sys.path.insert( 1, "./lib") # add the lib folder to sys so python can find the libraries import epd2in7b # import the display drivers from PIL import Image, ImageDraw, ImageFont # import the image libraries import time from gpiozero import Button # import the Button control from gpiozero btn1 = Button(5) # assign each button to a variable btn2 = Button(6) # by passing in the pin number btn3 = Button(13) # associated with the button btn4 = Button(19) # epd = epd2in7b.EPD() # get the display object and assing to epd epd.init() # initialize the display print("Clear...") # print message to console (not display) for debugging epd.Clear(0xFF) # clear the display # Print a message to the screen # @params string def printToDisplay(string): # Drawing on the Horizontal image. We must create an image object for both the black layer # and the red layer, event if we are only printing to one layer HBlackImage = Image.new('1', (epd2in7b.EPD_HEIGHT, epd2in7b.EPD_WIDTH), 255) # 298*126 HRedImage = Image.new('1', (epd2in7b.EPD_HEIGHT, epd2in7b.EPD_WIDTH), 255) # 298*126
def main(): if len(sys.argv) >= 2: # Update from queries config file if sys.argv[1] == "--print": print("printing image array") #frame_black = epd.get_frame_buffer(Image.open('black.bmp')) #frame_red = epd.get_frame_buffer(Image.open('red.bmp')) #epd.display_frame(frame_black, frame_red) #im.rotate(45).show() #data = [im.getpixel((x, y)) for x in range(im.width) for y in range(im.height)] #print(data) # Fetch images and shrinks them to the appropriate 8x8 size elif sys.argv[1] == "--fetch": if len(sys.argv) == 3: print("fetching and shrinking image") search_phrase = sys.argv[2] image_type = "all" url = "https://pixabay.com/api/?key=" + getPixabayKey() + "&q=" + search_phrase + \ "&image_type=all" result = (requests.get(url)).json() limit = 10 i = 0 for hits in result["hits"]: url = hits["webformatURL"] output_path = "img/" + search_phrase if not os.path.exists(output_path): os.makedirs(output_path) output_path = output_path + "/" + str(i) + get_extension( url) print(url) urllib.urlretrieve(url, output_path.replace(" ", "_")) # Convert image to correct size img = Image.open(output_path).convert('L') new_img = img.resize((176, 264)) new_img.save(output_path) i += 1 if i == limit: break elif sys.argv[1] == "--display": print("displaying images in img folder") epd = epd2in7b.EPD() epd.init() # clear the frame buffer frame_black = [0] * (epd.width * epd.height / 8) frame_red = [0] * (epd.width * epd.height / 8) output_path = "img/" folder = sys.argv[2] for filename in os.listdir(output_path + "/" + folder): with open(output_path + "/" + folder + "/" + filename) as img_file: print(filename) frame_black = epd.get_frame_buffer( Image.open(output_path + "/" + folder + "/" + filename)) #frame_red = epd.get_frame_buffer(Image.open('red.bmp')) epd.display_frame(frame_black, frame_red) time.sleep(30) elif sys.argv[1] == "--weather": updateWeather() elif sys.argv[1] == "--qr-code": epd = epd2in7b.EPD() epd.init() # clear the frame buffer frame_black = [0] * (epd.width * epd.height / 8) frame_red = [0] * (epd.width * epd.height / 8) frame_black = epd.get_frame_buffer( Image.open("jin-conception-qr-code_resized.png")) #frame_red = epd.get_frame_buffer(Image.open('red.bmp')) epd.display_frame(frame_black, frame_red) else: print("Please enter a valid argument")
def musicDisplaySmall(artist = "", title = "", album = "", timeAudio = "", albumBlack = 'albumOutBlack.bmp', albumRed = 'albumOutRed.bmp', spotifyConnect = True, isWelcomeScreen = False): if len(artist) > 8: artist = artist[:8]+"..." if len(title) > 9: title = title[:9]+"..." if len(album) > 9: album = album[:9]+"..." originAlbumX = 30 originAlbumy = 7 albumLineOffset = 3 albumSize = 130 try: epd = epd2in7b.EPD() epd.init() # Horizontal print("Drawing") albumOutBlack = Image.open(albumBlack).resize((albumSize,albumSize)) albumOutRed = Image.open(albumRed).resize((albumSize,albumSize)) blackimage1 = Image.new('1', (epd2in7b.EPD_HEIGHT,epd2in7b.EPD_WIDTH), 255)# 264*176 redimage1 = Image.new('1', (epd2in7b.EPD_HEIGHT,epd2in7b.EPD_WIDTH), 255)# 264*176 blackimage1.paste(albumOutBlack, (originAlbumX,originAlbumy)) redimage1.paste(albumOutRed, (originAlbumX,originAlbumy)) if(spotifyConnect == True): spotifyImage = Image.open("spotify.bmp").resize((30,30)) redimage1.paste(spotifyImage,(225,142)) drawblack = ImageDraw.Draw(blackimage1) drawred = ImageDraw.Draw(redimage1) font25Medium = ImageFont.truetype('./Noir/NoirStd-Medium.ttf', 19) font25Regular = ImageFont.truetype('./Noir/NoirStd-Regular.ttf', 16) font15Medium = ImageFont.truetype('./Noir/NoirStd-Medium.ttf', 15) font15Regular = ImageFont.truetype('./Noir/NoirStd-Regular.ttf', 15) textX = 170 drawblack.text((textX, 35), artist, font = font25Medium, fill = 0) drawred.text((textX, 60), "Title", font = font15Medium, fill = 0) drawblack.text((textX, 75), title, font = font25Regular, fill = 0) drawred.text((textX, 96), "Album", font = font15Medium, fill = 0) drawblack.text((textX, 110), album, font = font25Regular, fill = 0) drawred.text((textX, 125), timeAudio, font = font15Medium, fill = 0) if(spotifyConnect == True): drawblack.text((225-40, 142+20), "Connect", font = font15Medium, fill = 0) drawred.text((225-40, 142+20), "Connect", font = font15Medium, fill = 1) drawred.line((originAlbumX-albumLineOffset, originAlbumy-albumLineOffset, originAlbumX-albumLineOffset, originAlbumy+albumLineOffset+albumSize), fill = 0, width=2) drawred.line((originAlbumX-albumLineOffset, originAlbumy-albumLineOffset, originAlbumX+albumLineOffset+albumSize, originAlbumy-albumLineOffset), fill = 0, width=2) drawblack.line((originAlbumX+albumLineOffset+albumSize, originAlbumy+albumLineOffset+albumSize, originAlbumX-albumLineOffset, originAlbumy+albumLineOffset+albumSize), fill = 0, width=2) drawblack.line((originAlbumX+albumLineOffset+albumSize, originAlbumy+albumLineOffset+albumSize, originAlbumX+albumLineOffset+albumSize, originAlbumy-albumLineOffset), fill = 0, width=2) button = 20 buttonX = 2 buttonY = 0 drawred.polygon([(buttonX,buttonY), (buttonX, buttonY+button), (buttonX+button,buttonY+button/2)], fill = 0) if(spotifyConnect == False): buttonY = 50 drawred.rectangle([(buttonX,buttonY), (buttonX+7, buttonY+button)], fill = 0) drawred.rectangle([(buttonX+13,buttonY), (buttonX+button, buttonY+button)], fill = 0) buttonY = 100 drawred.polygon([(buttonX,buttonY), (buttonX, buttonY+button), (buttonX+button/2,buttonY+button/2)], fill = 0) drawred.polygon([(buttonX+button/2,buttonY), (buttonX+button/2, buttonY+button), (buttonX+button,buttonY+button/2)], fill = 0) buttonY = 150 drawred.polygon([(buttonX+button/2,buttonY), (buttonX+button/2, buttonY+button), (buttonX,buttonY+button/2)], fill = 0) drawred.polygon([(buttonX+button,buttonY), (buttonX+button, buttonY+button), (buttonX+button/2,buttonY+button/2)], fill = 0) else: font = ImageFont.load_default() fontRotate = ImageFont.truetype('./Noir/NoirStd-Regular.ttf', 16) # Text to be rotated... rotate_text = u'back in Mopidy' # Image for text to be rotated img_txt = Image.new('1', fontRotate.getsize(rotate_text),255) draw_txt = ImageDraw.Draw(img_txt) draw_txt.text((0,0), rotate_text, font=fontRotate, fill=0) t = img_txt.rotate(270, expand=1) redimage1.paste(t,(3,28)) ellipseRadius = 15 ellipseX = 225 ellipseY = 2 drawblack.ellipse((ellipseX,ellipseY,ellipseX+2*ellipseRadius,ellipseY+2*ellipseRadius),fill = 0) offsetLine = 5 line0 = 5 line1 = line0 + offsetLine line2 = line1 + offsetLine line3 = line2 + offsetLine line4 = line3 + offsetLine line5 = line4 + offsetLine randIndex = randrange(0,5) logoLines = [drawblack]*5 logoLinesFill = [1]*5 logoLines[randIndex] = drawred logoLinesFill[randIndex] = 0 lineX = 225 lineY = 25 logoLines[0].line((line0+lineX,lineY-10, line0+lineX,lineY), fill = logoLinesFill[0], width=3) logoLines[1].line((line1+lineX,lineY-15, line1+lineX,lineY), fill = logoLinesFill[1], width=3) logoLines[2].line((line2+lineX,lineY-7, line2+lineX,lineY), fill = logoLinesFill[2], width=3) logoLines[3].line((line3+lineX,lineY-13, line3+lineX,lineY), fill = logoLinesFill[3], width=3) logoLines[4].line((line4+lineX,lineY-10, line4+lineX,lineY), fill = logoLinesFill[4], width=3) startLineX = 27 startLineY = 148 lenght = 264-27-5 offset = 6 if(spotifyConnect == True): lenght = lenght - 40 drawblack.line((startLineX,startLineY,startLineX+lenght,startLineY), fill = 0, width=2) drawred.line((startLineX,startLineY+offset*1,startLineX+lenght,startLineY+offset*1),fill = 0, width=2) drawblack.line((startLineX,startLineY+offset*2,startLineX+lenght,startLineY+offset*2),fill = 0, width=2) if(spotifyConnect == True): lenght = lenght - 40 drawblack.line((startLineX,startLineY+offset*3,startLineX+lenght,startLineY+offset*3), fill = 0, width=2) epd.display(epd.getbuffer(blackimage1), epd.getbuffer(redimage1)) except: print('traceback.format_exc():\n%s',traceback.format_exc())
#!/usr/bin/python # -*- coding:utf-8 -*- import sys sys.path.append(r'../lib') import epd2in7b import epdconfig import time from PIL import Image, ImageDraw, ImageFont import traceback try: print("epd2in7b Demo") epd = epd2in7b.EPD() print("init and Clear") epd.init() epd.Clear() time.sleep(1) # Drawing on the image print("Drawing") blackimage = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame redimage = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame font24 = ImageFont.truetype('../lib/Font.ttc', 24) font18 = ImageFont.truetype('../lib/Font.ttc', 18) # Drawing on the Horizontal image
def get_epd2in7b(): return epd2in7b.EPD()
def main(): epd = epd2in7b.EPD() epd.init() # clear the frame buffer frame_black = [0] * (epd.width * epd.height / 8) frame_red = [0] * (epd.width * epd.height / 8) # For simplicity, the arguments are explicit numerical coordinates #epd.draw_rectangle(frame_black, 10, 130, 50, 180, COLORED); #epd.draw_line(frame_black, 10, 130, 50, 180, COLORED); #epd.draw_line(frame_black, 50, 130, 10, 180, COLORED); #epd.draw_circle(frame_black, 120, 150, 30, COLORED); #epd.draw_filled_rectangle(frame_red, 10, 200, 50, 250, COLORED); #epd.draw_filled_rectangle(frame_red, 0, 76, 176, 96, COLORED); #epd.draw_filled_circle(frame_red, 120, 220, 30, COLORED); # draw strings to the buffer font = ImageFont.truetype('/home/pi/iosevka.ttf', 32) font_clock = ImageFont.truetype('/home/pi/iosevka.ttf', 48) font_date = ImageFont.truetype('/home/pi/iosevka.ttf', 24) font_delta = ImageFont.truetype('/home/pi/iosevka.ttf', 20) # epd.draw_string_at(frame_red, 18, 80, " [o_o] [o_o] ", font, COLORED) # epd.draw_string_at(frame_red, 22, 110, " [o_o] ", font, COLORED) # Draw time epd.draw_string_at(frame_black, 15, 10, datetime.now().strftime('%H:%M'), font_clock, COLORED) epd.draw_string_at(frame_black, 52, 55, datetime.now().strftime('%m-%d'), font_date, COLORED) # Draw Temperature headers = {"Content-Type": "application/graphql"} r = requests.get('https://wttr.in/Otaniemi?format=j1') #print r.text data = json.loads(r.text)['current_condition'] old_count = None list_count = [] try: with open('/tmp/kk2020', 'r') as f: # Read the old count dat = f.readlines() old_count = dat[0] except IOError: print("Old status not found") try: with open('/tmp/e-ink-log_5min', 'r') as f: # Read the old count list_count = pickle.load(f) except IOError: print("Old 5min status not found") except EOFError: print("EOF while reading file") list_count = [] # Victory status url_list = [ 'https://430.fi/kiitos/hyvinvointiyhteiskunta-vahvemmaksi/', 'https://430.fi/kiitos/oikeudenmukaisia-ilmastotoimia/', 'https://430.fi/kiitos/lisaa-luonnon-monimuotoisuutta/' ] victory_count = 0 for url in url_list: req = requests.get(url) victory_count = victory_count + parse(req) # Append to list of values list_count.append(victory_count) try: with open('/tmp/kk2020', 'w') as f: # Read the old count f.write(str(victory_count)) except IOError: print("Something wrong with writing") try: with open('/tmp/kk2020_5min', 'w') as f: # Read the old count pickle.dump(list_count, f) except IOError: print("Something wrong with writing") epd.draw_string_at(frame_black, 15, 90, u"Effective ℃", font_date, COLORED) epd.draw_string_at(frame_red, 75, 120, data[0]['FeelsLikeC'], font, COLORED) epd.draw_string_at(frame_black, 10, 160, datetime.now().strftime('Kunnollisuus:'), font_date, COLORED) epd.draw_string_at(frame_red, 40, 190, str(victory_count), font, COLORED) if old_count: start = 30 epd.draw_string_at(frame_black, start, 235, u"Δ 1min:", font_delta, COLORED) epd.draw_string_at(frame_red, start + 80, 235, str(victory_count - int(old_count)), font_delta, COLORED) # display the frames epd.display_frame(frame_black, frame_red) # display images #frame_black = epd.get_frame_buffer(Image.open('black.bmp')) #frame_red = epd.get_frame_buffer(Image.open('red.bmp')) epd.display_frame(frame_black, frame_red)
def main(): epd = epd2in7b.EPD() while True: # Get Weather data from OWM obs = owm.weather_at_id(city_id) location = obs.get_location().get_name() weather = obs.get_weather() reftime = weather.get_reference_time() description = weather.get_detailed_status() temperature = weather.get_temperature(unit='fahrenheit') humidity = weather.get_humidity() pressure = weather.get_pressure() clouds = weather.get_clouds() wind = weather.get_wind() rain = weather.get_rain() sunrise = weather.get_sunrise_time() sunset = weather.get_sunset_time() print("location: " + location) print("weather: " + str(weather)) print("description: " + description) print("temperature: " + str(temperature)) print("humidity: " + str(humidity)) print("pressure: " + str(pressure)) print("clouds: " + str(clouds)) print("wind: " + str(wind)) print("rain: " + str(rain)) print("sunrise: " + time.strftime('%H:%M', time.localtime(sunrise))) print("sunset: " + time.strftime('%H:%M', time.localtime(sunset))) # Display Weather Information on e-Paper Display try: print("Clear...") epd.init() epd.Clear() # Drawing on the Horizontal image HBlackimage = Image.new('1', (epd2in7b.EPD_HEIGHT, epd2in7b.EPD_WIDTH), 255) # 298*126 HRedimage = Image.new('1', (epd2in7b.EPD_HEIGHT, epd2in7b.EPD_WIDTH), 255) # 298*126 print("Drawing") drawblack = ImageDraw.Draw(HBlackimage) drawred = ImageDraw.Draw(HRedimage) font24 = ImageFont.truetype('fonts/arial.ttf', 24) font16 = ImageFont.truetype('fonts/arial.ttf', 16) font20 = ImageFont.truetype('fonts/arial.ttf', 20) fontweather = ImageFont.truetype('fonts/meteocons-webfont.ttf', 30) fontweatherbig = ImageFont.truetype('fonts/meteocons-webfont.ttf', 60) w1, h1 = font24.getsize(location) w2, h2 = font20.getsize(description) w3, h3 = fontweatherbig.getsize( weather_icon_dict[weather.get_weather_code()]) drawblack.text((10, 0), location, font=font24, fill=0) drawblack.text((10 + (w1 / 2 - w2 / 2), 25), description, font=font20, fill=0) drawred.text((264 - w3 - 10, 0), weather_icon_dict[weather.get_weather_code()], font=fontweatherbig, fill=0) drawblack.text((10, 45), "Observed at: " + time.strftime('%I:%M %p', time.localtime(reftime)), font=font16, fill=0) tempstr = str("{0}{1}F".format(int(round(temperature['temp'])), u'\u00b0')) print(tempstr) w4, h4 = font24.getsize(tempstr) drawblack.text((10, 70), tempstr, font=font24, fill=0) drawred.text((10 + w4, 70), "'", font=fontweather, fill=0) drawblack.text((150, 70), str("{0}{1} | {2}{3}".format( int(round(temperature['temp_min'])), u'\u00b0', int(round(temperature['temp_max'])), u'\u00b0')), font=font24, fill=0) drawblack.text((10, 100), str("{} hPA".format(int(round(pressure['press'])))), font=font20, fill=0) drawblack.text((150, 100), str("{}% RH".format(int(round(humidity)))), font=font20, fill=0) drawred.text((20, 120), "A", font=fontweather, fill=0) drawred.text((160, 120), "J", font=fontweather, fill=0) drawblack.text((10, 150), time.strftime('%I:%M %p', time.localtime(sunrise)), font=font20, fill=0) drawblack.text((150, 150), time.strftime('%I:%M %p', time.localtime(sunset)), font=font20, fill=0) epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRedimage)) time.sleep(2) epd.sleep() except IOError as e: print('traceback.format_exc():\n%s', traceback.format_exc()) epdconfig.module_init() epdconfig.module_exit() exit() # Sleep for 10 minutes - loop will continue after 10 minutes time.sleep(600) # Wake up every 10 minutes to update weather display