-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch_display.py
More file actions
54 lines (44 loc) · 2.04 KB
/
switch_display.py
File metadata and controls
54 lines (44 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import logging
import time
from threading import Thread
from typing import Final
import RPi.GPIO as GPIO
from config_file import ConfigFile
from util import swap_config
class SwitchDisplay(Thread):
def __init__(self,
config_current: ConfigFile,
config_lcd: ConfigFile,
config_hdmi: ConfigFile,
reboot: bool = False,
hdmi_hdp_pin: int = 18,
sleep_seconds: int = 1
):
super().__init__()
self._hdmi_hdp_pin: Final = hdmi_hdp_pin
self._config_current: Final = config_current
self._config_lcd: Final = config_lcd
self._config_hdmi: Final = config_hdmi
self._reboot: Final = reboot
self._sleep_seconds: Final = sleep_seconds
self._log = logging.getLogger(__name__)
GPIO.setmode(GPIO.BCM)
GPIO.setup(self._hdmi_hdp_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def run(self):
time.sleep(self._sleep_seconds)
if GPIO.input(self._hdmi_hdp_pin) == GPIO.HIGH:
self._log.info(f'Currently connected to HDMI, pin "{self._hdmi_hdp_pin}" is HIGH.')
if self._config_current != self._config_hdmi:
swap_config(self._config_hdmi, self._config_current, reboot=self._reboot)
return
self._log.info(f'Waiting for HDMI disconnect now.')
GPIO.wait_for_edge(self._hdmi_hdp_pin, GPIO.FALLING)
swap_config(self._config_lcd, self._config_current, reboot=self._reboot)
elif GPIO.input(self._hdmi_hdp_pin) == GPIO.LOW:
self._log.info(f'Currently connected to LCD, pin "{self._hdmi_hdp_pin}" is LOW.')
if self._config_current != self._config_lcd:
swap_config(self._config_lcd, self._config_current, reboot=self._reboot)
return
self._log.info(f'Waiting for HDMI connect now.')
GPIO.wait_for_edge(self._hdmi_hdp_pin, GPIO.RISING)
swap_config(self._config_hdmi, self._config_current, reboot=self._reboot)