Skip to content

Commit 9e35273

Browse files
committed
first commit
1 parent 96a3d09 commit 9e35273

File tree

3 files changed

+14808
-0
lines changed

3 files changed

+14808
-0
lines changed

CLUE_BBQ/clue_bbq.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Adafruit BBQ display works with ibbq protocol-based BLE temperature probes
2+
3+
4+
import time
5+
6+
import displayio
7+
import _bleio
8+
import adafruit_ble
9+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
10+
from adafruit_ble_ibbq import IBBQService
11+
from adafruit_clue import clue
12+
from adafruit_display_shapes.circle import Circle
13+
from adafruit_display_text import label
14+
from adafruit_bitmap_font import bitmap_font
15+
16+
clue.display.brightness = 1.0
17+
homescreen_screen = displayio.Group(max_size=3)
18+
temperatures_screen = displayio.Group(max_size=2)
19+
20+
# define custom colors
21+
GREEN = 0x00d929
22+
BLUE = 0x0000ff
23+
RED = 0xff0000
24+
ORANGE = 0xff6a00
25+
YELLOW = 0xffff00
26+
PURPLE = 0xe400ff
27+
BLACK = 0x000000
28+
WHITE = 0xffffff
29+
BURNT = 0xbb4e00
30+
31+
unit_mode = False # set the temperature unit_mode. True = centigrade, False = farenheit
32+
33+
# background fill
34+
color_bitmap = displayio.Bitmap(120, 120, 1)
35+
color_palette = displayio.Palette(1)
36+
color_palette[0] = BURNT
37+
bg_sprite = displayio.TileGrid(color_bitmap, x=120, y=0, pixel_shader=color_palette)
38+
homescreen_screen.append(bg_sprite)
39+
40+
clue_color = [GREEN, BLUE, RED, ORANGE, YELLOW, PURPLE]
41+
42+
outer_circle = Circle(120, 120, 119, fill=BLACK, outline=BURNT)
43+
homescreen_screen.append(outer_circle)
44+
45+
46+
title_font = bitmap_font.load_font("/font/GothamBlack-50.bdf")
47+
title_font.load_glyphs("BQLUE".encode('utf-8'))
48+
title_label = label.Label(title_font, text="BBQLUE", color=clue.ORANGE, max_glyphs=15)
49+
title_label.x = 12
50+
title_label.y = 120
51+
homescreen_screen.append(title_label)
52+
53+
clue.display.show(homescreen_screen)
54+
55+
56+
temp_font = bitmap_font.load_font("/font/GothamBlack-25.bdf")
57+
temp_font.load_glyphs("0123456789FC.-<".encode('utf-8'))
58+
59+
my_labels_config = [(0, "", GREEN, 2, 100),
60+
(1, "", BLUE, 2, 150),
61+
(2, "", RED, 2, 200),
62+
(3, "", ORANGE, 135, 100),
63+
(4, "", YELLOW, 135, 150),
64+
(5, "", PURPLE, 135, 200)
65+
]
66+
67+
my_labels = {} # dictionary of configured my_labels
68+
69+
text_group = displayio.Group(max_size=8, scale=1)
70+
71+
for label_config in my_labels_config:
72+
(name, text, color, x, y) = label_config # unpack a tuple into five var names
73+
# old way sould have been: name = label_config[0], text = label_config[1]
74+
templabel = label.Label(temp_font, text=text, color=color, max_glyphs=15)
75+
templabel.x = x
76+
templabel.y = y
77+
my_labels[name] = templabel
78+
text_group.append(templabel)
79+
80+
temperatures_screen.append(text_group)
81+
82+
temp_title_label = label.Label(title_font, text="BBQLUE", color=clue.ORANGE, max_glyphs=15)
83+
temp_title_label.x = 12
84+
temp_title_label.y = 30
85+
temperatures_screen.append(temp_title_label)
86+
87+
# PyLint can't find BLERadio for some reason so special case it here.
88+
ble = adafruit_ble.BLERadio() # pylint: disable=no-member
89+
90+
ibbq_connection = None
91+
92+
while True:
93+
# re-display homescreen here
94+
clue.display.show(homescreen_screen)
95+
96+
print("Scanning...")
97+
for adv in ble.start_scan(ProvideServicesAdvertisement, timeout=5):
98+
clue.pixel.fill((50, 50, 0))
99+
if IBBQService in adv.services:
100+
print("found an IBBq advertisement")
101+
ibbq_connection = ble.connect(adv)
102+
print("Connected")
103+
break
104+
105+
# Stop scanning whether or not we are connected.
106+
ble.stop_scan()
107+
108+
try:
109+
if ibbq_connection and ibbq_connection.connected:
110+
clue.pixel.fill((0, 0, 50))
111+
ibbq_service = ibbq_connection[IBBQService]
112+
ibbq_service.init()
113+
while ibbq_connection.connected:
114+
115+
if clue.button_a: # hold a to swap between C and F
116+
print("unit_mode swapped")
117+
unit_mode = not unit_mode
118+
clue.red_led = True
119+
clue.play_tone(1200, 0.1)
120+
clue.red_led = False
121+
time.sleep(0.1) # debounce
122+
123+
temps = ibbq_service.temperatures
124+
batt = ibbq_service.battery_level
125+
if temps is not None:
126+
probe_count = len(temps) # check how many probes there are
127+
for i in range(probe_count):
128+
if (temps[i] is not 0 and temps[i] < 1000): # unplugged probes
129+
if unit_mode:
130+
clue.pixel.fill((50, 0, 0))
131+
temp = temps[i]
132+
my_labels[i].text = "{} C".format(temp)
133+
clue.pixel.fill((0, 0, 0))
134+
print("Probe", i+1, "Temperature:", temp,"C",)
135+
else: # F
136+
clue.pixel.fill((50, 0, 0))
137+
temp = temps[i] * 9 / 5 + 32
138+
my_labels[i].text = "{} F".format(temp)
139+
clue.pixel.fill((0, 0, 0))
140+
print("Probe", i+1, "Temperature:", temp,"F",)
141+
else:
142+
print("Probe", i+1, "is unplugged",)
143+
my_labels[i].text = (" ---")
144+
clue.display.show(temperatures_screen)
145+
146+
except _bleio.ConnectionError:
147+
# Redisplay splash screen here, or put it at top of while True:
148+
continue

0 commit comments

Comments
 (0)