From 46c6fedd5e1ffd8956bf5758b409b4922b4a3e2e Mon Sep 17 00:00:00 2001 From: pangduckwai Date: Mon, 6 May 2019 01:44:09 +0800 Subject: [PATCH] Fix refreshing code --- README.md | 5 +++-- monitor.py | 41 ++++++++++++++++------------------------- usb_drive.sh | 25 +++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 27 deletions(-) create mode 100644 usb_drive.sh diff --git a/README.md b/README.md index 4b184c5..934d615 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,10 @@ That's it, the display is ready to use. ## Next step The Python code in this repo (`monitor.py`) display system information of the Pi: -1. **Button 1** - Display system information of the Pi, such as _Disk space_, _WiFi_, _IP Address_, _CPU Idle %_, _Memory usage_, _Network status_ and _System temperature_, in 2 pages; use the Left/Right Joystick to toggle between these pages. +1. **Button 1** - Display system information of the Pi, such as _Disk space_, _WiFi status_, _IP Address_, _CPU Idle %_, _Memory usage_, _Network status_ and _System temperature_, in 2 pages; use the Left/Right Joystick to toggle between these pages. 1. **Button 3** - Display the system action dialog, use the Up/Down/Left/Right Joystick to select the options between _Reboot_, _Shutdown_, _Re-mount Samba_ and _Reload the USB driver_. Press **Button 3** to confirm your choice. * The screen will turn off after idling for around 20 seconds. +* The shell script (`usb_drive.sh`) referenced in the Python code is also included in this repo. ### CPU usage The original version was adopted directly from `demo.py` provided by the manufacturer, which is no good for 'production' use. Because your Pi will be too busy looking for button inputs instead of doing anything else useful. @@ -90,5 +91,5 @@ The latest version utilize GPIO input detection instead of busy wait, which is m ### Enable the display at startup * `sudo vi /etc/rc.local` * Add the following line at the end of the file, assuming `monitor.py` is in /home/pi/: - * `sudo python /home/pi/monitor.py &` + * `python /home/pi/monitor.py &` * _**IMPORTANT**_ Don't forget the `&` character at the end! \ No newline at end of file diff --git a/monitor.py b/monitor.py index 4a68857..8a9ce46 100644 --- a/monitor.py +++ b/monitor.py @@ -69,19 +69,15 @@ def take_act(channel): if state == BTN3_PIN: if vert == 1: if horz == 1: - draw_scn(996) - os.system("sudo shutdown -r now") - else: - draw_scn(995) + show_stt(995) os.system("sudo shutdown -h now") - elif vert == 2: - if horz == 1: - draw_scn(997) - os.system("sudo /usr/bin/usb_drive.sh remount") else: - draw_scn(998) - os.system("sudo /usr/bin/usb_drive.sh replug") - start = stamp - SCREEN_SAVER - 15 + show_stt(996) + os.system("sudo shutdown -r now") + elif vert == 2: + show_stt(997) + os.system("sudo usb_drive.sh refresh") + start = stamp - SCREEN_SAVER - 10 else: show_stt(BTN1_PIN) else: @@ -148,40 +144,35 @@ def draw_scn(channel): x6 = x3+9 y2 = y1*vert LINE1 = "| Shutdown..." - LINE2 = "| Refresh..." + LINE2 = "| Refresh" LINE3 = "| Cancel" if vert == 1: if horz == 1: - LINE1 = "> Reboot" - else: LINE1 = "> Shutdown" - elif vert == 2: - if horz == 1: - LINE2 = "> Remount SMB" else: - LINE2 = "> Reload USB" + LINE1 = "> Reboot" + elif vert == 2: + LINE2 = "> Refresh" else: LINE3 = "> Cancel" - if vert == 3: - draw.polygon([(x1,y2+6),(x2,y2-1),(x2,y2+4),(x3,y2+4),(x3,y2+8),(x2,y2+8),(x2,y2+13)], outline=255, fill=1) - else: + if vert == 1: if horz == 1: draw.polygon([(x4,y2+6),(x5,y2-1),(x5,y2+4),(x6,y2+4),(x6,y2+8),(x5,y2+8),(x5,y2+13)], outline=255, fill=0) draw.polygon([(x1,y2+6),(x2,y2-1),(x2,y2+4),(x3,y2+4),(x3,y2+8),(x2,y2+8),(x2,y2+13)], outline=255, fill=1) else: draw.polygon([(x1,y2+6),(x2,y2-1),(x2,y2+4),(x3,y2+4),(x3,y2+8),(x2,y2+8),(x2,y2+13)], outline=255, fill=0) draw.polygon([(x4,y2+6),(x5,y2-1),(x5,y2+4),(x6,y2+4),(x6,y2+8),(x5,y2+8),(x5,y2+13)], outline=255, fill=1) + else: + draw.polygon([(x1,y2+6),(x2,y2-1),(x2,y2+4),(x3,y2+4),(x3,y2+8),(x2,y2+8),(x2,y2+13)], outline=255, fill=1) elif channel == 995: LINE2 = " Shutting down..." elif channel == 996: LINE2 = " Rebooting..." elif channel == 997: - LINE2 = " Resetting SMB..." - elif channel == 998: - LINE2 = " Resetting USB..." + LINE2 = " Refreshing..." else: pass @@ -255,4 +246,4 @@ try: except: print "Stopped", sys.exc_info()[0] raise -GPIO.cleanup() +GPIO.cleanup() \ No newline at end of file diff --git a/usb_drive.sh b/usb_drive.sh new file mode 100644 index 0000000..123be09 --- /dev/null +++ b/usb_drive.sh @@ -0,0 +1,25 @@ +#!/bin/bash +FILE=/usb.bin +MOUNT=/mnt/usb + +case $1 in +stop) + modprobe -r g_mass_storage + ;; +refresh) + sync $MOUNT + sleep 1 + modprobe -r g_mass_storage + sleep 1 + modprobe g_mass_storage file=$FILE stall=0 ro=0 removable=1 nofua=1 + sleep 1 + service smbd restart + umount $MOUNT + sleep 1 + mount -a + ;; +*) + sleep 1 + modprobe g_mass_storage file=$FILE stall=0 ro=0 removable=1 nofua=1 + ;; +esac