diff --git a/CHANGELOG.md b/CHANGELOG.md index aafc4e5..0955461 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Dockerfile.template b/Dockerfile.template index 565e193..00d65a3 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md index aae7c55..3b1a679 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/VERSION b/VERSION index 1111c9c..6c6aa7c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.14 \ No newline at end of file +0.1.0 \ No newline at end of file diff --git a/balena.yml b/balena.yml index d852143..4dc5605 100644 --- a/balena.yml +++ b/balena.yml @@ -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 \ No newline at end of file +version: 0.1.0 \ No newline at end of file diff --git a/src/config.py b/src/config.py index 6681cc8..bc8ef70 100644 --- a/src/config.py +++ b/src/config.py @@ -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 diff --git a/src/main.py b/src/main.py index a3a0b0e..0ae66b4 100644 --- a/src/main.py +++ b/src/main.py @@ -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( @@ -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 @@ -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') +