Skip to content

Commit

Permalink
Merge pull request #10 from pimoroni/feature/round-lcd
Browse files Browse the repository at this point in the history
Update library and examples for RLCD
  • Loading branch information
Gadgetoid authored Mar 29, 2021
2 parents f9e3e4a + ae2b85f commit 130d76f
Show file tree
Hide file tree
Showing 14 changed files with 272 additions and 124 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [2.7, 3.4, 3.5, 3.7, 3.8]
python: [2.7, 3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
Expand All @@ -32,6 +32,6 @@ jobs:
working-directory: library
run: |
python -m pip install coveralls
coveralls
coveralls --service=github
if: ${{ matrix.python == '3.8' }}

8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ usage:
@echo "Usage: make <target>, where target is one of:\n"
@echo "install: install the library locally from source"
@echo "uninstall: uninstall the local library"
@echo "python-readme: generate library/README.rst from README.md"
@echo "python-readme: generate library/README.md from README.md"
@echo "python-wheels: build python .whl files for distribution"
@echo "python-sdist: build python source distribution"
@echo "python-clean: clean python build and dist directories"
Expand All @@ -15,12 +15,14 @@ install:
uninstall:
./uninstall.sh

python-readme: library/README.rst
python-readme: library/README.md

python-license: library/LICENSE.txt

library/README.rst: README.md
library/README.md: README.md library/CHANGELOG.txt
cp README.md library/README.md
printf "\n# Changelog\n" >> library/README.md
cat library/CHANGELOG.txt >> library/README.md

library/LICENSE.txt: LICENSE
cp LICENSE library/LICENSE.txt
Expand Down
23 changes: 23 additions & 0 deletions examples/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Examples originally modified from Adafruit_Python_ILI9341
https://github.com/adafruit/Adafruit_Python_ILI9341

Copyright (c 2014 Adafruit Industries
Author: Tony DiCola

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
48 changes: 22 additions & 26 deletions examples/framerate.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#!/usr/bin/env python3
import time
import math
import sys
Expand All @@ -26,19 +7,33 @@
from PIL import ImageDraw
import ST7789 as ST7789

SPI_SPEED_MHZ = 80 # Higher speed = higher framerate

if len(sys.argv) > 1:
# Higher SPI bus speed = higher framerate
try:
SPI_SPEED_MHZ = int(sys.argv[1])
except ValueError:
sys.exit(1)
except IndexError:
SPI_SPEED_MHZ = 80

try:
display_type = sys.argv[2]
except IndexError:
display_type = "square"

print("""
framerate.py - Test LCD framerate.
If you're using Breakout Garden, plug the 1.3" LCD (SPI)
breakout into the front slot.
Running at: {}MHz
""".format(SPI_SPEED_MHZ))
Usage: {} <spi_speed_mhz> <display_type>
Where <display_type> is one of:
* square - 240x240 1.3" Square LCD
* round - 240x240 1.3" Round LCD (applies an offset)
Running at: {}MHz on a {} display.
""".format(sys.argv[0], SPI_SPEED_MHZ, display_type))

# Create ST7789 LCD display class.
disp = ST7789.ST7789(
Expand All @@ -47,7 +42,8 @@
dc=9,
backlight=19, # 18 for back BG slot, 19 for front BG slot.
rotation=90,
spi_speed_hz=SPI_SPEED_MHZ * 1000000
spi_speed_hz=SPI_SPEED_MHZ * 1000000,
offset_left=40 if display_type == "round" else 0
)

WIDTH = disp.width
Expand Down
48 changes: 22 additions & 26 deletions examples/gif.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
# Copyright (c) 2014 Adafruit Industries
# Author: Phil Howard, Tony DiCola
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#!/usr/bin/env python3
from PIL import Image
import ST7789
import time
Expand All @@ -28,21 +9,36 @@
If you're using Breakout Garden, plug the 1.3" LCD (SPI)
breakout into the front slot.
""")

if len(sys.argv) > 1:
image_file = sys.argv[1]
else:
print("Usage: {} <filename.gif>".format(sys.argv[0]))
sys.exit(0)
if len(sys.argv) < 2:
print("""Usage: {path} <gif_file> <display_type>
Where <gif_file> is a .gif file.
Hint: {path} deployrainbows.gif
And <display_type> is one of:
* square - 240x240 1.3" Square LCD
* round - 240x240 1.3" Round LCD (applies an offset)
""".format(path=sys.argv[0]))
sys.exit(1)

image_file = sys.argv[1]

try:
display_type = sys.argv[2]
except IndexError:
display_type = "square"

# Create TFT LCD display class.
disp = ST7789.ST7789(
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.
spi_speed_hz=80 * 1000 * 1000
spi_speed_hz=80 * 1000 * 1000,
offset_left=40 if display_type == "round" else 0
)

# Initialize display.
Expand Down
37 changes: 15 additions & 22 deletions examples/image.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#!/usr/bin/env python3
import sys

from PIL import Image
Expand All @@ -28,21 +9,33 @@
If you're using Breakout Garden, plug the 1.3" LCD (SPI)
breakout into the front slot.
""")

if len(sys.argv) < 2:
print("Usage: {} <image_file>".format(sys.argv[0]))
print("""Usage: {} <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)
""".format(sys.argv[0]))
sys.exit(1)

image_file = sys.argv[1]

try:
display_type = sys.argv[2]
except IndexError:
display_type = "square"

# Create ST7789 LCD display class.
disp = ST7789.ST7789(
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.
spi_speed_hz=80 * 1000 * 1000
spi_speed_hz=80 * 1000 * 1000,
offset_left=40 if display_type == "round" else 0
)

WIDTH = disp.width
Expand Down
89 changes: 89 additions & 0 deletions examples/round.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env python3
import sys
import math
import time
import colorsys

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

import ST7789

print("""
round.py - Shiny shiny round LCD!
If you're using Breakout Garden, plug a 1.3" ROUND LCD
(SPI) breakout into the front slot.
Usage: {} <style>
Where style is one of:
* dots - swirly swooshy dots
* lines - 3D depth effect lines
""".format(sys.argv[0]))

try:
style = sys.argv[1]
except IndexError:
style = "dots"

# Create ST7789 LCD display class.
disp = ST7789.ST7789(
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.
rotation=90,
spi_speed_hz=80 * 1000 * 1000,
offset_left=40
)

# Initialize display.
disp.begin()

RADIUS = disp.width // 2

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


while True:
t = time.time()
draw.rectangle((0, 0, disp.width, disp.height), (0, 0, 0))
angle = t % (math.pi * 2)

prev_x = RADIUS
prev_y = RADIUS

steps = 100.0
angle_step = 1.0

if style == "lines":
steps *= 5
angle_step = 0.1

for step in range(int(steps)):
angle += angle_step

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)]

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

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

prev_x = x
prev_y = y

disp.display(img)
Loading

0 comments on commit 130d76f

Please sign in to comment.