mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-22 08:04:07 +08:00
Add udev-setup command to odrivetool
This commit is contained in:
@@ -7,6 +7,8 @@ import sys
|
||||
import time
|
||||
import threading
|
||||
import platform
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
try:
|
||||
if platform.system() == 'Windows':
|
||||
@@ -109,6 +111,17 @@ def rate_test(device):
|
||||
FramePerSec = loopsPerSec/loopsPerFrame
|
||||
print("Frames per second: " + str(FramePerSec))
|
||||
|
||||
def setup_udev_rules(logger):
|
||||
if platform.system() != 'Linux':
|
||||
logger.error("This command only makes sense on Linux")
|
||||
if os.getuid() != 0:
|
||||
logger.warn("you should run this as root, otherwise it will probably not work")
|
||||
with open('/etc/udev/rules.d/50-odrive.rules', 'w') as file:
|
||||
file.write('SUBSYSTEM=="usb", ATTR{idVendor}=="1209", ATTR{idProduct}=="0d3[0-9]", MODE="0666"\n')
|
||||
subprocess.run(["udevadm", "control", "--reload-rules"], check=True)
|
||||
subprocess.run(["udevadm", "trigger"], check=True)
|
||||
logger.info('udev rules configured successfully')
|
||||
|
||||
|
||||
## Exceptions ##
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ dfu_parser.add_argument('file', metavar='HEX', help='The .hex file to be flashed
|
||||
subparsers.add_parser('liveplotter', help="Upgrade the ODrive's Firmware")
|
||||
subparsers.add_parser('drv-status', help="Show status of the on-board DRV8301 chips (for debugging only)")
|
||||
subparsers.add_parser('rate-test', help="Estimate the average transmission bandwidth over USB")
|
||||
subparsers.add_parser('udev-setup', help="Linux only: Gives users on your system permission to access the ODrive by installing udev rules")
|
||||
|
||||
# General arguments
|
||||
parser.add_argument("-p", "--path", metavar="PATH", action="store",
|
||||
@@ -126,6 +127,10 @@ try:
|
||||
my_odrive = odrive.discovery.find_any(path=args.path, serial_number=args.serial_number)
|
||||
rate_test(my_odrive)
|
||||
|
||||
elif args.command == 'udev-setup':
|
||||
from odrive.utils import setup_udev_rules
|
||||
setup_udev_rules(logger)
|
||||
|
||||
else:
|
||||
raise Exception("unknown command: " + args.command)
|
||||
|
||||
|
||||
@@ -58,6 +58,12 @@ if creating_package:
|
||||
with open(version_file_path, mode='w') as version_file:
|
||||
version_file.write(version)
|
||||
|
||||
# TODO: find a better place for this
|
||||
if not creating_package:
|
||||
import platform
|
||||
if platform.system() == 'Linux':
|
||||
import odrive.utils
|
||||
odrive.utils.setup_udev_rules(odrive.utils.Logger())
|
||||
|
||||
setup(
|
||||
name = 'odrive',
|
||||
|
||||
Reference in New Issue
Block a user