From 968293daf77430d9e24bf9560a65233e7ab0ccbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Lev=C3=AD=C4=8Dek?= <46134697+Matesaktesak@users.noreply.github.com> Date: Mon, 23 Sep 2019 18:34:00 +0200 Subject: [PATCH 01/13] Starting development for 3D mouse (Multi-axis controller) Here is the HID descriptor as specified by https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf . Alrady working on the real code for its function, but I'm not a great coder so it may be full of errors... --- src/MultiReport/3DMouse.cpp | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/MultiReport/3DMouse.cpp diff --git a/src/MultiReport/3DMouse.cpp b/src/MultiReport/3DMouse.cpp new file mode 100644 index 00000000..85c65270 --- /dev/null +++ b/src/MultiReport/3DMouse.cpp @@ -0,0 +1,43 @@ +#include "3DMouse.h" + +static const uint8_t _hidMultiReportDescriptor3DMouse[] PROGMEM = { + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x08, // USAGE (Multiaxis) + 0xa1, 0x01, // COLLECTION (Application) + 0xa1, 0x00, // COLLECTION (Physical) + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, 0x03, // USAGE_MAXIMUM (Button 3) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x95, 0x03, // REPORT_COUNT (3) + 0x75, 0x01, // REPORT_SIZE (1) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) + 0x09, 0x32, // USAGE (Z) + 0x09, 0x33, // USAGE (Rx) + 0x09, 0x34, // USAGE (Ry) + 0x09, 0x35, // USAGE (Rz) + 0x16, 0x00, 0xfe, // LOGICAL_MINIMUM (-512) + 0x26, 0x00, 0x02, // LOGICAL_MAXIMUM (512) + 0x75, 0x0a, // REPORT_SIZE (10) + 0x95, 0x06, // REPORT_COUNT (6) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0xc0, // END_COLLECTION + 0xc0 // END_COLLECTION +}; + +3DMouse_::3DMouse_(void) +{ + static HIDSubDescriptor node(_hidMultiReportDescriptor3DMouse, sizeof(_hidMultiReportDescriptor3DMouse)); + HID().AppendDescriptor(&node); +} + +void 3DMouse_::SendReport(void *data, int length) +{ + HID().SendReport(HID_REPORTID_3DMOUSE, data, length); +} + +3DMouse_ 3DMouse; From 2ab124902cef2d8614127aa71a93b3dcbdebe247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Lev=C3=AD=C4=8Dek?= <46134697+Matesaktesak@users.noreply.github.com> Date: Mon, 23 Sep 2019 18:42:40 +0200 Subject: [PATCH 02/13] Fixed varieble size --- src/MultiReport/3DMouse.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MultiReport/3DMouse.cpp b/src/MultiReport/3DMouse.cpp index 85c65270..343e7e50 100644 --- a/src/MultiReport/3DMouse.cpp +++ b/src/MultiReport/3DMouse.cpp @@ -20,9 +20,9 @@ static const uint8_t _hidMultiReportDescriptor3DMouse[] PROGMEM = { 0x09, 0x33, // USAGE (Rx) 0x09, 0x34, // USAGE (Ry) 0x09, 0x35, // USAGE (Rz) - 0x16, 0x00, 0xfe, // LOGICAL_MINIMUM (-512) - 0x26, 0x00, 0x02, // LOGICAL_MAXIMUM (512) - 0x75, 0x0a, // REPORT_SIZE (10) + 0x16, 0x00, 0xfe, // LOGICAL_MINIMUM (-32K) + 0x26, 0x00, 0x02, // LOGICAL_MAXIMUM (32K) + 0x75, 0x10, // REPORT_SIZE (16) 0x95, 0x06, // REPORT_COUNT (6) 0x81, 0x06, // INPUT (Data,Var,Rel) 0xc0, // END_COLLECTION From bddb09c65edcdb96ac6595b59bacfeaebc01f458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Lev=C3=AD=C4=8Dek?= <46134697+Matesaktesak@users.noreply.github.com> Date: Mon, 23 Sep 2019 18:44:35 +0200 Subject: [PATCH 03/13] Update 3DMouse.cpp --- src/MultiReport/3DMouse.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MultiReport/3DMouse.cpp b/src/MultiReport/3DMouse.cpp index 343e7e50..d7f49840 100644 --- a/src/MultiReport/3DMouse.cpp +++ b/src/MultiReport/3DMouse.cpp @@ -20,8 +20,8 @@ static const uint8_t _hidMultiReportDescriptor3DMouse[] PROGMEM = { 0x09, 0x33, // USAGE (Rx) 0x09, 0x34, // USAGE (Ry) 0x09, 0x35, // USAGE (Rz) - 0x16, 0x00, 0xfe, // LOGICAL_MINIMUM (-32K) - 0x26, 0x00, 0x02, // LOGICAL_MAXIMUM (32K) + 0x16, 0x00, 0x80, // LOGICAL_MINIMUM (-32K) + 0x27, 0x00, 0x80, // LOGICAL_MAXIMUM (32K) 0x75, 0x10, // REPORT_SIZE (16) 0x95, 0x06, // REPORT_COUNT (6) 0x81, 0x06, // INPUT (Data,Var,Rel) From c103a554b00b797bec56388b1ea283431c7e24c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Lev=C3=AD=C4=8Dek?= <46134697+Matesaktesak@users.noreply.github.com> Date: Mon, 23 Sep 2019 18:46:33 +0200 Subject: [PATCH 04/13] Created 3D Mouse header --- src/MultiReport/3DMouse.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/MultiReport/3DMouse.h diff --git a/src/MultiReport/3DMouse.h b/src/MultiReport/3DMouse.h new file mode 100644 index 00000000..e67a327e --- /dev/null +++ b/src/MultiReport/3DMouse.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include "HID.h" +#include "HID-Settings.h" +#include "../HID-APIs/3DMouseAPI.h" + + +class 3DMouse_ : public 3DMouseAPI +{ +public: + 3DMouse_(void); + +protected: + virtual inline void SendReport(void* data, int length) override; +}; +extern 3DMouse_ 3DMouse; + From b136b787114e1c66e5abbae63bc7ef966240ded9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Lev=C3=AD=C4=8Dek?= <46134697+Matesaktesak@users.noreply.github.com> Date: Mon, 23 Sep 2019 19:18:51 +0200 Subject: [PATCH 05/13] Created the 3D mouse api --- src/HID-APIs/3DMouseAPI.hpp | 168 ++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 src/HID-APIs/3DMouseAPI.hpp diff --git a/src/HID-APIs/3DMouseAPI.hpp b/src/HID-APIs/3DMouseAPI.hpp new file mode 100644 index 00000000..2930a65b --- /dev/null +++ b/src/HID-APIs/3DMouseAPI.hpp @@ -0,0 +1,168 @@ +#pragma once + +3DMouseAPI::3DMouseAPI(void) : _button(false) +{ + // Empty +} + +void 3DMouseAPI::begin(void) +{ + end(); +} + +void 3DMouseAPI::end(void) +{ + _button0 = false; + _button1 = false; + _button2 = false; + rotate("x", 0); + rotate("y", 0); + rotate("z", 0); + move("x", 0); + move("y", 0); + move("z", 0); +} + +void 3DMouseAPI::click(int button) +{ + switch(button){ + case 0: + _button0 = true; + update(void); + _button0 = false; + update(void); + break; + case 0: + _button1 = true; + update(void); + _button1 = false; + update(void); + break; + case 0: + _button2 = true; + update(void); + _button2 = false; + update(void); + break; + } +} + +void 3DMouseAPI::rotate(string axis, int16_t rotation) +{ + if(axis == "x") + _xRot = rotation; + if (axis == "y") + _yRot = rotation; + if (axis == "y") + _zRot = rotation; +} + +void 3DMouseAPI::move(string axis, int16_t pos) +{ + if (axis == "x") + _x = pos; + if (axis == "y") + _y = pos; + if (axis == "y") + _z = pos; +} + +void 3DMouseAPI::update(void) +{ + HID_3DMouseReport_Data_t report; + report.button0 = _button0; + report.button1 = _button1; + report.button2 = _button2; + report.xRot = _xRot; + report.yRot = _yRot; + report.zRot = _zRot; + report.xAxis = _x; + report.yAxis = _y; + report.zAxis = _z; + + SendReport(&report, sizeof(report)); +} + +void 3DMouseAPI::button0(bool b) +{ + if (b != _button0) + { + _button0 = b; + update(); + } +} + +void 3DMouseAPI::button1(bool b) +{ + if (b != _button1) + { + _button1 = b; + update(); + } +} + +void 3DMouseAPI::button2(bool b) +{ + if (b != _button2) + { + _button2 = b; + update(); + } +} + + + +void 3DMouseAPI::press(int button) +{ + switch(button){ + case 0: + button0(true); + break; + case 1: + button1(true); + break; + case 2: + button2(true); + break; + } +} + +void 3DMouseAPI::release(void) +{ + switch (button) + { + case 0: + button0(false); + break; + case 1: + button1(false); + break; + case 2: + button2(false); + break; + } +} + +void 3DMouseAPI::releaseAll(void) +{ + _button0 = false; + _button1 = false; + _button2 = false; + update(); +} + +bool 3DMouseAPI::isPressed() +{ + switch (button) + { + case 0: + return _button0; + break; + case 1: + return _button1; + break; + case 2: + return _button2; + break; + } +} From 856efbf30322dc02824c4867d0a0b984989e7545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Lev=C3=AD=C4=8Dek?= <46134697+Matesaktesak@users.noreply.github.com> Date: Mon, 23 Sep 2019 19:20:14 +0200 Subject: [PATCH 06/13] Create 3DMouseAPI.h --- src/HID-APIs/3DMouseAPI.h | 69 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/HID-APIs/3DMouseAPI.h diff --git a/src/HID-APIs/3DMouseAPI.h b/src/HID-APIs/3DMouseAPI.h new file mode 100644 index 00000000..724c5518 --- /dev/null +++ b/src/HID-APIs/3DMouseAPI.h @@ -0,0 +1,69 @@ +#pragma once + +#include +#include "HID-Settings.h" + +typedef union{ + uint8_t whole8[0]; + uint16_t whole16[0]; + uint32_t whole32[0]; + + struct{ + uint8_t button0; + uint8_t button1; + uint8_t button2; + int16_t xAxis; + int16_t yAxis; + int16_t zAxis; + int16_t xRot; + int16_t yRot; + int16_t zRot; + }; +} HID_3DMouseReport_Data_t; + +class 3DMouseAPI +{ +public: + inline 3DMouseAPI(void); + inline void begin(void); + inline void end(void); + inline void click(int button); + inline void rotate(string axis, int16_t rotation); + inline void move(string axis, int16_t len); + inline void press(int button); + inline void release(int button); + inline void releaseAll(void); + inline bool isPressed(int button); + + virtual void SendReport(void* data, int length) = 0; + +protected: + bool _button0; + inline void button0(bool b); + + bool _button1; + inline void button1(bool b); + + bool _button2; + inline void button2(bool b); + + int16_t _xRot; + inline void xRot(int16_t rotation); + + int16_t _yRot; + inline void yRot(int16_t rotation); + + int16_t _zRot; + inline void zRot(int16_t rotation); + + int16_t _x; + inline void xAxis(int16_t pos); + + int16_t _y; + inline void yAxis(int16_t pos); + + int16_t _z; + inline void zAxis(int16_t pos); +}; + +#include "3DMouseAPI.hpp" From 717cc2aba634d4c80dc437571b29775e3f9fdeeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Lev=C3=AD=C4=8Dek?= <46134697+Matesaktesak@users.noreply.github.com> Date: Mon, 23 Sep 2019 21:41:36 +0200 Subject: [PATCH 07/13] Changed from 3DMouse to D3Mouse and more --- src/HID-APIs/3DMouseAPI.h | 69 -------------------------------------- src/HID-APIs/D3MouseAPI.h | 70 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 69 deletions(-) delete mode 100644 src/HID-APIs/3DMouseAPI.h create mode 100644 src/HID-APIs/D3MouseAPI.h diff --git a/src/HID-APIs/3DMouseAPI.h b/src/HID-APIs/3DMouseAPI.h deleted file mode 100644 index 724c5518..00000000 --- a/src/HID-APIs/3DMouseAPI.h +++ /dev/null @@ -1,69 +0,0 @@ -#pragma once - -#include -#include "HID-Settings.h" - -typedef union{ - uint8_t whole8[0]; - uint16_t whole16[0]; - uint32_t whole32[0]; - - struct{ - uint8_t button0; - uint8_t button1; - uint8_t button2; - int16_t xAxis; - int16_t yAxis; - int16_t zAxis; - int16_t xRot; - int16_t yRot; - int16_t zRot; - }; -} HID_3DMouseReport_Data_t; - -class 3DMouseAPI -{ -public: - inline 3DMouseAPI(void); - inline void begin(void); - inline void end(void); - inline void click(int button); - inline void rotate(string axis, int16_t rotation); - inline void move(string axis, int16_t len); - inline void press(int button); - inline void release(int button); - inline void releaseAll(void); - inline bool isPressed(int button); - - virtual void SendReport(void* data, int length) = 0; - -protected: - bool _button0; - inline void button0(bool b); - - bool _button1; - inline void button1(bool b); - - bool _button2; - inline void button2(bool b); - - int16_t _xRot; - inline void xRot(int16_t rotation); - - int16_t _yRot; - inline void yRot(int16_t rotation); - - int16_t _zRot; - inline void zRot(int16_t rotation); - - int16_t _x; - inline void xAxis(int16_t pos); - - int16_t _y; - inline void yAxis(int16_t pos); - - int16_t _z; - inline void zAxis(int16_t pos); -}; - -#include "3DMouseAPI.hpp" diff --git a/src/HID-APIs/D3MouseAPI.h b/src/HID-APIs/D3MouseAPI.h new file mode 100644 index 00000000..2358a1e4 --- /dev/null +++ b/src/HID-APIs/D3MouseAPI.h @@ -0,0 +1,70 @@ +#pragma once + +#include +#include "HID-Settings.h" + +typedef union { + uint8_t whole8[0]; + uint16_t whole16[0]; + uint32_t whole32[0]; + + struct + { + uint8_t button0; + uint8_t button1; + uint8_t button2; + int16_t xAxis; + int16_t yAxis; + int16_t zAxis; + int16_t xRot; + int16_t yRot; + int16_t zRot; + }; +} HID_D3MouseReport_Data_t; + +class D3MouseAPI +{ + public: + inline D3MouseAPI(void); + inline void begin(void); + inline void end(void); + inline void click(int button); + inline void rotate(String axis, int16_t rotation); + inline void move(String axis, int16_t len); + inline void press(int button); + inline void release(int button); + inline void releaseAll(void); + inline bool isPressed(int button); + + virtual void SendReport(void *data, int length) = 0; + + protected: + bool _button0; + inline void button0(bool b); + + bool _button1; + inline void button1(bool b); + + bool _button2; + inline void button2(bool b); + + int16_t _xRot; + inline void xRot(int16_t rotation); + + int16_t _yRot; + inline void yRot(int16_t rotation); + + int16_t _zRot; + inline void zRot(int16_t rotation); + + int16_t _x; + inline void xAxis(int16_t pos); + + int16_t _y; + inline void yAxis(int16_t pos); + + int16_t _z; + inline void zAxis(int16_t pos); +}; + +#include "D3MouseAPI.hpp" From a1bcf06edf6f5b936a2cb14dbe9182094a83984f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Lev=C3=AD=C4=8Dek?= <46134697+Matesaktesak@users.noreply.github.com> Date: Mon, 23 Sep 2019 21:42:28 +0200 Subject: [PATCH 08/13] Update and rename 3DMouseAPI.hpp to D3MouseAPI.hpp --- .../{3DMouseAPI.hpp => D3MouseAPI.hpp} | 94 +++++++++---------- 1 file changed, 47 insertions(+), 47 deletions(-) rename src/HID-APIs/{3DMouseAPI.hpp => D3MouseAPI.hpp} (54%) diff --git a/src/HID-APIs/3DMouseAPI.hpp b/src/HID-APIs/D3MouseAPI.hpp similarity index 54% rename from src/HID-APIs/3DMouseAPI.hpp rename to src/HID-APIs/D3MouseAPI.hpp index 2930a65b..356af1e4 100644 --- a/src/HID-APIs/3DMouseAPI.hpp +++ b/src/HID-APIs/D3MouseAPI.hpp @@ -1,16 +1,16 @@ #pragma once -3DMouseAPI::3DMouseAPI(void) : _button(false) +D3MouseAPI::D3MouseAPI(void) : _button(false) { // Empty } -void 3DMouseAPI::begin(void) +void D3MouseAPI::begin(void) { end(); } -void 3DMouseAPI::end(void) +void D3MouseAPI::end(void) { _button0 = false; _button1 = false; @@ -23,33 +23,34 @@ void 3DMouseAPI::end(void) move("z", 0); } -void 3DMouseAPI::click(int button) +void D3MouseAPI::click(int button) { - switch(button){ - case 0: - _button0 = true; - update(void); - _button0 = false; - update(void); - break; - case 0: - _button1 = true; - update(void); - _button1 = false; - update(void); - break; - case 0: - _button2 = true; - update(void); - _button2 = false; - update(void); - break; + switch (button) + { + case 0: + _button0 = true; + update(void); + _button0 = false; + update(void); + break; + case 1: + _button1 = true; + update(void); + _button1 = false; + update(void); + break; + case 2: + _button2 = true; + update(void); + _button2 = false; + update(void); + break; } } -void 3DMouseAPI::rotate(string axis, int16_t rotation) +void D3MouseAPI::rotate(String axis, int16_t rotation) { - if(axis == "x") + if (axis == "x") _xRot = rotation; if (axis == "y") _yRot = rotation; @@ -57,7 +58,7 @@ void 3DMouseAPI::rotate(string axis, int16_t rotation) _zRot = rotation; } -void 3DMouseAPI::move(string axis, int16_t pos) +void D3MouseAPI::move(String axis, int16_t pos) { if (axis == "x") _x = pos; @@ -67,9 +68,9 @@ void 3DMouseAPI::move(string axis, int16_t pos) _z = pos; } -void 3DMouseAPI::update(void) +void D3MouseAPI::update(void) { - HID_3DMouseReport_Data_t report; + HID_D3MouseReport_Data_t report; report.button0 = _button0; report.button1 = _button1; report.button2 = _button2; @@ -83,7 +84,7 @@ void 3DMouseAPI::update(void) SendReport(&report, sizeof(report)); } -void 3DMouseAPI::button0(bool b) +void D3MouseAPI::button0(bool b) { if (b != _button0) { @@ -92,7 +93,7 @@ void 3DMouseAPI::button0(bool b) } } -void 3DMouseAPI::button1(bool b) +void D3MouseAPI::button1(bool b) { if (b != _button1) { @@ -101,7 +102,7 @@ void 3DMouseAPI::button1(bool b) } } -void 3DMouseAPI::button2(bool b) +void D3MouseAPI::button2(bool b) { if (b != _button2) { @@ -110,24 +111,23 @@ void 3DMouseAPI::button2(bool b) } } - - -void 3DMouseAPI::press(int button) +void D3MouseAPI::press(int button) { - switch(button){ - case 0: - button0(true); - break; - case 1: - button1(true); - break; - case 2: - button2(true); - break; + switch (button) + { + case 0: + button0(true); + break; + case 1: + button1(true); + break; + case 2: + button2(true); + break; } } -void 3DMouseAPI::release(void) +void D3MouseAPI::release(void) { switch (button) { @@ -143,7 +143,7 @@ void 3DMouseAPI::release(void) } } -void 3DMouseAPI::releaseAll(void) +void D3MouseAPI::releaseAll(void) { _button0 = false; _button1 = false; @@ -151,7 +151,7 @@ void 3DMouseAPI::releaseAll(void) update(); } -bool 3DMouseAPI::isPressed() +bool D3MouseAPI::isPressed() { switch (button) { From dc1b28d612a258ebe9fd0e353eef98d1164b4633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Lev=C3=AD=C4=8Dek?= <46134697+Matesaktesak@users.noreply.github.com> Date: Mon, 23 Sep 2019 21:43:07 +0200 Subject: [PATCH 09/13] Update and rename 3DMouse.h to D3Mouse.h --- src/MultiReport/3DMouse.h | 18 ------------------ src/MultiReport/D3Mouse.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 18 deletions(-) delete mode 100644 src/MultiReport/3DMouse.h create mode 100644 src/MultiReport/D3Mouse.h diff --git a/src/MultiReport/3DMouse.h b/src/MultiReport/3DMouse.h deleted file mode 100644 index e67a327e..00000000 --- a/src/MultiReport/3DMouse.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include -#include "HID.h" -#include "HID-Settings.h" -#include "../HID-APIs/3DMouseAPI.h" - - -class 3DMouse_ : public 3DMouseAPI -{ -public: - 3DMouse_(void); - -protected: - virtual inline void SendReport(void* data, int length) override; -}; -extern 3DMouse_ 3DMouse; - diff --git a/src/MultiReport/D3Mouse.h b/src/MultiReport/D3Mouse.h new file mode 100644 index 00000000..83736a44 --- /dev/null +++ b/src/MultiReport/D3Mouse.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include "HID.h" +#include "HID-Settings.h" +#include "../HID-APIs/D3MouseAPI.h" + +class D3Mouse_ : public D3MouseAPI +{ + public: + D3Mouse_(void); + + protected: + virtual inline void SendReport(void *data, int length) override; +}; +extern D3Mouse_ D3Mouse; From fa53506e1ffdeb672c7fedb57e94106c9a45c913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Lev=C3=AD=C4=8Dek?= <46134697+Matesaktesak@users.noreply.github.com> Date: Mon, 23 Sep 2019 21:43:44 +0200 Subject: [PATCH 10/13] Update and rename 3DMouse.cpp to D3Mouse.cpp --- src/MultiReport/{3DMouse.cpp => D3Mouse.cpp} | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) rename src/MultiReport/{3DMouse.cpp => D3Mouse.cpp} (69%) diff --git a/src/MultiReport/3DMouse.cpp b/src/MultiReport/D3Mouse.cpp similarity index 69% rename from src/MultiReport/3DMouse.cpp rename to src/MultiReport/D3Mouse.cpp index d7f49840..ac887fcb 100644 --- a/src/MultiReport/3DMouse.cpp +++ b/src/MultiReport/D3Mouse.cpp @@ -1,6 +1,6 @@ -#include "3DMouse.h" +#include "D3Mouse.h" -static const uint8_t _hidMultiReportDescriptor3DMouse[] PROGMEM = { +static const uint8_t _hidMultiReportDescriptorD3Mouse[] PROGMEM = { 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x09, 0x08, // USAGE (Multiaxis) 0xa1, 0x01, // COLLECTION (Application) @@ -20,24 +20,24 @@ static const uint8_t _hidMultiReportDescriptor3DMouse[] PROGMEM = { 0x09, 0x33, // USAGE (Rx) 0x09, 0x34, // USAGE (Ry) 0x09, 0x35, // USAGE (Rz) - 0x16, 0x00, 0x80, // LOGICAL_MINIMUM (-32K) - 0x27, 0x00, 0x80, // LOGICAL_MAXIMUM (32K) - 0x75, 0x10, // REPORT_SIZE (16) + 0x16, 0x00, 0xfe, // LOGICAL_MINIMUM (-512) + 0x26, 0x00, 0x02, // LOGICAL_MAXIMUM (512) + 0x75, 0x0a, // REPORT_SIZE (10) 0x95, 0x06, // REPORT_COUNT (6) 0x81, 0x06, // INPUT (Data,Var,Rel) 0xc0, // END_COLLECTION 0xc0 // END_COLLECTION }; -3DMouse_::3DMouse_(void) +D3Mouse_ ::D3Mouse_(void) { - static HIDSubDescriptor node(_hidMultiReportDescriptor3DMouse, sizeof(_hidMultiReportDescriptor3DMouse)); + static HIDSubDescriptor node(_hidMultiReportDescriptorD3Mouse, sizeof(_hidMultiReportDescriptorD3Mouse)); HID().AppendDescriptor(&node); } -void 3DMouse_::SendReport(void *data, int length) +void D3Mouse_ ::SendReport(void *data, int length) { - HID().SendReport(HID_REPORTID_3DMOUSE, data, length); + HID().SendReport(HID_REPORTID_D3MOUSE, data, length); } -3DMouse_ 3DMouse; +D3Mouse_ D3Mouse; From 6af2158d9d7932f15a3d4cae2635f8c5fed27c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Lev=C3=AD=C4=8Dek?= <46134697+Matesaktesak@users.noreply.github.com> Date: Tue, 24 Sep 2019 19:13:40 +0200 Subject: [PATCH 11/13] Fixed beginer mistakes --- src/HID-APIs/D3MouseAPI.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/HID-APIs/D3MouseAPI.h b/src/HID-APIs/D3MouseAPI.h index 2358a1e4..7f9f93d4 100644 --- a/src/HID-APIs/D3MouseAPI.h +++ b/src/HID-APIs/D3MouseAPI.h @@ -10,15 +10,15 @@ typedef union { struct { - uint8_t button0; - uint8_t button1; - uint8_t button2; - int16_t xAxis; - int16_t yAxis; - int16_t zAxis; - int16_t xRot; - int16_t yRot; - int16_t zRot; + uint8_t button0 : 1; + uint8_t button1 : 1; + uint8_t button2 : 1; + int16_t xAxis : 15; + int16_t yAxis : 15; + int16_t zAxis : 15; + int16_t xRot : 15; + int16_t yRot : 15; + int16_t zRot : 15; }; } HID_D3MouseReport_Data_t; @@ -35,6 +35,7 @@ class D3MouseAPI inline void release(int button); inline void releaseAll(void); inline bool isPressed(int button); + inline void update(void); virtual void SendReport(void *data, int length) = 0; From 1f29d5a4ee1f1c829495d55bb44ce0216c65a1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Lev=C3=AD=C4=8Dek?= <46134697+Matesaktesak@users.noreply.github.com> Date: Tue, 24 Sep 2019 19:14:42 +0200 Subject: [PATCH 12/13] Update D3MouseAPI.hpp --- src/HID-APIs/D3MouseAPI.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/HID-APIs/D3MouseAPI.hpp b/src/HID-APIs/D3MouseAPI.hpp index 356af1e4..b0226672 100644 --- a/src/HID-APIs/D3MouseAPI.hpp +++ b/src/HID-APIs/D3MouseAPI.hpp @@ -1,6 +1,6 @@ #pragma once -D3MouseAPI::D3MouseAPI(void) : _button(false) +D3MouseAPI::D3MouseAPI(void) : _button0(false) { // Empty } @@ -29,21 +29,21 @@ void D3MouseAPI::click(int button) { case 0: _button0 = true; - update(void); + update(); _button0 = false; - update(void); + update(); break; case 1: _button1 = true; - update(void); + update(); _button1 = false; - update(void); + update(); break; case 2: _button2 = true; - update(void); + update(); _button2 = false; - update(void); + update(); break; } } @@ -127,7 +127,7 @@ void D3MouseAPI::press(int button) } } -void D3MouseAPI::release(void) +void D3MouseAPI::release(int button) { switch (button) { @@ -151,7 +151,7 @@ void D3MouseAPI::releaseAll(void) update(); } -bool D3MouseAPI::isPressed() +bool D3MouseAPI::isPressed(int button) { switch (button) { From db786e84e0bd0aea1d35dfbdb815f86ea645cee8 Mon Sep 17 00:00:00 2001 From: Adam Mazzarella <3219297+apm963@users.noreply.github.com> Date: Sat, 17 Jul 2021 10:04:01 -0400 Subject: [PATCH 13/13] Apply suggestions from code review --- src/HID-APIs/D3MouseAPI.h | 4 ++-- src/HID-APIs/D3MouseAPI.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/HID-APIs/D3MouseAPI.h b/src/HID-APIs/D3MouseAPI.h index 7f9f93d4..c49f95d6 100644 --- a/src/HID-APIs/D3MouseAPI.h +++ b/src/HID-APIs/D3MouseAPI.h @@ -3,12 +3,12 @@ #include #include "HID-Settings.h" -typedef union { +typedef union ATTRIBUTE_PACKED { uint8_t whole8[0]; uint16_t whole16[0]; uint32_t whole32[0]; - struct + struct ATTRIBUTE_PACKED { uint8_t button0 : 1; uint8_t button1 : 1; diff --git a/src/HID-APIs/D3MouseAPI.hpp b/src/HID-APIs/D3MouseAPI.hpp index b0226672..ae1b480f 100644 --- a/src/HID-APIs/D3MouseAPI.hpp +++ b/src/HID-APIs/D3MouseAPI.hpp @@ -54,7 +54,7 @@ void D3MouseAPI::rotate(String axis, int16_t rotation) _xRot = rotation; if (axis == "y") _yRot = rotation; - if (axis == "y") + if (axis == "z") _zRot = rotation; } @@ -64,7 +64,7 @@ void D3MouseAPI::move(String axis, int16_t pos) _x = pos; if (axis == "y") _y = pos; - if (axis == "y") + if (axis == "z") _z = pos; }