import RPi.GPIO as GPIO import os, subprocess, time os.environ['DISPLAY'] = ":0" CHROMIUM_REFRESH_PERIOD = 600 MINIMUM_TIME_ON = 180 displayison = False last_refresh = time.time() last_detected = time.time() GPIO.setwarnings(False) print('Pi Model is %s' % GPIO.RPI_INFO['P1_REVISION']) GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN) while True: if GPIO.input(17): if time.time() > (last_refresh + CHROMIUM_REFRESH_PERIOD): subprocess.call(['/home/pi/autorefresh-chromium.sh']) last_refresh = time.time() time.sleep(2) print('Refreshing...') elif not displayison: subprocess.call('vcgencmd display_power 1', shell=True) displayison = True last_detected = time.time() print('display turned on') else: last_detected = time.time() elif displayison: if time.time() > (last_detected + MINIMUM_TIME_ON): subprocess.call('vcgencmd display_power 0', shell=True) displayison = False print('display turned off') time.sleep(1)