Skip to content

Commit 2df1eeb

Browse files
brentrubrentru
authored andcommitted
pylinting
1 parent 4d58e74 commit 2df1eeb

2 files changed

Lines changed: 72 additions & 44 deletions

File tree

PyPortal_Azure_Plant_Monitor/azure_gfx_helper.py

Lines changed: 69 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
GFX Helper for pyportal_azure_iot_temperature.py
2+
GFX Helper for PyPortal Azure IoT Plant Monitor
33
"""
44
import board
55
import displayio
@@ -9,86 +9,114 @@
99
cwd = ("/"+__file__).rsplit('/', 1)[0] # the current working directory (where this file is)
1010

1111
# 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"
1414

1515
class Azure_GFX(displayio.Group):
16-
def __init__(self, celsius=False):
16+
def __init__(self, is_celsius=True, device_id="Azure"):
1717
"""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.
1920
"""
2021
# root displayio group
21-
root_group = displayio.Group(max_size=20)
22+
root_group = displayio.Group(max_size=23)
2223
board.DISPLAY.show(root_group)
23-
super().__init__(max_size=20)
24+
super().__init__(max_size=15)
2425

25-
self._celsius = celsius
26+
# temperature display option
27+
self._is_celsius = is_celsius
2628

2729
# create background icon group
28-
self._icon_group = displayio.Group(max_size=1)
30+
self._icon_group = displayio.Group(max_size=3)
2931
self.append(self._icon_group)
3032
board.DISPLAY.show(self._icon_group)
3133
# create text object group
32-
self._text_group = displayio.Group(max_size=6)
34+
self._text_group = displayio.Group(max_size=9)
3335
self.append(self._text_group)
3436

3537
self._icon_sprite = None
3638
self._icon_file = None
3739
self._cwd = cwd
3840
self.set_icon(self._cwd+"/images/azure_splash.bmp")
3941

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)
4849

4950
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
5354
self._text_group.append(self.title_text)
5455

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
5864
self._text_group.append(self.temp_text)
5965

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
6379
self._text_group.append(self.azure_status_text)
6480

6581
board.DISPLAY.show(self._text_group)
6682

83+
6784
def display_azure_status(self, status_text):
68-
"""Displays the current Azure IoT status.
85+
"""Displays the system status on the PyPortal
6986
:param str status_text: Description of Azure IoT status
7087
"""
7188
self.azure_status_text.text = status_text
7289

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.
76100
"""
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:
81105
self.temp_text.color = 0xFD2EE
82-
elif adt_data <= 32:
106+
elif temp_data <= 32:
83107
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)
85111
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:
88114
self.temp_text.color = 0xFD2EE
89-
elif adt_data >= 100:
115+
elif temp_data >= 100:
90116
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)
92120

93121
def set_icon(self, filename):
94122
"""Sets the background image to a bitmap file.

PyPortal_Azure_Plant_Monitor/code.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
77
Author: Brent Rubell for Adafruit Industries, 2019
88
"""
9+
import time
910
import board
1011
import busio
11-
import time
1212
from digitalio import DigitalInOut
1313
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
1414
import neopixel
@@ -42,7 +42,7 @@
4242
hub = IOT_Hub(wifi, secrets['azure_iot_hub'], secrets['azure_iot_sas'], secrets['azure_device_id'])
4343

4444
# init. graphics helper
45-
gfx = azure_gfx_helper.Azure_GFX(is_celsius=False)
45+
gfx = azure_gfx_helper.Azure_GFX(False)
4646

4747
while True:
4848
try:
@@ -63,4 +63,4 @@
6363
print("Failed to get data, retrying\n", e)
6464
wifi.reset()
6565
continue
66-
time.sleep(60)
66+
time.sleep(60)

0 commit comments

Comments
 (0)