Skip to content

Commit

Permalink
Updated the font used and the default location
Browse files Browse the repository at this point in the history
  • Loading branch information
05tb committed Feb 25, 2019
1 parent f5413c9 commit bb9ec43
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.pyc
.env
.venv
*.DS_Store
.vscode
config.txt
63 changes: 39 additions & 24 deletions whereis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
COLORED = 1
UNCOLORED = 0

config_location = "/home/pi/.whereabouts/config.txt"

try:
import requests
except ImportError:
Expand All @@ -41,57 +43,70 @@ def get_location( user_number, auth_token ):

def load_config():
lines = []
with open( "/home/pi/rpi-whereis-0.1/config.txt" ) as f:
with open( config_location ) as f:
lines = f.read().splitlines()
return {
"caption" : lines[0],
"user_number" : lines[1],
"auth_token" : lines[2],
"old_ds" : lines[3]
}

"old_ds" : lines[3],
}

def save_config(ds):
with open( "/home/pi/rpi-whereis-0.1/config.txt", 'r' ) as f:
lines = []
with open( config_location, 'r' ) as f:
lines = f.readlines()

lines[3] = ds+"\n"
with open("/home/pi/rpi-whereis-0.1/config.txt", 'w') as f:
f.writelines(lines)

with open( config_location, 'w') as f:
f.writelines(lines)


def main():

config = load_config()


print(config)

epd = epd2in13b.EPD()
epd.init()
epd.set_rotate(1)

# clear the frame buffer
frame_black = [0xFF] * (epd.width * epd.height / 8)
frame_red = [0xFF] * (epd.width * epd.height / 8)
epd.draw_filled_rectangle(frame_red, 0, 0, 250, 55, COLORED);
font = ImageFont.truetype('/usr/share/fonts/AmaticSC-Bold.ttf', 38)
epd.draw_string_at(frame_red, 25, 10, config["caption"], font, UNCOLORED)

epd.draw_filled_rectangle(frame_black, 0, 0, 250, 40, COLORED);

font = ImageFont.truetype('/usr/share/fonts/marvinVisions.otf', 28)
epd.draw_string_at(frame_black, 12, 6, config["caption"], font, UNCOLORED)

data = get_location( config["user_number"], config["auth_token"] )
ds = "unknown"
# Add this to config to make it customisable
ds = "MCUK (Probably)"
print(data)

if(u'description' in data):
print(data["description"])
ds = data["description"]

epd.draw_string_at(frame_black, 25, 60, ds, font, COLORED)


print(type(ds))
print(type(config["caption"]))
print(len(ds))
print(len(config["caption"]))

if(len(ds) > len(config["caption"])):
font1 = ImageFont.truetype('/usr/share/fonts/marvinVisions.otf', 20)
epd.draw_string_at(frame_black, 12, 45, ds, font1, COLORED)
else:
epd.draw_string_at(frame_black, 12, 45, ds, font, COLORED)

if (config["old_ds"] != ds):
epd.display_frame(frame_black, frame_red)
epd.display_frame(frame_black, frame_red)

save_config(ds)


if __name__ == '__main__':
main()

main()

0 comments on commit bb9ec43

Please sign in to comment.