1+ """
2+ GFX helper file for
3+ wake_up_light.py.py
4+ """
5+ import board
6+ import displayio
7+ from adafruit_display_text .label import Label
8+ from adafruit_bitmap_font import bitmap_font
9+
10+ cwd = ("/" + __file__ ).rsplit ('/' , 1 )[0 ] # the current working directory (where this file is)
11+
12+ # Fonts within /fonts folder
13+ info_font = cwd + "/fonts/Nunito-Black-17.bdf"
14+ time_font = cwd + "/fonts/Nunito-Light-75.bdf"
15+
16+ get_up_time = "6:30"
17+ get_up_time_text = "Wake up at: " + get_up_time + "am"
18+ light_on_time_text = "Light starting at: " # - 30 minutes? how?
19+
20+ class Thermometer_GFX (displayio .Group ):
21+ def __init__ (self , celsius = True , usa_date = True ):
22+ """Creates a Thermometer_GFX object.
23+ :param bool usa_date: Use mon/day/year date-time formatting.
24+ """
25+ # root displayio group
26+ root_group = displayio .Group (max_size = 20 )
27+ board .DISPLAY .show (root_group )
28+ super ().__init__ (max_size = 20 )
29+
30+ self ._usa_date = usa_date
31+
32+ # create text object group
33+ self ._text_group = displayio .Group (max_size = 6 )
34+ self .append (self ._text_group )
35+
36+ self ._cwd = cwd
37+
38+ print ('loading fonts...' )
39+ glyphs = b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.:/ '
40+ self .info_font = bitmap_font .load_font (info_font )
41+ self .info_font .load_glyphs (glyphs )
42+
43+ self .time_font = bitmap_font .load_font (time_font )
44+ self .time_font .load_glyphs (glyphs )
45+
46+ print ('setting up labels...' )
47+ self .title_text = Label (self .info_font , text = "PyPortal Wake-Up Light" )
48+ self .title_text .x = 15
49+ self .title_text .y = 15
50+ self ._text_group .append (self .title_text )
51+
52+ # Wake up time
53+ self .subtitle_text = Label (self .info_font , text = get_up_time_text )
54+ self .subtitle_text .x = 15
55+ self .subtitle_text .y = 200
56+ self ._text_group .append (self .subtitle_text )
57+
58+ #Light on time - how to subtract 30 min from time string
59+ self .subtitle2_text = Label (self .info_font , text = light_on_time_text )
60+ self .subtitle2_text .x = 15
61+ self .subtitle2_text .y = 240
62+ # self._text_group.append(self.subtitle2_text)
63+
64+ # Time
65+ self .time_text = Label (self .time_font , max_glyphs = 40 )
66+ self .time_text .x = 65
67+ self .time_text .y = 120
68+ self ._text_group .append (self .time_text )
69+
70+ # Date
71+ self .date_text = Label (self .info_font , max_glyphs = 40 )
72+ self .date_text .x = 30
73+ self .date_text .y = 160
74+ self ._text_group .append (self .date_text )
75+
76+ board .DISPLAY .show (self ._text_group )
77+
78+
79+ def display_date_time (self , io_time ):
80+ """Parses and displays the time obtained from Adafruit IO, based on IP
81+ :param struct_time io_time: Structure used for date/time, returned from Adafruit IO.
82+ """
83+ self .time_text .text = '%02d:%02d' % (io_time [3 ],io_time [4 ])
84+ '''
85+ # not siplaying date just yet
86+ if not self._usa_date:
87+ self.date_text.text = '{0}/{1}/{2}'.format(io_time[2], io_time[1], io_time[0])
88+ else:
89+ self.date_text.text = '{0}/{1}/{2}'.format(io_time[1], io_time[2], io_time[0])
90+ '''
0 commit comments