添加电源管理支持

USB HID 继电器支持
GPIO 添加初始文件
This commit is contained in:
mofeng-git
2024-10-02 12:55:48 +00:00
parent 758ba42838
commit 0f39312eac
9 changed files with 144 additions and 8 deletions

17
configs/kvmd/custom_atx/gpio.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
case $1 in
short)
gpioset -m time -s 1 SHUTDOWNPIN=0
gpioset SHUTDOWNPIN=1
;;
long)
gpioset -m time -s 5 SHUTDOWNPIN=0
gpioset SHUTDOWNPIN=1
;;
reset)
gpioset -m time -s 1 REBOOTPIN=0
gpioset REBOOTPIN=1
;;
*)
echo "No thing."
esac

View File

@@ -0,0 +1,52 @@
import sys
import hid
VENDOR_ID = 0x5131
PRODUCT_ID = 0x2007
def find_usbrelay():
for device in hid.enumerate():
if device.get("vendor_id") == VENDOR_ID and device.get("product_id") == PRODUCT_ID:
return device
return None
def send_command(device_info, channel, onoff):
device = hid.device()
device.open(device_info['vendor_id'], device_info['product_id'])
if device is None:
print("Failed to open device.")
return
try:
cmd = [0xA0, channel, onoff, 0xA0 + channel + onoff]
device.write(bytearray(cmd))
finally:
device.close()
def main():
if len(sys.argv) != 3:
print("Usage:\n"
"\tpython script.py id on|off")
return
try:
id = int(sys.argv[1])
if sys.argv[2].lower() == 'on':
onoff = 1
elif sys.argv[2].lower() == 'off':
onoff = 0
else:
raise ValueError
except ValueError:
print("Invalid command, use 'on' or 'off'")
return
device_info = find_usbrelay()
if device_info is None:
print("USB relay not found")
else:
send_command(device_info, id, onoff)
print(f"Sent command to channel {id}: {'ON' if onoff else 'OFF'}")
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,20 @@
#!/bin/bash
case $1 in
short)
python3 /etc/kvmd/custom_atx/usbrelay_hid.py 1 on
sleep 1
python3 /etc/kvmd/custom_atx/usbrelay_hid.py 1 off
;;
long)
python3 /etc/kvmd/custom_atx/usbrelay_hid.py 1 on
sleep 5
python3 /etc/kvmd/custom_atx/usbrelay_hid.py 1 off
;;
reset)
python3 /etc/kvmd/custom_atx/usbrelay_hid.py 2 on
sleep 1
python3 /etc/kvmd/custom_atx/usbrelay_hid.py 2 off
;;
*)
echo "No thing."
esac