66from adafruit_display_text .label import Label
77from adafruit_bitmap_font import bitmap_font
88
9- cwd = ("/" + __file__ ).rsplit ('/' , 1 )[0 ] # the current working directory (where this file is)
9+ # the current working directory (where this file is)
10+ cwd = ("/" + __file__ ).rsplit ("/" , 1 )[0 ]
1011
1112# Fonts within /fonts folder
12- main_font = cwd + "/fonts/EarthHeart-26.bdf"
13- data_font = cwd + "/fonts/Collegiate-50.bdf"
13+ main_font = cwd + "/fonts/EarthHeart-26.bdf"
14+ data_font = cwd + "/fonts/Collegiate-50.bdf"
15+
1416
1517class Azure_GFX (displayio .Group ):
1618 def __init__ (self , is_celsius ):
1719 """Creates an Azure_GFX object.
1820 :param bool is_celsius: Temperature displayed in Celsius.
1921 """
2022 # root displayio group
21- root_group = displayio .Group (max_size = 23 )
23+ root_group = displayio .Group ()
2224 board .DISPLAY .show (root_group )
23- super ().__init__ (max_size = 15 )
25+ super ().__init__ ()
2426
2527 # temperature display option
2628 self ._is_celsius = is_celsius
2729
2830 # create background icon group
29- self ._icon_group = displayio .Group (max_size = 3 )
31+ self ._icon_group = displayio .Group ()
3032 board .DISPLAY .show (self ._icon_group )
3133 # create text object group
32- self ._text_group = displayio .Group (max_size = 9 )
34+ self ._text_group = displayio .Group ()
3335
3436 self ._icon_sprite = None
3537 self ._icon_file = None
3638 self ._cwd = cwd
37- self .set_icon (self ._cwd + "/images/azure_splash.bmp" )
39+ self .set_icon (self ._cwd + "/images/azure_splash.bmp" )
3840
39- print (' loading fonts...' )
40- glyphs = b' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.: '
41- data_glyphs = b' 012345678-,.:/FC'
41+ print (" loading fonts..." )
42+ glyphs = b" 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.: "
43+ data_glyphs = b" 012345678-,.:/FC"
4244 self .main_font = bitmap_font .load_font (main_font )
4345 self .main_font .load_glyphs (glyphs )
4446 self .data_font = bitmap_font .load_font (data_font )
4547 self .data_font .load_glyphs (data_glyphs )
46- self .data_font .load_glyphs (('°' ,)) # extra glyph for temperature font
48+ self .data_font .load_glyphs (("°" ,)) # extra glyph for temperature font
4749
48- print (' setting up labels...' )
50+ print (" setting up labels..." )
4951 self .title_text = Label (self .main_font , text = "Azure Plant Monitor" )
5052 self .title_text .x = 35
5153 self .title_text .y = 25
@@ -56,7 +58,7 @@ def __init__(self, is_celsius):
5658 self .temp_label .y = 65
5759 self ._text_group .append (self .temp_label )
5860
59- self .temp_text = Label (self .data_font , max_glyphs = 10 )
61+ self .temp_text = Label (self .data_font )
6062 self .temp_text .x = 200
6163 self .temp_text .y = 85
6264 self ._text_group .append (self .temp_text )
@@ -66,12 +68,12 @@ def __init__(self, is_celsius):
6668 self .moisture_label .y = 135
6769 self ._text_group .append (self .moisture_label )
6870
69- self .moisture_text = Label (self .data_font , max_glyphs = 10 )
71+ self .moisture_text = Label (self .data_font )
7072 self .moisture_text .x = 200
7173 self .moisture_text .y = 175
7274 self ._text_group .append (self .moisture_text )
7375
74- self .azure_status_text = Label (self .main_font , max_glyphs = 15 )
76+ self .azure_status_text = Label (self .main_font )
7577 self .azure_status_text .x = 65
7678 self .azure_status_text .y = 225
7779 self ._text_group .append (self .azure_status_text )
@@ -89,7 +91,7 @@ def display_moisture(self, moisture_data):
8991 """Displays the moisture from the Stemma Soil Sensor.
9092 :param int moisture_data: Moisture value
9193 """
92- print (' Moisture Level: ' , moisture_data )
94+ print (" Moisture Level: " , moisture_data )
9395 self .moisture_text .text = str (moisture_data )
9496
9597 def display_temp (self , temp_data ):
@@ -98,22 +100,22 @@ def display_temp(self, temp_data):
98100 """
99101 if not self ._is_celsius :
100102 temp_data = (temp_data * 9 / 5 ) + 32 - 15
101- print (' Temperature: %0.0f°F' % temp_data )
103+ print (" Temperature: %0.0f°F" % temp_data )
102104 if temp_data >= 212 :
103105 self .temp_text .color = 0xFD2EE
104106 elif temp_data <= 32 :
105107 self .temp_text .color = 0xFF0000
106- self .temp_text .text = ' %0.0f°F' % temp_data
107- temp_data = ' %0.0f' % temp_data
108+ self .temp_text .text = " %0.0f°F" % temp_data
109+ temp_data = " %0.0f" % temp_data
108110 return int (temp_data )
109111 else :
110- print (' Temperature: %0.0f°C' % temp_data )
112+ print (" Temperature: %0.0f°C" % temp_data )
111113 if temp_data <= 0 :
112114 self .temp_text .color = 0xFD2EE
113115 elif temp_data >= 100 :
114116 self .temp_text .color = 0xFF0000
115- self .temp_text .text = ' %0.0f°C' % temp_data
116- temp_data = ' %0.0f' % temp_data
117+ self .temp_text .text = " %0.0f°C" % temp_data
118+ temp_data = " %0.0f" % temp_data
117119 return int (temp_data )
118120
119121 def set_icon (self , filename ):
@@ -127,16 +129,19 @@ def set_icon(self, filename):
127129
128130 if not filename :
129131 return # we're done, no icon desired
132+
133+ # CircuitPython 6 & 7 compatible
130134 if self ._icon_file :
131135 self ._icon_file .close ()
132136 self ._icon_file = open (filename , "rb" )
133137 icon = displayio .OnDiskBitmap (self ._icon_file )
134- try :
135- self ._icon_sprite = displayio .TileGrid (icon ,
136- pixel_shader = getattr (icon , 'pixel_shader' , displayio .ColorConverter ()))
137- except TypeError :
138- self ._icon_sprite = displayio .TileGrid (icon ,
139- pixel_shader = getattr (icon , 'pixel_shader' , displayio .ColorConverter ()),
140- position = (0 ,0 ))
138+ self ._icon_sprite = displayio .TileGrid (
139+ icon , pixel_shader = getattr (icon , "pixel_shader" , displayio .ColorConverter ())
140+ )
141+
142+ # CircuitPython 7 compatible
143+ # # Remove self._icon_file - it is no longer used
144+ # icon = displayio.OnDiskBitmap(filename)
145+ # self._icon_sprite = displayio.TileGrid(icon, pixel_shader=icon.pixel_shader)
141146
142147 self ._icon_group .append (self ._icon_sprite )
0 commit comments