···
#!/bin/bash
cd /sys/kernel/config/usb_gadget/
mkdir -p isticktoit
cd isticktoit
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
mkdir -p strings/0x409
echo "fedcba9876543210" > strings/0x409/serialnumber
echo "Tobias Girstmair" > strings/0x409/manufacturer
echo "iSticktoit.net USB Device" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
echo "Config 1: ECM network" > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPower
# Add functions here
mkdir -p functions/hid.usb0
echo 1 > functions/hid.usb0/protocol
echo 1 > functions/hid.usb0/subclass
echo 8 > functions/hid.usb0/report_length
echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.usb0/report_desc
ln -s functions/hid.usb0 configs/c.1/
# End functions
ls /sys/class/udc > UDC
···
···
#!/bin/bash
echo "" | sudo tee -a /boot/config.txt
echo "# BEGIN HID Keyboard Simulation" | sudo tee -a /boot/config.txt
echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt
echo "# END HID Keyboard Simulation" | sudo tee -a /boot/config.txt
echo "" | sudo tee -a /etc/modules
echo "# BEGIN HID Keyboard Simulation" | sudo tee -a /etc/modules
echo "dwc2" | sudo tee -a /etc/modules
echo "libcomposite" | sudo tee -a /etc/modules
echo "# END HID Keyboard Simulation" | sudo tee -a /etc/modules
# Move to before exit 0
echo "" | sudo tee -a /etc/rc.local
echo "# BEGIN HID Keyboard Simulation" | sudo tee -a /etc/rc.local
echo "sudo ./isticktoit_usb" | sudo tee -a /etc/rc.local
echo "# END HID Keyboard Simulation" | sudo tee -a /etc/rc.local
···
···
from typing import List
from .hid import hidwrite
from .hid.keycodes import KeyCodes
from time import sleep
import json
import pkgutil
import os
import pathlib
class Keyboard:
def __init__(self, dev='/dev/hidg0') -> None:
self.dev = dev
self.set_layout()
self.control_pressed = []
self.key_pressed = []
def list_layout(self):
keymaps_dir = pathlib.Path(__file__).parent.absolute() / 'keymaps'
keymaps = os.listdir(keymaps_dir)
files = [f for f in keymaps if f.endswith('.json')]
for count, fname in enumerate(files, 1):
with open(keymaps_dir / fname , encoding='UTF-8') as f:
content = json.load(f)
name, desc = content['Name'], content['Description']
print(f'{count}. {name}: {desc}')
def set_layout(self, language='US'):
self.layout = json.loads( pkgutil.get_data(__name__, f"keymaps/{language}.json").decode() )
def gen_list(self, keys = []):
_control_pressed = []
_key_pressed = []
for key in keys:
if key[:3] == "MOD":
_control_pressed.append(KeyCodes[key])
else:
_key_pressed.append(KeyCodes[key])
return _control_pressed, _key_pressed
def gen_buf(self):
self.buf = [sum(self.control_pressed),0] + self.key_pressed
self.buf += [0] * (8 - len(self.buf)) # fill to lenth 8
##########################################################################
# For user
def press(self, keys = [], additive=False, hold=False):
_control_pressed, _key_pressed = self.gen_list(keys)
if not additive:
self.control_pressed = []
self.key_pressed = []
self.control_pressed.extend(_control_pressed)
self.control_pressed = list(set(self.control_pressed)) # remove repeated items
self.key_pressed.extend(_key_pressed)
self.key_pressed = list(set(self.key_pressed))[:6] # remove repeated items and cut until 6 items
self.gen_buf()
hidwrite.write_to_hid_interface(self.dev, self.buf)
if not hold:
self.release(keys)
def release(self, keys = []):
_control_pressed, _key_pressed = self.gen_list(keys)
try:
self.control_pressed = list(set(self.control_pressed) - set(_control_pressed))
except:
pass
try:
self.key_pressed = list(set(self.key_pressed) - set(_key_pressed))
except:
pass
self.gen_buf()
hidwrite.write_to_hid_interface(self.dev, self.buf)
def release_all(self):
self.control_pressed = []
self.key_pressed = []
self.gen_buf()
hidwrite.write_to_hid_interface(self.dev, self.buf)
def text(self, string, delay=0):
for c in string:
key_map = self.layout['Mapping'][c]
key_map = key_map[0]
mods = key_map['Modifiers']
keys = key_map['Keys']
self.press(mods + keys)
sleep(delay)
···
···
import os
import zero_hid
if os.geteuid() != 0:
raise ImportError('You must be root to use this library on linux.')
k = zero_hid.Keyboard()
k.press(["KEY_H"], additive=False, hold=False)
k.press(["KEY_E"], additive=False, hold=False)
k.press(["KEY_L"], additive=False, hold=False)
k.press(["KEY_L"], additive=False, hold=False)
k.press(["KEY_O"], additive=False, hold=False)
···
···
import os
import evdev
if os.geteuid() != 0:
raise ImportError('You must be root to use this library on linux.')
dev = evdev.InputDevice('/dev/input/event0')
dev.grab() # grab 是为了独占,保证此设备不会被别的进程捕获
for event in dev.read_loop():
key = evdev.categorize(event)
if isinstance(key, evdev.KeyEvent) and key.keystate != 2:
print(key.keycode)
···
···
KEY_LEFTCTRL,MOD_LEFT_CONTROL
KEY_RIGHTCTRL,MOD_RIGHT_CONTROL
KEY_LEFTALT,MOD_LEFT_ALT
KEY_RIGHTALT,MOD_RIGHT_ALT
KEY_LEFTSHIFT,MOD_LEFT_SHIFT
KEY_RIGHTSHIFT,MOD_RIGHT_SHIFT
,
KEY_LEFTMETA,MOD_LEFT_GUI
,
,
KEY_ESC,KEY_ESC
KEY_TAB,KEY_TAB
KEY_CAPSLOCK,KEY_CAPSLOCK
,
KEY_NUMLOCK,KEY_NUMLOCK
KEY_SYSRQ,KEY_SYSRQ
KEY_DELETE,KEY_DELETE
KEY_INSERT,KEY_INSERT
KEY_BACKSPACE,KEY_BACKSPACE
KEY_ENTER,KEY_ENTER
,
KEY_SPACE,KEY_SPACE
,
KEY_UP,KEY_UP
KEY_DOWN,KEY_DOWN
KEY_LEFT,KEY_LEFT
KEY_RIGHT,KEY_RIGHT
,
KEY_PAGEUP,KEY_PAGEUP
KEY_PAGEDOWN,KEY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KP8,KEY_KP8
KEY_KP9,KEY_KP9
KEY_KPASTERISK,KEY_KPASTERISK
KEY_KPMINUS,KEY_KPMINUS
KEY_KPPLUS,KEY_KPPLUS
KEY_KPDOT,KEY_KPDOT
KEY_KPSLASH,KEY_KPSLASH
···
···
with open('./codemap.csv', 'r') as file:
reader = csv.reader(file)
codemap = {rows[0]:rows[1] for rows in reader}
del codemap[""]
···
···
pip uninstall torch torchvision
pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2
···
···
#elif defined(CAMERA_MODEL_ESP32S2_CAM_BOARD)
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 2
#define SIOD_GPIO_NUM 42
#define SIOC_GPIO_NUM 41
#define Y9_GPIO_NUM 1
#define Y8_GPIO_NUM 3
#define Y7_GPIO_NUM 4
#define Y6_GPIO_NUM 6
#define Y5_GPIO_NUM 8
#define Y4_GPIO_NUM 14
#define Y3_GPIO_NUM 9
#define Y2_GPIO_NUM 7
#define VSYNC_GPIO_NUM 16
#define HREF_GPIO_NUM 15
#define PCLK_GPIO_NUM 5
#define LED_GPIO_NUM 45
···
···
from ultralytics import YOLO
import requests
import time
url = "http://192.168.8.171"
model = YOLO("yolov8n.pt")
requests.get(url+"/control?var=framesize&val=" + str(8))
results = model.predict(url+":81/stream", stream=True, show=True, conf = 0.5)
for result in results:
for box in result.boxes:
class_id = result.names[box.cls[0].item()]
cords = box.xyxy[0].tolist()
cords = [round(x) for x in cords]
conf = round(box.conf[0].item(), 2)
print("Object type:", class_id)
print("Coordinates:", cords)
print("Probability:", conf)
print("---")
···
···
import zero_hid
import evdev
import csv
import signal
import os
import threading
if os.geteuid() != 0:
raise ImportError('You must be root to use this library on linux.')
k = zero_hid.Keyboard()
# dev = evdev.InputDevice('/dev/input/by-id/usb-_Raspberry_Pi_Internal_Keyboard-event-kbd')
dev = evdev.InputDevice('/dev/input/event0')
dev.grab() # grab 是为了独占,保证此设备不会被别的进程捕获
with open('./codemap.csv', 'r') as file:
reader = csv.reader(file)
codemap = {rows[0]:rows[1] for rows in reader}
del codemap[""]
curr_pressed = []
def key_input(key):
global curr_pressed
if isinstance(key, evdev.KeyEvent) and key.keystate != 2:
if key.keystate == 1:
curr_pressed.append(key.keycode)
if key.keystate == 0:
curr_pressed.remove(key.keycode)
print("\r" + "CODE: " + key.keycode + " ;STAT: " + str(key.keystate) + " "*40, end="")
keys = [codemap[i] for i in curr_pressed]
k.press(keys, additive=False, hold=True)
def handler(signal, frame):
k.release_all()
dev.ungrab()
dev.close()
exit()
signal.signal(signal.SIGTSTP, handler) # Ctrl+Z
signal.signal(signal.SIGINT, handler) # Ctrl+C
def thread1():
for event in dev.read_loop():
try:
key_input(evdev.categorize(event))
except Exception as error:
print(error)
t1 = threading.Thread(target=thread1, daemon=True)
t1.start()
from ultralytics import YOLO
import requests
url = "http://192.168.8.171"
model = YOLO("yolov8n.pt")
requests.get(url+"/control?var=framesize&val=" + str(8))
results = model.predict(url+":81/stream", stream=True, show=True, conf = 0.5)
delay = 1
count = 0
mode = 0
pre_mode = 0
for result in results:
try:
for box in result.boxes:
class_id = result.names[box.cls[0].item()]
cords = box.xyxy[0].tolist()
cords = [round(x) for x in cords]
conf = round(box.conf[0].item(), 2)
print("Object type:", class_id)
print("Coordinates:", cords)
print("Probability:", conf)
print("---")
if class_id == "person":
mode = 1
count = 0
if mode != pre_mode:
pre_mode = mode
k.press(["MOD_LEFT_ALT","KEY_TAB"], additive=False, hold=False)
print("triggered!!!")
count += 1
if count > delay:
mode = 0
pre_mode = mode
except Exception as error:
print(error)
···
我觉得是不是一些日常操作可以,直接语音识别。