|
1 | 1 | """ |
2 | | -GFX Helper for pyportal_azure_iot_temperature.py |
| 2 | +GFX Helper for PyPortal Azure IoT Plant Monitor |
3 | 3 | """ |
4 | 4 | import board |
5 | 5 | import displayio |
|
9 | 9 | cwd = ("/"+__file__).rsplit('/', 1)[0] # the current working directory (where this file is) |
10 | 10 |
|
11 | 11 | # Fonts within /fonts folder |
12 | | -info_font = cwd+"/fonts/Nunito-Black-17.bdf" |
13 | | -temperature_font = cwd+"/fonts/Nunito-Light-75.bdf" |
| 12 | +main_font = cwd+"/fonts/EarthHeart-26.bdf" |
| 13 | +data_font = cwd+"/fonts/Collegiate-50.bdf" |
14 | 14 |
|
15 | 15 | class Azure_GFX(displayio.Group): |
16 | | - def __init__(self, celsius=False): |
| 16 | + def __init__(self, is_celsius=True, device_id="Azure"): |
17 | 17 | """Creates an Azure_GFX object. |
18 | | - :param bool celsius: Temperature displayed as F or C |
| 18 | + :param bool is_celsius: Temperature displayed in Celsius. |
| 19 | + :param str device_id: Unique device identifier from secrets.py file. |
19 | 20 | """ |
20 | 21 | # root displayio group |
21 | | - root_group = displayio.Group(max_size=20) |
| 22 | + root_group = displayio.Group(max_size=23) |
22 | 23 | board.DISPLAY.show(root_group) |
23 | | - super().__init__(max_size=20) |
| 24 | + super().__init__(max_size=15) |
24 | 25 |
|
25 | | - self._celsius = celsius |
| 26 | + # temperature display option |
| 27 | + self._is_celsius = is_celsius |
26 | 28 |
|
27 | 29 | # create background icon group |
28 | | - self._icon_group = displayio.Group(max_size=1) |
| 30 | + self._icon_group = displayio.Group(max_size=3) |
29 | 31 | self.append(self._icon_group) |
30 | 32 | board.DISPLAY.show(self._icon_group) |
31 | 33 | # create text object group |
32 | | - self._text_group = displayio.Group(max_size=6) |
| 34 | + self._text_group = displayio.Group(max_size=9) |
33 | 35 | self.append(self._text_group) |
34 | 36 |
|
35 | 37 | self._icon_sprite = None |
36 | 38 | self._icon_file = None |
37 | 39 | self._cwd = cwd |
38 | 40 | self.set_icon(self._cwd+"/images/azure_splash.bmp") |
39 | 41 |
|
40 | | - print('Loading Fonts...') |
41 | | - glyphs = b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.:/ ' |
42 | | - self.info_font = bitmap_font.load_font(info_font) |
43 | | - self.info_font.load_glyphs(glyphs) |
44 | | - |
45 | | - self.c_font = bitmap_font.load_font(temperature_font) |
46 | | - self.c_font.load_glyphs(glyphs) |
47 | | - self.c_font.load_glyphs(('°',)) # extra glyph for temperature font |
| 42 | + print('loading fonts...') |
| 43 | + glyphs = b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.: ' |
| 44 | + data_glyphs = b'012345678-,.:/FC°' |
| 45 | + self.main_font = bitmap_font.load_font(main_font) |
| 46 | + self.main_font.load_glyphs(glyphs) |
| 47 | + self.data_font = bitmap_font.load_font(data_font) |
| 48 | + self.data_font.load_glyphs(data_glyphs) |
48 | 49 |
|
49 | 50 | print('setting up labels...') |
50 | | - self.title_text = Label(self.info_font, text="Azure IoT Temperature Logger") |
51 | | - self.title_text.x = 55 |
52 | | - self.title_text.y = 15 |
| 51 | + self.title_text = Label(self.main_font, text="Azure Plant Monitor") |
| 52 | + self.title_text.x = 35 |
| 53 | + self.title_text.y = 25 |
53 | 54 | self._text_group.append(self.title_text) |
54 | 55 |
|
55 | | - self.temp_text = Label(self.c_font, max_glyphs=8) |
56 | | - self.temp_text.x = 25 |
57 | | - self.temp_text.y = 110 |
| 56 | + self.temp_label = Label(self.main_font, text="Temperature") |
| 57 | + self.temp_label.x = 0 |
| 58 | + self.temp_label.y = 65 |
| 59 | + self._text_group.append(self.temp_label) |
| 60 | + |
| 61 | + self.temp_text = Label(self.data_font, max_glyphs=10) |
| 62 | + self.temp_text.x = 200 |
| 63 | + self.temp_text.y = 85 |
58 | 64 | self._text_group.append(self.temp_text) |
59 | 65 |
|
60 | | - self.azure_status_text = Label(self.info_font, max_glyphs=40) |
61 | | - self.azure_status_text.x = 100 |
62 | | - self.azure_status_text.y = 220 |
| 66 | + self.moisture_label = Label(self.main_font, text="Moisture Level") |
| 67 | + self.moisture_label.x = 0 |
| 68 | + self.moisture_label.y = 135 |
| 69 | + self._text_group.append(self.moisture_label) |
| 70 | + |
| 71 | + self.moisture_text = Label(self.data_font, max_glyphs=10) |
| 72 | + self.moisture_text.x = 200 |
| 73 | + self.moisture_text.y = 175 |
| 74 | + self._text_group.append(self.moisture_text) |
| 75 | + |
| 76 | + self.azure_status_text = Label(self.main_font, max_glyphs=15) |
| 77 | + self.azure_status_text.x = 65 |
| 78 | + self.azure_status_text.y = 225 |
63 | 79 | self._text_group.append(self.azure_status_text) |
64 | 80 |
|
65 | 81 | board.DISPLAY.show(self._text_group) |
66 | 82 |
|
| 83 | + |
67 | 84 | def display_azure_status(self, status_text): |
68 | | - """Displays the current Azure IoT status. |
| 85 | + """Displays the system status on the PyPortal |
69 | 86 | :param str status_text: Description of Azure IoT status |
70 | 87 | """ |
71 | 88 | self.azure_status_text.text = status_text |
72 | 89 |
|
73 | | - def display_temp(self, adt_data): |
74 | | - """Displays the data from the ADT7410 on the. |
75 | | - :param float adt_data: Value from the ADT7410 |
| 90 | + def display_moisture(self, moisture_data): |
| 91 | + """Displays the moisture from the Stemma Soil Sensor. |
| 92 | + :param int moisture_data: Moisture value |
| 93 | + """ |
| 94 | + print('Moisture Level: ', moisture_data) |
| 95 | + self.moisture_text.text = str(moisture_data) |
| 96 | + |
| 97 | + def display_temp(self, temp_data): |
| 98 | + """Displays the temperature from the Stemma Soil Sensor. |
| 99 | + :param float temp_data: Temperature value. |
76 | 100 | """ |
77 | | - if not self._celsius: |
78 | | - adt_data = (adt_data * 9 / 5) + 32 |
79 | | - print('Temperature: %0.2f°F'%adt_data) |
80 | | - if adt_data >= 212: |
| 101 | + if not self._is_celsius: |
| 102 | + temp_data = (temp_data * 9 / 5) + 32 - 15 |
| 103 | + print('Temperature: %0.0f°F'%temp_data) |
| 104 | + if temp_data >= 212: |
81 | 105 | self.temp_text.color = 0xFD2EE |
82 | | - elif adt_data <= 32: |
| 106 | + elif temp_data <= 32: |
83 | 107 | self.temp_text.color = 0xFF0000 |
84 | | - self.temp_text.text = '%0.2f°F'%adt_data |
| 108 | + self.temp_text.text = '%0.0f°F'%temp_data |
| 109 | + temp_data = '%0.0f'%temp_data |
| 110 | + return int(temp_data) |
85 | 111 | else: |
86 | | - print('Temperature: %0.2f°C'%adt_data) |
87 | | - if adt_data <= 0: |
| 112 | + print('Temperature: %0.0f°C'%temp_data) |
| 113 | + if temp_data <= 0: |
88 | 114 | self.temp_text.color = 0xFD2EE |
89 | | - elif adt_data >= 100: |
| 115 | + elif temp_data >= 100: |
90 | 116 | self.temp_text.color = 0xFF0000 |
91 | | - self.temp_text.text = '%0.2f°C'%adt_data |
| 117 | + self.temp_text.text = '%0.0f°C'%temp_data |
| 118 | + temp_data = '%0.0f'%temp_data |
| 119 | + return int(temp_data) |
92 | 120 |
|
93 | 121 | def set_icon(self, filename): |
94 | 122 | """Sets the background image to a bitmap file. |
|
0 commit comments