Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions examples/spectra6/buttons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env python3

import gpiod
import gpiodevice
from gpiod.line import Bias, Direction, Edge

print(
"""buttons.py - Detect which button has been pressed

This example should demonstrate how to:
1. set up gpiod to read buttons,
2. determine which button has been pressed

Press Ctrl+C to exit!

"""
)

# GPIO pins for each button (from top to bottom)
# These will vary depending on platform and the ones
# below should be correct for Raspberry Pi 5.
# Run "gpioinfo" to find out what yours might be.
#
# Raspberry Pi 5 Header pins used by Inky Impression:
# PIN29, PIN31, PIN36, PIN18.
# These header pins correspond to BCM GPIO numbers:
# GPIO05, GPIO06, GPIO16, GPIO24.
# These GPIO numbers are what is used below and not the
# header pin numbers.

SW_A = 5
SW_B = 6
SW_C = 16 # Set this value to '25' if you're using a Impression 13.3"
SW_D = 24

BUTTONS = [SW_A, SW_B, SW_C, SW_D]

# These correspond to buttons A, B, C and D respectively
LABELS = ["A", "B", "C", "D"]

# Create settings for all the input pins, we want them to be inputs
# with a pull-up and a falling edge detection.
INPUT = gpiod.LineSettings(direction=Direction.INPUT, bias=Bias.PULL_UP, edge_detection=Edge.FALLING)

# Find the gpiochip device we need, we'll use
# gpiodevice for this, since it knows the right device
# for its supported platforms.
chip = gpiodevice.find_chip_by_platform()

# Build our config for each pin/line we want to use
OFFSETS = [chip.line_offset_from_id(id) for id in BUTTONS]
line_config = dict.fromkeys(OFFSETS, INPUT)

# Request the lines, *whew*
request = chip.request_lines(consumer="spectra6-buttons", config=line_config)


# "handle_button" will be called every time a button is pressed
# It receives one argument: the associated gpiod event object.
def handle_button(event):
index = OFFSETS.index(event.line_offset)
gpio_number = BUTTONS[index]
label = LABELS[index]
print(f"Button press detected on GPIO #{gpio_number} label: {label}")


while True:
for event in request.read_edge_events():
handle_button(event)
35 changes: 35 additions & 0 deletions examples/spectra6/image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3

import argparse
import pathlib
import sys

from PIL import Image

from inky.auto import auto

parser = argparse.ArgumentParser()

parser.add_argument("--saturation", "-s", type=float, default=0.5, help="Colour palette saturation")
parser.add_argument("--file", "-f", type=pathlib.Path, help="Image file")

inky = auto(ask_user=True, verbose=True)

args, _ = parser.parse_known_args()

saturation = args.saturation

if not args.file:
print(f"""Usage:
{sys.argv[0]} --file image.png (--saturation 0.5)""")
sys.exit(1)

image = Image.open(args.file)
resizedimage = image.resize(inky.resolution)

try:
inky.set_image(resizedimage, saturation=saturation)
except TypeError:
inky.set_image(resizedimage)

inky.show()
32 changes: 32 additions & 0 deletions examples/spectra6/led.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3

import time

import gpiod
import gpiodevice
from gpiod.line import Bias, Direction, Value

print(
"""\nled.py - Blink the LED!

Press Ctrl+C to exit!

"""
)

LED_PIN = 13

# Find the gpiochip device we need, we'll use
# gpiodevice for this, since it knows the right device
# for its supported platforms.
chip = gpiodevice.find_chip_by_platform()

# Setup for the LED pin
led = chip.line_offset_from_id(LED_PIN)
gpio = chip.request_lines(consumer="inky", config={led: gpiod.LineSettings(direction=Direction.OUTPUT, bias=Bias.DISABLED)})

while True:
gpio.set_value(led, Value.ACTIVE)
time.sleep(1)
gpio.set_value(led, Value.INACTIVE)
time.sleep(1)
14 changes: 14 additions & 0 deletions examples/spectra6/stripes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python3

from inky.auto import auto

inky = auto(ask_user=True, verbose=True)

COLOURS = [0, 1, 2, 3, 5, 6]

for y in range(inky.height - 1):
c = y // (inky.height // 6)
for x in range(inky.width - 1):
inky.set_pixel(x, y, COLOURS[c])

inky.show()
2 changes: 2 additions & 0 deletions inky/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from .auto import auto # noqa: F401
from .inky import BLACK, RED, WHITE, YELLOW # noqa: F401
from .inky_ac073tc1a import Inky as Inky_Impressions_7 # noqa: F401
from .inky_e673 import Inky as InkyE673 # noqa: F401
from .inky_el133uf1 import Inky as InkyEL133UF1 # noqa: F401
from .inky_ssd1683 import Inky as InkyWHAT_SSD1683 # noqa: F401
from .inky_uc8159 import Inky as Inky7Colour # noqa: F401
from .mock import InkyMockPHAT, InkyMockWHAT # noqa: F401
Expand Down
12 changes: 11 additions & 1 deletion inky/auto.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

from . import eeprom
from .inky_ac073tc1a import Inky as InkyAC073TC1A # noqa: F401
from .inky_e673 import Inky as InkyE673 # noqa: F401
from .inky_el133uf1 import Inky as InkyEL133UF1 # noqa: F401
from .inky_ssd1683 import Inky as InkyWHAT_SSD1683 # noqa: F401
from .inky_uc8159 import Inky as InkyUC8159 # noqa: F401
from .phat import InkyPHAT, InkyPHAT_SSD1608 # noqa: F401
from .what import InkyWHAT # noqa: F401

DISPLAY_TYPES = ["what", "phat", "phatssd1608", "impressions", "7colour", "whatssd1683", "impressions73"]
DISPLAY_TYPES = ["what", "phat", "phatssd1608", "impressions", "7colour", "whatssd1683", "impressions73", "spectra13", "spectra73"]
DISPLAY_COLORS = ["red", "black", "yellow"]


Expand All @@ -34,6 +36,10 @@ def auto(i2c_bus=None, ask_user=False, verbose=False):
return InkyWHAT_SSD1683((400, 300), _eeprom.get_color())
if _eeprom.display_variant == 20:
return InkyAC073TC1A(resolution=(800, 480))
if _eeprom.display_variant == 21:
return InkyEL133UF1(resolution=(1600, 1200))
if _eeprom.display_variant == 22:
return InkyE673(resolution=(800, 480))

if ask_user:
if verbose:
Expand Down Expand Up @@ -78,6 +84,10 @@ def auto(i2c_bus=None, ask_user=False, verbose=False):
return InkyUC8159()
if args.type == "impressions73":
return InkyAC073TC1A()
if args.type == "spectra13":
return InkyEL133UF1()
if args.type == "spectra73":
return InkyE673()

if _eeprom is None:
raise RuntimeError("No EEPROM detected! You must manually initialise your Inky board.")
Expand Down
4 changes: 3 additions & 1 deletion inky/eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
"Red wHAT (SSD1683)",
"Yellow wHAT (SSD1683)",
"7-Colour 800x480 (AC073TC1A)",
"Spectra 6 13.3 1600 x 1200 (EL133UF1)",
"Spectra 6 7.3 800 x 480 (E673)"
]


class EPDType:
"""Class to represent EPD EEPROM structure."""

valid_colors = [None, "black", "red", "yellow", None, "7colour"]
valid_colors = [None, "black", "red", "yellow", None, "7colour", "spectra6"]

def __init__(self, width, height, color, pcb_variant, display_variant, write_time=None):
"""Initialise new EEPROM data structure."""
Expand Down
Loading