Verified Commit 649537fa authored by Jakob Moser's avatar Jakob Moser
Browse files

Try implementing balance view

parent dcd49848
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
import logging
from pathlib import Path
import signal
from pathlib import Path
from threading import Thread
from types import FrameType

@@ -8,17 +8,21 @@ from poolpay import db, paths
from poolpay.card.Pirc522CardReader import Pirc522CardReader
from poolpay.director.Director import Director
from poolpay.display.PygameDisplay import PygameDisplay
from poolpay.touch.EvdevTouchScreen import EvdevTouchScreen
from poolpay.ui.pygame.play import play
from poolpay.vault.Vault import Vault
from poolpay.wire.Message import Message
from poolpay.wire.Server import Server

logging.basicConfig(level=logging.INFO, format="[%(levelname)s] <%(module)s> %(message)s")
logging.basicConfig(
    level=logging.INFO, format="[%(levelname)s] <%(module)s> %(message)s"
)

logging.info("Starting PoolPay")
logging.info("Creating Vault, Display and Director")
vault = Vault(paths.vault_file, paths.instance_dir)
display = PygameDisplay(Path("/dev/fb1"), width=480, height=320)
touch_screen = EvdevTouchScreen(Path("/dev/input/event0"))
director = Director(play, display)


@@ -30,7 +34,7 @@ def launch_application(password: str) -> None:
        return

    logging.info("Opening vault, creating CardReader")
    with vault.open(password), Pirc522CardReader() as card_reader:
    with vault.open(password), Pirc522CardReader() as card_reader, touch_screen:
        try:
            logging.info("Opening database")
            db.open(paths.db_file)
@@ -38,6 +42,8 @@ def launch_application(password: str) -> None:
            director.start()
            logging.info("Registering card removal handler")
            card_reader.on_card_removed(lambda reader: director.card_removed())
            logging.info("Registering touch screen input handler")
            touch_screen.on_screen_touched(lambda _: director.screen_touched())
            logging.info("Registering card placement handler and starting to wait")
            card_reader.on_card_placed(
                lambda reader: director.card_placed(reader.read_id())
+29 −0
Original line number Diff line number Diff line
from collections.abc import Callable
from pathlib import Path
from threading import Thread
from typing import Self

from evdev import InputDevice, ecodes

from poolpay.touch.TouchScreen import TouchScreen


class EvdevTouchScreen(TouchScreen):
    def __init__(self, device_path: Path) -> None:
        self._device = InputDevice(device_path)

    def on_screen_touched(self, handle_touch: Callable[[], None]) -> None:
        def listen() -> None:
            for raw_event in self._device.read_loop():
                match raw_event.type:
                    case ecodes.EV_SYN:
                        handle_touch()

        Thread(target=listen, daemon=True).start()

    def __enter__(self) -> Self:
        self._device.grab()
        return self

    def close(self) -> None:
        self._device.ungrab()
+28 −0
Original line number Diff line number Diff line
from __future__ import annotations

from abc import ABC, abstractmethod
from collections.abc import Callable
from contextlib import AbstractContextManager
from typing import Any


class TouchScreen(AbstractContextManager, ABC):
    @abstractmethod
    def on_screen_touched(self, handle_touch: Callable[[], None]) -> None:
        """
        Register the function handle_touch so that it is called whenever the screen is touched.

        If this is called multiple times, the TouchScreen may decide whether it only remembers and calls the
        last registered function, or all of them.
        """
        ...

    @abstractmethod
    def close(self) -> None:
        """
        Close the touch screen, doing anything that is necessary to clean up after use (e.g., ungrabbing inputs).
        """
        ...

    def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
        self.close()
+0 −0

Empty file added.

+15 −2
Original line number Diff line number Diff line
@@ -20,10 +20,23 @@ class Idle(IdleBase):
        display.surface.fill((0, 0, 0))
        display.surface.blit(
            fira_sans_large.render(f"Getränk: {price}", True, white),
            (140, 110),
            (140, 40),
        )
        display.surface.blit(
            fira_sans.render("Poolkarte auflegen, um zu bezahlen", True, white),
            (80, 155),
            (80, 85),
        )

        display.surface.blit(
            fira_sans.render("————— oder —————", True, white),
            (130, 160),
        )

        display.surface.blit(
            fira_sans.render(
                "Bildschirm antippen, um Kontostand zu sehen", True, white
            ),
            (30, 240),
        )

        display.refresh()
Loading