]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - usb_mouse.c
revise Fn key processing.
[max/tmk_keyboard.git] / usb_mouse.c
index 539f2edd375c32586d45a4b12e2a3ca04663614f..dd5d0b0ac36bff64425b83b7b82d41d64a0b59d6 100644 (file)
@@ -1,8 +1,12 @@
 #include <avr/interrupt.h>
 #include <util/delay.h>
 #include "usb_mouse.h"
+#include "print.h"
+#include "debug.h"
 
 
+static bool is_sent = false;
+
 // which buttons are currently pressed
 uint8_t mouse_buttons=0;
 
@@ -22,11 +26,11 @@ int8_t usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right)
        if (middle) mask |= 4;
        if (right) mask |= 2;
        mouse_buttons = mask;
-       return usb_mouse_move(0, 0, 0);
+       return usb_mouse_move(0, 0, 0, 0);
 }
 
 // Move the mouse.  x, y and wheel are -127 to 127.  Use 0 for no movement.
-int8_t usb_mouse_move(int8_t x, int8_t y, int8_t wheel)
+int8_t usb_mouse_move(int8_t x, int8_t y, int8_t wheel, int8_t hwheel)
 {
        uint8_t intr_state, timeout;
 
@@ -34,6 +38,7 @@ int8_t usb_mouse_move(int8_t x, int8_t y, int8_t wheel)
        if (x == -128) x = -127;
        if (y == -128) y = -127;
        if (wheel == -128) wheel = -127;
+       if (hwheel == -128) hwheel = -127;
        intr_state = SREG;
        cli();
        UENUM = MOUSE_ENDPOINT;
@@ -55,8 +60,28 @@ int8_t usb_mouse_move(int8_t x, int8_t y, int8_t wheel)
        UEDATX = x;
        UEDATX = y;
        UEDATX = wheel;
+       UEDATX = hwheel;
+        
        UEINTX = 0x3A;
        SREG = intr_state;
+        is_sent = true;
        return 0;
 }
 
+void usb_mouse_clear(void) {
+    is_sent = false;
+}
+
+bool usb_mouse_is_sent(void) {
+    return is_sent;
+}
+
+void usb_mouse_print(int8_t mouse_x, int8_t mouse_y, int8_t wheel_v, int8_t wheel_h) {
+    if (!debug_mouse) return;
+    print("mouse btn|x y v h: ");
+    phex(mouse_buttons); print("|");
+    phex(mouse_x); print(" ");
+    phex(mouse_y); print(" ");
+    phex(wheel_v); print(" ");
+    phex(wheel_h); print("\n");
+}