Skip to content

Commit ceb426b

Browse files
committed
first example added flag "temp_in_fahrenheit"
As just done with the second example. Added possibility to switch temperature displayed in degrees Celsius or degrees Fahrenheit by setting the gVars flag variable "temp_in_fahrenheit"
1 parent 417c80a commit ceb426b

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

examples/hotplug_sensor_examples/displayio_layout_tab_layout_hotplug_ext_rtc_temp_sensor_test.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from adafruit_display_shapes.rect import Rect
1616
from adafruit_display_shapes.circle import Circle
1717
from adafruit_display_shapes.triangle import Triangle
18+
from adafruit_bitmap_font import bitmap_font
1819
from adafruit_displayio_layout.layouts.tab_layout import TabLayout
1920

2021
# +-------------------------------------------------------+
@@ -49,6 +50,7 @@ def __init__(self):
4950
18: "use_txt_in_month",
5051
19: "use_usa_notation",
5152
20: "content_sensor_idx",
53+
21: "temp_in_fahrenheit",
5254
}
5355

5456
self.gVars_rDict = {
@@ -73,6 +75,7 @@ def __init__(self):
7375
"use_txt_in_month": 18,
7476
"use_usa_notation": 19,
7577
"content_sensor_idx": 20,
78+
"temp_in_fahrenheit": 21,
7679
}
7780

7881
self.g_vars = {}
@@ -127,6 +130,7 @@ def clean(self):
127130
18: None,
128131
19: None,
129132
20: None,
133+
21: None,
130134
}
131135

132136
def list(self):
@@ -203,6 +207,7 @@ def list(self):
203207
myVars.write("use_usa_notation", True)
204208
myVars.write("use_ntp", False)
205209
myVars.write("content_sensor_idx", None)
210+
myVars.write("temp_in_fahrenheit", True)
206211
# -------------------------------------------------------------------------
207212
if myVars.read("my_debug"):
208213
# print list of all variables in myVars
@@ -221,15 +226,16 @@ def list(self):
221226
display.show(main_group)
222227

223228
# fon.gvars bitmap_font.load_font("fonts/Helvetica-Bold-16.bdf")
224-
font = terminalio.FONT
229+
font_arial = bitmap_font.load_font("/fonts/Arial-16.bdf")
230+
font_term = terminalio.FONT
225231

226232
# create the page layout
227233
test_page_layout = TabLayout(
228234
x=0,
229235
y=0,
230236
display=board.DISPLAY,
231237
tab_text_scale=2,
232-
custom_font=font,
238+
custom_font=font_term,
233239
inactive_tab_spritesheet="bmps/inactive_tab_sprite.bmp",
234240
showing_tab_spritesheet="bmps/active_tab_sprite.bmp",
235241
showing_tab_text_color=0x00AA59,
@@ -247,63 +253,63 @@ def list(self):
247253

248254
# labels
249255
pge1_lbl = Label(
250-
font=terminalio.FONT,
256+
font=font_term,
251257
scale=2,
252258
text="This is the first page!",
253259
anchor_point=(0, 0),
254260
anchored_position=(10, 10),
255261
)
256262
pge1_lbl2 = Label(
257-
font=terminalio.FONT,
263+
font=font_term,
258264
scale=2,
259265
text="Please wait...",
260266
anchor_point=(0, 0),
261267
anchored_position=(10, 150),
262268
)
263269
pge2_lbl = Label(
264-
font=terminalio.FONT,
270+
font=font_term,
265271
scale=2,
266272
text="This page is the second page!",
267273
anchor_point=(0, 0),
268274
anchored_position=(10, 10),
269275
)
270276
pge3_lbl = Label(
271-
font=terminalio.FONT,
277+
font=font_term,
272278
scale=2,
273279
text=myVars.read("pge3_lbl_dflt"), # Will be "Date/time:"
274280
anchor_point=(0, 0),
275281
anchored_position=(10, 10),
276282
)
277283
pge3_lbl2 = Label(
278-
font=terminalio.FONT,
284+
font=font_term,
279285
scale=2,
280286
text="", # pge3_lbl2_dflt, # Will be DD-MO-YYYY or Month-DD-YYYY
281287
anchor_point=(0, 0),
282288
anchored_position=(10, 40),
283289
)
284290
pge3_lbl3 = Label(
285-
font=terminalio.FONT,
291+
font=font_term,
286292
scale=2,
287293
text="", # pge3_lbl3_dflt, # Will be HH:MM:SS
288294
anchor_point=(0, 0),
289295
anchored_position=(10, 70),
290296
)
291297
pge4_lbl = Label(
292-
font=terminalio.FONT,
298+
font=font_term,
293299
scale=2,
294300
text=myVars.read("pge4_lbl_dflt"),
295301
anchor_point=(0, 0),
296302
anchored_position=(10, 10),
297303
)
298304
pge4_lbl2 = Label(
299-
font=terminalio.FONT,
305+
font=font_term,
300306
scale=2,
301307
text="", # Will be "Temperature"
302308
anchor_point=(0, 0),
303309
anchored_position=(10, 130),
304310
)
305311
pge4_lbl3 = Label(
306-
font=terminalio.FONT,
312+
font=font_arial,
307313
scale=2,
308314
text="", # Will be "xx.yy C"
309315
anchor_point=(0, 0),
@@ -405,7 +411,11 @@ def connect_temp_sensor():
405411
print(t)
406412
print("temperature sensor connected")
407413
myVars.write("t0", "Temperature")
408-
myVars.write("t1", " C")
414+
if myVars.read("temp_in_fahrenheit"):
415+
myVars.write("t1", chr(186) + "F")
416+
else:
417+
myVars.write("t1", chr(186) + "C")
418+
409419
myVars.write("t2", 27 * "_")
410420
else:
411421
print("no " + t)
@@ -460,6 +470,8 @@ def get_temp():
460470
if myVars.read("temp_sensor") is not None:
461471
try:
462472
temp = myVars.read("temp_sensor").temperature
473+
if myVars.read("temp_in_fahrenheit"):
474+
temp = (temp * 1.8) + 32
463475
t = "{:5.2f} ".format(temp) + myVars.read("t1")
464476
if (
465477
myVars.read("my_debug")

0 commit comments

Comments
 (0)