From 1ea2c7c993389b536fa1ff425c250fb5b02a9121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Olaiz?= Date: Thu, 21 Mar 2024 00:34:00 -0300 Subject: [PATCH] Add HID_DONT_CREATE_INSTANCES flag (workaround for #266 #316 #139) --- src/MultiReport/AbsoluteMouse.cpp | 3 ++- src/MultiReport/AbsoluteMouse.h | 4 +++- src/MultiReport/Consumer.cpp | 3 ++- src/MultiReport/Consumer.h | 4 +++- src/MultiReport/Gamepad.cpp | 3 ++- src/MultiReport/Gamepad.h | 4 +++- src/MultiReport/ImprovedKeyboard.cpp | 3 ++- src/MultiReport/ImprovedKeyboard.h | 4 +++- src/MultiReport/ImprovedMouse.cpp | 3 ++- src/MultiReport/ImprovedMouse.h | 4 +++- src/MultiReport/NKROKeyboard.cpp | 3 ++- src/MultiReport/NKROKeyboard.h | 4 +++- src/MultiReport/SurfaceDial.cpp | 2 ++ src/MultiReport/SurfaceDial.h | 4 +++- src/MultiReport/System.cpp | 4 +++- src/MultiReport/System.h | 4 +++- src/SingleReport/BootKeyboard.cpp | 5 ++--- src/SingleReport/BootKeyboard.h | 5 +++-- src/SingleReport/BootMouse.cpp | 4 ++-- src/SingleReport/BootMouse.h | 5 +++-- src/SingleReport/RawHID.cpp | 2 ++ src/SingleReport/RawHID.h | 3 +++ src/SingleReport/SingleAbsoluteMouse.cpp | 4 ++-- src/SingleReport/SingleAbsoluteMouse.h | 5 +++-- src/SingleReport/SingleConsumer.cpp | 4 ++-- src/SingleReport/SingleConsumer.h | 5 +++-- src/SingleReport/SingleGamepad.cpp | 4 ++-- src/SingleReport/SingleGamepad.h | 5 +++-- src/SingleReport/SingleNKROKeyboard.cpp | 4 ++-- src/SingleReport/SingleNKROKeyboard.h | 5 +++-- src/SingleReport/SingleSystem.cpp | 4 ++-- src/SingleReport/SingleSystem.h | 5 +++-- 32 files changed, 81 insertions(+), 44 deletions(-) diff --git a/src/MultiReport/AbsoluteMouse.cpp b/src/MultiReport/AbsoluteMouse.cpp index 6a2ee819..906794c7 100644 --- a/src/MultiReport/AbsoluteMouse.cpp +++ b/src/MultiReport/AbsoluteMouse.cpp @@ -75,5 +75,6 @@ void AbsoluteMouse_::SendReport(void* data, int length) HID().SendReport(HID_REPORTID_MOUSE_ABSOLUTE, data, length); } +#ifndef HID_DONT_CREATE_INSTANCES AbsoluteMouse_ AbsoluteMouse; - +#endif diff --git a/src/MultiReport/AbsoluteMouse.h b/src/MultiReport/AbsoluteMouse.h index 34d271a4..d6df0a3a 100644 --- a/src/MultiReport/AbsoluteMouse.h +++ b/src/MultiReport/AbsoluteMouse.h @@ -38,5 +38,7 @@ class AbsoluteMouse_ : public AbsoluteMouseAPI protected: virtual inline void SendReport(void* data, int length) override; }; -extern AbsoluteMouse_ AbsoluteMouse; +#ifndef HID_DONT_CREATE_INSTANCES +extern AbsoluteMouse_ AbsoluteMouse; +#endif diff --git a/src/MultiReport/Consumer.cpp b/src/MultiReport/Consumer.cpp index 0fa6841e..d4f7c250 100644 --- a/src/MultiReport/Consumer.cpp +++ b/src/MultiReport/Consumer.cpp @@ -53,5 +53,6 @@ void Consumer_::SendReport(void* data, int length) HID().SendReport(HID_REPORTID_CONSUMERCONTROL, data, length); } +#ifndef HID_DONT_CREATE_INSTANCES Consumer_ Consumer; - +#endif diff --git a/src/MultiReport/Consumer.h b/src/MultiReport/Consumer.h index c6951919..e0acd852 100644 --- a/src/MultiReport/Consumer.h +++ b/src/MultiReport/Consumer.h @@ -38,5 +38,7 @@ class Consumer_ : public ConsumerAPI protected: virtual inline void SendReport(void* data, int length) override; }; -extern Consumer_ Consumer; +#ifndef HID_DONT_CREATE_INSTANCES +extern Consumer_ Consumer; +#endif diff --git a/src/MultiReport/Gamepad.cpp b/src/MultiReport/Gamepad.cpp index 86b95e65..ef027b39 100644 --- a/src/MultiReport/Gamepad.cpp +++ b/src/MultiReport/Gamepad.cpp @@ -84,5 +84,6 @@ void Gamepad_::SendReport(void* data, int length) HID().SendReport(HID_REPORTID_GAMEPAD, data, length); } +#ifndef HID_DONT_CREATE_INSTANCES Gamepad_ Gamepad; - +#endif diff --git a/src/MultiReport/Gamepad.h b/src/MultiReport/Gamepad.h index 8ef216a6..c78a3d0e 100644 --- a/src/MultiReport/Gamepad.h +++ b/src/MultiReport/Gamepad.h @@ -38,5 +38,7 @@ class Gamepad_ : public GamepadAPI protected: virtual inline void SendReport(void* data, int length) override; }; -extern Gamepad_ Gamepad; +#ifndef HID_DONT_CREATE_INSTANCES +extern Gamepad_ Gamepad; +#endif diff --git a/src/MultiReport/ImprovedKeyboard.cpp b/src/MultiReport/ImprovedKeyboard.cpp index d805d66a..f38b2750 100644 --- a/src/MultiReport/ImprovedKeyboard.cpp +++ b/src/MultiReport/ImprovedKeyboard.cpp @@ -81,5 +81,6 @@ void Keyboard_::wakeupHost(void){ #endif } +#ifndef HID_DONT_CREATE_INSTANCES Keyboard_ Keyboard; - +#endif diff --git a/src/MultiReport/ImprovedKeyboard.h b/src/MultiReport/ImprovedKeyboard.h index f6c8084e..65e3a3a4 100644 --- a/src/MultiReport/ImprovedKeyboard.h +++ b/src/MultiReport/ImprovedKeyboard.h @@ -38,5 +38,7 @@ class Keyboard_ : public DefaultKeyboardAPI virtual inline int send(void) final; }; -extern Keyboard_ Keyboard; +#ifndef HID_DONT_CREATE_INSTANCES +extern Keyboard_ Keyboard; +#endif diff --git a/src/MultiReport/ImprovedMouse.cpp b/src/MultiReport/ImprovedMouse.cpp index 9e4ffebc..6fc017cb 100644 --- a/src/MultiReport/ImprovedMouse.cpp +++ b/src/MultiReport/ImprovedMouse.cpp @@ -69,5 +69,6 @@ void Mouse_::SendReport(void* data, int length) HID().SendReport(HID_REPORTID_MOUSE, data, length); } +#ifndef HID_DONT_CREATE_INSTANCES Mouse_ Mouse; - +#endif diff --git a/src/MultiReport/ImprovedMouse.h b/src/MultiReport/ImprovedMouse.h index fd99cf2c..e31e9540 100644 --- a/src/MultiReport/ImprovedMouse.h +++ b/src/MultiReport/ImprovedMouse.h @@ -38,5 +38,7 @@ class Mouse_ : public MouseAPI protected: virtual inline void SendReport(void* data, int length) override; }; -extern Mouse_ Mouse; +#ifndef HID_DONT_CREATE_INSTANCES +extern Mouse_ Mouse; +#endif diff --git a/src/MultiReport/NKROKeyboard.cpp b/src/MultiReport/NKROKeyboard.cpp index 27c21487..140f554e 100644 --- a/src/MultiReport/NKROKeyboard.cpp +++ b/src/MultiReport/NKROKeyboard.cpp @@ -73,5 +73,6 @@ int NKROKeyboard_::send(void) return HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, &_keyReport, sizeof(_keyReport)); } +#ifndef HID_DONT_CREATE_INSTANCES NKROKeyboard_ NKROKeyboard; - +#endif diff --git a/src/MultiReport/NKROKeyboard.h b/src/MultiReport/NKROKeyboard.h index 725697c4..4a69efcf 100644 --- a/src/MultiReport/NKROKeyboard.h +++ b/src/MultiReport/NKROKeyboard.h @@ -37,5 +37,7 @@ class NKROKeyboard_ : public NKROKeyboardAPI virtual int send(void) final; }; -extern NKROKeyboard_ NKROKeyboard; +#ifndef HID_DONT_CREATE_INSTANCES +extern NKROKeyboard_ NKROKeyboard; +#endif diff --git a/src/MultiReport/SurfaceDial.cpp b/src/MultiReport/SurfaceDial.cpp index f35d99ef..96e52efe 100644 --- a/src/MultiReport/SurfaceDial.cpp +++ b/src/MultiReport/SurfaceDial.cpp @@ -84,4 +84,6 @@ void SurfaceDial_::SendReport(void *data, int length) HID().SendReport(HID_REPORTID_SURFACEDIAL, data, length); } +#ifndef HID_DONT_CREATE_INSTANCES SurfaceDial_ SurfaceDial; +#endif diff --git a/src/MultiReport/SurfaceDial.h b/src/MultiReport/SurfaceDial.h index af042c67..07730d41 100644 --- a/src/MultiReport/SurfaceDial.h +++ b/src/MultiReport/SurfaceDial.h @@ -38,5 +38,7 @@ class SurfaceDial_ : public SurfaceDialAPI protected: virtual inline void SendReport(void* data, int length) override; }; -extern SurfaceDial_ SurfaceDial; +#ifndef HID_DONT_CREATE_INSTANCES +extern SurfaceDial_ SurfaceDial; +#endif diff --git a/src/MultiReport/System.cpp b/src/MultiReport/System.cpp index 6ba4ab40..41db1c25 100644 --- a/src/MultiReport/System.cpp +++ b/src/MultiReport/System.cpp @@ -54,5 +54,7 @@ void System_::SendReport(void* data, int length) HID().SendReport(HID_REPORTID_SYSTEMCONTROL, data, length); } -System_ System; +#ifndef HID_DONT_CREATE_INSTANCES +System_ System; +#endif diff --git a/src/MultiReport/System.h b/src/MultiReport/System.h index 0581f85c..2b3bc041 100644 --- a/src/MultiReport/System.h +++ b/src/MultiReport/System.h @@ -38,5 +38,7 @@ class System_ : public SystemAPI protected: virtual inline void SendReport(void* data, int length) override; }; -extern System_ System; +#ifndef HID_DONT_CREATE_INSTANCES +extern System_ System; +#endif diff --git a/src/SingleReport/BootKeyboard.cpp b/src/SingleReport/BootKeyboard.cpp index 3f29463d..2522bafd 100644 --- a/src/SingleReport/BootKeyboard.cpp +++ b/src/SingleReport/BootKeyboard.cpp @@ -211,7 +211,6 @@ void BootKeyboard_::wakeupHost(void){ #endif } - +#ifndef HID_DONT_CREATE_INSTANCES BootKeyboard_ BootKeyboard; - - +#endif diff --git a/src/SingleReport/BootKeyboard.h b/src/SingleReport/BootKeyboard.h index feb72bcf..a50b3464 100644 --- a/src/SingleReport/BootKeyboard.h +++ b/src/SingleReport/BootKeyboard.h @@ -80,6 +80,7 @@ class BootKeyboard_ : public PluggableUSBModule, public DefaultKeyboardAPI uint8_t* featureReport; int featureLength; }; -extern BootKeyboard_ BootKeyboard; - +#ifndef HID_DONT_CREATE_INSTANCES +extern BootKeyboard_ BootKeyboard; +#endif diff --git a/src/SingleReport/BootMouse.cpp b/src/SingleReport/BootMouse.cpp index 77b3573c..d24ffe07 100644 --- a/src/SingleReport/BootMouse.cpp +++ b/src/SingleReport/BootMouse.cpp @@ -160,6 +160,6 @@ void BootMouse_::SendReport(void* data, int length){ } } +#ifndef HID_DONT_CREATE_INSTANCES BootMouse_ BootMouse; - - +#endif diff --git a/src/SingleReport/BootMouse.h b/src/SingleReport/BootMouse.h index d227bc65..74578fe7 100644 --- a/src/SingleReport/BootMouse.h +++ b/src/SingleReport/BootMouse.h @@ -48,6 +48,7 @@ class BootMouse_ : public PluggableUSBModule, public MouseAPI virtual void SendReport(void* data, int length) override; }; -extern BootMouse_ BootMouse; - +#ifndef HID_DONT_CREATE_INSTANCES +extern BootMouse_ BootMouse; +#endif diff --git a/src/SingleReport/RawHID.cpp b/src/SingleReport/RawHID.cpp index 181d8b1f..bd14b8bb 100644 --- a/src/SingleReport/RawHID.cpp +++ b/src/SingleReport/RawHID.cpp @@ -146,4 +146,6 @@ bool RawHID_::setup(USBSetup& setup) return false; } +#ifndef HID_DONT_CREATE_INSTANCES RawHID_ RawHID; +#endif diff --git a/src/SingleReport/RawHID.h b/src/SingleReport/RawHID.h index b23aaa5a..69df25d0 100644 --- a/src/SingleReport/RawHID.h +++ b/src/SingleReport/RawHID.h @@ -175,4 +175,7 @@ class RawHID_ : public PluggableUSBModule, public Stream uint8_t* featureReport; int featureLength; }; + +#ifndef HID_DONT_CREATE_INSTANCES extern RawHID_ RawHID; +#endif diff --git a/src/SingleReport/SingleAbsoluteMouse.cpp b/src/SingleReport/SingleAbsoluteMouse.cpp index 94238cc3..79a2103b 100644 --- a/src/SingleReport/SingleAbsoluteMouse.cpp +++ b/src/SingleReport/SingleAbsoluteMouse.cpp @@ -150,6 +150,6 @@ void SingleAbsoluteMouse_::SendReport(void* data, int length) USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, length); } +#ifndef HID_DONT_CREATE_INSTANCES SingleAbsoluteMouse_ SingleAbsoluteMouse; - - +#endif diff --git a/src/SingleReport/SingleAbsoluteMouse.h b/src/SingleReport/SingleAbsoluteMouse.h index 7936be6f..715a84be 100644 --- a/src/SingleReport/SingleAbsoluteMouse.h +++ b/src/SingleReport/SingleAbsoluteMouse.h @@ -49,6 +49,7 @@ class SingleAbsoluteMouse_ : public PluggableUSBModule, public AbsoluteMouseAPI virtual inline void SendReport(void* data, int length) override; }; -extern SingleAbsoluteMouse_ SingleAbsoluteMouse; - +#ifndef HID_DONT_CREATE_INSTANCES +extern SingleAbsoluteMouse_ SingleAbsoluteMouse; +#endif diff --git a/src/SingleReport/SingleConsumer.cpp b/src/SingleReport/SingleConsumer.cpp index 6d11b0f7..852af05d 100644 --- a/src/SingleReport/SingleConsumer.cpp +++ b/src/SingleReport/SingleConsumer.cpp @@ -116,6 +116,6 @@ void SingleConsumer_::SendReport(void* data, int length) USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, length); } +#ifndef HID_DONT_CREATE_INSTANCES SingleConsumer_ SingleConsumer; - - +#endif diff --git a/src/SingleReport/SingleConsumer.h b/src/SingleReport/SingleConsumer.h index dcc823b7..1bc87e03 100644 --- a/src/SingleReport/SingleConsumer.h +++ b/src/SingleReport/SingleConsumer.h @@ -49,6 +49,7 @@ class SingleConsumer_ : public PluggableUSBModule, public ConsumerAPI virtual inline void SendReport(void* data, int length) override; }; -extern SingleConsumer_ SingleConsumer; - +#ifndef HID_DONT_CREATE_INSTANCES +extern SingleConsumer_ SingleConsumer; +#endif diff --git a/src/SingleReport/SingleGamepad.cpp b/src/SingleReport/SingleGamepad.cpp index fac0e6cb..c418b87b 100644 --- a/src/SingleReport/SingleGamepad.cpp +++ b/src/SingleReport/SingleGamepad.cpp @@ -146,9 +146,9 @@ void SingleGamepad_::SendReport(void* data, int length){ USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, length); } +#ifndef HID_DONT_CREATE_INSTANCES SingleGamepad_ Gamepad1; SingleGamepad_ Gamepad2; SingleGamepad_ Gamepad3; SingleGamepad_ Gamepad4; - - +#endif diff --git a/src/SingleReport/SingleGamepad.h b/src/SingleReport/SingleGamepad.h index 163a1078..983757aa 100644 --- a/src/SingleReport/SingleGamepad.h +++ b/src/SingleReport/SingleGamepad.h @@ -47,9 +47,10 @@ class SingleGamepad_ : public PluggableUSBModule, public GamepadAPI virtual void SendReport(void* data, int length) override; }; + +#ifndef HID_DONT_CREATE_INSTANCES extern SingleGamepad_ Gamepad1; extern SingleGamepad_ Gamepad2; extern SingleGamepad_ Gamepad3; extern SingleGamepad_ Gamepad4; - - +#endif diff --git a/src/SingleReport/SingleNKROKeyboard.cpp b/src/SingleReport/SingleNKROKeyboard.cpp index cb50743a..472b9f65 100644 --- a/src/SingleReport/SingleNKROKeyboard.cpp +++ b/src/SingleReport/SingleNKROKeyboard.cpp @@ -155,6 +155,6 @@ int SingleNKROKeyboard_::send(void){ return USB_Send(pluggedEndpoint | TRANSFER_RELEASE, &_keyReport, sizeof(_keyReport)); } +#ifndef HID_DONT_CREATE_INSTANCES SingleNKROKeyboard_ SingleNKROKeyboard; - - +#endif diff --git a/src/SingleReport/SingleNKROKeyboard.h b/src/SingleReport/SingleNKROKeyboard.h index 356af69d..5fd408a3 100644 --- a/src/SingleReport/SingleNKROKeyboard.h +++ b/src/SingleReport/SingleNKROKeyboard.h @@ -51,6 +51,7 @@ class SingleNKROKeyboard_ : public PluggableUSBModule, public NKROKeyboardAPI uint8_t leds; }; -extern SingleNKROKeyboard_ SingleNKROKeyboard; - +#ifndef HID_DONT_CREATE_INSTANCES +extern SingleNKROKeyboard_ SingleNKROKeyboard; +#endif diff --git a/src/SingleReport/SingleSystem.cpp b/src/SingleReport/SingleSystem.cpp index 3787b2f9..0505d9d1 100644 --- a/src/SingleReport/SingleSystem.cpp +++ b/src/SingleReport/SingleSystem.cpp @@ -118,6 +118,6 @@ void SingleSystem_::SendReport(void* data, int length) USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, length); } +#ifndef HID_DONT_CREATE_INSTANCES SingleSystem_ SingleSystem; - - +#endif diff --git a/src/SingleReport/SingleSystem.h b/src/SingleReport/SingleSystem.h index abb9b41c..f4d643c9 100644 --- a/src/SingleReport/SingleSystem.h +++ b/src/SingleReport/SingleSystem.h @@ -49,6 +49,7 @@ class SingleSystem_ : public PluggableUSBModule, public SystemAPI virtual inline void SendReport(void* data, int length) override; }; -extern SingleSystem_ SingleSystem; - +#ifndef HID_DONT_CREATE_INSTANCES +extern SingleSystem_ SingleSystem; +#endif