Skip to content
Snippets Groups Projects
Commit e68dfb51 authored by Jan Schlüter's avatar Jan Schlüter
Browse files

Correctly claim and release USB interface

parent 13ad7cd0
No related branches found
No related tags found
2 merge requests!2HighBlueParser dev branch merged to empty main branch,!1High blue rec
......@@ -4,7 +4,7 @@ if(POLICY CMP0063)
endif()
project(jasonrec)
set(JASONREC_VERSION "1.0")
set(JASONREC_VERSION "1.1")
add_definitions(-DJASONREC_VERSION="${JASONREC_VERSION}")
find_path(LIBUSB_INCLUDE_DIR
......@@ -15,4 +15,3 @@ find_library(LIBUSB_LIBRARY
PATH_SUFFIXES "lib" "lib32" "lib64")
add_subdirectory(src)
......@@ -44,6 +44,7 @@ JasonRecorder::JasonRecorder() {
JasonRecorder::~JasonRecorder() {
// free handle
if (handle) {
libusb_release_interface(handle, 0);
libusb_close(handle);
}
// free devices
......@@ -60,6 +61,7 @@ size_t JasonRecorder::get_device_count() {
void JasonRecorder::set_device(size_t number) {
if (handle) {
libusb_release_interface(handle, 0);
libusb_close(handle);
handle = NULL;
}
......@@ -69,6 +71,9 @@ void JasonRecorder::set_device(size_t number) {
if (libusb_open(devices[number], &handle) < 0) {
throw std::runtime_error("could not open USB device (try again as root)");
}
if (libusb_claim_interface(handle, 0) < 0) {
throw std::runtime_error("could not claim USB interface");
}
}
void JasonRecorder::send_message(std::uint8_t cmd) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment