From 38d0d97ad034a44a398b340ab02de0f7fb715561 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Tue, 24 Jul 2018 01:23:34 +0200 Subject: [PATCH] update raspi script --- README.md | 8 +++++--- raspberry-environment/display.py | 28 +++++++++++++++++++--------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0236006..24e8f50 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ * Plug USB into Computer * booting the Raspberry takes approximately ?? seconds. the ?? led will light up when ready * start freeze.exe from the (now attached) USB-Drive - * press WindowsKey+Y or PRINTSCREEN to take a screenshot + * press WindowsKey+Y or Alt+PRINTSCREEN to take a screenshot * simply unplug after use # Initial setup @@ -16,8 +16,8 @@ * Raspberry Pi Zero or Zero W or Model A (Model B/2B/3 not supported!) ## Hardware - D D (Status LEDs) - _______________||||___ + LED LED SW + _______|_______|_|____ | :::::::::::::::::::: | | | |_HDMI________USB__PWR_| @@ -49,6 +49,8 @@ apt clean echo "dtoverlay=dwc2" >> /boot/config.txt +echo "dtoverlay=gpio-poweroff,gpiopin=5,active_low" >> /boot/config.txt + echo "libcomposite" >> /etc/modules apt purge plymouth diff --git a/raspberry-environment/display.py b/raspberry-environment/display.py index 819113b..d53d8e0 100644 --- a/raspberry-environment/display.py +++ b/raspberry-environment/display.py @@ -13,6 +13,10 @@ import time import subprocess import glob +pin_led_ready=27 +pin_led_busy=5 +pin_switch=13 + try: import RPi.GPIO as GPIO except RuntimeError: @@ -125,15 +129,17 @@ def os_echo_bin(filename, string): def send_keypress(): with open('/dev/hidg0', 'wb') as f: f.write(bytearray(b'\x00\x00\x04\x00\x00\x00\x00\x00')) #press the A-button + time.sleep(0.05) f.write(bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00')) #release all keys if __name__ == '__main__': GPIO.setmode(GPIO.BCM) - GPIO.setup(18, GPIO.OUT) - GPIO.setup(23, GPIO.OUT) - GPIO.output(18, GPIO.LOW) - GPIO.output(23, GPIO.LOW) + GPIO.setup(pin_led_ready, GPIO.OUT) + GPIO.setup(pin_led_busy, GPIO.OUT) + GPIO.setup(pin_switch, GPIO.IN, pull_up_down=GPIO.PUD_UP) + GPIO.output(pin_led_ready, GPIO.LOW) + GPIO.output(pin_led_busy, GPIO.LOW) g="/sys/kernel/config/usb_gadget/freezer/" @@ -219,8 +225,8 @@ if __name__ == '__main__': # if paths: # for path in paths: # print(' {0}'.format(path)) - GPIO.output(18, GPIO.HIGH) - GPIO.output(23, GPIO.HIGH) + GPIO.output(pin_led_ready, GPIO.HIGH) + GPIO.output(pin_led_busy, GPIO.HIGH) print('file changed') subprocess.run(['killall', 'fim'], shell=False, check=False) subprocess.run(['umount', '/mnt'], shell=False, check=False) @@ -234,14 +240,18 @@ if __name__ == '__main__': latest_file = max(list_of_files, key=os.path.getctime) print(latest_file) subprocess.run('fim -d /dev/fb0 -T 1 --autozoom --quiet "'+latest_file+'" &', shell=True) - GPIO.output(23, GPIO.LOW) + GPIO.output(pin_led_busy, GPIO.LOW) + + def callback_switch(channel): + send_keypress() + GPIO.add_event_detect(pin_switch, GPIO.FALLING, callback=callback_switch, bouncetime=250) watch_delay_call('/tmp/usbdisk.img', callback, 0.5, True, pyinotify.IN_MODIFY) finally: - GPIO.output(23, GPIO.LOW) - GPIO.output(18, GPIO.LOW) + GPIO.output(pin_led_busy, GPIO.LOW) + GPIO.output(pin_led_ready, GPIO.LOW) subprocess.run(['killall', 'fim'], shell=False, check=False) subprocess.run(['umount', '/mnt'], shell=False, check=False) os_echo(g+"UDC", "")