Skip to content

Instantly share code, notes, and snippets.

@aceat64
Last active June 9, 2018 05:07
Show Gist options
  • Save aceat64/14df50a8cb9713ab7bc4e98e040707ea to your computer and use it in GitHub Desktop.
Save aceat64/14df50a8cb9713ab7bc4e98e040707ea to your computer and use it in GitHub Desktop.
import os
import sys
import time
import atexit
import asyncio
import subprocess
import evdev
from evdev import InputDevice, categorize, ecodes
import RPi.GPIO as GPIO
x = 0
y = 0
emu = False
slideshow = False
hack = False
next = False
previous = False
waifus = True
atexit.register(subprocess.call, ['killall', '/usr/bin/omxplayer.bin'])
touch = evdev.InputDevice('/dev/input/event0')
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
async def start_waifus():
global waifus
while True:
if not waifus:
await asyncio.sleep(.1)
else:
process = subprocess.Popen(['omxplayer', '--loop', '--no-osd', '--layer', '1', '/badge/WaifusAnimation.mp4'], stdin=subprocess.PIPE, shell=False, preexec_fn=os.setsid)
while process.poll() == None:
if not waifus:
process.communicate(b'q')
break
await asyncio.sleep(.1)
async def start_emu():
global emu
global waifus
while True:
if not emu:
await asyncio.sleep(.1)
else:
process = subprocess.Popen(['emulationstation'], stdin=subprocess.PIPE, shell=False, preexec_fn=os.setsid)
while process.poll() == None:
if not emu:
subprocess.call(['killall', 'retroarch'])
waifus = True
await asyncio.sleep(3)
subprocess.call(['killall', 'emulationstation'])
break
await asyncio.sleep(.1)
async def haptic():
GPIO.output(18,GPIO.HIGH)
await asyncio.sleep(.1)
GPIO.output(18,GPIO.LOW)
async def start_slideshow():
global slideshow
global next
global previous
while True:
if not slideshow:
await asyncio.sleep(.1)
else:
files = os.listdir('/badge')
print(files)
for file in files:
if file == 'System Volume Information':
files.remove(file)
for file in files:
if file == 'WaifusAnimation.mp4':
files.remove(file)
index = 0
while True:
if index > len(files) - 1:
index = 0
elif index < 0:
index = len(files) - 1
if not slideshow:
break
print(index)
print(len(files) - 1)
file = files[index]
path = os.path.join('/badge', file)
print(path)
process = subprocess.Popen(['omxplayer', '--layer', '2', '--aspect-mode', 'fill', path], stdin=subprocess.PIPE, shell=False, preexec_fn=os.setsid)
while process.poll() == None:
if not slideshow:
process.communicate(b'q')
break
if next:
process.communicate(b'q')
next = False
break
if previous:
process.communicate(b'q')
previous = False
index -= 2
break
await asyncio.sleep(.1)
index += 1
async def print_events(device):
global x, y
global slideshow
global emu
global hack
global waifus
global next
global previous
async for event in device.async_read_loop():
if event.type == ecodes.EV_ABS:
absevent = categorize(event)
if ecodes.bytype[absevent.event.type][absevent.event.code] == "ABS_X":
x = absevent.event.value
elif ecodes.bytype[absevent.event.type][absevent.event.code] == "ABS_Y":
y = absevent.event.value
quad = get_quad(x, y)
if event.type == ecodes.EV_KEY and event.value == 1 and quad:
await haptic()
elif event.type == ecodes.EV_KEY and event.value == 0 and quad:
if slideshow:
if quad == 2:
slideshow = False
elif quad == 3:
previous = True
elif quad == 4:
next = True
elif emu == True:
if quad == 2:
waifus = True
emu = False
elif hack == True:
if quad == 2:
hack = False
else:
if quad == 1:
print('starting slide')
slideshow = True
elif quad == 3:
print('starting emu')
emu = True
await asyncio.sleep(3)
waifus = False
elif quad == 4:
print('starting hack')
hack = True
return
def get_quad(x, y):
if x < 1588:
if y < 1548:
return 1
elif y > 2548:
return 3
elif x > 2588:
if y < 1548:
return 2
elif y > 2548:
return 4
return False
asyncio.ensure_future(start_waifus())
asyncio.ensure_future(start_emu())
asyncio.ensure_future(print_events(touch))
asyncio.ensure_future(start_slideshow())
loop = asyncio.get_event_loop()
loop.run_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment