Created
March 3, 2018 12:12
-
-
Save MultiMote/3673200104bebeb0c2b3088d9bac2c87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import call | |
MAX_DISPLAY_IDLE_SECONDS = 60 * 5 | |
class DisplayPower(object): | |
def __init__(self): | |
self.display_idle_time = 0 | |
self.display_on = False | |
self.on() | |
def off(self): | |
self.display_on = False | |
try: | |
call(["vcgencmd", "display_power 0"]) | |
except FileNotFoundError: | |
print("vcgencmd not found") | |
def on(self): | |
self.display_on = True | |
try: | |
call(["vcgencmd", "display_power 1"]) | |
except FileNotFoundError: | |
print("vcgencmd not found") | |
def update(self, sensor_value): | |
if sensor_value == 1: | |
self.display_idle_time = 0 | |
if not self.display_on: | |
self.on() | |
else: | |
if self.display_on: | |
self.display_idle_time += 1 | |
if self.display_on and self.display_idle_time > MAX_DISPLAY_IDLE_SECONDS: | |
self.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment