summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-12-13 00:00:02 +0100
committerPeter Wu <peter@lekensteyn.nl>2014-12-13 00:00:02 +0100
commit30c7e2000caf359e4f205c17fc822ebde629826e (patch)
tree3f4e6a6e79fdf9ae6882450f25048b36285a8a9f
parent0c2bd445f484677bcdb62430bf5ad065eb67392f (diff)
downloadltunify-30c7e2000caf359e4f205c17fc822ebde629826e.tar.gz
lib: make aware of DJ reports, fix debug msg
-rw-r--r--lib/hidpp.c10
-rw-r--r--lib/hidpp.h22
2 files changed, 24 insertions, 8 deletions
diff --git a/lib/hidpp.c b/lib/hidpp.c
index ae286f6..c47f434 100644
--- a/lib/hidpp.c
+++ b/lib/hidpp.c
@@ -205,19 +205,23 @@ bool hidpp_read_msg(int fd, int timeout, HidppMessage *msg,
memset(&response, 0, sizeof(response));
r = poll_read(fd, timeout, &response, sizeof(response));
if (r > 0) {
- trace_dump_data("rd", (uint8_t *) msg, r);
+ trace_dump_data("rd", (uint8_t *) &response, r);
if (r < HIDPP_SHORT_LEN) {
trace_log("Impossible short read: %i\n", r);
} else if (response.report_id == HIDPP_SHORT ||
- response.report_id == HIDPP_LONG) {
+ response.report_id == HIDPP_LONG ||
+ response.report_id == DJ_SHORT ||
+ response.report_id == DJ_LONG) {
uint8_t ix = response.device_index;
if (!is_valid_device_index(ix) && ix != 0xFF) {
trace_log("Invalid device index: %i\n", ix);
} else if (cb(&response, userdata)) {
/* response is accepted, return message */
- memcpy(msg, &response, sizeof(response));
+ if (msg) {
+ memcpy(msg, &response, sizeof(response));
+ }
return true;
}
}
diff --git a/lib/hidpp.h b/lib/hidpp.h
index 2970f46..51dea6b 100644
--- a/lib/hidpp.h
+++ b/lib/hidpp.h
@@ -29,6 +29,10 @@
#define HIDPP_SHORT_LEN 7
#define HIDPP_LONG 0x11
#define HIDPP_LONG_LEN 20
+#define DJ_SHORT 0x20
+#define DJ_SHORT_LEN 15
+#define DJ_LONG 0x21
+#define DJ_LONG_LEN 32
typedef struct HidppMessage {
uint8_t report_id;
@@ -39,13 +43,16 @@ typedef struct HidppMessage {
uint8_t address;
}; /**< HID++ 1.0 naming */
struct {
- uint8_t feature_id;
+ uint8_t feature_index;
+#define HIDPP20_FUNC(func) (((func) << 4) | 4) /* swId is arbitrary */
uint8_t func; /* (func << 4) | swId */
}; /**< HID++ 2.0 naming */
};
union {
- uint8_t params[3];
- uint8_t params_l[16];
+ uint8_t params[HIDPP_SHORT_LEN - 4];
+ uint8_t params_l[HIDPP_LONG_LEN - 4];
+ uint8_t dj_params[DJ_SHORT_LEN - 4];
+ uint8_t dj_params_l[DJ_LONG_LEN - 4];
};
} HidppMessage;
@@ -82,10 +89,15 @@ bool hidpp_write_report(int fd, HidppMessage *msg);
* @param fd File descriptor of the hidraw device.
* @param timeout Timeout for this function in milliseconds.
* @param msg[out] On success, the message is written to this pointer.
- * Otherwise, the contents are unmodified.
- * @param cb Function that should be called for new HID++ messages.
+ * Otherwise, the contents are unmodified. If this pointer is
+ * NULL, then the caller won't be able to see the message that
+ * got accepted.
+ * @param cb Callback function for incoming HID++ and DJ reports.
* If true is returned, then no more messages are read. msg is
* not allowed to be modified if the callback returns false.
+ * The callback must check the report_id field as it is
+ * possible that non-HID++ reports are received (DJ enumerator
+ * messages for example).
* @param userdata Data that is passed unchanged to the callback function.
* @return true iff there exists a message that was accepted by the callback
* function within the timeout.