This prevents the use of responses from other HID++ applications (such
as Solaar and ltunify).

Signed-off-by: Peter Wu <lekenst...@gmail.com>
---
 src/linux/hidpp-device.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/linux/hidpp-device.c b/src/linux/hidpp-device.c
index 6d02bf1..2d4e550 100644
--- a/src/linux/hidpp-device.c
+++ b/src/linux/hidpp-device.c
@@ -271,6 +271,24 @@ hidpp_device_print_buffer (HidppDevice *device, const 
HidppMessage *msg)
        g_print ("param[0]=%02x\n\n", msg->s.params[0]);
 }
 
+static void
+hidpp_discard_messages (HidppDevice    *device)
+{
+       HidppDevicePrivate *priv = device->priv;
+       GPollFD poll[] = {
+               {
+                       .fd = priv->fd,
+                       .events = G_IO_IN | G_IO_OUT | G_IO_ERR,
+               },
+       };
+       char c;
+
+       while (g_poll (poll, G_N_ELEMENTS(poll), 0) > 0) {
+               /* kernel discards remainder of packet */
+               read (priv->fd, &c, 1);
+       }
+}
+
 /**
  * hidpp_device_cmd:
  **/
@@ -302,6 +320,9 @@ hidpp_device_cmd (HidppDevice       *device,
 
        msg_len = HIDPP_MSG_LENGTH(request);
 
+       /* ignore all unrelated queued messages */
+       hidpp_discard_messages(device);
+
        /* write to the device */
        wrote = write (priv->fd, (const char *)request, msg_len);
        if ((gsize) wrote != msg_len) {
-- 
1.8.3.4

_______________________________________________
devkit-devel mailing list
devkit-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/devkit-devel

Reply via email to