User Tools

Site Tools


haussteuerung:display_panel

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
haussteuerung:display_panel [2025/12/27 06:54] – [Display On / Off] dominikhaussteuerung:display_panel [2025/12/27 08:11] (current) – [Service] dominik
Line 9: Line 9:
   * '' sudo raspi-config''   * '' sudo raspi-config''
     * 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 ====
-  * ''sudo apt -y update && sudo apt-get install -y build-essential cmake make gcc pkg-config python3-dev python3-virtualenv libsystemd-dev libopenblas-dev''+  * ''sudo apt -y update && sudo apt-get install -y build-essential cmake make gcc pkg-config python3-dev python3-virtualenv libsystemd-dev libopenblas-dev python3-setuptools''
   * ''cd ~ && mkdir -p DisplayHA && cd DisplayHA''   * ''cd ~ && mkdir -p DisplayHA && cd DisplayHA''
   * ''python -m venv . && source bin/activate''   * ''python -m venv . && source bin/activate''
-  * ''pip3 install %%--%%upgrade pip && pip3 install RPi.GPIO pynput smbus paho-mqtt psutil''+  * ''pip3 install %%--%%upgrade pip && pip3 install RPi.GPIO pynput smbus paho-mqtt psutil setuptools''
  
   * Compile VL53 Lib ...    * Compile VL53 Lib ... 
     * ''sudo apt-get install build-essential python-dev''     * ''sudo apt-get install build-essential python-dev''
-    * ''cd ~'' +    * ''cd ~ && git clone https://github.com/pimoroni/VL53L0X_rasp_python.git && cd VL53L0X_rasp_python'' 
-    * ''git clone https://github.com/pimoroni/VL53L0X_rasp_python.git'' +    * ''pip install .'' 
-    * ''cd VL53L0X-python'' +    * VL53L0X.py in den Scriptordner kopieren ... \\ ''cp ~/VL53L0X_rasp_python/python/VL53L0X.py ~/DisplayHA/''
-    * ''make'' +
-    * VL53L0X.py in den Scriptordner kopieren ... +
   * Tests starten ...    * Tests starten ... 
  
-==== Tests ==== 
-=== VL === 
  
  
Line 206: Line 203:
   * Sensor : VL53L0X   * Sensor : VL53L0X
  
-  Altes Script \\ <code Motiondetect.py>import sys +==== Service ==== 
-import time +  Aktivieren \\ ''sudo systemctl enable display.service'' \\ ''sudo systemctl daemon-reload'' \\ ''sudo systemctl start display.service'' 
-import VL53L0X +  * Log ansehen \\ ''journalctl -u display.service -f'' 
-import os +  * ''sudo nano /lib/systemd/system/display.service'' \\ <code display.service
-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] 
-    global Display_Last_Action +# --- User Context --- 
-    print('Pointer moved to {0}'.format((x, y))) +User=pi 
-    sys.stdout.flush() +Group=pi
-    Display_Last_Action time.time() +
-    print("Time %d" % (Display_Last_Action))+
  
-def on_click(x, y, button, pressed): +# --- Arbeitsverzeichnis --- 
-    global Display_Last_Action +# Setzt das Verzeichnisdamit relative Pfade funktionieren 
-    print('{0} at {1}'.format('Pressed' if pressed else 'Released'(x, y))) +WorkingDirectory=/home/pi/DisplayHA
-    sys.stdout.flush() +
-    Display_Last_Action time.time() +
-    print("Time %d" % (Display_Last_Action))+
  
-def on_scroll(x, y, dx, dy): +# --- Environment --- 
-    global Display_Last_Action +# Diese Variablen sind wichtig für DDC/CI oder xrandr Interaktionen 
-    print('Scrolled {0} at {1}'.format('down' if dy < 0 else 'up'(x, y))) +Environment=DISPLAY=:0 
-    sys.stdout.flush() +Environment=XAUTHORITY=/home/pi/.Xauthority 
-    Display_Last_Action time.time() +# Erzwingt unbuffered Outputdamit Logs sofort im Journal erscheinen 
-    print("Time %d" % (Display_Last_Action))+Environment=PYTHONUNBUFFERED=1
  
-def toggleOnOff()+# --- ExecStartDer Trick für das venv --- 
-    GPIO.output(36, GPIO.HIGH) +# Statt 'source bin/activate' rufen wir direkt das Python im venv auf
-    time.sleep(0.4) +# PASSE DEN PFAD ZUM VENV ANfalls dein Ordner anders heißt (z.B. .venv)! 
-    GPIO.output(36GPIO.LOW) +ExecStart=/home/pi/DisplayHA/bin/python /home/pi/DisplayHA/SmartDisplay.py
-    print("Toggle Switch ...."+
-    sys.stdout.flush() +
-   +
-listener mouse.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 time.time() +Restart=always 
-Display_State       True +RestartSec=10s
-Display_Timeout_Sec = 180+
  
-# RPi.GPIO Layout verwenden (wie Pin-Nummern) 
-GPIO.setmode(GPIO.BOARD) 
-# RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings. 
-GPIO.setwarnings(False) 
- 
-# Pin 36 (GPIO 16) auf Output setzen -> Display ON / OFF 
-GPIO.setup(36, GPIO.OUT) 
-# Pin 38 (GPIO 20) auf Output setzen -> Brightness + 
-GPIO.setup(38, GPIO.OUT) 
-# Pin 40 (GPIO 21) auf Output setzen -> Brightness - 
-GPIO.setup(40, GPIO.OUT) 
- 
-# Create a VL53L0X object 
-tof = VL53L0X.VL53L0X(i2c_bus=1,i2c_address=0x29) 
-tof.open() 
-tof.start_ranging(VL53L0X.Vl53l0xAccuracyMode.BETTER) 
- 
-while 1: 
-    # Distanz vom VL53L0X Sensor messen 
-    distance = tof.get_distance() 
-    #print("%d mm, %d cm" % (distance, (distance/10))) 
- 
-    # Display ggf. abschalten  
-    if time.time()-Display_Last_Action >= Display_Timeout_Sec: 
-        if Display_State == True: 
-            #subprocess.call("DISPLAY=:0 xset dpms force off", shell=True) 
-            toggleOnOff() 
-            Display_State = False 
-            print("Display wird abgeschaltet ...") 
-            sys.stdout.flush() 
- 
-    # Abstand vom Sensor pruefen 
-    if distance < 900: 
-        print("DETECTED, %d cm , %d sec" % (distance/10, time.time()-Display_Last_Action )) 
-        sys.stdout.flush() 
-        Display_Last_Action = time.time() 
-        print("Time %d" % (Display_Last_Action)) 
- 
-    # Display ggf. wieder einschalten  
-    if time.time()-Display_Last_Action < Display_Timeout_Sec: 
-        if Display_State == False: 
-            #subprocess.call("DISPLAY=:0 xset dpms force on", shell=True) 
-            toggleOnOff() 
-            Display_State = True 
-            print("Display wird eingeschaltet ...") 
-            sys.stdout.flush() 
- 
-        # Display Einschalten 
-        #os.system('DISPLAY=:0 xdotool key "shift"') 
-        ###subprocess.call("DISPLAY=:0 xset s reset", shell=True) 
-        #subprocess.call("DISPLAY=:0 xset dpms force on", shell=True) 
-        #subprocess.call("DISPLAY=:0 xset dpms 120 120 120", shell=True) 
- 
-    time.sleep(0.1) 
- 
-tof.stop_ranging() 
-tof.close() 
-</code> 
-  * Service \\ <code display.service> 
-pi@SHome-Display-VPN-DNS:/ $ cat lib/systemd/system/display.service 
-[Unit] 
-Description=Display Controller 
-  
-[Service] 
-Environment=DISPLAY=:0 
-Environment=XAUTHORITY=/home/pi/.Xauthority 
-ExecStart=/usr/bin/python /home/pi/DisplayOn/MotionDetect.py 
-Restart=always 
-RestartSec=30s 
-KillMode=process 
-TimeoutSec=infinity 
-  
 [Install] [Install]
 WantedBy=graphical.target WantedBy=graphical.target
- 
 </code> </code>
  
haussteuerung/display_panel.1766814844.txt.gz · Last modified: by dominik

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki