Skip to content

Commit a15e2b5

Browse files
committed
pylint disables, Debouncer and import fixes
excellent thanks @BlitzCityDIY @TheKitty here are the round of adjustments: 1. f-string syntax error (line 2009) Extracted conditional to zoom_label variable 2. DRV2605 shouldn't be optional import Moved to normal import adafruit_drv2605 at top 3. Haptic init shouldn't have try/except Direct haptic = adafruit_drv2605.DRV2605(i2c) 4. Don't wrap single-call code in functions Unwrapped _build_bars() back to module-level loop 5. Redefined-outer-name from loop vars Renamed to bar_idx, bar_x (unique names) 6. Consolidate graph functions Already done previous pass — create_sensor_graph() / update_sensor_graph() 7. Use f-strings Already converted all 36 .format() calls Memory updated with reviewer's patterns (#7, #14). Remaining for next PR: Migrate manual button polling to adafruit_debouncer.Button — that's a substantial refactor of the entire polling loop but will eliminate the manual timestamp tracking, pending flags, and double-tap state machine. The debouncer library's short_count and long_press APIs handle all of that natively.
1 parent f545a70 commit a15e2b5

File tree

1 file changed

+59
-75
lines changed

1 file changed

+59
-75
lines changed

Star_Trek_Data_Dispenser/code.py

Lines changed: 59 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@
3131
from adafruit_display_text import label
3232
import adafruit_stcc4
3333
import adafruit_max1704x
34-
35-
try:
36-
import adafruit_drv2605
37-
except ImportError:
38-
adafruit_drv2605 = None
34+
import adafruit_drv2605
3935

4036
# ============================================================
4137
# TUNABLES
@@ -336,14 +332,8 @@ def save_co2_offset():
336332

337333
batt = adafruit_max1704x.MAX17048(i2c)
338334

339-
haptic = None
340-
drv_effect = None
341-
if adafruit_drv2605 is not None:
342-
try:
343-
haptic = adafruit_drv2605.DRV2605(i2c)
344-
drv_effect = adafruit_drv2605.Effect
345-
except (ValueError, RuntimeError, OSError):
346-
print("No haptic motor found.")
335+
haptic = adafruit_drv2605.DRV2605(i2c)
336+
drv_effect = adafruit_drv2605.Effect
347337

348338
# ============================================================
349339
# BUILD BAR GRAPH UI
@@ -369,73 +359,68 @@ def save_co2_offset():
369359
pct_labels = []
370360

371361

372-
def _build_bars():
373-
"""Build the bar graph UI elements."""
374-
for idx in range(NUM_BARS):
375-
bx = X_OFFSET + idx * (BAR_W + BAR_GAP)
376-
377-
out_pal = displayio.Palette(1)
378-
out_pal[0] = OUTLINE_COLORS[idx]
379-
root.append(
380-
vectorio.Polygon(
381-
pixel_shader=out_pal,
382-
points=outline_shape(),
383-
x=bx, y=BAR_Y,
384-
)
385-
)
386-
387-
trk_pal = displayio.Palette(1)
388-
trk_pal[0] = TRACK_COLORS[idx]
389-
root.append(
390-
vectorio.Polygon(
391-
pixel_shader=trk_pal,
392-
points=bar_shape(),
393-
x=bx, y=BAR_Y,
394-
)
395-
)
362+
for bar_idx in range(NUM_BARS):
363+
bar_x = X_OFFSET + bar_idx * (BAR_W + BAR_GAP)
396364

397-
fill_pal = displayio.Palette(1)
398-
fill_pal[0] = BAR_COLORS[idx]
399-
root.append(
400-
vectorio.Polygon(
401-
pixel_shader=fill_pal,
402-
points=bar_shape(),
403-
x=bx, y=BAR_Y,
404-
)
365+
out_pal = displayio.Palette(1)
366+
out_pal[0] = OUTLINE_COLORS[bar_idx]
367+
root.append(
368+
vectorio.Polygon(
369+
pixel_shader=out_pal,
370+
points=outline_shape(),
371+
x=bar_x, y=BAR_Y,
405372
)
373+
)
406374

407-
soft_pal = displayio.Palette(1)
408-
soft_pal[0] = SOFT_COLORS[idx]
409-
soft = vectorio.Polygon(
410-
pixel_shader=soft_pal,
375+
trk_pal = displayio.Palette(1)
376+
trk_pal[0] = TRACK_COLORS[bar_idx]
377+
root.append(
378+
vectorio.Polygon(
379+
pixel_shader=trk_pal,
411380
points=bar_shape(),
412-
x=bx, y=BAR_Y,
381+
x=bar_x, y=BAR_Y,
413382
)
414-
root.append(soft)
415-
soft_masks.append(soft)
383+
)
416384

417-
mask = vectorio.Polygon(
418-
pixel_shader=trk_pal,
385+
fill_pal = displayio.Palette(1)
386+
fill_pal[0] = BAR_COLORS[bar_idx]
387+
root.append(
388+
vectorio.Polygon(
389+
pixel_shader=fill_pal,
419390
points=bar_shape(),
420-
x=bx, y=BAR_Y,
391+
x=bar_x, y=BAR_Y,
421392
)
422-
root.append(mask)
423-
bar_masks.append(mask)
393+
)
424394

425-
lbl = label.Label(
426-
terminalio.FONT,
427-
text="---",
428-
color=BAR_COLORS[idx],
429-
anchor_point=(0.5, 0.0),
430-
anchored_position=(
431-
bx + BAR_W // 2, LABEL_Y
432-
),
433-
)
434-
root.append(lbl)
435-
pct_labels.append(lbl)
395+
soft_pal = displayio.Palette(1)
396+
soft_pal[0] = SOFT_COLORS[bar_idx]
397+
soft = vectorio.Polygon(
398+
pixel_shader=soft_pal,
399+
points=bar_shape(),
400+
x=bar_x, y=BAR_Y,
401+
)
402+
root.append(soft)
403+
soft_masks.append(soft)
436404

405+
mask = vectorio.Polygon(
406+
pixel_shader=trk_pal,
407+
points=bar_shape(),
408+
x=bar_x, y=BAR_Y,
409+
)
410+
root.append(mask)
411+
bar_masks.append(mask)
437412

438-
_build_bars()
413+
lbl = label.Label(
414+
terminalio.FONT,
415+
text="---",
416+
color=BAR_COLORS[bar_idx],
417+
anchor_point=(0.5, 0.0),
418+
anchored_position=(
419+
bar_x + BAR_W // 2, LABEL_Y
420+
),
421+
)
422+
root.append(lbl)
423+
pct_labels.append(lbl)
439424

440425
# ============================================================
441426
# CHARGING INDICATOR
@@ -619,8 +604,6 @@ def update_bar(idx, pct, txt):
619604

620605
def scan_buzz():
621606
"""Three quick haptic pulses for scan events."""
622-
if haptic is None:
623-
return
624607
for pulse in range(3): # pylint: disable=unused-variable
625608
haptic.sequence[0] = drv_effect(47)
626609
haptic.play()
@@ -633,8 +616,6 @@ def scan_buzz():
633616
def buzz_alert(force=False):
634617
"""Double-pulse haptic warning."""
635618
global last_haptic
636-
if haptic is None:
637-
return
638619
now = time.monotonic()
639620
if not force:
640621
if now - last_haptic < HAPTIC_COOLDOWN:
@@ -2006,8 +1987,11 @@ def compute_display(co2_r, hum_r, tmp_r, # pylint: disable=too-many-locals,too-
20061987
):
20071988
# Zoom toggle on graph views
20081989
graph_zoomed = not graph_zoomed
2009-
print(f"Zoom: {"15min" if graph_zoomed
2010-
else "full"}")
1990+
zoom_label = (
1991+
"15min" if graph_zoomed
1992+
else "full"
1993+
)
1994+
print(f"Zoom: {zoom_label}")
20111995
else:
20121996
# F/C toggle on other views
20131997
use_fahrenheit = not use_fahrenheit

0 commit comments

Comments
 (0)