|
@ -7,6 +7,7 @@ __author__ = "Hendrik Langer <hendrik.langer@iul.tu-dortmund.de>" |
|
|
|
|
|
|
|
|
import multiprocessing |
|
|
import multiprocessing |
|
|
import os.path |
|
|
import os.path |
|
|
|
|
|
import signal |
|
|
import sys |
|
|
import sys |
|
|
import threading |
|
|
import threading |
|
|
import time |
|
|
import time |
|
@ -125,6 +126,31 @@ def os_echo_bin(filename, string): |
|
|
with open(filename, 'wb') as f: |
|
|
with open(filename, 'wb') as f: |
|
|
f.write(string) |
|
|
f.write(string) |
|
|
|
|
|
|
|
|
|
|
|
def cleanup(): |
|
|
|
|
|
g="/sys/kernel/config/usb_gadget/freezer/" |
|
|
|
|
|
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", "") |
|
|
|
|
|
time.sleep(0.5) |
|
|
|
|
|
subprocess.run(['rmdir', g+"configs/c.1/strings/0x409"], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['rm', g+"configs/c.1/mass_storage.usb0"], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['rm', g+"configs/c.1/hid.usb0"], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['rmdir', g+"configs/c.1"], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['rmdir', g+"functions/mass_storage.usb0"], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['rmdir', g+"functions/hid.usb0"], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['rmdir', g+"strings/0x409"], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['rmdir', g], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['modprobe', '-r', 'usb_f_mass_storage'], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['modprobe', '-r', 'usb_f_hid'], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['modprobe', '-r', 'libcomposite'], shell=False, check=False) |
|
|
|
|
|
|
|
|
|
|
|
def signal_term_handler(signal, frame): |
|
|
|
|
|
print('got SIGTERM') |
|
|
|
|
|
cleanup() |
|
|
|
|
|
sys.exit(0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def send_keypress(): |
|
|
def send_keypress(): |
|
|
with open('/dev/hidg0', 'wb') as f: |
|
|
with open('/dev/hidg0', 'wb') as f: |
|
@ -155,6 +181,8 @@ if __name__ == '__main__': |
|
|
subprocess.run('cp /opt/freezer/freeze.exe /mnt/', shell=True, check=True) |
|
|
subprocess.run('cp /opt/freezer/freeze.exe /mnt/', shell=True, check=True) |
|
|
subprocess.run(['umount', '/mnt'], shell=False, check=True) |
|
|
subprocess.run(['umount', '/mnt'], shell=False, check=True) |
|
|
|
|
|
|
|
|
|
|
|
signal.signal(signal.SIGTERM, signal_term_handler) |
|
|
|
|
|
|
|
|
# http://irq5.io/2016/12/22/raspberry-pi-zero-as-multiple-usb-gadgets/ |
|
|
# http://irq5.io/2016/12/22/raspberry-pi-zero-as-multiple-usb-gadgets/ |
|
|
# http://isticktoit.net/?p=1383 |
|
|
# http://isticktoit.net/?p=1383 |
|
|
subprocess.run(['modprobe', 'libcomposite'], shell=False, check=True) |
|
|
subprocess.run(['modprobe', 'libcomposite'], shell=False, check=True) |
|
@ -223,7 +251,7 @@ if __name__ == '__main__': |
|
|
p = subprocess.Popen(['tvservice', '-s'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
|
p = subprocess.Popen(['tvservice', '-s'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
|
_stdout, _stderr = p.communicate() |
|
|
_stdout, _stderr = p.communicate() |
|
|
if (len(_stdout) > 0 and _stdout == fallback_str): |
|
|
if (len(_stdout) > 0 and _stdout == fallback_str): |
|
|
subprocess.run(['tvservice', '--explicit="CEA 16 HDMI"'], shell=False, check=False) |
|
|
subprocess.run('tvservice --explicit="CEA 16 HDMI"', shell=True, check=False) |
|
|
subprocess.run(['fbset', '-fb', '/dev/fb0', '-depth', '16'], shell=False, check=False) |
|
|
subprocess.run(['fbset', '-fb', '/dev/fb0', '-depth', '16'], shell=False, check=False) |
|
|
subprocess.run(['fbset', '-fb', '/dev/fb0', '-depth', '32'], shell=False, check=False) |
|
|
subprocess.run(['fbset', '-fb', '/dev/fb0', '-depth', '32'], shell=False, check=False) |
|
|
|
|
|
|
|
@ -264,18 +292,6 @@ if __name__ == '__main__': |
|
|
watch_delay_call('/tmp/usbdisk.img', callback, 0.2, True, pyinotify.IN_MODIFY) |
|
|
watch_delay_call('/tmp/usbdisk.img', callback, 0.2, True, pyinotify.IN_MODIFY) |
|
|
|
|
|
|
|
|
finally: |
|
|
finally: |
|
|
GPIO.output(pin_led_busy, GPIO.LOW) |
|
|
cleanup() |
|
|
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", "") |
|
|
|
|
|
time.sleep(0.5) |
|
|
|
|
|
subprocess.run(['rmdir', g+"configs/c.1/strings/0x409"], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['rmdir', g+"configs/c.1"], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['rmdir', g+"functions/mass_storage.usb0"], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['rmdir', g+"strings/0x409"], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['rmdir', g], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['modprobe', '-r', 'usb_f_mass_storage'], shell=False, check=False) |
|
|
|
|
|
subprocess.run(['modprobe', '-r', 'libcomposite'], shell=False, check=False) |
|
|
|
|
|
sys.exit(0) |
|
|
sys.exit(0) |
|
|
|
|
|
|
|
|