Automated Change by GitHub Action

This commit is contained in:
okunze
2026-01-02 21:07:33 +00:00
committed by github-actions[bot]
parent c26498ae91
commit f0aeadea8b
2 changed files with 135 additions and 117 deletions

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
VERSIONINFO="2512002" VERSIONINFO="2512003"
echo "Version $VERSIONINFO" echo "Version $VERSIONINFO"
if [ -z "$1" ] if [ -z "$1" ]

View File

@@ -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,27 +131,8 @@ 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")
monitormode = True
# 0 - Lid is closed, 1 - Lid is open
# Pin Assignments
LINE_LIDMONITOR=27
try:
# Pi5 mapping
chip = gpiod.Chip('4')
except Exception as gpioerr:
# Old mapping
chip = gpiod.Chip('0')
lineobj = chip.get_line(LINE_LIDMONITOR)
lineobj.request(consumer="argon", type=gpiod.LINE_REQ_EV_BOTH_EDGES, flags=gpiod.LINE_REQ_FLAG_BIAS_PULL_UP)
while monitormode == True:
hasevent = lineobj.event_wait(10)
if hasevent:
eventdata = lineobj.event_read()
if eventdata.type == gpiod.LineEvent.FALLING_EDGE:
targetsecs = argonpowerbutton_getconfigval("lidshutdownsecs") targetsecs = argonpowerbutton_getconfigval("lidshutdownsecs")
if targetsecs > 0: if targetsecs > 0:
argonpowerbutton_debuglog("lid-monitor", "Close Detect; Wait for :"+str(targetsecs)) argonpowerbutton_debuglog("lid-monitor", "Close Detect; Wait for :"+str(targetsecs))
@@ -87,51 +141,29 @@ def argonpowerbutton_monitorlid(writeq):
# Time pulse data # Time pulse data
time.sleep(1) time.sleep(1)
pulsetimesec = 1 pulsetimesec = 1
while lineobj.get_value() == 0: # 0 - Lid is closed, 1 - Lid is open
while argonpowerbutton_getvalue(lineobj, lineid) == 0:
if targetsecs > 0: if targetsecs > 0:
if pulsetimesec >= targetsecs: if pulsetimesec >= targetsecs:
argonpowerbutton_debuglog("lid-monitor", "Target Reached, shutting down") argonpowerbutton_debuglog("lid-monitor", "Target Reached, shutting down")
monitormode = False monitormode = False
os.system("shutdown now -h") os.system("shutdown now -h")
break return False
time.sleep(1) time.sleep(1)
pulsetimesec += 1 pulsetimesec += 1
argonpowerbutton_debuglog("lid-monitor", "Open Detected") argonpowerbutton_debuglog("lid-monitor", "Open Detected")
return True
lineobj.release() def argonpowerbutton_monitorlid(writeq):
chip.close() LINE_LIDMONITOR=27
except Exception as liderror: argonpowerbutton_watchline("lid-monitor", writeq, LINE_LIDMONITOR, argonpowerbutton_monitorlidevent)
try:
argonpowerbutton_debuglog("lid-monitor-error", str(liderror))
except:
argonpowerbutton_debuglog("lid-monitor-error", "Error aborting")
#pass
def argonpowerbutton_monitor(writeq): def argonpowerbutton_monitorevent(isrising, lineobj, writeq, lineid):
try:
# Reference https://github.com/brgl/libgpiod/blob/master/bindings/python/examples/gpiomon.py
# 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 pulsetime = 0
eventdata = lineobj.event_read() if isrising == True:
if eventdata.type == gpiod.LineEvent.RISING_EDGE:
# Time pulse data # Time pulse data
while lineobj.get_value() == 1: while argonpowerbutton_getvalue(lineobj, lineid) == 1:
time.sleep(0.01) time.sleep(0.01)
pulsetime += 1 pulsetime += 1
@@ -140,49 +172,35 @@ def argonpowerbutton_monitor(writeq):
#writeq.put("OLEDSWITCH") #writeq.put("OLEDSWITCH")
writeq.put("OLEDSTOP") writeq.put("OLEDSTOP")
os.system("reboot") os.system("reboot")
break return False
elif pulsetime >=4 and pulsetime <=5: elif pulsetime >=4 and pulsetime <=5:
writeq.put("OLEDSTOP") writeq.put("OLEDSTOP")
os.system("shutdown now -h") os.system("shutdown now -h")
break return False
elif pulsetime >=6 and pulsetime <=7: elif pulsetime >=6 and pulsetime <=7:
writeq.put("OLEDSWITCH") writeq.put("OLEDSWITCH")
lineobj.release() return True
chip.close()
except Exception:
writeq.put("ERROR")
def argonpowerbutton_monitor(writeq):
def argonpowerbutton_monitorswitch(writeq):
try:
# Reference https://github.com/brgl/libgpiod/blob/master/bindings/python/examples/gpiomon.py
# Pin Assignments
LINE_SHUTDOWN=4 LINE_SHUTDOWN=4
try: argonpowerbutton_watchline("button", writeq, LINE_SHUTDOWN, argonpowerbutton_monitorevent)
# 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) def argonpowerbutton_monitorswitchevent(isrising, lineobj, writeq, lineid):
while True:
hasevent = lineobj.event_wait(10)
if hasevent:
pulsetime = 0 pulsetime = 0
eventdata = lineobj.event_read() if isrising == True:
if eventdata.type == gpiod.LineEvent.RISING_EDGE:
# Time pulse data # Time pulse data
while lineobj.get_value() == 1: while argonpowerbutton_getvalue(lineobj, lineid) == 1:
time.sleep(0.01) time.sleep(0.01)
pulsetime += 1 pulsetime += 1
if pulsetime >= 10: if pulsetime >= 10:
writeq.put("OLEDSWITCH") writeq.put("OLEDSWITCH")
lineobj.release() return True
chip.close()
except Exception: def argonpowerbutton_monitorswitch(writeq):
writeq.put("ERROR") LINE_SHUTDOWN=4
argonpowerbutton_watchline("button-switch", writeq, LINE_SHUTDOWN, argonpowerbutton_monitorswitchevent)
# Testing
#argonpowerbutton_monitor(None)