# Skip the MBR partition table, back up OneCloud U-Boot contents and compressgzip-dcBoot_SkipUSBBurning.gz|ddof=/dev/mmcblk1bs=512seek=1count=32767# Restore the backed up U-Boot contentsddif=/dev/mmcblk1bs=512skip=1count=32767|gzip>Boot_SkipUSBBurning.gz
In practice, starting with Linux 4.8, the sysfs interface (/sys/class/gpio) is no longer recommended for GPIO operations. Instead, use character devices in userspace. libgpiod is a library for GPIO character devices and provides tools to help developers debug. libgpiod includes commands such as gpioget, gpioset, gpiodetect, gpioinfo, gpiofind, and gpiomon.
The examples below show two ways to control OneCloud GPIO: the sysfs interface and libgpiod commands.
# Set the display background imagefbitext.png-T1-d/dev/fb0
# Clear the ttyecho-e"\033c">/dev/tty1
# Hide the cursorecho-e"\033[?25l">/dev/tty1
# Output capture card video to the HDMI displayustreamer-dump--sink=kvmd::ustreamer::jpeg--output-|ffmpeg-use_wallclock_as_timestamps1-ipipe:c:v-an-pix_fmtbgr24-ffbdev/dev/fb0
importsysimporthidVENDOR_ID=0x5131PRODUCT_ID=0x2007deffind_usbrelay():fordeviceinhid.enumerate():ifdevice.get("vendor_id")==VENDOR_IDanddevice.get("product_id")==PRODUCT_ID:returndevicereturnNonedefsend_command(device_info,channel,onoff):device=hid.device()device.open(device_info['vendor_id'],device_info['product_id'])ifdeviceisNone:print("Failed to open device.")returntry:cmd=[0xA0,channel,onoff,0xA0+channel+onoff]device.write(bytearray(cmd))finally:device.close()defmain():iflen(sys.argv)!=3:print("Usage:\n""\tpython script.py id on|off")returntry:id=int(sys.argv[1])ifsys.argv[2].lower()=='on':onoff=1elifsys.argv[2].lower()=='off':onoff=0else:raiseValueErrorexceptValueError:print("Invalid command, use 'on' or 'off'")returndevice_info=find_usbrelay()ifdevice_infoisNone:print("USB relay not found")else:send_command(device_info,id,onoff)print(f"Sent command to channel {id}: {'ON'ifonoffelse'OFF'}")if__name__=="__main__":main()
If a USB device is in an abnormal state, you can use the usbreset utility to reset it. Install usbreset with the following commands for your distribution.