From b133768ec5d86c7924fc5fb376c67da4a139ef7e Mon Sep 17 00:00:00 2001 From: Taki7o7 Date: Mon, 26 Dec 2022 06:10:21 +0100 Subject: [PATCH 1/9] Horizontal Scroll Support --- src/MultiReport/ImprovedMouse.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/MultiReport/ImprovedMouse.cpp b/src/MultiReport/ImprovedMouse.cpp index 9e4ffebc..9e04a029 100644 --- a/src/MultiReport/ImprovedMouse.cpp +++ b/src/MultiReport/ImprovedMouse.cpp @@ -51,6 +51,15 @@ static const uint8_t _hidMultiReportDescriptorMouse[] PROGMEM = { 0x75, 0x08, /* REPORT_SIZE (8) */ 0x95, 0x03, /* REPORT_COUNT (3) */ 0x81, 0x06, /* INPUT (Data,Var,Rel) */ + + /* X, Y, Wheel Horizontal*/ + 0x05, 0x0c, /* USAGE PAGE (Consumer Devices) */ + 0x0a, 0x38, 0x02, /* USAGE (AC Pan) */ + 0x15, 0x81, /* LOGICAL_MINIMUM (-127) */ + 0x25, 0x7f, /* LOGICAL_MAXIMUM (127) */ + 0x75, 0x08, /* REPORT_SIZE (8) */ + 0x95, 0x01, /* REPORT_COUNT (1) */ + 0x81, 0x06, /* INPUT (Data, Var, Rel) */ /* End */ 0xc0 /* END_COLLECTION */ From 509c9120deeb5bee9e63cbf06178311fd69f0efa Mon Sep 17 00:00:00 2001 From: Taki7o7 Date: Mon, 26 Dec 2022 06:12:15 +0100 Subject: [PATCH 2/9] Horizontal Scroll Support --- src/HID-APIs/MouseAPI.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HID-APIs/MouseAPI.h b/src/HID-APIs/MouseAPI.h index b3e17dbd..23838040 100644 --- a/src/HID-APIs/MouseAPI.h +++ b/src/HID-APIs/MouseAPI.h @@ -70,7 +70,7 @@ class MouseAPI inline void begin(void); inline void end(void); inline void click(uint8_t b = MOUSE_LEFT); - inline void move(signed char x, signed char y, signed char wheel = 0); + inline void move(signed char x, signed char y, signed char wheel = 0, signed char hWheel = 0); inline void press(uint8_t b = MOUSE_LEFT); // press LEFT by default inline void release(uint8_t b = MOUSE_LEFT); // release LEFT by default inline void releaseAll(void); From b604c4bcb5a41324aa5b570b1bd4701b0f08ecca Mon Sep 17 00:00:00 2001 From: Taki7o7 Date: Mon, 26 Dec 2022 06:13:04 +0100 Subject: [PATCH 3/9] Horizontal Scroll Support --- src/HID-APIs/MouseAPI.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/HID-APIs/MouseAPI.hpp b/src/HID-APIs/MouseAPI.hpp index 332201ff..8c4de250 100644 --- a/src/HID-APIs/MouseAPI.hpp +++ b/src/HID-APIs/MouseAPI.hpp @@ -48,13 +48,14 @@ void MouseAPI::click(uint8_t b) move(0,0,0); } -void MouseAPI::move(signed char x, signed char y, signed char wheel) +void MouseAPI::move(signed char x, signed char y, signed char wheel, signed char hWheel) { HID_MouseReport_Data_t report; report.buttons = _buttons; report.xAxis = x; report.yAxis = y; report.wheel = wheel; + report.hWheel = hWheel; SendReport(&report, sizeof(report)); } From 1f3205734ca76bf3510462d4054915c613cf951d Mon Sep 17 00:00:00 2001 From: Taki7o7 Date: Mon, 26 Dec 2022 06:19:40 +0100 Subject: [PATCH 4/9] Horizontal Scroll Support --- src/HID-APIs/MouseAPI.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/HID-APIs/MouseAPI.h b/src/HID-APIs/MouseAPI.h index 23838040..55242ca0 100644 --- a/src/HID-APIs/MouseAPI.h +++ b/src/HID-APIs/MouseAPI.h @@ -47,6 +47,7 @@ typedef union ATTRIBUTE_PACKED { int8_t xAxis; int8_t yAxis; int8_t wheel; + int8_t hWheel; }; } HID_MouseReport_Data_t; From ce867689a06cd89ce8ced1df8f618a71675abb4e Mon Sep 17 00:00:00 2001 From: Taki7o7 Date: Mon, 26 Dec 2022 06:22:02 +0100 Subject: [PATCH 5/9] Horizontal Scroll Support --- src/MultiReport/AbsoluteMouse.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/MultiReport/AbsoluteMouse.cpp b/src/MultiReport/AbsoluteMouse.cpp index 6a2ee819..13e4330b 100644 --- a/src/MultiReport/AbsoluteMouse.cpp +++ b/src/MultiReport/AbsoluteMouse.cpp @@ -58,6 +58,15 @@ static const uint8_t _hidMultiReportDescriptorAbsoluteMouse[] PROGMEM = { 0x75, 0x08, /* REPORT_SIZE (8) */ 0x95, 0x01, /* REPORT_COUNT (1) */ 0x81, 0x06, /* INPUT (Data,Var,Rel) */ + + /* Wheel Horizontal*/ + 0x05, 0x0c, /* USAGE PAGE (Consumer Devices) */ + 0x0a, 0x38, 0x02, /* USAGE (AC Pan) */ + 0x15, 0x81, /* LOGICAL_MINIMUM (-127) */ + 0x25, 0x7f, /* LOGICAL_MAXIMUM (127) */ + 0x75, 0x08, /* REPORT_SIZE (8) */ + 0x95, 0x01, /* REPORT_COUNT (1) */ + 0x81, 0x06, /* INPUT (Data, Var, Rel) */ /* End */ 0xc0 /* END_COLLECTION */ From 569f1910253bb47b9b83a36ff984482e914e7f6a Mon Sep 17 00:00:00 2001 From: Taki7o7 Date: Mon, 26 Dec 2022 06:22:51 +0100 Subject: [PATCH 6/9] Horizontal Scroll Support --- src/MultiReport/ImprovedMouse.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MultiReport/ImprovedMouse.cpp b/src/MultiReport/ImprovedMouse.cpp index 9e04a029..0ac0edff 100644 --- a/src/MultiReport/ImprovedMouse.cpp +++ b/src/MultiReport/ImprovedMouse.cpp @@ -52,7 +52,7 @@ static const uint8_t _hidMultiReportDescriptorMouse[] PROGMEM = { 0x95, 0x03, /* REPORT_COUNT (3) */ 0x81, 0x06, /* INPUT (Data,Var,Rel) */ - /* X, Y, Wheel Horizontal*/ + /* Wheel Horizontal Support */ 0x05, 0x0c, /* USAGE PAGE (Consumer Devices) */ 0x0a, 0x38, 0x02, /* USAGE (AC Pan) */ 0x15, 0x81, /* LOGICAL_MINIMUM (-127) */ From 046388c468335e371e3d0c9655a9b42bdb92eff5 Mon Sep 17 00:00:00 2001 From: Taki7o7 Date: Mon, 26 Dec 2022 06:24:28 +0100 Subject: [PATCH 7/9] Horizontal Scroll Support --- src/HID-APIs/AbsoluteMouseAPI.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/HID-APIs/AbsoluteMouseAPI.h b/src/HID-APIs/AbsoluteMouseAPI.h index 66dbe42b..ee84148c 100644 --- a/src/HID-APIs/AbsoluteMouseAPI.h +++ b/src/HID-APIs/AbsoluteMouseAPI.h @@ -47,6 +47,7 @@ typedef union ATTRIBUTE_PACKED { int16_t xAxis; int16_t yAxis; int8_t wheel; + int8_t hWheel; }; } HID_MouseAbsoluteReport_Data_t; @@ -67,8 +68,8 @@ class AbsoluteMouseAPI inline void end(void); inline void click(uint8_t b = MOUSE_LEFT); - inline void moveTo(int x, int y, signed char wheel = 0); - inline void move(int x, int y, signed char wheel = 0); + inline void moveTo(int x, int y, signed char wheel = 0, signed char hWheel = 0); + inline void move(int x, int y, signed char wheel = 0, signed char hWheel = 0); inline void press(uint8_t b = MOUSE_LEFT); inline void release(uint8_t b = MOUSE_LEFT); inline void releaseAll(void); From 3f8d36431cc0817d52994d153edf7564991d6f9f Mon Sep 17 00:00:00 2001 From: Taki7o7 Date: Mon, 26 Dec 2022 06:25:55 +0100 Subject: [PATCH 8/9] Horizontal Scroll Support --- src/HID-APIs/AbsoluteMouseAPI.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/HID-APIs/AbsoluteMouseAPI.hpp b/src/HID-APIs/AbsoluteMouseAPI.hpp index 0913c8a8..92b7ad5c 100644 --- a/src/HID-APIs/AbsoluteMouseAPI.hpp +++ b/src/HID-APIs/AbsoluteMouseAPI.hpp @@ -73,7 +73,7 @@ void AbsoluteMouseAPI::click(uint8_t b){ moveTo(xAxis, yAxis, 0); } -void AbsoluteMouseAPI::moveTo(int x, int y, signed char wheel){ +void AbsoluteMouseAPI::moveTo(int x, int y, signed char wheel, signed char hWheel){ xAxis = x; yAxis = y; HID_MouseAbsoluteReport_Data_t report; @@ -85,11 +85,12 @@ void AbsoluteMouseAPI::moveTo(int x, int y, signed char wheel){ report.xAxis = ((int32_t)x + 32768) / 2; report.yAxis = ((int32_t)y + 32768) / 2; report.wheel = wheel; + report.hWheel = hWheel; SendReport(&report, sizeof(report)); } -void AbsoluteMouseAPI::move(int x, int y, signed char wheel){ - moveTo(qadd16(xAxis, x), qadd16(yAxis, y), wheel); +void AbsoluteMouseAPI::move(int x, int y, signed char wheel, signed char hWheel){ + moveTo(qadd16(xAxis, x), qadd16(yAxis, y), wheel, hWheel); } void AbsoluteMouseAPI::press(uint8_t b){ From cc8a5c5bf8f65ac1af39e8c27649379f4a100993 Mon Sep 17 00:00:00 2001 From: Daryl Wright Date: Fri, 31 Mar 2023 12:39:29 -0300 Subject: [PATCH 9/9] Moved horizontal scroll functionality to a separate method The new scroll method ensures that we can add horizontal scroll support without breaking existing projects by changing the API. --- src/HID-APIs/AbsoluteMouseAPI.h | 5 +++-- src/HID-APIs/AbsoluteMouseAPI.hpp | 14 ++++++++++---- src/HID-APIs/MouseAPI.h | 25 +++++++++++++------------ src/HID-APIs/MouseAPI.hpp | 11 +++++++++-- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/HID-APIs/AbsoluteMouseAPI.h b/src/HID-APIs/AbsoluteMouseAPI.h index ee84148c..8edf0053 100644 --- a/src/HID-APIs/AbsoluteMouseAPI.h +++ b/src/HID-APIs/AbsoluteMouseAPI.h @@ -68,8 +68,9 @@ class AbsoluteMouseAPI inline void end(void); inline void click(uint8_t b = MOUSE_LEFT); - inline void moveTo(int x, int y, signed char wheel = 0, signed char hWheel = 0); - inline void move(int x, int y, signed char wheel = 0, signed char hWheel = 0); + inline void moveTo(int x, int y, signed char wheel = 0); + inline void move(int x, int y, signed char wheel = 0); + inline void scroll(signed char wheel = 0, signed char hWheel = 0); inline void press(uint8_t b = MOUSE_LEFT); inline void release(uint8_t b = MOUSE_LEFT); inline void releaseAll(void); diff --git a/src/HID-APIs/AbsoluteMouseAPI.hpp b/src/HID-APIs/AbsoluteMouseAPI.hpp index 92b7ad5c..cba32b35 100644 --- a/src/HID-APIs/AbsoluteMouseAPI.hpp +++ b/src/HID-APIs/AbsoluteMouseAPI.hpp @@ -73,7 +73,7 @@ void AbsoluteMouseAPI::click(uint8_t b){ moveTo(xAxis, yAxis, 0); } -void AbsoluteMouseAPI::moveTo(int x, int y, signed char wheel, signed char hWheel){ +void AbsoluteMouseAPI::moveTo(int x, int y, signed char wheel){ xAxis = x; yAxis = y; HID_MouseAbsoluteReport_Data_t report; @@ -85,12 +85,18 @@ void AbsoluteMouseAPI::moveTo(int x, int y, signed char wheel, signed char hWhee report.xAxis = ((int32_t)x + 32768) / 2; report.yAxis = ((int32_t)y + 32768) / 2; report.wheel = wheel; - report.hWheel = hWheel; SendReport(&report, sizeof(report)); } -void AbsoluteMouseAPI::move(int x, int y, signed char wheel, signed char hWheel){ - moveTo(qadd16(xAxis, x), qadd16(yAxis, y), wheel, hWheel); +void AbsoluteMouseAPI::move(int x, int y, signed char wheel){ + moveTo(qadd16(xAxis, x), qadd16(yAxis, y), wheel); +} + +void AbsoluteMouseAPI::scroll(signed char wheel, signed char hWheel){ + HID_MouseAbsoluteReport_Data_t report; + report.wheel = wheel; + report.hWheel = hWheel; + SendReport(&report, sizeof(report)); } void AbsoluteMouseAPI::press(uint8_t b){ diff --git a/src/HID-APIs/MouseAPI.h b/src/HID-APIs/MouseAPI.h index 55242ca0..47e1f996 100644 --- a/src/HID-APIs/MouseAPI.h +++ b/src/HID-APIs/MouseAPI.h @@ -67,22 +67,23 @@ typedef union ATTRIBUTE_PACKED { class MouseAPI { public: - inline MouseAPI(void); - inline void begin(void); - inline void end(void); - inline void click(uint8_t b = MOUSE_LEFT); - inline void move(signed char x, signed char y, signed char wheel = 0, signed char hWheel = 0); - inline void press(uint8_t b = MOUSE_LEFT); // press LEFT by default - inline void release(uint8_t b = MOUSE_LEFT); // release LEFT by default + inline MouseAPI(void); + inline void begin(void); + inline void end(void); + inline void click(uint8_t b = MOUSE_LEFT); + inline void move(signed char x, signed char y, signed char wheel = 0); + inline void scroll(signed char wheel = 0, signed char hWheel = 0); + inline void press(uint8_t b = MOUSE_LEFT); // press LEFT by default + inline void release(uint8_t b = MOUSE_LEFT); // release LEFT by default inline void releaseAll(void); - inline bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default + inline bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default - // Sending is public in the base class for advanced users. - virtual void SendReport(void* data, int length) = 0; + // Sending is public in the base class for advanced users. + virtual void SendReport(void* data, int length) = 0; protected: - uint8_t _buttons; - inline void buttons(uint8_t b); + uint8_t _buttons; + inline void buttons(uint8_t b); }; // Implementation is inline diff --git a/src/HID-APIs/MouseAPI.hpp b/src/HID-APIs/MouseAPI.hpp index 8c4de250..3d5d1c87 100644 --- a/src/HID-APIs/MouseAPI.hpp +++ b/src/HID-APIs/MouseAPI.hpp @@ -48,14 +48,21 @@ void MouseAPI::click(uint8_t b) move(0,0,0); } -void MouseAPI::move(signed char x, signed char y, signed char wheel, signed char hWheel) +void MouseAPI::move(signed char x, signed char y, signed char wheel) { HID_MouseReport_Data_t report; report.buttons = _buttons; report.xAxis = x; report.yAxis = y; report.wheel = wheel; - report.hWheel = hWheel; + SendReport(&report, sizeof(report)); +} + +void MouseAPI::scroll(signed char wheel, signed char hWheel) +{ + HID_MouseReport_Data_t report; + report.wheel = wheel; + report.hWheel = hWheel; SendReport(&report, sizeof(report)); }