Update from the argon40 site the latest python code
0
pythonscript/Latest/argon-uninstall.sh → pythonscript/latest/argon-uninstall.sh
Executable file → Normal file
0
pythonscript/Latest/argon-versioninfo.sh → pythonscript/latest/argon-versioninfo.sh
Executable file → Normal file
5
pythonscript/Latest/argondashboard.py → pythonscript/latest/argondashboard.py
Executable file → Normal file
@@ -368,4 +368,7 @@ def mainloop(stdscr):
|
||||
except Exception as closeerr:
|
||||
pass
|
||||
|
||||
curses.wrapper(mainloop)
|
||||
try:
|
||||
curses.wrapper(mainloop)
|
||||
except Exception as wrapperr:
|
||||
pass
|
||||
670
pythonscript/latest/argonkeyboard.py
Normal file
@@ -0,0 +1,670 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
#
|
||||
# This script monitor battery via ic2 and keyboard events.
|
||||
#
|
||||
# Additional comments are found in each function below
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
from evdev import InputDevice, categorize, ecodes, list_devices
|
||||
from select import select
|
||||
|
||||
|
||||
import subprocess
|
||||
|
||||
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
|
||||
from threading import Thread
|
||||
from queue import Queue
|
||||
|
||||
|
||||
UPS_LOGFILE="/dev/shm/upslog.txt"
|
||||
KEYBOARD_LOCKFILE="/dev/shm/argononeupkeyboardlock.txt"
|
||||
|
||||
###################
|
||||
# Utilty Functions
|
||||
###################
|
||||
|
||||
# Debug Logger
|
||||
def debuglog(typestr, logstr):
|
||||
try:
|
||||
DEBUGFILE="/dev/shm/argononeupkeyboarddebuglog.txt"
|
||||
tmpstrpadding = " "
|
||||
|
||||
with open(DEBUGFILE, "a") as txt_file:
|
||||
txt_file.write("["+time.asctime(time.localtime(time.time()))+"] "+typestr.upper()+" "+logstr.strip().replace("\n","\n"+tmpstrpadding)+"\n")
|
||||
except:
|
||||
pass
|
||||
|
||||
def runcmdlist(key, cmdlist):
|
||||
try:
|
||||
result = subprocess.run(cmdlist,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
#debuglog(key+"-result-output",str(result.stdout))
|
||||
if result.stderr:
|
||||
debuglog(key+"-result-error",str(result.stderr))
|
||||
#debuglog(key+"-result-code",str(result.returncode))
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
debuglog(key+"-error-output",str(e.stdout))
|
||||
if result.stderr:
|
||||
debuglog(key+"-error-error",str(e.stderr))
|
||||
debuglog(key+"-error-code",str(e.returncode))
|
||||
except FileNotFoundError:
|
||||
debuglog(key+"-error-filenotfound","Command Not Found")
|
||||
except Exception as othererr:
|
||||
try:
|
||||
debuglog(key+"-error-other", str(othererr))
|
||||
except:
|
||||
debuglog(key+"-error-other", "Other Error")
|
||||
|
||||
def createlockfile(fname):
|
||||
try:
|
||||
if os.path.isfile(fname):
|
||||
return True
|
||||
except Exception as checklockerror:
|
||||
try:
|
||||
debuglog("keyboard-lock-error", str(checklockerror))
|
||||
except:
|
||||
debuglog("keyboard-lock-error", "Error Checking Lock File")
|
||||
try:
|
||||
with open(fname, "w") as txt_file:
|
||||
txt_file.write(time.asctime(time.localtime(time.time()))+"\n")
|
||||
except Exception as lockerror:
|
||||
try:
|
||||
debuglog("keyboard-lock-error", str(lockerror))
|
||||
except:
|
||||
debuglog("keyboard-lock-error", "Error Creating Lock File")
|
||||
return False
|
||||
|
||||
def deletelockfile(fname):
|
||||
try:
|
||||
os.remove(fname)
|
||||
except Exception as lockerror:
|
||||
try:
|
||||
debuglog("keyboard-lock-error", str(lockerror))
|
||||
except:
|
||||
debuglog("keyboard-lock-error", "Error Removing Lock File")
|
||||
|
||||
|
||||
# System Notifcation
|
||||
def notifymessage(message, iscritical):
|
||||
if not isinstance(message, str) or len(message.strip()) == 0:
|
||||
return
|
||||
|
||||
wftype="notify"
|
||||
if iscritical:
|
||||
wftype="critical"
|
||||
os.system("export SUDO_UID=1000; wfpanelctl "+wftype+" \""+message+"\"")
|
||||
os.system("export DISPLAY=:0.0; lxpanelctl notify \""+message+"\"")
|
||||
|
||||
|
||||
#############
|
||||
# Battery (copied)
|
||||
#############
|
||||
|
||||
def battery_loadlogdata():
|
||||
# status, version, time, schedule
|
||||
outobj = {}
|
||||
try:
|
||||
fp = open(UPS_LOGFILE, "r")
|
||||
logdata = fp.read()
|
||||
alllines = logdata.split("\n")
|
||||
ctr = 0
|
||||
while ctr < len(alllines):
|
||||
tmpval = alllines[ctr].strip()
|
||||
curinfo = tmpval.split(":")
|
||||
if len(curinfo) > 1:
|
||||
tmpattrib = curinfo[0].lower().split(" ")
|
||||
# The rest are assumed to be value
|
||||
outobj[tmpattrib[0]] = tmpval[(len(curinfo[0])+1):].strip()
|
||||
ctr = ctr + 1
|
||||
except Exception as einit:
|
||||
try:
|
||||
debuglog("keyboard-battery-error", str(einit))
|
||||
except:
|
||||
debuglog("keyboard-battery-error", "Error getting battery status")
|
||||
#pass
|
||||
|
||||
return outobj
|
||||
|
||||
|
||||
def keyboardevent_getdevicepaths():
|
||||
outlist = []
|
||||
try:
|
||||
for path in list_devices():
|
||||
try:
|
||||
tmpdevice = InputDevice(path)
|
||||
keyeventlist = tmpdevice.capabilities().get(ecodes.EV_KEY, [])
|
||||
# Keyboard has EV_KEY (key) and EV_REP (autorepeat)
|
||||
if ecodes.KEY_BRIGHTNESSDOWN in keyeventlist and ecodes.KEY_BRIGHTNESSDOWN in keyeventlist:
|
||||
outlist.append(path)
|
||||
elif ecodes.KEY_F2 in keyeventlist and ecodes.KEY_F3 in keyeventlist:
|
||||
# Keyboards with FN key sometimes do not include KEY_BRIGHTNESS in declaration
|
||||
outlist.append(path)
|
||||
tmpdevice.close()
|
||||
except:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
return outlist
|
||||
|
||||
def keyboardevent_devicechanged(curlist, newlist):
|
||||
try:
|
||||
for curpath in curlist:
|
||||
if curpath not in newlist:
|
||||
return True
|
||||
for newpath in newlist:
|
||||
if newpath not in curlist:
|
||||
return True
|
||||
except:
|
||||
pass
|
||||
return False
|
||||
|
||||
def keyboardevent_getbrigthnessinfo(defaultlevel=50):
|
||||
level = defaultlevel
|
||||
try:
|
||||
# VCP code x10(Brightness ): current value = 90, max value = 100
|
||||
output = subprocess.check_output(["ddcutil", "getvcp", "10"], text=True, stderr=subprocess.DEVNULL)
|
||||
debuglog("keyboard-brightness-info", output)
|
||||
level = int(output.split(":")[-1].split(",")[0].split("=")[-1].strip())
|
||||
except Exception as einit:
|
||||
try:
|
||||
debuglog("keyboard-brightness-error", str(einit))
|
||||
except:
|
||||
debuglog("keyboard-brightness-error", "Error getting base value")
|
||||
|
||||
|
||||
return {
|
||||
"level": level
|
||||
}
|
||||
|
||||
|
||||
def keyboardevent_adjustbrigthness(baselevel, adjustval=5):
|
||||
curlevel = baselevel
|
||||
if adjustval == 0:
|
||||
return {
|
||||
"level": baselevel
|
||||
}
|
||||
|
||||
try:
|
||||
tmpobj = keyboardevent_getbrigthnessinfo(curlevel)
|
||||
curlevel = tmpobj["level"]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
tmpval = max(10, min(100, curlevel + adjustval))
|
||||
if tmpval != curlevel:
|
||||
try:
|
||||
debuglog("keyboard-brightness", str(curlevel)+"% to "+str(tmpval)+"%")
|
||||
runcmdlist("brightness", ["ddcutil", "setvcp", "10", str(tmpval)])
|
||||
notifymessage("Brightness: "+str(tmpval)+"%", False)
|
||||
except Exception as adjusterr:
|
||||
try:
|
||||
debuglog("keyboard-brightness-error", str(adjusterr))
|
||||
except:
|
||||
debuglog("keyboard-brightness-error", "Error adjusting value")
|
||||
return {
|
||||
"level": curlevel
|
||||
}
|
||||
|
||||
# DEBUG: Checking
|
||||
#keyboardevent_getbrigthnessinfo(tmpval)
|
||||
return {
|
||||
"level": tmpval
|
||||
}
|
||||
|
||||
|
||||
def keyboardevent_getvolumesinkid(usedefault=True):
|
||||
if usedefault == True:
|
||||
return "@DEFAULT_SINK@"
|
||||
cursinkid = 0
|
||||
try:
|
||||
output = subprocess.check_output(["wpctl", "status"], text=True, encoding='utf-8', stderr=subprocess.DEVNULL)
|
||||
|
||||
# Find Audio section
|
||||
tmpline = ""
|
||||
foundidx = 0
|
||||
lines = output.splitlines()
|
||||
lineidx = 0
|
||||
while lineidx < len(lines):
|
||||
tmpline = lines[lineidx].strip()
|
||||
if tmpline == "Audio":
|
||||
foundidx = lineidx
|
||||
break
|
||||
lineidx = lineidx + 1
|
||||
|
||||
if foundidx < 1:
|
||||
return 0
|
||||
|
||||
# Find Sinks section
|
||||
foundidx = 0
|
||||
lineidx = lineidx + 1
|
||||
while lineidx < len(lines):
|
||||
if "Sinks:" in lines[lineidx]:
|
||||
foundidx = lineidx
|
||||
break
|
||||
elif len(lines[lineidx]) < 1:
|
||||
break
|
||||
lineidx = lineidx + 1
|
||||
|
||||
if foundidx < 1:
|
||||
return 0
|
||||
|
||||
# Get find default id, or first id
|
||||
lineidx = lineidx + 1
|
||||
while lineidx < len(lines):
|
||||
if "vol:" in lines[lineidx] and "." in lines[lineidx]:
|
||||
tmpstr = lines[lineidx].split(".")[0]
|
||||
tmplist = tmpstr.split()
|
||||
if len(tmplist) > 1:
|
||||
if tmplist[len(tmplist)-2] == "*":
|
||||
return int(tmplist[len(tmplist)-1])
|
||||
if len(tmplist) > 0 and cursinkid < 1:
|
||||
cursinkid = int(tmplist[len(tmplist)-1])
|
||||
elif len(lines[lineidx]) < 3:
|
||||
break
|
||||
lineidx = lineidx + 1
|
||||
except Exception as einit:
|
||||
try:
|
||||
debuglog("keyboard-volume-error", str(einit))
|
||||
except:
|
||||
debuglog("keyboard-volume-error", "Error getting device ID")
|
||||
|
||||
return cursinkid
|
||||
|
||||
|
||||
def keyboardevent_getvolumeinfo(deviceidstr="", defaultlevel=50, defaultmuted=0):
|
||||
muted = defaultmuted
|
||||
level = defaultlevel
|
||||
try:
|
||||
if deviceidstr == "":
|
||||
audioidstr = str(keyboardevent_getvolumesinkid())
|
||||
if audioidstr == "0":
|
||||
debuglog("keyboard-volume-error", "Error getting device id")
|
||||
return {
|
||||
"level": defaultmuted,
|
||||
"muted": defaultlevel
|
||||
}
|
||||
|
||||
deviceidstr = audioidstr
|
||||
|
||||
output = subprocess.check_output(["wpctl", "get-volume", deviceidstr], text=True, stderr=subprocess.DEVNULL)
|
||||
debuglog("keyboard-volume-info", output)
|
||||
|
||||
muted = 0
|
||||
level = 0
|
||||
# Parse output, examples
|
||||
# Volume: 0.65
|
||||
# Volume: 0.55 [MUTED]
|
||||
outlist = output.split()
|
||||
if len(outlist) > 0:
|
||||
# Get last element
|
||||
tmpstr = outlist[len(outlist)-1]
|
||||
# Check if muted
|
||||
if "MUTE" in tmpstr:
|
||||
muted = 1
|
||||
if len(outlist) > 1:
|
||||
tmpstr = outlist[len(outlist)-2]
|
||||
if tmpstr.endswith("%"):
|
||||
# Level 100% to 0%
|
||||
level = int(float(tmpstr[:-1]))
|
||||
elif tmpstr.replace('.', '').isdigit():
|
||||
# Level 1.00 to 0.00
|
||||
level = int(float(tmpstr) * 100.0)
|
||||
except Exception as einit:
|
||||
try:
|
||||
debuglog("keyboard-volume-error", str(einit))
|
||||
except:
|
||||
debuglog("keyboard-volume-error", "Error getting base value")
|
||||
return {
|
||||
"level": defaultmuted,
|
||||
"muted": defaultlevel
|
||||
}
|
||||
|
||||
#debuglog("keyboard-volume-get", str(level)+"% Mute:"+str(muted))
|
||||
|
||||
return {
|
||||
"level": level,
|
||||
"muted": muted
|
||||
}
|
||||
|
||||
|
||||
def keyboardevent_adjustvolume(baselevel, basemuted, adjustval=5):
|
||||
curlevel = baselevel
|
||||
curmuted = basemuted
|
||||
needsnotification = False
|
||||
|
||||
deviceidstr = str(keyboardevent_getvolumesinkid())
|
||||
if deviceidstr == "0":
|
||||
debuglog("keyboard-volume-error", "Error getting device id")
|
||||
return {
|
||||
"level": baselevel,
|
||||
"muted": basemuted
|
||||
}
|
||||
|
||||
try:
|
||||
tmpobj = keyboardevent_getvolumeinfo(deviceidstr, curlevel, curmuted)
|
||||
curlevel = tmpobj["level"]
|
||||
curmuted = tmpobj["muted"]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
tmpmuted = curmuted
|
||||
if adjustval == 0:
|
||||
# Toggle Mute
|
||||
if curmuted == 0:
|
||||
tmpmuted = 1
|
||||
else:
|
||||
tmpmuted = 0
|
||||
|
||||
tmpval = max(10, min(100, curlevel + adjustval))
|
||||
if tmpval != curlevel:
|
||||
try:
|
||||
debuglog("keyboard-volume", str(curlevel)+"% to "+str(tmpval)+"%")
|
||||
runcmdlist("volume", ["wpctl", "set-volume", deviceidstr, f"{tmpval}%"])
|
||||
needsnotification = True
|
||||
tmpmuted = 0
|
||||
except Exception as adjusterr:
|
||||
try:
|
||||
debuglog("keyboard-volume-error", str(adjusterr))
|
||||
except:
|
||||
debuglog("keyboard-volume-error", "Error adjusting value")
|
||||
return {
|
||||
"level": curlevel,
|
||||
"muted": curmuted
|
||||
}
|
||||
elif adjustval != 0:
|
||||
# To unmute even if no volume level change
|
||||
tmpmuted = 0
|
||||
|
||||
if tmpmuted != curmuted:
|
||||
try:
|
||||
debuglog("keyboard-mute", str(tmpmuted))
|
||||
runcmdlist("mute", ["wpctl", "set-mute", deviceidstr, str(tmpmuted)])
|
||||
needsnotification = True
|
||||
except Exception as adjusterr:
|
||||
try:
|
||||
debuglog("keyboard-mute-error", str(adjusterr))
|
||||
except:
|
||||
debuglog("keyboard-mute-error", "Error adjusting value")
|
||||
return {
|
||||
"level": tmpval,
|
||||
"muted": curmuted
|
||||
}
|
||||
#if tmpmuted == 1:
|
||||
# notifymessage("Volume: Muted", False)
|
||||
#else:
|
||||
# notifymessage("Volume: "+str(tmpval)+"%", False)
|
||||
|
||||
# DEBUG: Checking
|
||||
#keyboardevent_getvolumeinfo(deviceidstr, tmpval, tmpmuted)
|
||||
|
||||
return {
|
||||
"level": tmpval,
|
||||
"muted": tmpmuted
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def keyboardevent_check(readq):
|
||||
ADJUSTTYPE_NONE=0
|
||||
ADJUSTTYPE_BRIGHTNESS=1
|
||||
ADJUSTTYPE_VOLUME=2
|
||||
ADJUSTTYPE_MUTE=3
|
||||
ADJUSTTYPE_BATTERYINFO=4
|
||||
|
||||
READTIMEOUTSECS = 1.0
|
||||
|
||||
PRESSWAITINTERVALSEC = 2
|
||||
HOLDWAITINTERVALSEC = 1
|
||||
while True:
|
||||
try:
|
||||
keypresstimestamp = {}
|
||||
keyholdtimestamp = {}
|
||||
# Get Devices
|
||||
devicelist = []
|
||||
devicefdlist = []
|
||||
devicepathlist = keyboardevent_getdevicepaths()
|
||||
|
||||
deviceidx = 0
|
||||
while deviceidx < len(devicepathlist):
|
||||
try:
|
||||
tmpdevice = InputDevice(devicepathlist[deviceidx])
|
||||
devicelist.append(tmpdevice)
|
||||
devicefdlist.append(tmpdevice.fd)
|
||||
except Exception as deverr:
|
||||
try:
|
||||
debuglog("keyboard-deviceerror-", str(deverr)+ " "+ devicepathlist[deviceidx])
|
||||
except:
|
||||
debuglog("keyboard-deviceerror", "Error "+devicepathlist[deviceidx])
|
||||
deviceidx = deviceidx + 1
|
||||
|
||||
|
||||
# Get current levels
|
||||
curvolumemuted = 0
|
||||
curvolume = 50
|
||||
|
||||
curbrightness = 50
|
||||
|
||||
try:
|
||||
tmpobj = keyboardevent_getbrigthnessinfo()
|
||||
curbrightness = tmpobj["level"]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
tmpobj = keyboardevent_getvolumeinfo()
|
||||
curvolumemuted = tmpobj["muted"]
|
||||
curvolume = tmpobj["level"]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
debuglog("keyboard-update", str(len(devicefdlist))+" Devices")
|
||||
while len(devicefdlist) > 0:
|
||||
# Exception when one of the devices gets removed
|
||||
# Wait for events on any registered device
|
||||
r, w, x = select(devicefdlist, [], [], READTIMEOUTSECS)
|
||||
for fd in r:
|
||||
found = False
|
||||
deviceidx = 0
|
||||
while deviceidx < len(devicefdlist):
|
||||
if devicefdlist[deviceidx] == fd:
|
||||
found = True
|
||||
break
|
||||
deviceidx = deviceidx + 1
|
||||
if found:
|
||||
for event in devicelist[deviceidx].read():
|
||||
try:
|
||||
# Process the event
|
||||
#print("Device: "+devicelist[deviceidx].path+", Event: ", event)
|
||||
#debuglog("keyboard-event", "Device: "+devicelist[deviceidx].path+", Event: "+str(event))
|
||||
if event.type == ecodes.EV_KEY:
|
||||
key_event = categorize(event)
|
||||
keycodelist = []
|
||||
if event.value == 1 or event.value == 0:
|
||||
#debuglog("keyboard-event", "Mode:"+str(event.value)+" Key Code: "+str(key_event.keycode))
|
||||
|
||||
if isinstance(key_event.keycode, str):
|
||||
keycodelist = [key_event.keycode]
|
||||
else:
|
||||
keycodelist = key_event.keycode
|
||||
|
||||
keycodelistidx = 0
|
||||
while keycodelistidx < len(keycodelist):
|
||||
tmpkeycode = keycodelist[keycodelistidx]
|
||||
keycodelistidx = keycodelistidx + 1
|
||||
if tmpkeycode not in ["KEY_BRIGHTNESSDOWN", "KEY_BRIGHTNESSUP", "KEY_VOLUMEDOWN", "KEY_VOLUMEUP"]:
|
||||
if event.value == 0:
|
||||
# Hold for unhandled keys
|
||||
continue
|
||||
elif tmpkeycode not in ["KEY_PAUSE", "KEY_MUTE"]:
|
||||
# Press for unhandled keys
|
||||
continue
|
||||
|
||||
adjustval = 0
|
||||
adjusttype = ADJUSTTYPE_NONE
|
||||
|
||||
if event.value == 1:
|
||||
# Press
|
||||
debuglog("keyboard-event", "Press Key Code: "+str(tmpkeycode))
|
||||
|
||||
tmptime = time.time()
|
||||
# Guard time for press
|
||||
if tmpkeycode not in ["KEY_MUTE"]:
|
||||
# Buttons w/o guard time
|
||||
keypresstimestamp[tmpkeycode] = tmptime
|
||||
elif tmpkeycode in keypresstimestamp:
|
||||
if (tmptime - keypresstimestamp[tmpkeycode]) >= PRESSWAITINTERVALSEC:
|
||||
keypresstimestamp[tmpkeycode] = tmptime
|
||||
else:
|
||||
continue
|
||||
else:
|
||||
# First Press
|
||||
keypresstimestamp[tmpkeycode] = tmptime
|
||||
|
||||
if tmpkeycode == "KEY_BRIGHTNESSDOWN" or tmpkeycode == "KEY_BRIGHTNESSUP":
|
||||
adjusttype = ADJUSTTYPE_BRIGHTNESS
|
||||
if tmpkeycode == "KEY_BRIGHTNESSDOWN":
|
||||
adjustval = -5
|
||||
else:
|
||||
adjustval = 5
|
||||
elif tmpkeycode == "KEY_VOLUMEDOWN" or tmpkeycode == "KEY_VOLUMEUP":
|
||||
adjusttype = ADJUSTTYPE_VOLUME
|
||||
if tmpkeycode == "KEY_VOLUMEDOWN":
|
||||
adjustval = -5
|
||||
else:
|
||||
adjustval = 5
|
||||
elif tmpkeycode == "KEY_PAUSE":
|
||||
adjusttype = ADJUSTTYPE_BATTERYINFO
|
||||
elif tmpkeycode == "KEY_MUTE":
|
||||
adjusttype = ADJUSTTYPE_MUTE
|
||||
adjustval = 0
|
||||
|
||||
elif event.value == 0:
|
||||
# Hold
|
||||
debuglog("keyboard-event", "Hold Key Code: "+str(tmpkeycode))
|
||||
|
||||
tmptime = time.time()
|
||||
if tmpkeycode in keypresstimestamp:
|
||||
# Guard time before first for hold
|
||||
if (tmptime - keypresstimestamp[tmpkeycode]) >= PRESSWAITINTERVALSEC:
|
||||
# Guard time for hold
|
||||
if tmpkeycode in keyholdtimestamp:
|
||||
if (tmptime - keyholdtimestamp[tmpkeycode]) >= HOLDWAITINTERVALSEC:
|
||||
keyholdtimestamp[tmpkeycode] = tmptime
|
||||
else:
|
||||
continue
|
||||
else:
|
||||
# First Hold event
|
||||
keyholdtimestamp[tmpkeycode] = tmptime
|
||||
else:
|
||||
continue
|
||||
else:
|
||||
# Should not happen, but treat as if first press
|
||||
keypresstimestamp[tmpkeycode] = tmptime
|
||||
|
||||
if tmpkeycode == "KEY_BRIGHTNESSDOWN" or tmpkeycode == "KEY_BRIGHTNESSUP":
|
||||
adjusttype = ADJUSTTYPE_BRIGHTNESS
|
||||
if tmpkeycode == "KEY_BRIGHTNESSDOWN":
|
||||
adjustval = -10
|
||||
else:
|
||||
adjustval = 10
|
||||
elif tmpkeycode == "KEY_VOLUMEDOWN" or tmpkeycode == "KEY_VOLUMEUP":
|
||||
adjusttype = ADJUSTTYPE_VOLUME
|
||||
if tmpkeycode == "KEY_VOLUMEDOWN":
|
||||
adjustval = -10
|
||||
else:
|
||||
adjustval = 10
|
||||
|
||||
|
||||
|
||||
tmplockfilea = KEYBOARD_LOCKFILE+".a"
|
||||
if createlockfile(tmplockfilea) == False:
|
||||
# Debug ONLY
|
||||
if event.value == 1:
|
||||
debuglog("keyboard-event", "Press Key Code: "+str(tmpkeycode)+ " => "+str(adjusttype))
|
||||
else:
|
||||
debuglog("keyboard-event", "Hold Key Code: "+str(tmpkeycode)+ " => "+str(adjusttype))
|
||||
|
||||
if adjusttype == ADJUSTTYPE_BRIGHTNESS:
|
||||
try:
|
||||
tmpobj = keyboardevent_adjustbrigthness(curbrightness, adjustval)
|
||||
curbrightness = tmpobj["level"]
|
||||
except Exception:
|
||||
pass
|
||||
elif adjusttype == ADJUSTTYPE_VOLUME or adjusttype == ADJUSTTYPE_MUTE:
|
||||
try:
|
||||
tmpobj = keyboardevent_adjustvolume(curvolume, curvolumemuted, adjustval)
|
||||
curvolumemuted = tmpobj["muted"]
|
||||
curvolume = tmpobj["level"]
|
||||
except Exception:
|
||||
pass
|
||||
elif adjusttype == ADJUSTTYPE_BATTERYINFO:
|
||||
outobj = battery_loadlogdata()
|
||||
try:
|
||||
notifymessage(outobj["power"], False)
|
||||
except:
|
||||
pass
|
||||
deletelockfile(tmplockfilea)
|
||||
|
||||
except Exception as keyhandleerr:
|
||||
try:
|
||||
debuglog("keyboard-keyerror", str(keyhandleerr))
|
||||
except:
|
||||
debuglog("keyboard-keyerror", "Error")
|
||||
|
||||
else:
|
||||
# No events received within the timeout
|
||||
pass
|
||||
newpathlist = keyboardevent_getdevicepaths()
|
||||
if keyboardevent_devicechanged(devicepathlist, newpathlist):
|
||||
debuglog("keyboard-update", "Device list changed")
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
try:
|
||||
debuglog("keyboard-mainerror", str(e))
|
||||
except:
|
||||
debuglog("keyboard-mainerror", "Error")
|
||||
|
||||
# Close devices
|
||||
while len(devicelist) > 0:
|
||||
tmpdevice = devicelist.pop(0)
|
||||
try:
|
||||
tmpdevice.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
except Exception as mainerr:
|
||||
time.sleep(10)
|
||||
# While True
|
||||
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
cmd = sys.argv[1].upper()
|
||||
if cmd == "SERVICE":
|
||||
if createlockfile(KEYBOARD_LOCKFILE) == True:
|
||||
debuglog("keyboard-service", "Already running")
|
||||
else:
|
||||
try:
|
||||
debuglog("keyboard-service", "Service Starting")
|
||||
keyboardevent_check("")
|
||||
except Exception as einit:
|
||||
try:
|
||||
debuglog("keyboard-service-error", str(einit))
|
||||
except:
|
||||
debuglog("keyboard-service-error", "Error")
|
||||
checklockerror(KEYBOARD_LOCKFILE)
|
||||
debuglog("keyboard-service", "Service Stopped")
|
||||
0
pythonscript/Latest/argononeup-eepromconfig.py → pythonscript/latest/argononeup-eepromconfig.py
Executable file → Normal file
114
pythonscript/latest/argononeup-lidconfig.sh
Normal file
@@ -0,0 +1,114 @@
|
||||
#!/bin/bash
|
||||
|
||||
tmpfile="/dev/shm/argontmpconf.txt"
|
||||
daemonconfigfile="/etc/argononeupd.conf"
|
||||
|
||||
if [ -f "$daemonconfigfile" ]
|
||||
then
|
||||
. $daemonconfigfile
|
||||
fi
|
||||
|
||||
if [ -z "$lidshutdownsecs" ]
|
||||
then
|
||||
lidshutdownsecs=0
|
||||
fi
|
||||
|
||||
|
||||
mainloopflag=1
|
||||
newmode=0
|
||||
|
||||
|
||||
get_number () {
|
||||
read curnumber
|
||||
if [ -z "$curnumber" ]
|
||||
then
|
||||
echo "-2"
|
||||
return
|
||||
elif [[ $curnumber =~ ^[+-]?[0-9]+$ ]]
|
||||
then
|
||||
if [ $curnumber -lt 0 ]
|
||||
then
|
||||
echo "-1"
|
||||
return
|
||||
fi
|
||||
echo $curnumber
|
||||
return
|
||||
fi
|
||||
echo "-1"
|
||||
return
|
||||
}
|
||||
|
||||
while [ $mainloopflag -eq 1 ]
|
||||
do
|
||||
|
||||
lidshutdownmins=$((lidshutdownsecs / 60))
|
||||
|
||||
|
||||
echo "------------------------------------------"
|
||||
echo " Argon One Up Lid Configuration Tool"
|
||||
echo "------------------------------------------"
|
||||
|
||||
echo
|
||||
echo "Lid Close Behavior:"
|
||||
if [ $lidshutdownsecs -lt 1 ]
|
||||
then
|
||||
echo "(Do Nothing)"
|
||||
else
|
||||
echo "(Shut down after $lidshutdownmins minute(s))"
|
||||
fi
|
||||
echo " 1. Do Nothing"
|
||||
echo " 2. Shutdown"
|
||||
echo
|
||||
echo " 0. Exit"
|
||||
echo "NOTE: You can also edit $daemonconfigfile directly"
|
||||
echo -n "Enter Number (0-2):"
|
||||
newmode=$( get_number )
|
||||
|
||||
if [[ $newmode -eq 0 ]]
|
||||
then
|
||||
mainloopflag=0
|
||||
elif [ $newmode -eq 1 ]
|
||||
then
|
||||
lidshutdownsecs=0
|
||||
elif [ $newmode -eq 2 ]
|
||||
then
|
||||
maxmins=120
|
||||
echo "Please provide number of minutes until shutdown:"
|
||||
echo -n "Enter Number (1-$maxmins):"
|
||||
curval=$( get_number )
|
||||
if [ $curval -gt $maxmins ]
|
||||
then
|
||||
newmode=0
|
||||
echo "Invalid input"
|
||||
elif [ $curval -lt 1 ]
|
||||
then
|
||||
newmode=0
|
||||
echo "Invalid input"
|
||||
else
|
||||
lidshutdownsecs=$((curval * 60))
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $newmode -eq 1 ] || [ $newmode -eq 2 ]
|
||||
then
|
||||
if [ -f "$daemonconfigfile" ]
|
||||
then
|
||||
grep -v 'lidshutdownsecs' "$daemonconfigfile" > $tmpfile
|
||||
else
|
||||
echo '#' > $tmpfile
|
||||
echo '# Argon One Up Configuration' >> $tmpfile
|
||||
echo '#' >> $tmpfile
|
||||
fi
|
||||
echo '# lidshutdownsecs number of seconds till shutdown when lid is closed 0 if do nothing' >> $tmpfile
|
||||
echo "lidshutdownsecs=$lidshutdownsecs" >> $tmpfile
|
||||
|
||||
sudo cp $tmpfile $daemonconfigfile
|
||||
sudo chmod 666 $daemonconfigfile
|
||||
|
||||
echo "Configuration updated."
|
||||
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
|
||||
65
pythonscript/Latest/argononeup.sh → pythonscript/latest/argononeup.sh
Executable file → Normal file
@@ -44,7 +44,6 @@ versioninfoscript=$INSTALLATIONFOLDER/argon-versioninfo.sh
|
||||
|
||||
uninstallscript=$INSTALLATIONFOLDER/argon-uninstall.sh
|
||||
configscript=$INSTALLATIONFOLDER/argon-config
|
||||
unitconfigscript=$INSTALLATIONFOLDER/argon-unitconfig.sh
|
||||
argondashboardscript=$INSTALLATIONFOLDER/argondashboard.py
|
||||
|
||||
|
||||
@@ -85,6 +84,10 @@ set_nvme_default() {
|
||||
set_config_var dtparam=pciex1_gen 3 $CONFIG
|
||||
}
|
||||
|
||||
set_external_antenna() {
|
||||
set_config_var dtparam ant2 $CONFIG
|
||||
}
|
||||
|
||||
|
||||
argon_check_pkg() {
|
||||
RESULT=$(dpkg-query -W -f='${Status}\n' "$1" 2> /dev/null | grep "installed")
|
||||
@@ -143,6 +146,7 @@ fi
|
||||
|
||||
pkglist=($gpiopkg python3-smbus i2c-tools python3-evdev ddcutil)
|
||||
|
||||
echo "Installing/updating dependencies..."
|
||||
|
||||
for curpkg in ${pkglist[@]}; do
|
||||
sudo apt-get install -y $curpkg
|
||||
@@ -156,7 +160,7 @@ for curpkg in ${pkglist[@]}; do
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
echo "Updating configuration ..."
|
||||
|
||||
# Ubuntu Mate for RPi has raspi-config too
|
||||
command -v raspi-config &> /dev/null
|
||||
@@ -176,6 +180,28 @@ eepromrpiscript="/usr/bin/rpi-eeprom-config"
|
||||
eepromconfigscript=$INSTALLATIONFOLDER/${basename}-eepromconfig.py
|
||||
daemonscript=$INSTALLATIONFOLDER/$daemonname.py
|
||||
daemonservice=/lib/systemd/system/$daemonname.service
|
||||
userdaemonservice=/etc/systemd/user/${daemonname}user.service
|
||||
daemonconfigfile=/etc/$daemonname.conf
|
||||
|
||||
lidconfigscript=$INSTALLATIONFOLDER/${basename}-lidconfig.sh
|
||||
|
||||
echo "Installing/Updating scripts and services ..."
|
||||
|
||||
if [ ! -f $daemonconfigfile ]; then
|
||||
# Generate config file for fan speed
|
||||
sudo touch $daemonconfigfile
|
||||
sudo chmod 666 $daemonconfigfile
|
||||
echo '#' >> $daemonconfigfile
|
||||
echo '# Argon One Up Configuration' >> $daemonconfigfile
|
||||
echo '#' >> $daemonconfigfile
|
||||
echo '# lidshutdownsecs number of seconds till shutdown when lid is closed 0 if do nothing' >> $daemonconfigfile
|
||||
echo 'lidshutdownsecs=300' >> $daemonconfigfile
|
||||
fi
|
||||
|
||||
# Lid Config Script
|
||||
sudo wget $ARGONDOWNLOADSERVER/scripts/argononeup-lidconfig.sh -O $lidconfigscript --quiet
|
||||
sudo chmod 755 $lidconfigscript
|
||||
|
||||
|
||||
if [ -f "$eepromrpiscript" ]
|
||||
then
|
||||
@@ -189,6 +215,10 @@ sudo wget $ARGONDOWNLOADSERVER/scripts/${daemonname}.py -O $daemonscript --quiet
|
||||
sudo wget $ARGONDOWNLOADSERVER/scripts/${daemonname}.service -O $daemonservice --quiet
|
||||
sudo chmod 644 $daemonservice
|
||||
|
||||
sudo wget $ARGONDOWNLOADSERVER/scripts/${daemonname}user.service -O $userdaemonservice --quiet
|
||||
sudo chmod 644 $userdaemonservice
|
||||
|
||||
|
||||
# Battery Images
|
||||
if [ ! -d "$INSTALLATIONFOLDER/ups" ]
|
||||
then
|
||||
@@ -198,10 +228,12 @@ sudo wget $ARGONDOWNLOADSERVER/ups/upsimg.tar.gz -O $INSTALLATIONFOLDER/ups/upsi
|
||||
sudo tar xfz $INSTALLATIONFOLDER/ups/upsimg.tar.gz -C $INSTALLATIONFOLDER/ups/
|
||||
sudo rm -Rf $INSTALLATIONFOLDER/ups/upsimg.tar.gz
|
||||
|
||||
sudo wget "$ARGONDOWNLOADSERVER/scripts/argonpowerbutton-${CHECKGPIOMODE}.py" -O $INSTALLATIONFOLDER/argonpowerbutton.py --quiet
|
||||
|
||||
sudo wget $ARGONDOWNLOADSERVER/scripts/argonkeyboard.py -O $INSTALLATIONFOLDER/argonkeyboard.py --quiet
|
||||
|
||||
# Other utility scripts
|
||||
sudo wget $ARGONDOWNLOADSERVER/scripts/argondashboard.py -O $INSTALLATIONFOLDER/argondashboard.py --quiet
|
||||
sudo wget $ARGONDOWNLOADSERVER/scripts/argonpowerbutton.py -O $INSTALLATIONFOLDER/argonpowerbutton.py --quiet
|
||||
|
||||
sudo wget $ARGONDOWNLOADSERVER/scripts/argon-versioninfo.sh -O $versioninfoscript --quiet
|
||||
sudo chmod 755 $versioninfoscript
|
||||
@@ -264,7 +296,10 @@ echo ' echo "Choose Option:"' >> $configscript
|
||||
|
||||
|
||||
echo ' echo " 1. Get Battery Status"' >> $configscript
|
||||
uninstalloption="3"
|
||||
echo ' echo " 2. Configure Lid Behavior"' >> $configscript
|
||||
|
||||
|
||||
uninstalloption="4"
|
||||
|
||||
statusoption=$(($uninstalloption-1))
|
||||
echo " echo \" $statusoption. Dashboard\"" >> $configscript
|
||||
@@ -287,6 +322,12 @@ echo ' then' >> $configscript
|
||||
# Option 1
|
||||
echo " $pythonbin $daemonscript GETBATTERY" >> $configscript
|
||||
|
||||
echo ' elif [ $newmode -eq 2 ]' >> $configscript
|
||||
echo ' then' >> $configscript
|
||||
|
||||
# Option 2
|
||||
echo " $lidconfigscript" >> $configscript
|
||||
|
||||
# Standard options
|
||||
echo " elif [ \$newmode -eq $statusoption ]" >> $configscript
|
||||
echo ' then' >> $configscript
|
||||
@@ -315,6 +356,8 @@ fi
|
||||
shortcutfile="/home/$destfoldername/Desktop/argononeup.desktop"
|
||||
if [ -d "/home/$destfoldername/Desktop" ]
|
||||
then
|
||||
echo "Creating/Updating Desktop Elements ..."
|
||||
|
||||
terminalcmd="lxterminal --working-directory=/home/$destfoldername/ -t"
|
||||
if [ -f "/home/$destfoldername/.twisteros.twid" ]
|
||||
then
|
||||
@@ -341,6 +384,12 @@ fi
|
||||
|
||||
configcmd="$(basename -- $configscript)"
|
||||
|
||||
echo "Initializing Services ..."
|
||||
|
||||
# Force remove lock files
|
||||
sudo rm -f /dev/shm/argononeupkeyboardlock.txt
|
||||
sudo rm -f /dev/shm/argononeupkeyboardlock.txt.a
|
||||
|
||||
if [ "$setupmode" = "Setup" ]
|
||||
then
|
||||
if [ -f "/usr/bin/$configcmd" ]
|
||||
@@ -353,15 +402,23 @@ then
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable argononeupd.service
|
||||
sudo systemctl start argononeupd.service
|
||||
|
||||
# Enable and Start User Service(s)
|
||||
sudo systemctl --global enable argononeupduser.service
|
||||
sudo systemctl --global start argononeupduser.service
|
||||
|
||||
else
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl restart argononeupd.service
|
||||
|
||||
sudo systemctl --global restart argononeupduser.service
|
||||
fi
|
||||
|
||||
if [ "$CHECKPLATFORM" = "Raspbian" ]
|
||||
then
|
||||
if [ -f "$eepromrpiscript" ]
|
||||
then
|
||||
echo "Checking EEPROM ..."
|
||||
sudo apt-get update && sudo apt-get upgrade -y
|
||||
sudo rpi-eeprom-update
|
||||
# EEPROM Config Script
|
||||
4
pythonscript/Latest/argononeupd.py → pythonscript/latest/argononeupd.py
Executable file → Normal file
@@ -443,10 +443,10 @@ if len(sys.argv) > 1:
|
||||
if len(sys.argv) > 2:
|
||||
cmd = sys.argv[2].upper()
|
||||
t1 = Thread(target = battery_check, args =(ipcq, ))
|
||||
#t2 = Thread(target = argonpowerbutton_monitorlid, args =(ipcq, ))
|
||||
t2 = Thread(target = argonpowerbutton_monitorlid, args =(ipcq, ))
|
||||
|
||||
t1.start()
|
||||
#t2.start()
|
||||
t2.start()
|
||||
|
||||
ipcq.join()
|
||||
except Exception:
|
||||
10
pythonscript/latest/argononeupd.service
Normal file
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Argon ONE UP Service
|
||||
After=multi-user.target
|
||||
[Service]
|
||||
Type=simple
|
||||
Restart=always
|
||||
RemainAfterExit=true
|
||||
ExecStart=/usr/bin/python3 /etc/argon/argononeupd.py SERVICE
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
10
pythonscript/latest/argononeupduser.service
Normal file
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Argon ONE UP Service
|
||||
After=multi-user.target
|
||||
[Service]
|
||||
Type=simple
|
||||
Restart=always
|
||||
RemainAfterExit=true
|
||||
ExecStart=/usr/bin/python3 /etc/argon/argonkeyboard.py SERVICE
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
188
pythonscript/latest/argonpowerbutton.py
Normal file
@@ -0,0 +1,188 @@
|
||||
|
||||
# For Libreelec/Lakka, note that we need to add system paths
|
||||
# import sys
|
||||
# sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
|
||||
import gpiod
|
||||
import os
|
||||
import time
|
||||
|
||||
# Debug Logger
|
||||
def argonpowerbutton_debuglog(typestr, logstr):
|
||||
try:
|
||||
DEBUGFILE="/dev/shm/argononegpiodebuglog.txt"
|
||||
tmpstrpadding = " "
|
||||
|
||||
with open(DEBUGFILE, "a") as txt_file:
|
||||
txt_file.write("["+time.asctime(time.localtime(time.time()))+"] "+typestr.upper()+" "+logstr.strip().replace("\n","\n"+tmpstrpadding)+"\n")
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
def argonpowerbutton_getconfigval(keyname, datatype="int"):
|
||||
keyname = keyname.lower()
|
||||
fname = "/etc/argononeupd.conf"
|
||||
try:
|
||||
with open(fname, "r") as fp:
|
||||
for curline in fp:
|
||||
if not curline:
|
||||
continue
|
||||
tmpline = curline.replace(" ", "").replace("\t", "")
|
||||
if not tmpline:
|
||||
continue
|
||||
if tmpline[0] == "#":
|
||||
continue
|
||||
tmppair = tmpline.split("=")
|
||||
if len(tmppair) != 2:
|
||||
continue
|
||||
|
||||
tmpvar = tmppair[0].lower()
|
||||
if tmpvar != keyname:
|
||||
continue
|
||||
|
||||
try:
|
||||
if datatype == "int":
|
||||
return int(tmppair[1])
|
||||
elif datatype == "float":
|
||||
return float(tmppair[1])
|
||||
return tmppair[1]
|
||||
except:
|
||||
continue
|
||||
except:
|
||||
pass
|
||||
if datatype == "int":
|
||||
return -1
|
||||
elif datatype == "float":
|
||||
return -1
|
||||
return ""
|
||||
|
||||
def argonpowerbutton_monitorlid(writeq):
|
||||
try:
|
||||
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")
|
||||
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)
|
||||
pulsetimesec += 1
|
||||
argonpowerbutton_debuglog("lid-monitor", "Open Detected")
|
||||
|
||||
lineobj.release()
|
||||
chip.close()
|
||||
except Exception as liderror:
|
||||
try:
|
||||
argonpowerbutton_debuglog("lid-monitor-error", str(liderror))
|
||||
except:
|
||||
argonpowerbutton_debuglog("lid-monitor-error", "Error aborting")
|
||||
#pass
|
||||
|
||||
def argonpowerbutton_monitor(writeq):
|
||||
|
||||
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
|
||||
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")
|
||||
|
||||
|
||||
def argonpowerbutton_monitorswitch(writeq):
|
||||
|
||||
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
|
||||
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")
|
||||
0
pythonscript/Latest/argonregister.py → pythonscript/latest/argonregister.py
Executable file → Normal file
0
pythonscript/Latest/argonsysinfo.py → pythonscript/latest/argonsysinfo.py
Executable file → Normal file
35
pythonscript/latest/pull.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
ARGONDOWNLOADSERVER=http://files.iamnet.com.ph/argon/setup
|
||||
INSTALLATIONFOLDER=.
|
||||
CHECKGPIOMODE="libgpiod"
|
||||
basename="argononeup"
|
||||
daemonname=$basename"d"
|
||||
versioninfoscript=$INSTALLATIONFOLDER/argon-versioninfo.sh
|
||||
uninstallscript=$INSTALLATIONFOLDER/argon-uninstall.sh
|
||||
configscript=$INSTALLATIONFOLDER/argon-config
|
||||
argondashboardscript=$INSTALLATIONFOLDER/argondashboard.py
|
||||
eepromconfigscript=$INSTALLATIONFOLDER/${basename}-eepromconfig.py
|
||||
daemonscript=$INSTALLATIONFOLDER/$daemonname.py
|
||||
daemonservice=./$daemonname.service
|
||||
userdaemonservice=./${daemonname}user.service
|
||||
lidconfigscript=$INSTALLATIONFOLDER/${basename}-lidconfig.sh
|
||||
imagefile=argon40.png
|
||||
daemonconfigfile=$daemonname.conf
|
||||
|
||||
wget $ARGONDOWNLOADSERVER/argononeup.sh -O argononeup.sh
|
||||
wget $ARGONDOWNLOADSERVER/scripts/argononeup-lidconfig.sh -O $lidconfigscript
|
||||
wget $ARGONDOWNLOADSERVER/scripts/argon-rpi-eeprom-config-psu.py -O $eepromconfigscript
|
||||
wget $ARGONDOWNLOADSERVER/scripts/${daemonname}.py -O $daemonscript
|
||||
wget $ARGONDOWNLOADSERVER/scripts/${daemonname}.service -O $daemonservice
|
||||
wget $ARGONDOWNLOADSERVER/scripts/${daemonname}user.service -O $userdaemonservice
|
||||
mkdir -p $INSTALLATIONFOLDER/ups
|
||||
wget $ARGONDOWNLOADSERVER/ups/upsimg.tar.gz -O $INSTALLATIONFOLDER/ups/upsimg.tar.gz
|
||||
tar xfz $INSTALLATIONFOLDER/ups/upsimg.tar.gz -C $INSTALLATIONFOLDER/ups/
|
||||
rm -Rf $INSTALLATIONFOLDER/ups/upsimg.tar.gz
|
||||
wget "$ARGONDOWNLOADSERVER/scripts/argonpowerbutton-${CHECKGPIOMODE}.py" -O $INSTALLATIONFOLDER/argonpowerbutton.py
|
||||
wget $ARGONDOWNLOADSERVER/scripts/argonkeyboard.py -O $INSTALLATIONFOLDER/argonkeyboard.py
|
||||
wget $ARGONDOWNLOADSERVER/scripts/argondashboard.py -O $INSTALLATIONFOLDER/argondashboard.py
|
||||
wget $ARGONDOWNLOADSERVER/scripts/argon-versioninfo.sh -O $versioninfoscript
|
||||
wget $ARGONDOWNLOADSERVER/scripts/argonsysinfo.py -O $INSTALLATIONFOLDER/argonsysinfo.py
|
||||
wget $ARGONDOWNLOADSERVER/scripts/argonregister-v1.py -O $INSTALLATIONFOLDER/argonregister.py
|
||||
wget $ARGONDOWNLOADSERVER/scripts/argon-uninstall.sh -O $uninstallscript
|
||||
wget $ARGONDOWNLOADSERVER/argon40.png -O ./argon40.png
|
||||
BIN
pythonscript/latest/ups/charge_0.png
Normal file
|
After Width: | Height: | Size: 408 B |
BIN
pythonscript/latest/ups/charge_1.png
Normal file
|
After Width: | Height: | Size: 404 B |
BIN
pythonscript/latest/ups/charge_10.png
Normal file
|
After Width: | Height: | Size: 422 B |
BIN
pythonscript/latest/ups/charge_100.png
Normal file
|
After Width: | Height: | Size: 388 B |
BIN
pythonscript/latest/ups/charge_11.png
Normal file
|
After Width: | Height: | Size: 410 B |
BIN
pythonscript/latest/ups/charge_12.png
Normal file
|
After Width: | Height: | Size: 417 B |
BIN
pythonscript/latest/ups/charge_13.png
Normal file
|
After Width: | Height: | Size: 424 B |
BIN
pythonscript/latest/ups/charge_14.png
Normal file
|
After Width: | Height: | Size: 415 B |
BIN
pythonscript/latest/ups/charge_15.png
Normal file
|
After Width: | Height: | Size: 424 B |
BIN
pythonscript/latest/ups/charge_16.png
Normal file
|
After Width: | Height: | Size: 420 B |
BIN
pythonscript/latest/ups/charge_17.png
Normal file
|
After Width: | Height: | Size: 410 B |
BIN
pythonscript/latest/ups/charge_18.png
Normal file
|
After Width: | Height: | Size: 419 B |
BIN
pythonscript/latest/ups/charge_19.png
Normal file
|
After Width: | Height: | Size: 420 B |
BIN
pythonscript/latest/ups/charge_2.png
Normal file
|
After Width: | Height: | Size: 407 B |
BIN
pythonscript/latest/ups/charge_20.png
Normal file
|
After Width: | Height: | Size: 424 B |
BIN
pythonscript/latest/ups/charge_21.png
Normal file
|
After Width: | Height: | Size: 418 B |
BIN
pythonscript/latest/ups/charge_22.png
Normal file
|
After Width: | Height: | Size: 418 B |
BIN
pythonscript/latest/ups/charge_23.png
Normal file
|
After Width: | Height: | Size: 431 B |
BIN
pythonscript/latest/ups/charge_24.png
Normal file
|
After Width: | Height: | Size: 421 B |
BIN
pythonscript/latest/ups/charge_25.png
Normal file
|
After Width: | Height: | Size: 430 B |
BIN
pythonscript/latest/ups/charge_26.png
Normal file
|
After Width: | Height: | Size: 427 B |
BIN
pythonscript/latest/ups/charge_27.png
Normal file
|
After Width: | Height: | Size: 421 B |
BIN
pythonscript/latest/ups/charge_28.png
Normal file
|
After Width: | Height: | Size: 429 B |
BIN
pythonscript/latest/ups/charge_29.png
Normal file
|
After Width: | Height: | Size: 423 B |
BIN
pythonscript/latest/ups/charge_3.png
Normal file
|
After Width: | Height: | Size: 410 B |
BIN
pythonscript/latest/ups/charge_30.png
Normal file
|
After Width: | Height: | Size: 425 B |
BIN
pythonscript/latest/ups/charge_31.png
Normal file
|
After Width: | Height: | Size: 420 B |
BIN
pythonscript/latest/ups/charge_32.png
Normal file
|
After Width: | Height: | Size: 426 B |
BIN
pythonscript/latest/ups/charge_33.png
Normal file
|
After Width: | Height: | Size: 421 B |
BIN
pythonscript/latest/ups/charge_34.png
Normal file
|
After Width: | Height: | Size: 428 B |
BIN
pythonscript/latest/ups/charge_35.png
Normal file
|
After Width: | Height: | Size: 430 B |
BIN
pythonscript/latest/ups/charge_36.png
Normal file
|
After Width: | Height: | Size: 427 B |
BIN
pythonscript/latest/ups/charge_37.png
Normal file
|
After Width: | Height: | Size: 423 B |
BIN
pythonscript/latest/ups/charge_38.png
Normal file
|
After Width: | Height: | Size: 432 B |
BIN
pythonscript/latest/ups/charge_39.png
Normal file
|
After Width: | Height: | Size: 426 B |
BIN
pythonscript/latest/ups/charge_4.png
Normal file
|
After Width: | Height: | Size: 414 B |
BIN
pythonscript/latest/ups/charge_40.png
Normal file
|
After Width: | Height: | Size: 427 B |
BIN
pythonscript/latest/ups/charge_41.png
Normal file
|
After Width: | Height: | Size: 420 B |
BIN
pythonscript/latest/ups/charge_42.png
Normal file
|
After Width: | Height: | Size: 430 B |
BIN
pythonscript/latest/ups/charge_43.png
Normal file
|
After Width: | Height: | Size: 436 B |
BIN
pythonscript/latest/ups/charge_44.png
Normal file
|
After Width: | Height: | Size: 424 B |
BIN
pythonscript/latest/ups/charge_45.png
Normal file
|
After Width: | Height: | Size: 430 B |
BIN
pythonscript/latest/ups/charge_46.png
Normal file
|
After Width: | Height: | Size: 429 B |
BIN
pythonscript/latest/ups/charge_47.png
Normal file
|
After Width: | Height: | Size: 423 B |
BIN
pythonscript/latest/ups/charge_48.png
Normal file
|
After Width: | Height: | Size: 434 B |
BIN
pythonscript/latest/ups/charge_49.png
Normal file
|
After Width: | Height: | Size: 431 B |
BIN
pythonscript/latest/ups/charge_5.png
Normal file
|
After Width: | Height: | Size: 411 B |
BIN
pythonscript/latest/ups/charge_50.png
Normal file
|
After Width: | Height: | Size: 426 B |
BIN
pythonscript/latest/ups/charge_51.png
Normal file
|
After Width: | Height: | Size: 421 B |
BIN
pythonscript/latest/ups/charge_52.png
Normal file
|
After Width: | Height: | Size: 424 B |
BIN
pythonscript/latest/ups/charge_53.png
Normal file
|
After Width: | Height: | Size: 426 B |
BIN
pythonscript/latest/ups/charge_54.png
Normal file
|
After Width: | Height: | Size: 419 B |
BIN
pythonscript/latest/ups/charge_55.png
Normal file
|
After Width: | Height: | Size: 422 B |
BIN
pythonscript/latest/ups/charge_56.png
Normal file
|
After Width: | Height: | Size: 428 B |
BIN
pythonscript/latest/ups/charge_57.png
Normal file
|
After Width: | Height: | Size: 415 B |
BIN
pythonscript/latest/ups/charge_58.png
Normal file
|
After Width: | Height: | Size: 418 B |
BIN
pythonscript/latest/ups/charge_59.png
Normal file
|
After Width: | Height: | Size: 419 B |
BIN
pythonscript/latest/ups/charge_6.png
Normal file
|
After Width: | Height: | Size: 406 B |
BIN
pythonscript/latest/ups/charge_60.png
Normal file
|
After Width: | Height: | Size: 414 B |
BIN
pythonscript/latest/ups/charge_61.png
Normal file
|
After Width: | Height: | Size: 411 B |
BIN
pythonscript/latest/ups/charge_62.png
Normal file
|
After Width: | Height: | Size: 412 B |
BIN
pythonscript/latest/ups/charge_63.png
Normal file
|
After Width: | Height: | Size: 423 B |
BIN
pythonscript/latest/ups/charge_64.png
Normal file
|
After Width: | Height: | Size: 409 B |
BIN
pythonscript/latest/ups/charge_65.png
Normal file
|
After Width: | Height: | Size: 420 B |
BIN
pythonscript/latest/ups/charge_66.png
Normal file
|
After Width: | Height: | Size: 409 B |
BIN
pythonscript/latest/ups/charge_67.png
Normal file
|
After Width: | Height: | Size: 415 B |
BIN
pythonscript/latest/ups/charge_68.png
Normal file
|
After Width: | Height: | Size: 422 B |
BIN
pythonscript/latest/ups/charge_69.png
Normal file
|
After Width: | Height: | Size: 420 B |
BIN
pythonscript/latest/ups/charge_7.png
Normal file
|
After Width: | Height: | Size: 405 B |
BIN
pythonscript/latest/ups/charge_70.png
Normal file
|
After Width: | Height: | Size: 417 B |
BIN
pythonscript/latest/ups/charge_71.png
Normal file
|
After Width: | Height: | Size: 415 B |
BIN
pythonscript/latest/ups/charge_72.png
Normal file
|
After Width: | Height: | Size: 419 B |
BIN
pythonscript/latest/ups/charge_73.png
Normal file
|
After Width: | Height: | Size: 418 B |
BIN
pythonscript/latest/ups/charge_74.png
Normal file
|
After Width: | Height: | Size: 409 B |
BIN
pythonscript/latest/ups/charge_75.png
Normal file
|
After Width: | Height: | Size: 419 B |
BIN
pythonscript/latest/ups/charge_76.png
Normal file
|
After Width: | Height: | Size: 423 B |
BIN
pythonscript/latest/ups/charge_77.png
Normal file
|
After Width: | Height: | Size: 408 B |
BIN
pythonscript/latest/ups/charge_78.png
Normal file
|
After Width: | Height: | Size: 423 B |
BIN
pythonscript/latest/ups/charge_79.png
Normal file
|
After Width: | Height: | Size: 419 B |
BIN
pythonscript/latest/ups/charge_8.png
Normal file
|
After Width: | Height: | Size: 404 B |
BIN
pythonscript/latest/ups/charge_80.png
Normal file
|
After Width: | Height: | Size: 418 B |
BIN
pythonscript/latest/ups/charge_81.png
Normal file
|
After Width: | Height: | Size: 417 B |
BIN
pythonscript/latest/ups/charge_82.png
Normal file
|
After Width: | Height: | Size: 423 B |