aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt16
-rw-r--r--README.adoc6
-rw-r--r--eizoctl.c48
3 files changed, 38 insertions, 32 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ab4dcf9..4e4ddd3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,6 @@
cmake_minimum_required (VERSION 3.10)
-project (usb-drivers VERSION 0.1.0 DESCRIPTION "USB drivers" LANGUAGES C)
+project (usb-drivers VERSION 0.1.0
+ DESCRIPTION "User space USB drivers" LANGUAGES C)
# Moar warnings
set (CMAKE_C_STANDARD 99)
@@ -27,6 +28,9 @@ if (WIN32 AND CMAKE_CROSSCOMPILING)
set (ENV{PKG_CONFIG_PATH} "${win32_deps_pcpath}")
set (ENV{PKG_CONFIG_LIBDIR} "${win32_deps_pcpath}")
endif ()
+if (WIN32)
+ add_link_options (-static)
+endif ()
# Dependencies
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/liberty/cmake)
@@ -35,8 +39,8 @@ find_package (PkgConfig REQUIRED)
pkg_check_modules (libusb libusb-1.0)
pkg_search_module (hidapi hidapi hidapi-hidraw)
-option (WITH_LIBUSB "Compile with libusb utilities" ${libusb_FOUND})
-option (WITH_HIDRAW "Compile with hidraw utilities" ${hidapi_FOUND})
+option (WITH_LIBUSB "Compile with libusb-based utilities" ${libusb_FOUND})
+option (WITH_HIDAPI "Compile with hidapi-based utilities" ${hidapi_FOUND})
# Generate a configuration file
configure_file (${PROJECT_SOURCE_DIR}/config.h.in
@@ -67,14 +71,14 @@ if (WITH_LIBUSB)
target_link_libraries (razer-bw-te-ctl ${libusb_LIBRARIES})
endif ()
-if (WITH_HIDRAW)
+if (WITH_HIDAPI)
list (APPEND targets eizoctl)
add_executable (eizoctl eizoctl.c)
target_include_directories (eizoctl PUBLIC ${hidapi_INCLUDE_DIRS})
target_link_directories (eizoctl PUBLIC ${hidapi_LIBRARY_DIRS})
target_link_libraries (eizoctl ${hidapi_LIBRARIES})
endif ()
-if (WITH_HIDRAW AND WIN32)
+if (WITH_HIDAPI AND WIN32)
list (APPEND targets_gui eizoctltray)
include (IconUtils)
@@ -95,7 +99,7 @@ if (WITH_HIDRAW AND WIN32)
add_executable (eizoctltray WIN32 eizoctl.c eizoctltray.rc)
target_compile_definitions (eizoctltray PUBLIC -DUNICODE -D_UNICODE -DTRAY)
- target_link_options (eizoctltray PUBLIC -static -municode)
+ target_link_options (eizoctltray PUBLIC -municode)
target_include_directories (eizoctltray PUBLIC ${hidapi_INCLUDE_DIRS})
target_link_directories (eizoctltray PUBLIC ${hidapi_LIBRARY_DIRS})
target_link_libraries (eizoctltray ${hidapi_LIBRARIES} powrprof)
diff --git a/README.adoc b/README.adoc
index b715932..255dfed 100644
--- a/README.adoc
+++ b/README.adoc
@@ -37,8 +37,8 @@ Runtime dependencies:
libusb-1.0 (elksmart-comm, razer-bw-te-ctl), hidapi (eizoctl)
$ git clone --recursive https://git.janouch.name/p/usb-drivers.git
- $ mkdir desktop-tools/build
- $ cd desktop-tools/build
+ $ mkdir usb-drivers/build
+ $ cd usb-drivers/build
$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug
$ make
@@ -53,7 +53,7 @@ Or you can try telling CMake to make a package for you. For Debian it is:
Contributing and Support
------------------------
-Use https://git.janouch.name/p/desktop-tools to report bugs, request features,
+Use https://git.janouch.name/p/usb-drivers to report bugs, request features,
or submit pull requests. `git send-email` is tolerated. If you want to discuss
the project, feel free to join me at ircs://irc.janouch.name, channel #dev.
diff --git a/eizoctl.c b/eizoctl.c
index a1e5da5..7dc468d 100644
--- a/eizoctl.c
+++ b/eizoctl.c
@@ -433,8 +433,8 @@ eizo_monitor_read_secondary_descriptor(struct eizo_monitor *m)
"secondary descriptor Get_Feature failed: %ls",
hid_error(m->dev));
if (peek_u16le(&buf[1]) != offset)
- return eizo_monitor_failf(
- m, "secondary descriptor starts at an unexpected offset");
+ return eizo_monitor_failf(m,
+ "secondary descriptor starts at an unexpected offset");
// We could also limit the amount we copy, but whatever.
if (offset + lenr - HEADER_LEN > sizeof descriptor)
@@ -444,7 +444,7 @@ eizo_monitor_read_secondary_descriptor(struct eizo_monitor *m)
offset += lenr - HEADER_LEN;
}
-#if DEBUG
+#if DUMP_DESCRIPTORS
for (size_t i = 0; i < descriptor_len; i++)
printf("%02x ", descriptor[i]);
printf("\n");
@@ -491,18 +491,14 @@ eizo_monitor_open(struct eizo_monitor *m, const struct hid_device_info *info)
m->vid = info->vendor_id;
m->pid = info->product_id;
if (info->usage_page != USB_USAGE_PAGE__MONITOR ||
- info->usage != USB_USAGE_PAGE_MONITOR_ID__MONITOR_CONTROL) {
- eizo_monitor_failf(m, "unexpected HID usage");
- return false;
- }
+ info->usage != USB_USAGE_PAGE_MONITOR_ID__MONITOR_CONTROL)
+ return eizo_monitor_failf(m, "unexpected HID usage");
// There can be more displays with the same VID/PID,
// and info does not contain the serial number to tell them apart.
hid_device *dev = hid_open_path(info->path);
- if (!dev) {
- eizo_monitor_failf(m, "failed to open: %ls", hid_error(NULL));
- return false;
- }
+ if (!dev)
+ return eizo_monitor_failf(m, "%ls", hid_error(NULL));
uint8_t descriptor[HID_API_MAX_REPORT_DESCRIPTOR_SIZE] = {};
int len = hid_get_report_descriptor(dev, descriptor, sizeof descriptor);
@@ -525,6 +521,12 @@ eizo_monitor_open(struct eizo_monitor *m, const struct hid_device_info *info)
goto out;
}
+#if DUMP_DESCRIPTORS
+ for (size_t i = 0; i < (size_t) len; i++)
+ printf("%02x ", descriptor[i]);
+ printf("\n");
+#endif
+
uint8_t pinbuf[3] = {EIZO_REPORT_ID_PIN_CODE, 0, 0};
if (hid_get_feature_report(dev, pinbuf, sizeof pinbuf) != sizeof pinbuf) {
eizo_monitor_failf(m, "failed to get PIN code: %ls", hid_error(dev));
@@ -914,16 +916,15 @@ eizo_restart(struct eizo_monitor *m)
// --- Main --------------------------------------------------------------------
-static void
+static bool
eizo_watch(struct eizo_monitor *m)
{
- uint8_t buf[1024];
+ uint8_t buf[1024] = {};
int res = 0;
while (true) {
- if ((res = hid_read(m->dev, buf, sizeof buf)) < 0) {
- eizo_monitor_failf(m, "watch: %ls\n", hid_error(m->dev));
- return;
- }
+ if ((res = hid_read(m->dev, buf, sizeof buf)) < 0)
+ return eizo_monitor_failf(m, "watch: %ls", hid_error(m->dev));
+
if (buf[0] != EIZO_REPORT_ID_GET &&
buf[0] != EIZO_REPORT_ID_GET_LONG) {
printf("Unknown report ID\n");
@@ -1025,8 +1026,10 @@ run(int argc, char *argv[], print_fn output, print_fn error, bool verbose)
struct hid_device_info *devs = hid_enumerate(USB_VID_EIZO, 0), *p = devs;
for (; p; p = p->next) {
struct eizo_monitor m = {};
- if (!eizo_monitor_open(&m, p))
+ if (!eizo_monitor_open(&m, p)) {
+ error("%s\n", m.error);
continue;
+ }
if (isfinite(brightness)) {
double prev = 0.;
@@ -1066,10 +1069,10 @@ run(int argc, char *argv[], print_fn output, print_fn error, bool verbose)
output("%s %s: restart\n", m.product, m.serial);
}
if (events) {
- if (verbose)
- eizo_watch(&m);
- else
+ if (!verbose)
error("Watching events is not possible in this mode\n");
+ else if (!eizo_watch(&m))
+ error("%s\n", m.error);
}
eizo_monitor_close(&m);
@@ -1308,9 +1311,8 @@ show_menu(void)
id = id % 0x1000;
double brightness = 0.;
if (id >= IDM_INPUT_0) {
- // FIXME: This seems to be too fast.
if (process_any_power_request())
- eizo_set_input_port(m, id);
+ eizo_set_input_port(m, id - IDM_INPUT_0);
} else if (id == IDM_BRIGHTER) {
if (eizo_get_brightness(m, &brightness))
eizo_set_brightness(m, min(1., brightness + .1));