-
Notifications
You must be signed in to change notification settings - Fork 0
/
thermometer.py
157 lines (130 loc) · 6.11 KB
/
thermometer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import inkyphat
import os
import pyowm
import math
from PIL import ImageFont, ImageDraw, ImageOps
from PIL import Image
import schedule
inkyphat.set_rotation(180)
bulb_width = 50
bulb_space = 3
bulb_fill = bulb_width - (bulb_space * 2)
font_size = 10
margin_bottom = 5
margin_top = 5
margin_left = (inkyphat.HEIGHT - bulb_width) / 2
margin_right = (inkyphat.HEIGHT - bulb_width) / 2
fill_max = inkyphat.WIDTH - margin_top
tube_width = math.ceil((bulb_width / 3) / 2.) * 2
tube_x = margin_bottom + bulb_width
tube_y = margin_left + (bulb_width - (tube_width * 2))
tube_end = fill_max
tubeline_top_x = tube_x - 2
tubeline_top_y = tube_y - 1
tubeline_bottom_x = tubeline_top_x
tubeline_bottom_y = tube_y + tube_width + 1
fmax = fill_max - (tube_width / 2)
currtemp = 0
hi_temp_c = 50
low_temp_c = -20
# hi_temp_f = 122
# lo_temp_f = -4
def get_temp():
global currtemp
"""Data for Openweathermap Query"""
owm_key = os.environ["OWM_KEY"]
owm = pyowm.OWM(owm_key)
observation = owm.weather_at_zip_code("61449","de")
w = observation.get_weather()
currtemp = w.get_temperature('celsius')['temp']
def draw_therm():
inkyphat.arc((margin_bottom,margin_left,margin_bottom+bulb_width,margin_right+bulb_width), 0, 360, 1)
inkyphat.arc((margin_bottom-1,margin_left-1,margin_bottom+bulb_width+1,margin_right+bulb_width+1), 0, 360, 1)
inkyphat.rectangle((tube_x - (bulb_width/2), tube_y, (fill_max - tube_width), (tube_y + tube_width)), 0, 0)
inkyphat.line((tubeline_top_x, tubeline_top_y, fill_max - tube_width / 2, tubeline_top_y), 1, 1)
inkyphat.line((tubeline_top_x, (tubeline_top_y - 1), fill_max - tube_width / 2, (tubeline_top_y - 1)), 1, 1)
inkyphat.line((tubeline_top_x, tubeline_bottom_y, (fill_max - tube_width / 2), tubeline_bottom_y), 1, 1)
inkyphat.line((tubeline_top_x, (tubeline_bottom_y + 1), fill_max - tube_width / 2, (tubeline_bottom_y + 1)), 1, 1)
inkyphat.arc(((fill_max - tube_width), tubeline_top_y, fill_max, tubeline_bottom_y), 270, 90, 1)
inkyphat.arc(((fill_max - tube_width + 1), tubeline_top_y - 1, fill_max + 1, tubeline_bottom_y + 1), 270, 90, 1)
def fill_up():
global currtemp
# inkyphat.pieslice((), 0, 360, 2, 2)
# Filled bulb
inkyphat.pieslice((margin_bottom + bulb_space, margin_left + bulb_space, margin_bottom + bulb_space + bulb_fill, margin_left + bulb_space + bulb_fill), 0, 360, 2, 2)
# Filled tube
#inkyphat.rectangle((tubeline_top_x - (bulb_width / 2), tubeline_top_y + bulb_space, (fill_max - tube_width + tube_width / 2), (tubeline_bottom_y - bulb_space)), 2, 2)
if currtemp <= 0:
inv = currtemp * -1
inkyphat.rectangle((tubeline_top_x - (bulb_width / 2), tubeline_top_y + bulb_space, (fmax - 100 - (inv * 2)), (tubeline_bottom_y - bulb_space)), 2, 2)
else:
inkyphat.rectangle((tubeline_top_x - (bulb_width / 2), tubeline_top_y + bulb_space, (fmax - 140 + 40 + (currtemp * 2)), (tubeline_bottom_y - bulb_space)), 2, 2)
# inkyphat.pieslice((tubeline_top_x - (bulb_width / 2), 42, (fill_max - tube_width + tube_width / 2), 62), 270, 90, 2, 2)
def decorate():
#draw_fahrenheit_scale()
draw_celsius_scale()
draw_temperature()
# reflection()
#def reflection():
# Reflection
#inkyphat.pieslice(((tubeline_bottom_x - (bulb_width / 5)), (tubeline_bottom_y - (bulb_width / 5)), (tubeline_bottom_x - (bulb_width / 5)) - 20, (tubeline_bottom_y - (bulb_width / 5)) + 10), 0, 360, 0, 0)
# Tube reflection, broken
#inkyphat.arc((tubeline_top_x,tubeline_top_y,tubeline_bottom_x+tube_width,tubeline_bottom_y), 90, 270, 0)
def draw_temperature():
"""Draw current temperature in the bulb area"""
font = ImageFont.truetype(inkyphat.fonts.PressStart2P, font_size)
text = str(int(round(currtemp))) + "C"
pr = inkyphat.text((margin_bottom + bulb_space + (bulb_width / 4),tubeline_top_y + (font_size - bulb_space)), text, inkyphat.WHITE, font)
def draw_fahrenheit_scale():
"""Does not work"""
inkyphat.line((fill_max - 140, 0, fill_max, 0), 1, 1)
inkyphat.line((fill_max - 140, 1, fill_max, 1), 1, 1)
i = 0
while i < 126:
if i % 10 == 0:
inkyphat.line((fill_max - i, 2, fill_max -i, 22), 1, 1)
else:
inkyphat.line((fill_max - i, 2, fill_max - i, 12), 1, 1)
i += 2
def draw_celsius_scale():
# inkyphat.line((fill_max - 140, 102, fill_max, 102), 1, 1)
# inkyphat.line((fill_max - 140, 103, fill_max, 103), 1, 1)
i = 0
while i < 141:
if i == 100:
inkyphat.line((fmax - i, tubeline_top_y - 5, fmax - i, tubeline_top_y - 5 - 33), 1, 1)
inkyphat.line((fmax - i, tubeline_bottom_y + 5, fmax - i, tubeline_bottom_y + 5 + 33), 1, 1)
elif i % 20 == 0:
inkyphat.line((fmax - i, tubeline_top_y - 5, fmax - i, tubeline_top_y - 5 - 18), 1, 1)
inkyphat.line((fmax - i, tubeline_bottom_y + 5, fmax - i, tubeline_bottom_y + 5 + 18), 1, 1)
# inkyphat.line((fmax - i, 103, fmax - i, 85), 1, 1)
elif i % 10 == 0:
inkyphat.line((fmax - i, tubeline_top_y - 5, fmax - i, tubeline_top_y - 5 - 12), 1, 1)
inkyphat.line((fmax - i, tubeline_bottom_y + 5, fmax - i, tubeline_bottom_y + 5 + 12), 1, 1)
# inkyphat.line((fmax - i, 103, fmax - i, 91), 1, 1)
elif i % 2 == 0:
inkyphat.line((fmax - i, tubeline_top_y - 5, fmax - i, tubeline_top_y - 5 - 8), 1, 1)
inkyphat.line((fmax - i, tubeline_bottom_y + 5, fmax - i, tubeline_bottom_y + 5 + 8), 1, 1)
# inkyphat.line((fmax - i, 103, fmax - i, 95), 1, 1)
else:
inkyphat.line((fmax - i, tubeline_top_y - 5, fmax - i, tubeline_top_y - 5 - 8), 0, 0)
inkyphat.line((fmax - i, tubeline_bottom_y + 5, fmax - i, tubeline_bottom_y + 5 + 8), 0, 0)
# inkyphat.line((fmax - i, 103, fmax - i, 95), 0, 0)
i += 1
def refresh():
get_temp()
draw_therm()
fill_up()
decorate()
inkyphat.show()
# test = "20 \xb0"
#
# inkyphat.text((150, 15), test, inkyphat.BLACK, font)
refresh()
schedule.every(5).minutes.do(refresh)
while True:
schedule.run_pending()
time.sleep(30)