Add remount function
This commit is contained in:
+103
-63
@@ -35,10 +35,13 @@ CHAR_WIDTH = 19
|
|||||||
font = ImageFont.load_default()
|
font = ImageFont.load_default()
|
||||||
width = 128
|
width = 128
|
||||||
height = 64
|
height = 64
|
||||||
padding = -2
|
x0 = 0
|
||||||
top = padding
|
x1 = 70
|
||||||
bottom = height-padding
|
y0 = -2
|
||||||
xpos = 0
|
y1 = 12
|
||||||
|
# ypos2 = 24
|
||||||
|
# ypos3 = 36
|
||||||
|
# ypos4 = 48
|
||||||
|
|
||||||
# init GPIO
|
# init GPIO
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
@@ -58,87 +61,123 @@ draw = ImageDraw.Draw(Image.new('1', (width, height)))
|
|||||||
draw.rectangle((0,0,width,height), outline=0, fill=0)
|
draw.rectangle((0,0,width,height), outline=0, fill=0)
|
||||||
|
|
||||||
state = 0 #System state: 0 - scrren is off; equal to channel number (e.g. BTN2_PIN, JS_P_PIN) otherwise
|
state = 0 #System state: 0 - scrren is off; equal to channel number (e.g. BTN2_PIN, JS_P_PIN) otherwise
|
||||||
stops = 0 #Shutdown choice: 0 - No; 1 - Yes
|
horz = 0 #Selection choice: 0 - Left; 1 - Right
|
||||||
|
vert = 4 #Selection choice: 1 - Top; 2 - Second; 3 - Third; 4 - Bottom
|
||||||
stamp = time.time() #Current timestamp
|
stamp = time.time() #Current timestamp
|
||||||
start = time.time() #Start screen saver count down
|
start = time.time() #Start screen saver count down
|
||||||
|
|
||||||
def shutdown(channel):
|
def take_act(channel):
|
||||||
global stops
|
global start
|
||||||
|
global vert
|
||||||
if state == BTN3_PIN:
|
if state == BTN3_PIN:
|
||||||
if stops == 1:
|
if vert == 1:
|
||||||
draw_process(RST_PIN)
|
draw_scn(RST_PIN)
|
||||||
os.system("sudo shutdown -h now")
|
os.system("sudo shutdown -h now")
|
||||||
|
elif vert == 2:
|
||||||
|
# Remount
|
||||||
|
draw_scn(997)
|
||||||
|
start = stamp - SCREEN_SAVER - 10
|
||||||
|
os.system("sudo /usr/bin/usb_drive.sh remount")
|
||||||
|
elif vert == 3:
|
||||||
|
# Replug USB
|
||||||
|
draw_scn(998)
|
||||||
|
start = stamp - SCREEN_SAVER - 10
|
||||||
|
os.system("sudo /usr/bin/usb_drive.sh replug")
|
||||||
else:
|
else:
|
||||||
main_process(BTN1_PIN)
|
show_stt(BTN1_PIN)
|
||||||
else:
|
else:
|
||||||
stops = 0
|
vert = 4 # Default
|
||||||
main_process(BTN3_PIN)
|
show_stt(BTN3_PIN)
|
||||||
|
|
||||||
def select(channel):
|
def select_h(channel):
|
||||||
global stops
|
global start
|
||||||
if state == BTN3_PIN:
|
global horz
|
||||||
if channel == JS_L_PIN:
|
if channel == JS_L_PIN:
|
||||||
stops = 1
|
start = time.time()
|
||||||
draw_process(state)
|
horz = 1
|
||||||
elif channel == JS_R_PIN:
|
draw_scn(state)
|
||||||
stops = 0
|
elif channel == JS_R_PIN:
|
||||||
draw_process(state)
|
start = time.time()
|
||||||
else:
|
horz = 0
|
||||||
pass
|
draw_scn(state)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
def draw_process(channel):
|
def select_v(channel):
|
||||||
|
global start
|
||||||
|
global vert
|
||||||
|
if channel == JS_U_PIN:
|
||||||
|
start = time.time()
|
||||||
|
if vert > 1:
|
||||||
|
vert = vert - 1
|
||||||
|
elif channel == JS_D_PIN:
|
||||||
|
start = time.time()
|
||||||
|
if vert < 4:
|
||||||
|
vert = vert + 1
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def draw_scn(channel):
|
||||||
with canvas(device) as draw:
|
with canvas(device) as draw:
|
||||||
LINE0 = subprocess.check_output("date +\"%Y-%m-%d %H:%M:%S\"", shell = True)
|
LINE0 = subprocess.check_output("date +\"%Y-%m-%d %H:%M:%S\"", shell = True)
|
||||||
LINE1 = ""
|
LINE1 = ""
|
||||||
LINE2 = ""
|
LINE2 = ""
|
||||||
LINE3 = ""
|
LINE3 = ""
|
||||||
LINE4 = ""
|
LINE4 = ""
|
||||||
if channel == BTN2_PIN:
|
if channel == BTN1_PIN:
|
||||||
LINE1 = subprocess.check_output("hostname -I | awk '{printf \"IP :%s\", $1}'", shell = True )
|
if horz == 0:
|
||||||
LINE2 = subprocess.check_output("top -bn1 | awk 'NR==3{printf \"CPU:%.1f%% idle\", $8}'", shell = True )
|
ssid = subprocess.check_output("iwgetid --raw | awk '{printf \"WiFi:%s\", $0}'", shell = True)
|
||||||
LINE3 = subprocess.check_output("free -mh | awk 'NR==2{printf \"Mem:%s/%s %.1f%%\", $3,$2,$3*100/$2 }'", shell = True )
|
freq = subprocess.check_output("iwgetid --freq | awk '{gsub(/Frequency:/,\"\"); printf \" %.1f %s\", $2,$3}'", shell = True)
|
||||||
LINE4 = subprocess.check_output("cat /sys/class/thermal/thermal_zone0/temp | awk '{printf \"Tmp:%.1fC\", $1/1000}'", shell = True )
|
LINE1 = subprocess.check_output("df -h /mnt/usb | awk '$NF==\"/mnt/usb\"{printf \"Disk:%s/%s %s\", $3,$2,$5}'", shell = True )
|
||||||
elif channel == BTN1_PIN:
|
LINE2 = ssid + freq
|
||||||
ssid = subprocess.check_output("iwgetid --raw | awk '{printf \"WiFi:%s\", $0}'", shell = True)
|
LINE3 = " in Kbps out Kbps"
|
||||||
freq = subprocess.check_output("iwgetid --freq | awk '{gsub(/Frequency:/,\"\"); printf \" %.1f %s\", $2,$3}'", shell = True)
|
LINE4 = subprocess.check_output("ifstat -bT 0.1 1 | awk 'NR==3{printf \"%9.2f %9.2f\",$3,$4}'", shell = True)
|
||||||
LINE1 = subprocess.check_output("df -h /mnt/usb | awk '$NF==\"/mnt/usb\"{printf \"Disk:%s/%s %s\", $3,$2,$5}'", shell = True )
|
draw.rectangle((19,61,48,63), outline=255, fill=0)
|
||||||
LINE2 = ssid + freq
|
draw.rectangle((49,61,109,63), outline=255, fill=1)
|
||||||
LINE3 = " in Kbps out Kbps"
|
|
||||||
LINE4 = subprocess.check_output("ifstat -bT 0.1 1 | awk 'NR==3{printf \"%9.2f %9.2f\",$3,$4}'", shell = True)
|
|
||||||
elif channel == BTN3_PIN:
|
|
||||||
LINE1 = " Shutdown ?"
|
|
||||||
LINE3 = " Yes No"
|
|
||||||
if stops == 0:
|
|
||||||
draw.rectangle((72,50,94,52), outline=255, fill=1)
|
|
||||||
else:
|
else:
|
||||||
draw.rectangle((15,50,37,52), outline=255, fill=1)
|
LINE1 = subprocess.check_output("hostname -I | awk '{printf \"IP :%s\", $1}'", shell = True )
|
||||||
|
LINE2 = subprocess.check_output("top -bn1 | awk 'NR==3{printf \"CPU:%.1f%% idle\", $8}'", shell = True )
|
||||||
|
LINE3 = subprocess.check_output("free -mh | awk 'NR==2{printf \"Mem:%s/%s %.1f%%\", $3,$2,$3*100/$2 }'", shell = True )
|
||||||
|
LINE4 = subprocess.check_output("cat /sys/class/thermal/thermal_zone0/temp | awk '{printf \"Tmp:%.1fC\", $1/1000}'", shell = True )
|
||||||
|
draw.rectangle((19,61,78,63), outline=255, fill=1)
|
||||||
|
draw.rectangle((79,61,109,63), outline=255, fill=0)
|
||||||
|
elif channel == BTN3_PIN:
|
||||||
|
LINE1 = "> Shutdown"
|
||||||
|
LINE2 = "> Reset SMB"
|
||||||
|
LINE3 = "> Reset USB"
|
||||||
|
LINE4 = "> Cancel"
|
||||||
|
draw.polygon([(x1,y1*vert+6),(x1+7,y1*vert-1),(x1+7,y1*vert+4),(x1+14,y1*vert+4),(x1+14,y1*vert+8),(x1+7,y1*vert+8),(x1+7,y1*vert+13)], outline=255, fill=1)
|
||||||
elif channel == RST_PIN:
|
elif channel == RST_PIN:
|
||||||
LINE2 = " Shutting down..."
|
LINE2 = " Shutting down..."
|
||||||
|
elif channel == 997:
|
||||||
|
LINE2 = " Resetting SMB..."
|
||||||
|
elif channel == 998:
|
||||||
|
LINE2 = " Resetting USB..."
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
draw.text((xpos, top), LINE0, font=font, fill=255)
|
draw.text((x0, y0), LINE0, font=font, fill=255)
|
||||||
if len(LINE1) > CHAR_WIDTH:
|
if len(LINE1) > CHAR_WIDTH:
|
||||||
draw.text((xpos, top+12), LINE1[:CHAR_WIDTH], font=font, fill=255)
|
draw.text((x0, y1), LINE1[:CHAR_WIDTH], font=font, fill=255)
|
||||||
else:
|
else:
|
||||||
draw.text((xpos, top+12), LINE1, font=font, fill=255)
|
draw.text((x0, y1), LINE1, font=font, fill=255)
|
||||||
|
|
||||||
if len(LINE2) > CHAR_WIDTH:
|
if len(LINE2) > CHAR_WIDTH:
|
||||||
draw.text((xpos, top+28), LINE2[:CHAR_WIDTH], font=font, fill=255)
|
draw.text((x0, y1*2), LINE2[:CHAR_WIDTH], font=font, fill=255)
|
||||||
else:
|
else:
|
||||||
draw.text((xpos, top+28), LINE2, font=font, fill=255)
|
draw.text((x0, y1*2), LINE2, font=font, fill=255)
|
||||||
|
|
||||||
if len(LINE3) > CHAR_WIDTH:
|
if len(LINE3) > CHAR_WIDTH:
|
||||||
draw.text((xpos, top+40), LINE3[:CHAR_WIDTH], font=font, fill=255)
|
draw.text((x0, y1*3), LINE3[:CHAR_WIDTH], font=font, fill=255)
|
||||||
else:
|
else:
|
||||||
draw.text((xpos, top+40), LINE3, font=font, fill=255)
|
draw.text((x0, y1*3), LINE3, font=font, fill=255)
|
||||||
|
|
||||||
if len(LINE4) > CHAR_WIDTH:
|
if len(LINE4) > CHAR_WIDTH:
|
||||||
draw.text((xpos, top+52), LINE4[:CHAR_WIDTH], font=font, fill=255)
|
draw.text((x0, y1*4), LINE4[:CHAR_WIDTH], font=font, fill=255)
|
||||||
else:
|
else:
|
||||||
draw.text((xpos, top+52), LINE4, font=font, fill=255)
|
draw.text((x0, y1*4), LINE4, font=font, fill=255)
|
||||||
|
|
||||||
def main_process(channel):
|
def show_stt(channel):
|
||||||
global serial
|
global serial
|
||||||
global device
|
global device
|
||||||
global draw
|
global draw
|
||||||
@@ -155,7 +194,7 @@ def main_process(channel):
|
|||||||
|
|
||||||
state = channel
|
state = channel
|
||||||
start = time.time()
|
start = time.time()
|
||||||
draw_process(channel)
|
draw_scn(channel)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
else: # Display is on
|
else: # Display is on
|
||||||
@@ -165,22 +204,23 @@ def main_process(channel):
|
|||||||
elif (channel > 0) and (channel != state):
|
elif (channel > 0) and (channel != state):
|
||||||
state = channel
|
state = channel
|
||||||
start = time.time()
|
start = time.time()
|
||||||
draw_process(channel)
|
draw_scn(channel)
|
||||||
else: # state > 0 && channel == 0 && not-yet-timeout, refresh screen
|
else: # state > 0 && channel == 0 && not-yet-timeout, refresh screen
|
||||||
draw_process(state)
|
draw_scn(state)
|
||||||
|
|
||||||
GPIO.add_event_detect(BTN1_PIN, GPIO.RISING, callback=main_process, bouncetime=200)
|
|
||||||
GPIO.add_event_detect(BTN2_PIN, GPIO.RISING, callback=main_process, bouncetime=200)
|
|
||||||
GPIO.add_event_detect(BTN3_PIN, GPIO.RISING, callback=shutdown, bouncetime=200)
|
|
||||||
GPIO.add_event_detect(JS_L_PIN, GPIO.RISING, callback=select, bouncetime=200)
|
|
||||||
GPIO.add_event_detect(JS_R_PIN, GPIO.RISING, callback=select, bouncetime=200)
|
|
||||||
|
|
||||||
|
GPIO.add_event_detect(BTN1_PIN, GPIO.RISING, callback=show_stt, bouncetime=200)
|
||||||
|
GPIO.add_event_detect(BTN3_PIN, GPIO.RISING, callback=take_act, bouncetime=200)
|
||||||
|
GPIO.add_event_detect(JS_L_PIN, GPIO.RISING, callback=select_h, bouncetime=200)
|
||||||
|
GPIO.add_event_detect(JS_R_PIN, GPIO.RISING, callback=select_h, bouncetime=200)
|
||||||
|
GPIO.add_event_detect(JS_U_PIN, GPIO.RISING, callback=select_v, bouncetime=200)
|
||||||
|
GPIO.add_event_detect(JS_D_PIN, GPIO.RISING, callback=select_v, bouncetime=200)
|
||||||
|
|
||||||
|
# Main Loop
|
||||||
try:
|
try:
|
||||||
main_process(BTN1_PIN)
|
show_stt(BTN1_PIN)
|
||||||
while True:
|
while True:
|
||||||
stamp = time.time()
|
stamp = time.time()
|
||||||
main_process(0)
|
show_stt(0)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
|
|||||||
Reference in New Issue
Block a user