mirror of
https://github.com/okunze/Argon40-ArgonOne-Script.git
synced 2026-01-02 23:20:36 +01:00
Automated Change by GitHub Action
This commit is contained in:
committed by
github-actions[bot]
parent
c26498ae91
commit
f0aeadea8b
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
VERSIONINFO="2512002"
|
VERSIONINFO="2512003"
|
||||||
|
|
||||||
echo "Version $VERSIONINFO"
|
echo "Version $VERSIONINFO"
|
||||||
if [ -z "$1" ]
|
if [ -z "$1" ]
|
||||||
|
|||||||
@@ -17,6 +17,79 @@ def argonpowerbutton_debuglog(typestr, logstr):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def argonpowerbutton_getvalue(lineobj,lineid):
|
||||||
|
if lineid is not None:
|
||||||
|
tmpval = lineobj.get_value(lineid) != gpiod.line.Value.INACTIVE
|
||||||
|
if tmpval == False:
|
||||||
|
return 0
|
||||||
|
return 1
|
||||||
|
return lineobj.get_value()
|
||||||
|
|
||||||
|
def argonpowerbutton_watchline(debugname, dataq, lineid, callback):
|
||||||
|
monitormode = True
|
||||||
|
argonpowerbutton_debuglog(debugname, "Starting")
|
||||||
|
# Pi5 mapping, 0 for older
|
||||||
|
chippath = '/dev/gpiochip4'
|
||||||
|
try:
|
||||||
|
chip = gpiod.Chip(chippath)
|
||||||
|
except Exception as gpioerr:
|
||||||
|
try:
|
||||||
|
# Old mapping
|
||||||
|
chippath = '/dev/gpiochip0'
|
||||||
|
chip = gpiod.Chip(chippath)
|
||||||
|
except Exception as gpioolderr:
|
||||||
|
chippath = ""
|
||||||
|
|
||||||
|
if len(chippath) == 0:
|
||||||
|
argonpowerbutton_debuglog(debugname+"-error", "Unable to initialize GPIO")
|
||||||
|
try:
|
||||||
|
dataq.put("ERROR")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return
|
||||||
|
|
||||||
|
# Monitoring starts
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
# Reference https://github.com/brgl/libgpiod/blob/master/bindings/python/examples/gpiomon.py
|
||||||
|
|
||||||
|
lineobj = chip.get_line(lineid)
|
||||||
|
if lineid == 27:
|
||||||
|
lineobj.request(consumer="argon", type=gpiod.LINE_REQ_EV_BOTH_EDGES, flags=gpiod.LINE_REQ_FLAG_BIAS_PULL_UP)
|
||||||
|
else:
|
||||||
|
lineobj.request(consumer="argon", type=gpiod.LINE_REQ_EV_BOTH_EDGES)
|
||||||
|
while monitormode == True:
|
||||||
|
hasevent = lineobj.event_wait(10)
|
||||||
|
if hasevent:
|
||||||
|
eventdata = lineobj.event_read()
|
||||||
|
monitormode = callback(eventdata.type == gpiod.LineEvent.RISING_EDGE, lineobj, dataq, None)
|
||||||
|
|
||||||
|
lineobj.release()
|
||||||
|
chip.close()
|
||||||
|
except Exception:
|
||||||
|
# https://github.com/brgl/libgpiod/blob/master/bindings/python/examples/watch_line_rising.py
|
||||||
|
configobj = {lineid: gpiod.LineSettings(direction=gpiod.line.Direction.INPUT, edge_detection=gpiod.line.Edge.BOTH)}
|
||||||
|
if lineid == 27:
|
||||||
|
configobj = {lineid: gpiod.LineSettings(direction=gpiod.line.Direction.INPUT, edge_detection=gpiod.line.Edge.BOTH, bias=gpiod.line.Bias.PULL_UP )}
|
||||||
|
|
||||||
|
with gpiod.request_lines(
|
||||||
|
chippath,
|
||||||
|
consumer="argon",
|
||||||
|
config=configobj,
|
||||||
|
) as request:
|
||||||
|
while monitormode:
|
||||||
|
# Blocks until at least one event is available
|
||||||
|
for event in request.read_edge_events():
|
||||||
|
monitormode = callback(event.event_type == event.Type.RISING_EDGE, request, dataq, event.line_offset)
|
||||||
|
except Exception as monitorerror:
|
||||||
|
try:
|
||||||
|
argonpowerbutton_debuglog(debugname+"-error", str(monitorerror))
|
||||||
|
except:
|
||||||
|
argonpowerbutton_debuglog(debugname+"-error", "Error aborting")
|
||||||
|
try:
|
||||||
|
dataq.put("ERROR")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# This function is the thread that monitors activity in our shutdown pin
|
# This function is the thread that monitors activity in our shutdown pin
|
||||||
# The pulse width is measured, and the corresponding shell command will be issued
|
# The pulse width is measured, and the corresponding shell command will be issued
|
||||||
@@ -58,131 +131,76 @@ def argonpowerbutton_getconfigval(keyname, datatype="int"):
|
|||||||
return -1
|
return -1
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def argonpowerbutton_monitorlid(writeq):
|
def argonpowerbutton_monitorlidevent(isrising, lineobj, writeq, lineid):
|
||||||
try:
|
if isrising == False:
|
||||||
argonpowerbutton_debuglog("lid-monitor", "Starting")
|
targetsecs = argonpowerbutton_getconfigval("lidshutdownsecs")
|
||||||
monitormode = True
|
if targetsecs > 0:
|
||||||
|
argonpowerbutton_debuglog("lid-monitor", "Close Detect; Wait for :"+str(targetsecs))
|
||||||
|
else:
|
||||||
|
argonpowerbutton_debuglog("lid-monitor", "Close Detected; Do nothing")
|
||||||
|
# Time pulse data
|
||||||
|
time.sleep(1)
|
||||||
|
pulsetimesec = 1
|
||||||
# 0 - Lid is closed, 1 - Lid is open
|
# 0 - Lid is closed, 1 - Lid is open
|
||||||
# Pin Assignments
|
while argonpowerbutton_getvalue(lineobj, lineid) == 0:
|
||||||
LINE_LIDMONITOR=27
|
if targetsecs > 0:
|
||||||
try:
|
if pulsetimesec >= targetsecs:
|
||||||
# Pi5 mapping
|
argonpowerbutton_debuglog("lid-monitor", "Target Reached, shutting down")
|
||||||
chip = gpiod.Chip('4')
|
monitormode = False
|
||||||
except Exception as gpioerr:
|
os.system("shutdown now -h")
|
||||||
# Old mapping
|
return False
|
||||||
chip = gpiod.Chip('0')
|
|
||||||
|
|
||||||
lineobj = chip.get_line(LINE_LIDMONITOR)
|
time.sleep(1)
|
||||||
lineobj.request(consumer="argon", type=gpiod.LINE_REQ_EV_BOTH_EDGES, flags=gpiod.LINE_REQ_FLAG_BIAS_PULL_UP)
|
pulsetimesec += 1
|
||||||
while monitormode == True:
|
argonpowerbutton_debuglog("lid-monitor", "Open Detected")
|
||||||
hasevent = lineobj.event_wait(10)
|
return True
|
||||||
if hasevent:
|
|
||||||
eventdata = lineobj.event_read()
|
|
||||||
if eventdata.type == gpiod.LineEvent.FALLING_EDGE:
|
|
||||||
targetsecs = argonpowerbutton_getconfigval("lidshutdownsecs")
|
|
||||||
if targetsecs > 0:
|
|
||||||
argonpowerbutton_debuglog("lid-monitor", "Close Detect; Wait for :"+str(targetsecs))
|
|
||||||
else:
|
|
||||||
argonpowerbutton_debuglog("lid-monitor", "Close Detected; Do nothing")
|
|
||||||
# Time pulse data
|
|
||||||
time.sleep(1)
|
|
||||||
pulsetimesec = 1
|
|
||||||
while lineobj.get_value() == 0:
|
|
||||||
if targetsecs > 0:
|
|
||||||
if pulsetimesec >= targetsecs:
|
|
||||||
argonpowerbutton_debuglog("lid-monitor", "Target Reached, shutting down")
|
|
||||||
monitormode = False
|
|
||||||
os.system("shutdown now -h")
|
|
||||||
break
|
|
||||||
|
|
||||||
time.sleep(1)
|
def argonpowerbutton_monitorlid(writeq):
|
||||||
pulsetimesec += 1
|
LINE_LIDMONITOR=27
|
||||||
argonpowerbutton_debuglog("lid-monitor", "Open Detected")
|
argonpowerbutton_watchline("lid-monitor", writeq, LINE_LIDMONITOR, argonpowerbutton_monitorlidevent)
|
||||||
|
|
||||||
lineobj.release()
|
def argonpowerbutton_monitorevent(isrising, lineobj, writeq, lineid):
|
||||||
chip.close()
|
pulsetime = 0
|
||||||
except Exception as liderror:
|
if isrising == True:
|
||||||
try:
|
# Time pulse data
|
||||||
argonpowerbutton_debuglog("lid-monitor-error", str(liderror))
|
while argonpowerbutton_getvalue(lineobj, lineid) == 1:
|
||||||
except:
|
time.sleep(0.01)
|
||||||
argonpowerbutton_debuglog("lid-monitor-error", "Error aborting")
|
pulsetime += 1
|
||||||
#pass
|
|
||||||
|
if pulsetime >=2 and pulsetime <=3:
|
||||||
|
# Testing
|
||||||
|
#writeq.put("OLEDSWITCH")
|
||||||
|
writeq.put("OLEDSTOP")
|
||||||
|
os.system("reboot")
|
||||||
|
return False
|
||||||
|
elif pulsetime >=4 and pulsetime <=5:
|
||||||
|
writeq.put("OLEDSTOP")
|
||||||
|
os.system("shutdown now -h")
|
||||||
|
return False
|
||||||
|
elif pulsetime >=6 and pulsetime <=7:
|
||||||
|
writeq.put("OLEDSWITCH")
|
||||||
|
return True
|
||||||
|
|
||||||
def argonpowerbutton_monitor(writeq):
|
def argonpowerbutton_monitor(writeq):
|
||||||
|
LINE_SHUTDOWN=4
|
||||||
|
argonpowerbutton_watchline("button", writeq, LINE_SHUTDOWN, argonpowerbutton_monitorevent)
|
||||||
|
|
||||||
try:
|
|
||||||
# Reference https://github.com/brgl/libgpiod/blob/master/bindings/python/examples/gpiomon.py
|
|
||||||
|
|
||||||
# Pin Assignments
|
def argonpowerbutton_monitorswitchevent(isrising, lineobj, writeq, lineid):
|
||||||
LINE_SHUTDOWN=4
|
pulsetime = 0
|
||||||
try:
|
if isrising == True:
|
||||||
# Pi5 mapping
|
# Time pulse data
|
||||||
chip = gpiod.Chip('4')
|
while argonpowerbutton_getvalue(lineobj, lineid) == 1:
|
||||||
except Exception as gpioerr:
|
time.sleep(0.01)
|
||||||
# Old mapping
|
pulsetime += 1
|
||||||
chip = gpiod.Chip('0')
|
|
||||||
|
|
||||||
lineobj = chip.get_line(LINE_SHUTDOWN)
|
|
||||||
lineobj.request(consumer="argon", type=gpiod.LINE_REQ_EV_BOTH_EDGES)
|
|
||||||
while True:
|
|
||||||
hasevent = lineobj.event_wait(10)
|
|
||||||
if hasevent:
|
|
||||||
pulsetime = 0
|
|
||||||
eventdata = lineobj.event_read()
|
|
||||||
if eventdata.type == gpiod.LineEvent.RISING_EDGE:
|
|
||||||
# Time pulse data
|
|
||||||
while lineobj.get_value() == 1:
|
|
||||||
time.sleep(0.01)
|
|
||||||
pulsetime += 1
|
|
||||||
|
|
||||||
if pulsetime >=2 and pulsetime <=3:
|
|
||||||
# Testing
|
|
||||||
#writeq.put("OLEDSWITCH")
|
|
||||||
writeq.put("OLEDSTOP")
|
|
||||||
os.system("reboot")
|
|
||||||
break
|
|
||||||
elif pulsetime >=4 and pulsetime <=5:
|
|
||||||
writeq.put("OLEDSTOP")
|
|
||||||
os.system("shutdown now -h")
|
|
||||||
break
|
|
||||||
elif pulsetime >=6 and pulsetime <=7:
|
|
||||||
writeq.put("OLEDSWITCH")
|
|
||||||
lineobj.release()
|
|
||||||
chip.close()
|
|
||||||
except Exception:
|
|
||||||
writeq.put("ERROR")
|
|
||||||
|
|
||||||
|
if pulsetime >= 10:
|
||||||
|
writeq.put("OLEDSWITCH")
|
||||||
|
return True
|
||||||
|
|
||||||
def argonpowerbutton_monitorswitch(writeq):
|
def argonpowerbutton_monitorswitch(writeq):
|
||||||
|
LINE_SHUTDOWN=4
|
||||||
|
argonpowerbutton_watchline("button-switch", writeq, LINE_SHUTDOWN, argonpowerbutton_monitorswitchevent)
|
||||||
|
|
||||||
try:
|
# Testing
|
||||||
# Reference https://github.com/brgl/libgpiod/blob/master/bindings/python/examples/gpiomon.py
|
#argonpowerbutton_monitor(None)
|
||||||
|
|
||||||
# Pin Assignments
|
|
||||||
LINE_SHUTDOWN=4
|
|
||||||
try:
|
|
||||||
# Pi5 mapping
|
|
||||||
chip = gpiod.Chip('4')
|
|
||||||
except Exception as gpioerr:
|
|
||||||
# Old mapping
|
|
||||||
chip = gpiod.Chip('0')
|
|
||||||
|
|
||||||
lineobj = chip.get_line(LINE_SHUTDOWN)
|
|
||||||
lineobj.request(consumer="argon", type=gpiod.LINE_REQ_EV_BOTH_EDGES)
|
|
||||||
while True:
|
|
||||||
hasevent = lineobj.event_wait(10)
|
|
||||||
if hasevent:
|
|
||||||
pulsetime = 0
|
|
||||||
eventdata = lineobj.event_read()
|
|
||||||
if eventdata.type == gpiod.LineEvent.RISING_EDGE:
|
|
||||||
# Time pulse data
|
|
||||||
while lineobj.get_value() == 1:
|
|
||||||
time.sleep(0.01)
|
|
||||||
pulsetime += 1
|
|
||||||
|
|
||||||
if pulsetime >= 10:
|
|
||||||
writeq.put("OLEDSWITCH")
|
|
||||||
lineobj.release()
|
|
||||||
chip.close()
|
|
||||||
except Exception:
|
|
||||||
writeq.put("ERROR")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user