Skip to content

Commit

Permalink
QA: Reformat with black.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Jun 12, 2024
1 parent 027da75 commit 3348a0a
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 101 deletions.
6 changes: 5 additions & 1 deletion ST7789.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

from st7789 import * # noqa F403

warn("Using \"import ST7789\" is deprecated. Please \"import st7789\" (all lowercase)!", DeprecationWarning, stacklevel=2)
warn(
'Using "import ST7789" is deprecated. Please "import st7789" (all lowercase)!',
DeprecationWarning,
stacklevel=2,
)
10 changes: 5 additions & 5 deletions examples/320x240.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
draw = ImageDraw.Draw(buffer)

draw.rectangle((0, 0, 50, 50), (255, 0, 0))
draw.rectangle((320-50, 0, 320, 50), (0, 255, 0))
draw.rectangle((0, 240-50, 50, 240), (0, 0, 255))
draw.rectangle((320-50, 240-50, 320, 240), (255, 255, 0))
draw.rectangle((320 - 50, 0, 320, 50), (0, 255, 0))
draw.rectangle((0, 240 - 50, 50, 240), (0, 0, 255))
draw.rectangle((320 - 50, 240 - 50, 320, 240), (255, 255, 0))

display = ST7789(
port=SPI_PORT,
Expand All @@ -42,9 +42,9 @@
width=WIDTH,
height=HEIGHT,
rotation=180,
spi_speed_hz=60 * 1000 * 1000
spi_speed_hz=60 * 1000 * 1000,
)

while True:
display.display(buffer)
time.sleep(1.0 / 60)
time.sleep(1.0 / 60)
20 changes: 12 additions & 8 deletions examples/framerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
except IndexError:
display_type = "square"

print(f"""
print(
f"""
framerate.py - Test LCD framerate.
If you're using Breakout Garden, plug the 1.3" LCD (SPI)
Expand All @@ -35,14 +36,15 @@
* dhmini - 320x240 2.0" Rectangular LCD
Running at: {SPI_SPEED_MHZ}MHz on a {display_type} display.
""")
"""
)

try:
width, height, rotation, backlight, offset_left, offset_top = {
"square": (240, 240, 90, 19, 0, 0),
"round": (240, 240, 90, 19, 40, 0),
"rect": (240, 135, 0, 19, 40, 53),
"dhmini": (320, 240, 180, 13, 0, 0)
"dhmini": (320, 240, 180, 13, 0, 0),
}[display_type]
except IndexError:
raise RuntimeError(f"Unsupported display type: {display_type}")
Expand All @@ -55,10 +57,10 @@
port=0,
cs=st7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
dc=9,
backlight=backlight, # 18 for back BG slot, 19 for front BG slot.
backlight=backlight, # 18 for back BG slot, 19 for front BG slot.
spi_speed_hz=SPI_SPEED_MHZ * 1000000,
offset_left=offset_left,
offset_top=offset_top
offset_top=offset_top,
)

WIDTH = disp.width
Expand All @@ -71,9 +73,9 @@
draw = ImageDraw.Draw(image)

if step % 2 == 0:
draw.rectangle((WIDTH/2, int(HEIGHT/2), WIDTH, HEIGHT), (0, 128, 0))
draw.rectangle((WIDTH / 2, int(HEIGHT / 2), WIDTH, HEIGHT), (0, 128, 0))
else:
draw.rectangle((0, 0, WIDTH/2-1, int(HEIGHT/2)-1), (0, 128, 0))
draw.rectangle((0, 0, WIDTH / 2 - 1, int(HEIGHT / 2) - 1), (0, 128, 0))

f = math.sin((float(step) / STEPS) * math.pi)
offset_left = int(f * WIDTH)
Expand All @@ -89,4 +91,6 @@
count += 1
time_current = time.time() - time_start
if count % 120 == 0:
print(f"Time: {time_current:8.3f}, Frames: {count:6d}, FPS: {count / time_current:8.3f}")
print(
f"Time: {time_current:8.3f}, Frames: {count:6d}, FPS: {count / time_current:8.3f}"
)
26 changes: 15 additions & 11 deletions examples/gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@

import st7789

print("""
print(
"""
gif.py - Display a gif on the LCD.
If you're using Breakout Garden, plug the 1.3" LCD (SPI)
breakout into the front slot.
""")
"""
)

if len(sys.argv) < 2:
print(f"""Usage: {sys.argv[0]} <gif_file> <display_type>
print(
f"""Usage: {sys.argv[0]} <gif_file> <display_type>
Where <gif_file> is a .gif file.
Hint: {sys.argv[0]} deployrainbows.gif
Expand All @@ -25,7 +28,8 @@
* round - 240x240 1.3" Round LCD (applies an offset)
* rect - 240x135 1.14" Rectangular LCD (applies an offset)
* dhmini - 320x240 2.0" Display HAT Mini
""")
"""
)
sys.exit(1)

image_file = sys.argv[1]
Expand All @@ -44,10 +48,10 @@
port=0,
cs=st7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
dc=9,
backlight=19, # 18 for back BG slot, 19 for front BG slot.
backlight=19, # 18 for back BG slot, 19 for front BG slot.
spi_speed_hz=80 * 1000 * 1000,
offset_left=0 if display_type == "square" else 40,
offset_top=53 if display_type == "rect" else 0
offset_top=53 if display_type == "rect" else 0,
)

elif display_type == "dhmini":
Expand All @@ -61,11 +65,11 @@
backlight=13,
spi_speed_hz=60 * 1000 * 1000,
offset_left=0,
offset_top=0
)
offset_top=0,
)

else:
print ("Invalid display type!")
print("Invalid display type!")

# Initialize display.
disp.begin()
Expand All @@ -74,10 +78,10 @@
height = disp.height

# Load an image.
print(f'Loading gif: {image_file}...')
print(f"Loading gif: {image_file}...")
image = Image.open(image_file)

print('Drawing gif, press Ctrl+C to exit!')
print("Drawing gif, press Ctrl+C to exit!")

frame = 0

Expand Down
26 changes: 15 additions & 11 deletions examples/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@

import st7789

print("""
print(
"""
image.py - Display an image on the LCD.
If you're using Breakout Garden, plug the 1.3" LCD (SPI)
breakout into the front slot.
""")
"""
)

if len(sys.argv) < 2:
print(f"""Usage: {sys.argv[0]} <image_file> <display_type>
print(
f"""Usage: {sys.argv[0]} <image_file> <display_type>
Where <display_type> is one of:
* square - 240x240 1.3" Square LCD
* round - 240x240 1.3" Round LCD (applies an offset)
* rect - 240x135 1.14" Rectangular LCD (applies an offset)
* dhmini - 320x240 2.0" Display HAT Mini
""")
"""
)
sys.exit(1)

image_file = sys.argv[1]
Expand All @@ -40,10 +44,10 @@
port=0,
cs=st7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
dc=9,
backlight=19, # 18 for back BG slot, 19 for front BG slot.
backlight=19, # 18 for back BG slot, 19 for front BG slot.
spi_speed_hz=80 * 1000 * 1000,
offset_left=0 if display_type == "square" else 40,
offset_top=53 if display_type == "rect" else 0
offset_top=53 if display_type == "rect" else 0,
)

elif display_type == "dhmini":
Expand All @@ -57,11 +61,11 @@
backlight=13,
spi_speed_hz=60 * 1000 * 1000,
offset_left=0,
offset_top=0
)
offset_top=0,
)

else:
print ("Invalid display type!")
print("Invalid display type!")

WIDTH = disp.width
HEIGHT = disp.height
Expand All @@ -70,13 +74,13 @@
disp.begin()

# Load an image.
print(f'Loading image: {image_file}...')
print(f"Loading image: {image_file}...")
image = Image.open(image_file)

# Resize the image
image = image.resize((WIDTH, HEIGHT))

# Draw the image on the display hardware.
print('Drawing image')
print("Drawing image")

disp.display(image)
25 changes: 17 additions & 8 deletions examples/round.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import st7789

print(f"""
print(
f"""
round.py - Shiny shiny round LCD!
If you're using Breakout Garden, plug a 1.3" ROUND LCD
Expand All @@ -21,7 +22,8 @@
* dots - swirly swooshy dots
* lines - 3D depth effect lines
""")
"""
)

try:
style = sys.argv[1]
Expand All @@ -33,18 +35,18 @@
port=0,
cs=st7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
dc=9,
backlight=19, # 18 for back BG slot, 19 for front BG slot.
backlight=19, # 18 for back BG slot, 19 for front BG slot.
rotation=90,
spi_speed_hz=80 * 1000 * 1000,
offset_left=40
offset_left=40,
)

# Initialize display.
disp.begin()

RADIUS = disp.width // 2

img = Image.new('RGB', (disp.width, disp.height), color=(0, 0, 0))
img = Image.new("RGB", (disp.width, disp.height), color=(0, 0, 0))
draw = ImageDraw.Draw(img)


Expand All @@ -69,17 +71,24 @@
distance = RADIUS / steps * step
distance += step * 0.2

r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb((t / 10.0) + distance / 120.0, 1.0, 1.0)]
r, g, b = [
int(c * 255)
for c in colorsys.hsv_to_rgb((t / 10.0) + distance / 120.0, 1.0, 1.0)
]

x = RADIUS + int(distance * math.cos(angle))
y = RADIUS + int(distance * math.sin(angle))

line = ((math.sin(t + angle) + 1) / 2.0) * 10
if style == "lines":
draw.line((prev_x + line, prev_y + line, x - line, y - line), fill=(r, g, b))
draw.line(
(prev_x + line, prev_y + line, x - line, y - line), fill=(r, g, b)
)
else:
line += 1
draw.ellipse((x - line, y - line, x + (line * 2), y + (line * 2)), fill=(r, g, b))
draw.ellipse(
(x - line, y - line, x + (line * 2), y + (line * 2)), fill=(r, g, b)
)

prev_x = x
prev_y = y
Expand Down
20 changes: 11 additions & 9 deletions examples/scrolling-text.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

MESSAGE = "Hello World! How are you today?"

print(f"""
print(
f"""
scrolling-test.py - Display scrolling text.
If you're using Breakout Garden, plug the 1.3" LCD (SPI)
Expand All @@ -22,7 +23,8 @@
* round - 240x240 1.3" Round LCD (applies an offset)
* rect - 240x135 1.14" Rectangular LCD (applies an offset)
* dhmini - 320x240 2.0" Display HAT Mini
""")
"""
)

try:
MESSAGE = sys.argv[1]
Expand All @@ -44,10 +46,10 @@
port=0,
cs=st7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
dc=9,
backlight=19, # 18 for back BG slot, 19 for front BG slot.
backlight=19, # 18 for back BG slot, 19 for front BG slot.
spi_speed_hz=80 * 1000 * 1000,
offset_left=0 if display_type == "square" else 40,
offset_top=53 if display_type == "rect" else 0
offset_top=53 if display_type == "rect" else 0,
)

elif display_type == "dhmini":
Expand All @@ -61,11 +63,11 @@
backlight=13,
spi_speed_hz=60 * 1000 * 1000,
offset_left=0,
offset_top=0
)
offset_top=0,
)

else:
print ("Invalid display type!")
print("Invalid display type!")

# Initialize display.
disp.begin()
Expand All @@ -74,7 +76,7 @@
HEIGHT = disp.height


img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0))
img = Image.new("RGB", (WIDTH, HEIGHT), color=(0, 0, 0))

draw = ImageDraw.Draw(img)

Expand All @@ -89,7 +91,7 @@

while True:
x = (time.time() - t_start) * 100
x %= (size_x + disp.width)
x %= size_x + disp.width
draw.rectangle((0, 0, disp.width, disp.height), (0, 0, 0))
draw.text((int(text_x - x), text_y), MESSAGE, font=font, fill=(255, 255, 255))
disp.display(img)
Loading

0 comments on commit 3348a0a

Please sign in to comment.