Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add other display support via luma.emulator #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/).

# v0.1.0
## (2021-08-04)

* Add support for non-oled displays via luma.emulator [Rahul Thakoor]
- Container size increased to ~200MB with this support
* Simplified dependency resolving for apt

# v0.0.14
## (2021-07-29)

Expand Down
31 changes: 23 additions & 8 deletions Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,45 @@ FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-python:3.7-buster-run AS builder

WORKDIR /usr/src/app

RUN mkdir -p /usr/src/debian-rootfs
# make folder readable by other users -> _apt can access some deb files otherwise
RUN chmod 777 /usr/src/app

RUN install_packages apt-rdepends
RUN mkdir -p /usr/src/debian-rootfs

RUN apt-get update && \
apt-get download \
$(apt-rdepends python3 libopenjp2-7 libfreetype6-dev libjpeg-dev libtiff5 libxcb1 | grep -v "^ " | sed 's/debconf-2.0/debconf/g' | sed 's/^libc-dev$/libc6-dev/g' | sed 's/^libz-dev$/zlib1g-dev/g')
RUN install_packages build-essential

# list of packages to be installed in rootfs we will use in next stage
ARG PACKAGES="tzdata python3 python3-pygame libopenjp2-7 libfreetype6-dev libjpeg-dev libtiff5 libxcb1"

# download all packages and dependencies
RUN apt update && apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances ${PACKAGES} | grep "^\w" | sort -u)

# install packages to separate rootfs
RUN for pkg in *.deb; \
do dpkg-deb -x $pkg /usr/src/debian-rootfs; \
done

COPY ./requirements.txt .
RUN pip install -t /usr/src/python-packages -r requirements.txt --no-cache-dir --extra-index-url=https://www.piwheels.org/simple

RUN pip install -t /usr/src/python-packages -r requirements.txt --extra-index-url=https://www.piwheels.org/simple

# download luma.emulator separately without pygame(installed from debian source) -> if same directory, pip throws err: Target directory exists
RUN pip install -t /usr/src/luma-emulator luma.emulator --no-deps --ignore-installed --no-cache-dir --extra-index-url=https://www.piwheels.org/simple

RUN cp -rf /usr/src/luma-emulator/luma/emulator /usr/src/python-packages/luma

FROM busybox:stable


FROM busybox:stable

COPY --from=builder /usr/src/debian-rootfs ./
COPY --from=builder /usr/src/python-packages/ /usr/src/python-packages/

COPY --from=builder /usr/src/python-packages/ /usr/src/python-packages

COPY src ./src

COPY VERSION ./

ENV PYTHONPATH=/usr/src/python-packages/

CMD ["python3", "src/main.py"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ These environment variables are specified using the [balenaCloud dashboard](http
|`transportApi_apiKey` | `798c7ddfdeadbeef87987e9a8e79` (transport API key)
|`transportApi_appId` | `12345678` (transport API application ID)
|`transportApi_operatingHours` | `8-22` (hours during which the data will refresh at the interval above)
|`DISPLAY_DEVICE` | `SSD1322`(default) or `MONITOR`

## Hardware

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.14
0.1.0
3 changes: 2 additions & 1 deletion balena.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ data:
- raspberrypi3
applicationEnvironmentVariables:
- TZ: Europe/London
- DISPLAY_DEVICE: SSD1322
- departureStation: PAD
- outOfHoursName: London Paddington
- refreshTime: 120
- transportApi_apiKey: UPDATE_ME
- transportApi_appId: UPDATE_ME
- transportApi_operatingHours: 8-22
version: 0.0.14
version: 0.1.0
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def loadConfig():
}

data["refreshTime"] = int(os.getenv("refreshTime") or 180)
data["display"] = os.getenv("DISPLAY_DEVICE") or "SSD1322"

data["journey"]["departureStation"] = os.getenv("departureStation") or "PAD"
data["journey"]["destinationStation"] = os.getenv("destinationStation") or None
Expand Down
25 changes: 19 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from luma.core.virtual import viewport, snapshot, hotspot
from luma.core.sprite_system import framerate_regulator

from luma.emulator.device import pygame as emulator

def makeFont(name, size):
font_path = os.path.abspath(
os.path.join(
Expand Down Expand Up @@ -258,16 +260,24 @@ def drawSignage(device, width, height, data):
print('Starting Train Departure Display v' + version_file.read())
config = loadConfig()

serial = spi()
device = ssd1322(serial, mode="1", rotate=2)
device = None
widgetWidth = 256
widgetHeight = 64

if config["display"] == "SSD1322":
serial = spi()
device = ssd1322(serial, mode="1", rotate=2)
elif config["display"] == "MONITOR":
device = emulator(width=widgetWidth, height=widgetHeight,frame_rate=20)
device._pygame.mouse.set_visible(False)

if device == None:
sys.exit(1)
font = makeFont("Dot Matrix Regular.ttf", 10)
fontBold = makeFont("Dot Matrix Bold.ttf", 10)
fontBoldTall = makeFont("Dot Matrix Bold Tall.ttf", 10)
fontBoldLarge = makeFont("Dot Matrix Bold.ttf", 20)

widgetWidth = 256
widgetHeight = 64


stationRenderCount = 0
pauseCount = 0
loop_count = 0
Expand Down Expand Up @@ -308,3 +318,6 @@ def drawSignage(device, width, height, data):
print(f"Error: {err}")
except KeyError as err:
print(f"Error: Please ensure the {err} environment variable is set")
except:
print('Unexpected Error')