Skip to content

Commit

Permalink
Merge pull request bitcraze#532 from bitcraze/jonasdn/444
Browse files Browse the repository at this point in the history
main: warn once about USB permissions on scan
  • Loading branch information
jonasdn authored Sep 8, 2021
2 parents 96d00f9 + e5dadc1 commit 1a9f350
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/cfclient/ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"""
import logging
import sys
import usb

import cfclient
from cfclient.ui.pose_logger import PoseLogger
Expand All @@ -54,6 +55,7 @@
from PyQt5.QtCore import QDir
from PyQt5.QtCore import QThread
from PyQt5.QtCore import QUrl
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QAction
from PyQt5.QtWidgets import QActionGroup
from PyQt5.QtWidgets import QShortcut
Expand Down Expand Up @@ -185,7 +187,7 @@ def __init__(self, *args):
scan_button=self.scanButton))

self._connectivity_manager.connect_button_clicked.connect(self._connect)
self._connectivity_manager.scan_button_clicked.connect(self._scan)
self._connectivity_manager.scan_button_clicked.connect(self._scan_from_button)

self._disable_input = False

Expand Down Expand Up @@ -359,6 +361,9 @@ def __init__(self, *args):
self._theme_group.addAction(node)
self.menuThemes.addAction(node)

# We only want to warn about USB permission once
self._permission_warned = False

def _set_address(self):
address = 0xE7E7E7E7E7
try:
Expand Down Expand Up @@ -598,6 +603,30 @@ def _scan(self, address):
self._update_ui_state()
self.scanner.scanSignal.emit(address)

def _scan_from_button(self, address):
#
# Below we check if we can open the Crazyradio device.
# If it is there, but we have no permissions we inform the user, once,
# about how to install the udev rules.
#
if not self._permission_warned:
try:
radio = cflib.crtp.radiodriver.RadioManager.open(0)
radio.close()
except usb.core.USBError as e:
if e.errno == 13: # Permission denied
link = "<a href='https://www.bitcraze.io/documentation/repository/crazyflie-lib-python/master/installation/usb_permissions/'>Install USB Permissions</a>" # noqa
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setTextFormat(Qt.RichText)
msg.setText("Could not access Crazyradio")
msg.setInformativeText(link)
msg.setWindowTitle("Crazyradio permissions")
msg.exec()
self._permission_warned = True

self._scan(address)

def _display_input_device_error(self, error):
self.cf.close_link()
QMessageBox.critical(self, "Input device error", error)
Expand Down

0 comments on commit 1a9f350

Please sign in to comment.