haussteuerung:display_panel
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| haussteuerung:display_panel [2025/12/27 06:56] – [Venv einrichten] dominik | haussteuerung:display_panel [2025/12/27 08:11] (current) – [Service] dominik | ||
|---|---|---|---|
| Line 9: | Line 9: | ||
| * '' | * '' | ||
| * I2C Aktivieren | * I2C Aktivieren | ||
| + | * 1Wire aktivieren | ||
| * umstellen von Wayland auf X11 | * umstellen von Wayland auf X11 | ||
| * Screen Blanking aus ! | * Screen Blanking aus ! | ||
| Line 183: | Line 184: | ||
| ==== Venv einrichten ==== | ==== Venv einrichten ==== | ||
| - | * '' | + | * '' |
| * '' | * '' | ||
| * '' | * '' | ||
| - | * '' | + | * '' |
| * Compile VL53 Lib ... | * Compile VL53 Lib ... | ||
| * '' | * '' | ||
| - | * '' | + | * '' |
| - | * VL53L0X.py in den Scriptordner kopieren ... | + | * '' |
| + | * VL53L0X.py in den Scriptordner kopieren ... \\ '' | ||
| * Tests starten ... | * Tests starten ... | ||
| - | ==== Tests ==== | ||
| - | === VL === | ||
| Line 203: | Line 203: | ||
| * Sensor : VL53L0X | * Sensor : VL53L0X | ||
| - | | + | ==== Service ==== |
| - | import time | + | |
| - | import VL53L0X | + | * Log ansehen \\ '' |
| - | import os | + | * '' |
| - | import subprocess | + | [Unit] |
| - | import RPi.GPIO as GPIO | + | Description=Smart Display Controller (venv/User Mode) |
| - | from pynput import mouse | + | # Wir warten, bis das Netzwerk und die Grafikoberfläche da sind |
| + | After=network-online.target graphical.target | ||
| + | Wants=network-online.target | ||
| - | def on_move(x, y): | + | [Service] |
| - | | + | # --- User Context --- |
| - | | + | User=pi |
| - | | + | Group=pi |
| - | Display_Last_Action | + | |
| - | print(" | + | |
| - | def on_click(x, y, button, pressed): | + | # --- Arbeitsverzeichnis --- |
| - | | + | # Setzt das Verzeichnis, damit relative Pfade funktionieren |
| - | print(' | + | WorkingDirectory=/ |
| - | | + | |
| - | Display_Last_Action | + | |
| - | print(" | + | |
| - | def on_scroll(x, | + | # --- Environment --- |
| - | | + | # Diese Variablen sind wichtig für DDC/CI oder xrandr Interaktionen |
| - | | + | Environment=DISPLAY=: |
| - | sys.stdout.flush() | + | Environment=XAUTHORITY=/ |
| - | | + | # Erzwingt unbuffered Output, damit Logs sofort im Journal erscheinen |
| - | print(" | + | Environment=PYTHONUNBUFFERED=1 |
| - | def toggleOnOff(): | + | # --- ExecStart: Der Trick für das venv --- |
| - | GPIO.output(36, GPIO.HIGH) | + | # Statt ' |
| - | | + | # PASSE DEN PFAD ZUM VENV AN, falls dein Ordner anders heißt |
| - | GPIO.output(36, GPIO.LOW) | + | ExecStart=/ |
| - | print(" | + | |
| - | | + | |
| - | + | ||
| - | listener | + | |
| - | on_move=on_move, | + | |
| - | on_click=on_click, | + | |
| - | on_scroll=on_scroll) | + | |
| - | listener.start() | + | |
| - | # Last Time Event happend on Display | + | # --- Restart Verhalten --- |
| - | Display_Last_Action | + | Restart=always |
| - | Display_State | + | RestartSec=10s |
| - | Display_Timeout_Sec = 180 | + | |
| - | # RPi.GPIO Layout verwenden (wie Pin-Nummern) | ||
| - | GPIO.setmode(GPIO.BOARD) | ||
| - | # RuntimeWarning: | ||
| - | GPIO.setwarnings(False) | ||
| - | |||
| - | # Pin 36 (GPIO 16) auf Output setzen -> Display ON / OFF | ||
| - | GPIO.setup(36, | ||
| - | # Pin 38 (GPIO 20) auf Output setzen -> Brightness + | ||
| - | GPIO.setup(38, | ||
| - | # Pin 40 (GPIO 21) auf Output setzen -> Brightness - | ||
| - | GPIO.setup(40, | ||
| - | |||
| - | # Create a VL53L0X object | ||
| - | tof = VL53L0X.VL53L0X(i2c_bus=1, | ||
| - | tof.open() | ||
| - | tof.start_ranging(VL53L0X.Vl53l0xAccuracyMode.BETTER) | ||
| - | |||
| - | while 1: | ||
| - | # Distanz vom VL53L0X Sensor messen | ||
| - | distance = tof.get_distance() | ||
| - | # | ||
| - | |||
| - | # Display ggf. abschalten | ||
| - | if time.time()-Display_Last_Action >= Display_Timeout_Sec: | ||
| - | if Display_State == True: | ||
| - | # | ||
| - | toggleOnOff() | ||
| - | Display_State = False | ||
| - | print(" | ||
| - | sys.stdout.flush() | ||
| - | |||
| - | # Abstand vom Sensor pruefen | ||
| - | if distance < 900: | ||
| - | print(" | ||
| - | sys.stdout.flush() | ||
| - | Display_Last_Action = time.time() | ||
| - | print(" | ||
| - | |||
| - | # Display ggf. wieder einschalten | ||
| - | if time.time()-Display_Last_Action < Display_Timeout_Sec: | ||
| - | if Display_State == False: | ||
| - | # | ||
| - | toggleOnOff() | ||
| - | Display_State = True | ||
| - | print(" | ||
| - | sys.stdout.flush() | ||
| - | |||
| - | # Display Einschalten | ||
| - | # | ||
| - | ### | ||
| - | # | ||
| - | # | ||
| - | |||
| - | time.sleep(0.1) | ||
| - | |||
| - | tof.stop_ranging() | ||
| - | tof.close() | ||
| - | </ | ||
| - | * Service \\ <code display.service> | ||
| - | pi@SHome-Display-VPN-DNS:/ | ||
| - | [Unit] | ||
| - | Description=Display Controller | ||
| - | |||
| - | [Service] | ||
| - | Environment=DISPLAY=: | ||
| - | Environment=XAUTHORITY=/ | ||
| - | ExecStart=/ | ||
| - | Restart=always | ||
| - | RestartSec=30s | ||
| - | KillMode=process | ||
| - | TimeoutSec=infinity | ||
| - | |||
| [Install] | [Install] | ||
| WantedBy=graphical.target | WantedBy=graphical.target | ||
| - | |||
| </ | </ | ||
haussteuerung/display_panel.1766815007.txt.gz · Last modified: by dominik
