scroll

scroll stuff on phatscroll
git clone git://shroom.party/scroll.git
Log | Files | Refs | README | LICENSE

commit 54ae21b1d86e01e44502c27b12647675cbe3f898
parent e4d76fea7c4352a1911e503945d1deb6c0d58371
Author: tx <trqx@goat.si>
Date:   Thu, 12 Jul 2018 17:30:10 +0200

blacked 🏴

Diffstat:
scroll.py | 60++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 36 insertions(+), 24 deletions(-)

diff --git a/scroll.py b/scroll.py @@ -12,7 +12,10 @@ import sys try: from PIL import Image except ImportError: - exit("This script requires the pillow module\nInstall with: sudo pip install pillow") + exit( + "This script requires the pillow module\nInstall with: sudo pip install pillow" + ) + def convert_png2font(font_file): font = {} @@ -29,9 +32,11 @@ def convert_png2font(font_file): for x in range(0, 5): bits = 0 for y in range(0, 5): - pixel=font_image.getpixel((border+(char_x * 6) + x , border+(char_y * 6) + y )) - if pixel == 1: - bits |= (1 << y) + pixel = font_image.getpixel( + (border + (char_x * 6) + x, border + (char_y * 6) + y) + ) + if pixel == 1: + bits |= 1 << y char_bits.append(bits) # remove all "empty" columns from the right of the character @@ -47,36 +52,44 @@ def convert_png2font(font_file): def get_timeout(): return ticks_per_second * refresh_interval + def get_api_msg(): - displaymsg = 'nothing' - try: - with open('/tmp/displaymsg') as f: - displaymsg = f.readline().strip() - except: - pass - return unicodedata.normalize('NFKD', displaymsg.decode('utf8')).encode('ASCII', 'ignore').upper() + displaymsg = "nothing" + try: + with open("/tmp/displaymsg") as f: + displaymsg = f.readline().strip() + except: + pass + return ( + unicodedata.normalize("NFKD", displaymsg.decode("utf8")) + .encode("ASCII", "ignore") + .upper() + ) + def get_msg(): - t = get_time() - if t == '16:20' or t == '04:20': - return '420 BLAZE IT! g ' - #with open('/home/pi/.scroll') as f: - # lines = f.readlines() - #truc = random.choice(lines).strip() - return 'g {} '.format(get_api_msg()) + t = get_time() + if t == "16:20" or t == "04:20": + return "420 BLAZE IT! g " + # with open('/home/pi/.scroll') as f: + # lines = f.readlines() + # truc = random.choice(lines).strip() + return "g {} ".format(get_api_msg()) + def get_time(): - return time.strftime('%H:%M') + return time.strftime("%H:%M") + # Every refresh_interval seconds we'll refresh the time # Only has to change every 60 seconds. scrollphat.set_brightness(2) scrollphat.set_rotate(True) -scrollphat.load_font(convert_png2font('font.png')) +scrollphat.load_font(convert_png2font("font.png")) pause = 0.07 -ticks_per_second = 1/pause +ticks_per_second = 1 / pause refresh_interval = 3 timeout = get_timeout() @@ -90,7 +103,7 @@ while True: scrollphat.scroll() time.sleep(pause) - if(count > timeout): + if count > timeout: old_msg = msg msg = get_msg() if msg != old_msg: @@ -99,8 +112,7 @@ while True: timeout = get_timeout() count = 0 else: - count = count+ 1 + count = count + 1 except KeyboardInterrupt: scrollphat.clear() sys.exit(-1) -