Skip to content

Commit

Permalink
feat: configurable rotation and flip parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
sassanh committed May 8, 2024
1 parent 5f20684 commit a5abbeb
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 24 deletions.
82 changes: 62 additions & 20 deletions .github/workflows/integration_delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
- uses: actions/checkout@v4
name: Checkout

- name: Save Cached Poetry
- name: Load Cached Poetry
id: cached-poetry
uses: actions/cache@v4
with:
path: |
~/.cache
~/.local
key: poetry-${{ hashFiles('poetry.lock') }}
key: poetry-${{ hashFiles('poetry.lock') }}-${{ env.PYTHON_VERSION}}

- uses: actions/setup-python@v5
name: Setup Python
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
path: |
~/.cache
~/.local
key: poetry-${{ hashFiles('poetry.lock') }}
key: poetry-${{ hashFiles('poetry.lock') }}-${{ env.PYTHON_VERSION}}

- name: Create stub files
run: poetry run pyright --createstub kivy
Expand All @@ -78,8 +78,8 @@ jobs:
- uses: actions/checkout@v4
name: Checkout

- uses: actions/setup-python@v5
name: Setup Python
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
Expand All @@ -91,7 +91,7 @@ jobs:
path: |
~/.cache
~/.local
key: poetry-${{ hashFiles('poetry.lock') }}
key: poetry-${{ hashFiles('poetry.lock') }}-${{ env.PYTHON_VERSION}}

- name: Lint
run: poetry run poe lint
Expand All @@ -102,8 +102,8 @@ jobs:
- dependencies
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract_version.outputs.version }}
name: ${{ steps.extract_version.outputs.name }}
version: ${{ steps.extract-version.outputs.VERSION }}
name: ${{ steps.extract-version.outputs.NAME }}
steps:
- uses: actions/checkout@v4
name: Checkout
Expand All @@ -121,16 +121,41 @@ jobs:
path: |
~/.cache
~/.local
key: poetry-${{ hashFiles('poetry.lock') }}

- name: Build
run: poetry build
key: poetry-${{ hashFiles('poetry.lock') }}-${{ env.PYTHON_VERSION}}

- name: Extract Version
id: extract_version
id: extract-version
run: |
echo "version=$(poetry version --short)" >> "$GITHUB_OUTPUT"
echo "name=$(poetry version | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
echo "VERSION=$(poetry version --short)" >> "$GITHUB_OUTPUT"
echo "VERSION=$(poetry version --short)"
echo "NAME=$(poetry version | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
echo "NAME=$(poetry version | cut -d' ' -f1)"
- name: Extract Version from CHANGELOG.md
run: |
VERSION_CHANGELOG=$(sed -n '3 s/## Version //p' CHANGELOG.md)
echo "VERSION_CHANGELOG=$VERSION_CHANGELOG"
if [ "${{ steps.extract-version.outputs.VERSION }}" != "$VERSION_CHANGELOG" ]; then
echo "Error: Version extracted from CHANGELOG.md does not match the version in pyproject.toml"
exit 1
else
echo "Versions are consistent."
fi
- name: Extract Version from Tag
if: startsWith(github.ref, 'refs/tags/v')
run: |
VERSION_TAG=$(sed 's/^v//' <<< ${{ github.ref_name }})
echo "VERSION_TAG=$VERSION_TAG"
if [ "${{ steps.extract-version.outputs.VERSION }}" != "$VERSION_TAG" ]; then
echo "Error: Version extracted from tag does not match the version in pyproject.toml"
exit 1
else
echo "Versions are consistent."
fi
- name: Build
run: poetry build

- name: Upload wheel
uses: actions/upload-artifact@v4
Expand All @@ -156,7 +181,7 @@ jobs:
- build
runs-on: ubuntu-latest
environment:
name: release
name: pypi
url: https://pypi.org/p/${{ needs.build.outputs.name }}
permissions:
id-token: write
Expand All @@ -178,19 +203,21 @@ jobs:
verbose: true

release:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
name: Release
needs:
- type-check
- lint
- build
- pypi-publish
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/${{ needs.build.outputs.name }}
runs-on: ubuntu-latest
url:
https://github.com/${{ github.repository }}/releases/tag/v${{
needs.build.outputs.version }}
permissions:
contents: write
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- name: Procure Wheel
uses: actions/download-artifact@v4
Expand All @@ -204,13 +231,28 @@ jobs:
name: binary
path: artifacts

- uses: actions/checkout@v4
name: Checkout

- name: Extract Changelog
id: changelog
run: |
perl -0777 -ne 'while (/## Version ${{ needs.build.outputs.version }}\n(\s*\n)*(.*?)(\s*\n)*## Version \d+\.\d+\.\d+\n/sg) {print "$2\n"}' CHANGELOG.md > CURRENT_CHANGELOG.md
{
echo "CONTENT<<EOF"
cat CURRENT_CHANGELOG.md
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Release
uses: softprops/action-gh-release@v2
with:
files: artifacts/*
tag_name: v${{ needs.build.outputs.version }}
body: |
Release of version ${{ needs.build.outputs.version }}
PyPI package: https://pypi.org/project/${{ needs.build.outputs.name }}/${{ needs.build.outputs.version }}
# Changes:
${{ steps.changelog.outputs.CONTENT }}
prerelease: false
draft: false
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.7.3

- feat: configurable rotation and flip parameters

## Version 0.7.2

- fix: revert numpy data structure storing display data to uint16 as 2 bytes are
Expand Down
27 changes: 26 additions & 1 deletion headless_kivy_pi/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyright: reportMissingImports=false
"""Implement `setup_headless_kivy`, it configures headless-kivy-pi."""

from __future__ import annotations

import atexit
Expand Down Expand Up @@ -76,7 +77,7 @@ class SetupHeadlessConfig(TypedDict):
a while, it will drop the fps to the minimum."""
automatic_fps: NotRequired[bool]
"""If set to `True`, it will clear the screen before exiting."""
clear_at_eixt: NotRequired[bool]
clear_at_exit: NotRequired[bool]


_config: SetupHeadlessConfig | None = None
Expand Down Expand Up @@ -265,6 +266,30 @@ def automatic_fps() -> bool:
report_uninitialized()


@cache
def rotation() -> int:
"""Return the rotation of the display."""
if _config:
return _config.get('rotation', 0)
report_uninitialized()


@cache
def flip_horizontal() -> bool:
"""Return `True` if the display is flipped horizontally."""
if _config:
return _config.get('flip_horizontal', False)
report_uninitialized()


@cache
def flip_vertical() -> bool:
"""Return `True` if the display is flipped vertically."""
if _config:
return _config.get('flip_vertical', False)
report_uninitialized()


_is_paused: bool = False


Expand Down
8 changes: 6 additions & 2 deletions headless_kivy_pi/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ def transfer_to_display(
"""Transfer data to the display via SPI controller."""
logger.debug(f'Rendering frame with hash "{data_hash}"')

# Flip the image vertically
data = data.reshape(rectangle[2], rectangle[3], -1)[::-1, :, :3].astype(np.uint16)
data = data.reshape(rectangle[2], rectangle[3], -1)[:, :, :3].astype(np.uint16)
data = np.rot90(data, config.rotation())
if config.flip_horizontal():
data = np.fliplr(data)
if config.flip_vertical():
data = np.flipud(data)

color = (
((data[:, :, 0] & 0xF8) << 8)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "headless-kivy-pi"
version = "0.7.2"
version = "0.7.3"
description = "Headless renderer for Kivy framework on Raspberry Pi"
authors = ["Sassan Haradji <[email protected]>"]
license = "Apache-2.0"
Expand Down

0 comments on commit a5abbeb

Please sign in to comment.