Skip to content

Commit 87221e4

Browse files
authored
Merge pull request #57 from pimoroni/test-tweaks-and-linting
Test tweaks and linting
2 parents 97ee1d8 + e72e568 commit 87221e4

File tree

12 files changed

+426
-283
lines changed

12 files changed

+426
-283
lines changed

examples/all-in-one-no-pm.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,22 @@ def display_text(variable, data, unit):
6767
# Maintain length of list
6868
values[variable] = values[variable][1:] + [data]
6969
# Scale the values for the variable between 0 and 1
70-
colours = [(v - min(values[variable]) + 1) / (max(values[variable])
71-
- min(values[variable]) + 1) for v in values[variable]]
70+
vmin = min(values[variable])
71+
vmax = max(values[variable])
72+
colours = [(v - vmin + 1) / (vmax - vmin + 1) for v in values[variable]]
7273
# Format the variable name and value
7374
message = "{}: {:.1f} {}".format(variable[:4], data, unit)
7475
logging.info(message)
7576
draw.rectangle((0, 0, WIDTH, HEIGHT), (255, 255, 255))
7677
for i in range(len(colours)):
7778
# Convert the values to colours from red to blue
7879
colour = (1.0 - colours[i]) * 0.6
79-
r, g, b = [int(x * 255.0) for x in colorsys.hsv_to_rgb(colour,
80-
1.0, 1.0)]
80+
r, g, b = [int(x * 255.0) for x in colorsys.hsv_to_rgb(colour, 1.0, 1.0)]
8181
# Draw a 1-pixel wide rectangle of colour
82-
draw.rectangle((i, top_pos, i+1, HEIGHT), (r, g, b))
82+
draw.rectangle((i, top_pos, i + 1, HEIGHT), (r, g, b))
8383
# Draw a line graph in black
84-
line_y = HEIGHT - (top_pos + (colours[i] * (HEIGHT - top_pos)))\
85-
+ top_pos
86-
draw.rectangle((i, line_y, i+1, line_y+1), (0, 0, 0))
84+
line_y = HEIGHT - (top_pos + (colours[i] * (HEIGHT - top_pos))) + top_pos
85+
draw.rectangle((i, line_y, i + 1, line_y + 1), (0, 0, 0))
8786
# Write the text at the top in black
8887
draw.text((0, 0), message, font=font, fill=(0, 0, 0))
8988
st7735.display(img)

examples/all-in-one.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import time
44
import colorsys
5-
import os
65
import sys
76
import ST7735
87
try:
@@ -72,23 +71,22 @@ def display_text(variable, data, unit):
7271
# Maintain length of list
7372
values[variable] = values[variable][1:] + [data]
7473
# Scale the values for the variable between 0 and 1
75-
colours = [(v - min(values[variable]) + 1) / (max(values[variable])
76-
- min(values[variable]) + 1) for v in values[variable]]
74+
vmin = min(values[variable])
75+
vmax = max(values[variable])
76+
colours = [(v - vmin + 1) / (vmax - vmin + 1) for v in values[variable]]
7777
# Format the variable name and value
7878
message = "{}: {:.1f} {}".format(variable[:4], data, unit)
7979
logging.info(message)
8080
draw.rectangle((0, 0, WIDTH, HEIGHT), (255, 255, 255))
8181
for i in range(len(colours)):
8282
# Convert the values to colours from red to blue
8383
colour = (1.0 - colours[i]) * 0.6
84-
r, g, b = [int(x * 255.0) for x in colorsys.hsv_to_rgb(colour,
85-
1.0, 1.0)]
84+
r, g, b = [int(x * 255.0) for x in colorsys.hsv_to_rgb(colour, 1.0, 1.0)]
8685
# Draw a 1-pixel wide rectangle of colour
87-
draw.rectangle((i, top_pos, i+1, HEIGHT), (r, g, b))
86+
draw.rectangle((i, top_pos, i + 1, HEIGHT), (r, g, b))
8887
# Draw a line graph in black
89-
line_y = HEIGHT - (top_pos + (colours[i] * (HEIGHT - top_pos)))\
90-
+ top_pos
91-
draw.rectangle((i, line_y, i+1, line_y+1), (0, 0, 0))
88+
line_y = HEIGHT - (top_pos + (colours[i] * (HEIGHT - top_pos))) + top_pos
89+
draw.rectangle((i, line_y, i + 1, line_y + 1), (0, 0, 0))
9290
# Write the text at the top in black
9391
draw.text((0, 0), message, font=font, fill=(0, 0, 0))
9492
st7735.display(img)

0 commit comments

Comments
 (0)