Commit 054370fe authored by Jakob Moser's avatar Jakob Moser
Browse files

Merge branch 'frontend/add-ui-mvp' into 'master'

Add minimum viable product with UI

See merge request moser/poolpay!24
parents a66936fa a4414838
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -132,6 +132,8 @@ Then, connect the cables to the Pi as described in this chart:
    ```ini
    dtoverlay=fbtft,spi0-0,ili9486,width=320,height=480,regwidth=16,reset_pin=25,dc_pin=24,rotate=270
    ```
3. Add `fbcon=map:2` at the end of the line to `/boot/firmware/cmdline.txt`
   * This will tell the framebuffer console (fbcon) to map all its terminals to `/dev/fb2` (which doesn't exist), i.e. don't show a Linux TTY on the display

<details>
<summary>Links</summary>
@@ -139,10 +141,17 @@ Then, connect the cables to the Pi as described in this chart:
- [Raspberry Pi Forum post mentioning the line to include in the config (German)](https://forum-raspberrypi.de/forum/thread/55290-displays-mit-spi-anschluss-unter-raspberry-pi-os-bullseye-bookworm/)
- [Device tree overlays README](https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README)
- [RB-TFT3.5 Manual (German)](https://joy-it.net/files/files/Produkte/RB-TFT3.5/RB-TFT-Anleitung_04082020.pdf)
- [Frame Buffer Kernel Docs](https://www.kernel.org/doc/html/latest/fb/fbcon.html)
</details>

### Software

Install dependencies:

```bash
sudo apt install cryptsetup
```

Clone the repository (you can use a Project Access Token for that, Settings → Access Tokens) and cd into it.

```bash
+18 −0
Original line number Diff line number Diff line
## PyGame doesn't want to talk to the Framebuffer

This does not work:

```python
#!/bin/env python3
import os

import pygame

os.environ["SDL_FBDEV"] = "/dev/fb0"
os.environ["SDL_VIDEODRIVER"] = "directfb"

screen = pygame.display.set_mode()
print(screen)  # This does not show the dimensions of my small extra screen. Feels like it writes to HDMI.
```

Which is sad, because I think it should work.
+8 −6
Original line number Diff line number Diff line
@@ -6,8 +6,11 @@ from sqlalchemy.orm import Session
from poolpay import db
from poolpay.card.Pirc522CardReader import Pirc522CardReader
from poolpay.director.Director import Director
from poolpay.display.PygameDisplay import PygameDisplay
from poolpay.model.Retrievable import Retrievable
from poolpay.ui.Play import Play
from poolpay.ui.pygame.scenes.Idle import Idle
from poolpay.ui.pygame.scenes.PaymentSuccess import PaymentSuccess
from poolpay.vault.Vault import Vault

proj_dir = Path(__file__).parent.parent.resolve()
@@ -20,14 +23,15 @@ password = "hunter2" # TODO Prompt for this instead of hardcoding it into the f

vault = Vault(vault_file, instance_dir)
play = Play(
    Idle=Idle,
    PaymentSuccess=PaymentSuccess,
    # TODO Insert types here
    Idle=...,
    PaymentSuccess=...,
    Balance=...,
    Reversal=...,
    WaitForCard=...,
)
director = Director(play)
display = PygameDisplay(Path("/dev/fb0"), width=480, height=320)
director = Director(play, display)

with vault.open(password), Pirc522CardReader() as card_reader:
    try:
@@ -38,9 +42,7 @@ with vault.open(password), Pirc522CardReader() as card_reader:
        card_reader.on_card_presented(
            lambda reader: director.card_presented(reader.read_id())
        )
        card_reader.on_card_removed(
            lambda reader: director.card_removed()
        )
        card_reader.on_card_removed(lambda reader: director.card_removed())
        director.start()
    finally:
        db.session.close()
+4 −0
Original line number Diff line number Diff line
@@ -52,5 +52,9 @@ class Pirc522CardReader(CardReader):
    def on_card_removed(self, handle_removal: Callable[[CardReader], None]) -> None:
        self._handle_removal = handle_removal

    def on_card_removed(self, handle_removal: Callable[[CardReader], None]) -> None:
        # TODO Implement
        pass

    def close(self) -> None:
        self._reader.cleanup()
+7 −2
Original line number Diff line number Diff line
import time
from dataclasses import dataclass, field

from poolpay import db
from poolpay.display.Display import Display
from poolpay.model.Card import Card
from poolpay.price.constants import DRINK
from poolpay.ui.Play import Play
@@ -20,6 +22,7 @@ class Director:
    """

    play: Play
    display: Display
    _next_scene_on_card_presented: type[Scene] = field(init=False)

    def start(self) -> None:
@@ -65,7 +68,8 @@ class Director:
        card.owner.pay(DRINK)
        new_balance_cents = card.owner.balance_cents

        # TODO Commit to the database
        db.session.add(card.owner)
        db.session.commit()

        self.play.PaymentSuccess(
            self,
@@ -80,7 +84,8 @@ class Director:
        card.owner.pay(-DRINK)
        new_balance_cents = card.owner.balance_cents

        # TODO Commit to the database
        db.session.add(card.owner)
        db.session.commit()

        self.play.Reversal(
            self,
Loading