-
Notifications
You must be signed in to change notification settings - Fork 30
/
menu_screenoff.py
executable file
·52 lines (42 loc) · 1.27 KB
/
menu_screenoff.py
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
#!/usr/bin/env python
import pygame, os, subprocess, time
import RPi.GPIO as GPIO
from pygame.locals import *
from subprocess import *
os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ["SDL_MOUSEDEV"] = "/dev/input/touchscreen"
os.environ["SDL_MOUSEDRV"] = "TSLIB"
# Initialize pygame modules individually (to avoid ALSA errors) and hide mouse
pygame.font.init()
pygame.display.init()
pygame.mouse.set_visible(0)
# Initialise GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
def run_cmd(cmd):
process = Popen(cmd.split(), stdout=PIPE)
output = process.communicate()[0]
return output
# Turn screen on
def screen_on():
pygame.quit()
backlight = GPIO.PWM(18, 1023)
backlight.start(100)
GPIO.cleanup()
page=os.environ["MENUDIR"] + "menu_kali-1.py"
os.execvp("python", ["python", page])
# Turn screen off
def screen_off():
backlight = GPIO.PWM(18, 0.1)
backlight.start(0)
#While loop to manage touch screen inputs
screen_off()
while 1:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
screen_on()
#ensure there is always a safe way to end the program if the touch screen fails
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit()
time.sleep(0.4)