-
Notifications
You must be signed in to change notification settings - Fork 10
/
paperclock.py
68 lines (48 loc) · 1.44 KB
/
paperclock.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
import logging
import babel
import babel.dates
import weather
import drawing
EPD_WIDTH = 400
EPD_HEIGHT = 300
# only update once an hour within these ranges
DEAD_TIMES = [
range(0,6),
range(10,16)
]
class PaperClock( object ):
def __init__( self, debug_mode=False ):
self._debug_mode = debug_mode
if not debug_mode:
import epd4in2
self._epd = epd4in2.EPD()
self._epd.init()
self._str_time = "XXXX"
def display_buffer( self, buf ):
if self._debug_mode:
buf.save( "debug.bmp" )
return
self._epd.display_frame(
self._epd.get_frame_buffer( buf )
)
def update_for_datetime( self, dt ):
tz_display = babel.dates.get_timezone('Europe/London')
formatted = babel.dates.format_time(
dt,
"HHmm",
tzinfo=tz_display
)
# set blank minutes if time's hour is within dead ranges
h = formatted[:2]
for dead_range in DEAD_TIMES:
if int(h) in dead_range:
formatted = "{} ".format( h )
if formatted != self._str_time:
w = weather.get_weather()
frame = drawing.draw_frame(
EPD_WIDTH, EPD_HEIGHT,
formatted,
w
)
self.display_buffer( frame )
self._str_time = formatted