From 1bbe759c96e82cd97bc0e945f0b5290de45993cd Mon Sep 17 00:00:00 2001 From: Maschell Date: Tue, 31 Dec 2024 12:51:42 +0100 Subject: [PATCH 1/3] ButtonComboAPI: Split up header into api and defines, move into directory --- .../{button_combo.h => button_combo/api.h} | 156 +---------------- include/wups/button_combo/defines.h | 159 ++++++++++++++++++ include/wups/button_combo_internal.h | 2 +- .../wups/config/WUPSConfigItemButtonCombo.h | 2 +- .../libwups/WUPSConfigItemButtonCombo.cpp | 2 +- libraries/libwups/button_combo.cpp | 2 +- 6 files changed, 169 insertions(+), 154 deletions(-) rename include/wups/{button_combo.h => button_combo/api.h} (60%) create mode 100644 include/wups/button_combo/defines.h diff --git a/include/wups/button_combo.h b/include/wups/button_combo/api.h similarity index 60% rename from include/wups/button_combo.h rename to include/wups/button_combo/api.h index 9e4fd80..3c598ec 100644 --- a/include/wups/button_combo.h +++ b/include/wups/button_combo/api.h @@ -1,159 +1,14 @@ #pragma once +#include "WUPSButtonCombo.h" + +#include #include -#include +#include #ifdef __cplusplus extern "C" { #endif -typedef enum WUPSButtonCombo_Buttons { - //! The A button. - WUPS_BUTTON_COMBO_BUTTON_A = 0x8000, - //! The B button. - WUPS_BUTTON_COMBO_BUTTON_B = 0x4000, - //! The X button. - WUPS_BUTTON_COMBO_BUTTON_X = 0x2000, - //! The Y button. - WUPS_BUTTON_COMBO_BUTTON_Y = 0x1000, - //! The left button of the D-pad. - WUPS_BUTTON_COMBO_BUTTON_LEFT = 0x0800, - //! The right button of the D-pad. - WUPS_BUTTON_COMBO_BUTTON_RIGHT = 0x0400, - //! The up button of the D-pad. - WUPS_BUTTON_COMBO_BUTTON_UP = 0x0200, - //! The down button of the D-pad. - WUPS_BUTTON_COMBO_BUTTON_DOWN = 0x0100, - //! The ZL button. - WUPS_BUTTON_COMBO_BUTTON_ZL = 0x0080, - //! The ZR button. - WUPS_BUTTON_COMBO_BUTTON_ZR = 0x0040, - //! The L button. - WUPS_BUTTON_COMBO_BUTTON_L = 0x0020, - //! The R button. - WUPS_BUTTON_COMBO_BUTTON_R = 0x0010, - //! The + button. - WUPS_BUTTON_COMBO_BUTTON_PLUS = 0x0008, - //! The - button. - WUPS_BUTTON_COMBO_BUTTON_MINUS = 0x0004, - //! The right stick button. - WUPS_BUTTON_COMBO_BUTTON_STICK_R = 0x00020000, - //! The left stick button. - WUPS_BUTTON_COMBO_BUTTON_STICK_L = 0x00040000, - //! The TV button. - WUPS_BUTTON_COMBO_BUTTON_TV = 0x00010000, - //! The reserved bit - WUPS_BUTTON_COMBO_BUTTON_RESERVED_BIT = 0x80000, -} WUPSButtonCombo_Buttons; -WUT_ENUM_BITMASK_TYPE(WUPSButtonCombo_Buttons); - -typedef enum WUPSButtonCombo_ControllerTypes { - WUPS_BUTTON_COMBO_CONTROLLER_NONE = 0, - WUPS_BUTTON_COMBO_CONTROLLER_VPAD_0 = 1 << 0, - WUPS_BUTTON_COMBO_CONTROLLER_VPAD_1 = 1 << 1, - WUPS_BUTTON_COMBO_CONTROLLER_WPAD_0 = 1 << 2, - WUPS_BUTTON_COMBO_CONTROLLER_WPAD_1 = 1 << 3, - WUPS_BUTTON_COMBO_CONTROLLER_WPAD_2 = 1 << 4, - WUPS_BUTTON_COMBO_CONTROLLER_WPAD_3 = 1 << 5, - WUPS_BUTTON_COMBO_CONTROLLER_WPAD_4 = 1 << 6, - WUPS_BUTTON_COMBO_CONTROLLER_WPAD_5 = 1 << 7, - WUPS_BUTTON_COMBO_CONTROLLER_WPAD_6 = 1 << 8, - WUPS_BUTTON_COMBO_CONTROLLER_VPAD = WUPS_BUTTON_COMBO_CONTROLLER_VPAD_0 | WUPS_BUTTON_COMBO_CONTROLLER_VPAD_1, - WUPS_BUTTON_COMBO_CONTROLLER_WPAD = (WUPS_BUTTON_COMBO_CONTROLLER_WPAD_0 | - WUPS_BUTTON_COMBO_CONTROLLER_WPAD_1 | - WUPS_BUTTON_COMBO_CONTROLLER_WPAD_2 | - WUPS_BUTTON_COMBO_CONTROLLER_WPAD_3 | - WUPS_BUTTON_COMBO_CONTROLLER_WPAD_4 | - WUPS_BUTTON_COMBO_CONTROLLER_WPAD_5 | - WUPS_BUTTON_COMBO_CONTROLLER_WPAD_6), - WUPS_BUTTON_COMBO_CONTROLLER_ALL = WUPS_BUTTON_COMBO_CONTROLLER_VPAD | WUPS_BUTTON_COMBO_CONTROLLER_WPAD, -} WUPSButtonCombo_ControllerTypes; -WUT_ENUM_BITMASK_TYPE(WUPSButtonCombo_ControllerTypes); - -typedef enum WUPSButtonCombo_ComboType { - WUPS_BUTTON_COMBO_COMBO_TYPE_INVALID = 0, - WUPS_BUTTON_COMBO_COMBO_TYPE_HOLD = 1, // Does check for conflicts - WUPS_BUTTON_COMBO_COMBO_TYPE_PRESS_DOWN = 2, // Does check for conflicts - WUPS_BUTTON_COMBO_COMBO_TYPE_HOLD_OBSERVER = 3, // Does not check for conflicts - WUPS_BUTTON_COMBO_COMBO_TYPE_PRESS_DOWN_OBSERVER = 4, // Does not check for conflicts -} WUPSButtonCombo_ComboType; - -typedef enum WUPSButtonCombo_ComboStatus { - WUPS_BUTTON_COMBO_COMBO_STATUS_INVALID_STATUS = 0, - WUPS_BUTTON_COMBO_COMBO_STATUS_VALID = 1, - WUPS_BUTTON_COMBO_COMBO_STATUS_CONFLICT = 2, -} WUPSButtonCombo_ComboStatus; - -/** - * @enum WUPSButtonComboError - * @brief Represents error codes returned by storage API functions. - */ -typedef enum { - WUPS_BUTTON_COMBO_ERROR_SUCCESS = 0, /**< Success. */ - WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS = -0x01, /**< Invalid arguments passed to the function. */ - WUPS_BUTTON_COMBO_ERROR_MALLOC_FAILED = -0x02, /**< Memory allocation failed. */ - WUPS_BUTTON_COMBO_ERROR_NOT_FOUND = -0x03, /**< Not found. */ - WUPS_BUTTON_COMBO_ERROR_ABORTED = -0x04, /**< Not found. */ - WUPS_BUTTON_COMBO_ERROR_INTERNAL_NOT_INITIALIZED = -0xF0, /**< Library not initialized properly. */ - WUPS_BUTTON_COMBO_ERROR_INTERNAL_INVALID_VERSION = -0xF1, /**< Invalid API version. */ - WUPS_BUTTON_COMBO_ERROR_UNKNOWN_ERROR = -0x100 /**< Unknown error. */ -} WUPSButtonCombo_Error; - -typedef struct WUPSButtonCombo_ComboHandle { - void *handle; -#ifdef __cplusplus - WUPSButtonCombo_ComboHandle() { - handle = nullptr; - } - explicit WUPSButtonCombo_ComboHandle(void *handle) : handle(handle) {} - bool operator==(const WUPSButtonCombo_ComboHandle other) const { - return handle == other.handle; - } - bool operator==(const void *other) const { - return handle == other; - } -#endif -} WUPSButtonCombo_ComboHandle; - -typedef void (*WUPSButtonCombo_ComboCallback)(WUPSButtonCombo_ComboHandle handle, void *context); - -typedef struct WUPSButtonCombo_MetaOptions { - const char *label; -} WUPSButtonCombo_MetaOptions; - -typedef struct WUPSButtonCombo_MetaOptionsOut { - char *labelBuffer; - uint32_t labelBufferLength; -} WUPSButtonCombo_MetaOptionsOut; - -typedef struct WUPSButtonCombo_CallbackOptions { - WUPSButtonCombo_ComboCallback callback; - void *context; -} WUPSButtonCombo_CallbackOptions; - -typedef struct WUPSButtonCombo_ButtonComboOptions { - WUPSButtonCombo_ControllerTypes controllerMask; - WUPSButtonCombo_Buttons combo; -} WUPSButtonCombo_ButtonComboOptions; - -typedef struct WUPSButtonCombo_ButtonComboInfoEx { - WUPSButtonCombo_ComboType type; - WUPSButtonCombo_ButtonComboOptions basicCombo; - uint32_t optionalHoldForXMs; -} WUPSButtonCombo_ButtonComboInfoEx; - -typedef struct WUPSButtonCombo_ComboOptions { - WUPSButtonCombo_MetaOptions metaOptions; - WUPSButtonCombo_CallbackOptions callbackOptions; - WUPSButtonCombo_ButtonComboInfoEx buttonComboOptions; -} WUPSButtonCombo_ComboOptions; - -typedef struct WUPSButtonCombo_DetectButtonComboOptions { - WUPSButtonCombo_ControllerTypes controllerMask; - uint32_t holdComboForInMs; - uint32_t holdAbortForInMs; - WUPSButtonCombo_Buttons abortButtonCombo; -} WUPSButtonCombo_DetectButtonComboOptions; - /** * @brief Get a string representation of the specified button_combo status. * @@ -186,7 +41,8 @@ const char *WUPSButtonComboAPI_GetStatusStr(WUPSButtonCombo_Error status); * * @param label Label of this button combo * @param combo Combination which should be checked - * @param callbackOptions Information about the callbacks that will be called if the combo is triggered + * @param callback + * @param context * @param outHandle The handle of the combo will be stored here. Must not be nullptr. * @param outStatus The status of the combo will be stored here. Only if the status is WUPS_BUTTON_COMBO_COMBO_STATUS_VALID the combo is valid. Must not be nullptr. * @return diff --git a/include/wups/button_combo/defines.h b/include/wups/button_combo/defines.h new file mode 100644 index 0000000..7348008 --- /dev/null +++ b/include/wups/button_combo/defines.h @@ -0,0 +1,159 @@ +#pragma once +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum WUPSButtonCombo_Buttons { + //! The A button. + WUPS_BUTTON_COMBO_BUTTON_A = 0x8000, + //! The B button. + WUPS_BUTTON_COMBO_BUTTON_B = 0x4000, + //! The X button. + WUPS_BUTTON_COMBO_BUTTON_X = 0x2000, + //! The Y button. + WUPS_BUTTON_COMBO_BUTTON_Y = 0x1000, + //! The left button of the D-pad. + WUPS_BUTTON_COMBO_BUTTON_LEFT = 0x0800, + //! The right button of the D-pad. + WUPS_BUTTON_COMBO_BUTTON_RIGHT = 0x0400, + //! The up button of the D-pad. + WUPS_BUTTON_COMBO_BUTTON_UP = 0x0200, + //! The down button of the D-pad. + WUPS_BUTTON_COMBO_BUTTON_DOWN = 0x0100, + //! The ZL button. + WUPS_BUTTON_COMBO_BUTTON_ZL = 0x0080, + //! The ZR button. + WUPS_BUTTON_COMBO_BUTTON_ZR = 0x0040, + //! The L button. + WUPS_BUTTON_COMBO_BUTTON_L = 0x0020, + //! The R button. + WUPS_BUTTON_COMBO_BUTTON_R = 0x0010, + //! The + button. + WUPS_BUTTON_COMBO_BUTTON_PLUS = 0x0008, + //! The - button. + WUPS_BUTTON_COMBO_BUTTON_MINUS = 0x0004, + //! The right stick button. + WUPS_BUTTON_COMBO_BUTTON_STICK_R = 0x00020000, + //! The left stick button. + WUPS_BUTTON_COMBO_BUTTON_STICK_L = 0x00040000, + //! The TV button. + WUPS_BUTTON_COMBO_BUTTON_TV = 0x00010000, + //! The reserved bit + WUPS_BUTTON_COMBO_BUTTON_RESERVED_BIT = 0x80000, +} WUPSButtonCombo_Buttons; +WUT_ENUM_BITMASK_TYPE(WUPSButtonCombo_Buttons); + +typedef enum WUPSButtonCombo_ControllerTypes { + WUPS_BUTTON_COMBO_CONTROLLER_NONE = 0, + WUPS_BUTTON_COMBO_CONTROLLER_VPAD_0 = 1 << 0, + WUPS_BUTTON_COMBO_CONTROLLER_VPAD_1 = 1 << 1, + WUPS_BUTTON_COMBO_CONTROLLER_WPAD_0 = 1 << 2, + WUPS_BUTTON_COMBO_CONTROLLER_WPAD_1 = 1 << 3, + WUPS_BUTTON_COMBO_CONTROLLER_WPAD_2 = 1 << 4, + WUPS_BUTTON_COMBO_CONTROLLER_WPAD_3 = 1 << 5, + WUPS_BUTTON_COMBO_CONTROLLER_WPAD_4 = 1 << 6, + WUPS_BUTTON_COMBO_CONTROLLER_WPAD_5 = 1 << 7, + WUPS_BUTTON_COMBO_CONTROLLER_WPAD_6 = 1 << 8, + WUPS_BUTTON_COMBO_CONTROLLER_VPAD = WUPS_BUTTON_COMBO_CONTROLLER_VPAD_0 | WUPS_BUTTON_COMBO_CONTROLLER_VPAD_1, + WUPS_BUTTON_COMBO_CONTROLLER_WPAD = (WUPS_BUTTON_COMBO_CONTROLLER_WPAD_0 | + WUPS_BUTTON_COMBO_CONTROLLER_WPAD_1 | + WUPS_BUTTON_COMBO_CONTROLLER_WPAD_2 | + WUPS_BUTTON_COMBO_CONTROLLER_WPAD_3 | + WUPS_BUTTON_COMBO_CONTROLLER_WPAD_4 | + WUPS_BUTTON_COMBO_CONTROLLER_WPAD_5 | + WUPS_BUTTON_COMBO_CONTROLLER_WPAD_6), + WUPS_BUTTON_COMBO_CONTROLLER_ALL = WUPS_BUTTON_COMBO_CONTROLLER_VPAD | WUPS_BUTTON_COMBO_CONTROLLER_WPAD, +} WUPSButtonCombo_ControllerTypes; +WUT_ENUM_BITMASK_TYPE(WUPSButtonCombo_ControllerTypes); + +typedef enum WUPSButtonCombo_ComboType { + WUPS_BUTTON_COMBO_COMBO_TYPE_INVALID = 0, + WUPS_BUTTON_COMBO_COMBO_TYPE_HOLD = 1, // Does check for conflicts + WUPS_BUTTON_COMBO_COMBO_TYPE_PRESS_DOWN = 2, // Does check for conflicts + WUPS_BUTTON_COMBO_COMBO_TYPE_HOLD_OBSERVER = 3, // Does not check for conflicts + WUPS_BUTTON_COMBO_COMBO_TYPE_PRESS_DOWN_OBSERVER = 4, // Does not check for conflicts +} WUPSButtonCombo_ComboType; + +typedef enum WUPSButtonCombo_ComboStatus { + WUPS_BUTTON_COMBO_COMBO_STATUS_INVALID_STATUS = 0, + WUPS_BUTTON_COMBO_COMBO_STATUS_VALID = 1, + WUPS_BUTTON_COMBO_COMBO_STATUS_CONFLICT = 2, +} WUPSButtonCombo_ComboStatus; + +/** + * @enum WUPSButtonComboError + * @brief Represents error codes returned by storage API functions. + */ +typedef enum { + WUPS_BUTTON_COMBO_ERROR_SUCCESS = 0, /**< Success. */ + WUPS_BUTTON_COMBO_ERROR_INVALID_ARGS = -0x01, /**< Invalid arguments passed to the function. */ + WUPS_BUTTON_COMBO_ERROR_MALLOC_FAILED = -0x02, /**< Memory allocation failed. */ + WUPS_BUTTON_COMBO_ERROR_NOT_FOUND = -0x03, /**< Not found. */ + WUPS_BUTTON_COMBO_ERROR_ABORTED = -0x04, /**< Not found. */ + WUPS_BUTTON_COMBO_ERROR_INTERNAL_NOT_INITIALIZED = -0xF0, /**< Library not initialized properly. */ + WUPS_BUTTON_COMBO_ERROR_INTERNAL_INVALID_VERSION = -0xF1, /**< Invalid API version. */ + WUPS_BUTTON_COMBO_ERROR_UNKNOWN_ERROR = -0x100 /**< Unknown error. */ +} WUPSButtonCombo_Error; + +typedef struct WUPSButtonCombo_ComboHandle { + void *handle; +#ifdef __cplusplus + WUPSButtonCombo_ComboHandle() { + handle = nullptr; + } + explicit WUPSButtonCombo_ComboHandle(void *handle) : handle(handle) {} + bool operator==(const WUPSButtonCombo_ComboHandle other) const { + return handle == other.handle; + } + bool operator==(const void *other) const { + return handle == other; + } +#endif +} WUPSButtonCombo_ComboHandle; + +typedef void (*WUPSButtonCombo_ComboCallback)(WUPSButtonCombo_ComboHandle handle, void *context); + +typedef struct WUPSButtonCombo_MetaOptions { + const char *label; +} WUPSButtonCombo_MetaOptions; + +typedef struct WUPSButtonCombo_MetaOptionsOut { + char *labelBuffer; + uint32_t labelBufferLength; +} WUPSButtonCombo_MetaOptionsOut; + +typedef struct WUPSButtonCombo_CallbackOptions { + WUPSButtonCombo_ComboCallback callback; + void *context; +} WUPSButtonCombo_CallbackOptions; + +typedef struct WUPSButtonCombo_ButtonComboOptions { + WUPSButtonCombo_ControllerTypes controllerMask; + WUPSButtonCombo_Buttons combo; +} WUPSButtonCombo_ButtonComboOptions; + +typedef struct WUPSButtonCombo_ButtonComboInfoEx { + WUPSButtonCombo_ComboType type; + WUPSButtonCombo_ButtonComboOptions basicCombo; + uint32_t optionalHoldForXMs; +} WUPSButtonCombo_ButtonComboInfoEx; + +typedef struct WUPSButtonCombo_ComboOptions { + WUPSButtonCombo_MetaOptions metaOptions; + WUPSButtonCombo_CallbackOptions callbackOptions; + WUPSButtonCombo_ButtonComboInfoEx buttonComboOptions; +} WUPSButtonCombo_ComboOptions; + +typedef struct WUPSButtonCombo_DetectButtonComboOptions { + WUPSButtonCombo_ControllerTypes controllerMask; + uint32_t holdComboForInMs; + uint32_t holdAbortForInMs; + WUPSButtonCombo_Buttons abortButtonCombo; +} WUPSButtonCombo_DetectButtonComboOptions; + +#ifdef __cplusplus +} +#endif diff --git a/include/wups/button_combo_internal.h b/include/wups/button_combo_internal.h index e02a0e2..8c85f57 100644 --- a/include/wups/button_combo_internal.h +++ b/include/wups/button_combo_internal.h @@ -1,5 +1,5 @@ #pragma once -#include +#include /** * @typedef WUPSButtonCombo_AddButtonComboFunction diff --git a/include/wups/config/WUPSConfigItemButtonCombo.h b/include/wups/config/WUPSConfigItemButtonCombo.h index b1598db..f36efac 100644 --- a/include/wups/config/WUPSConfigItemButtonCombo.h +++ b/include/wups/config/WUPSConfigItemButtonCombo.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #ifdef __cplusplus diff --git a/libraries/libwups/WUPSConfigItemButtonCombo.cpp b/libraries/libwups/WUPSConfigItemButtonCombo.cpp index ef84aee..bbcf971 100644 --- a/libraries/libwups/WUPSConfigItemButtonCombo.cpp +++ b/libraries/libwups/WUPSConfigItemButtonCombo.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include namespace { diff --git a/libraries/libwups/button_combo.cpp b/libraries/libwups/button_combo.cpp index 4413f06..0f1a36a 100644 --- a/libraries/libwups/button_combo.cpp +++ b/libraries/libwups/button_combo.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include struct wups_internal_button_combo_functions_t { From 71fec4899b8108b1ba8f6a82f9e7778a1bee842c Mon Sep 17 00:00:00 2001 From: Maschell Date: Tue, 31 Dec 2024 12:52:14 +0100 Subject: [PATCH 2/3] ButtonComboAPI: Added "triggeredBy param to combo callback --- include/wups/button_combo/defines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/wups/button_combo/defines.h b/include/wups/button_combo/defines.h index 7348008..0396f0f 100644 --- a/include/wups/button_combo/defines.h +++ b/include/wups/button_combo/defines.h @@ -114,7 +114,7 @@ typedef struct WUPSButtonCombo_ComboHandle { #endif } WUPSButtonCombo_ComboHandle; -typedef void (*WUPSButtonCombo_ComboCallback)(WUPSButtonCombo_ComboHandle handle, void *context); +typedef void (*WUPSButtonCombo_ComboCallback)(WUPSButtonCombo_ControllerTypes triggeredBy, WUPSButtonCombo_ComboHandle handle, void *context); typedef struct WUPSButtonCombo_MetaOptions { const char *label; From eb5f8de005e2fe81c276837889b60835b19ba491 Mon Sep 17 00:00:00 2001 From: Maschell Date: Tue, 31 Dec 2024 12:52:55 +0100 Subject: [PATCH 3/3] ButtonComboAPI: Add C++ wrapper for button combo api --- include/wups/button_combo/WUPSButtonCombo.h | 57 +++++++ include/wups/button_combo/api.h | 107 +++++++++++++ libraries/libwups/WUPSButtonCombo.cpp | 103 +++++++++++++ libraries/libwups/button_comboCPP.cpp | 161 ++++++++++++++++++++ 4 files changed, 428 insertions(+) create mode 100644 include/wups/button_combo/WUPSButtonCombo.h create mode 100644 libraries/libwups/WUPSButtonCombo.cpp create mode 100644 libraries/libwups/button_comboCPP.cpp diff --git a/include/wups/button_combo/WUPSButtonCombo.h b/include/wups/button_combo/WUPSButtonCombo.h new file mode 100644 index 0000000..56cedb0 --- /dev/null +++ b/include/wups/button_combo/WUPSButtonCombo.h @@ -0,0 +1,57 @@ +#pragma once + +#ifdef __cplusplus + +#include "defines.h" + +#include +#include + +class WUPSButtonCombo { +public: + static std::optional Create(const WUPSButtonCombo_ComboOptions &options, + WUPSButtonCombo_ComboStatus &outStatus, + WUPSButtonCombo_Error &outError) noexcept; + + static WUPSButtonCombo Create(const WUPSButtonCombo_ComboOptions &options, + WUPSButtonCombo_ComboStatus &outStatus); + + ~WUPSButtonCombo(); + WUPSButtonCombo(const WUPSButtonCombo &) = delete; + + WUPSButtonCombo(WUPSButtonCombo &&other) noexcept; + + WUPSButtonCombo &operator=(const WUPSButtonCombo &) = delete; + + WUPSButtonCombo &operator=(WUPSButtonCombo &&other) noexcept; + + [[nodiscard]] WUPSButtonCombo_ComboHandle getHandle() const; + + WUPSButtonCombo_Error GetButtonComboStatus(WUPSButtonCombo_ComboStatus &outStatus) const; + + [[nodiscard]] WUPSButtonCombo_Error UpdateButtonComboMeta(const WUPSButtonCombo_MetaOptions &metaOptions) const; + + [[nodiscard]] WUPSButtonCombo_Error UpdateButtonComboCallback(const WUPSButtonCombo_CallbackOptions &callbackOptions) const; + + [[nodiscard]] WUPSButtonCombo_Error UpdateControllerMask(WUPSButtonCombo_ControllerTypes controllerMask, + WUPSButtonCombo_ComboStatus &outStatus) const; + + [[nodiscard]] WUPSButtonCombo_Error UpdateButtonCombo(WUPSButtonCombo_Buttons combo, + WUPSButtonCombo_ComboStatus &outStatus) const; + + [[nodiscard]] WUPSButtonCombo_Error UpdateHoldDuration(uint32_t holdDurationInFrames) const; + + [[nodiscard]] WUPSButtonCombo_Error GetButtonComboMeta(WUPSButtonCombo_MetaOptionsOut &outOptions) const; + + WUPSButtonCombo_Error GetButtonComboCallback(WUPSButtonCombo_CallbackOptions &outOptions) const; + + WUPSButtonCombo_Error GetButtonComboInfoEx(WUPSButtonCombo_ButtonComboInfoEx &outOptions) const; + +private: + void ReleaseButtonComboHandle(); + + explicit WUPSButtonCombo(WUPSButtonCombo_ComboHandle handle); + + WUPSButtonCombo_ComboHandle mHandle = WUPSButtonCombo_ComboHandle(nullptr); +}; +#endif \ No newline at end of file diff --git a/include/wups/button_combo/api.h b/include/wups/button_combo/api.h index 3c598ec..64ee231 100644 --- a/include/wups/button_combo/api.h +++ b/include/wups/button_combo/api.h @@ -154,3 +154,110 @@ WUPSButtonCombo_Error WUPSButtonComboAPI_DetectButtonCombo_Blocking(const WUPSBu #ifdef __cplusplus } #endif + +#ifdef __cplusplus +namespace WUPSButtonComboAPI { + + + std::string_view GetStatusStr(WUPSButtonCombo_Error status); + + std::optional CreateComboPressDownEx(std::string_view label, + WUPSButtonCombo_ControllerTypes controllerMask, + WUPSButtonCombo_Buttons combo, + WUPSButtonCombo_ComboCallback callback, + void *context, + bool observer, + WUPSButtonCombo_ComboStatus &outStatus, + WUPSButtonCombo_Error &outError) noexcept; + + std::optional CreateComboPressDown(std::string_view label, + WUPSButtonCombo_Buttons combo, + WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus, + WUPSButtonCombo_Error &outError) noexcept; + + std::optional CreateComboPressDownObserver(std::string_view label, + WUPSButtonCombo_Buttons combo, + WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus, + WUPSButtonCombo_Error &outError) noexcept; + + std::optional CreateComboHoldEx(std::string_view label, + WUPSButtonCombo_ControllerTypes controllerMask, + WUPSButtonCombo_Buttons combo, + uint32_t holdDurationInMs, + WUPSButtonCombo_ComboCallback callback, + void *context, + bool observer, + WUPSButtonCombo_ComboStatus &outStatus, + WUPSButtonCombo_Error &outError) noexcept; + + std::optional CreateComboHold(std::string_view label, + WUPSButtonCombo_Buttons combo, + uint32_t holdDurationInMs, + WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus, + WUPSButtonCombo_Error &outError) noexcept; + + std::optional CreateComboHoldObserver(std::string_view label, + WUPSButtonCombo_Buttons combo, + uint32_t holdDurationInMs, + WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus, + WUPSButtonCombo_Error &outError) noexcept; + + + WUPSButtonCombo CreateComboPressDownEx(std::string_view label, + WUPSButtonCombo_ControllerTypes controllerMask, + WUPSButtonCombo_Buttons combo, + WUPSButtonCombo_ComboCallback callback, + void *context, + bool observer, + WUPSButtonCombo_ComboStatus &outStatus); + + WUPSButtonCombo CreateComboPressDown(std::string_view label, + WUPSButtonCombo_Buttons combo, + WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus); + + WUPSButtonCombo CreateComboPressDownObserver(std::string_view label, + WUPSButtonCombo_Buttons combo, + WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus); + + WUPSButtonCombo CreateComboHoldEx(std::string_view label, + WUPSButtonCombo_ControllerTypes controllerMask, + WUPSButtonCombo_Buttons combo, + uint32_t holdDurationInMs, + WUPSButtonCombo_ComboCallback callback, + void *context, + bool observer, + WUPSButtonCombo_ComboStatus &outStatus); + + WUPSButtonCombo CreateComboHold(std::string_view label, + WUPSButtonCombo_Buttons combo, + uint32_t holdDurationInMs, + WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus); + + WUPSButtonCombo CreateComboHoldObserver(std::string_view label, + WUPSButtonCombo_Buttons combo, + uint32_t holdDurationInMs, + WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus); + WUPSButtonCombo_Error CheckComboAvailable(const WUPSButtonCombo_ButtonComboOptions &options, + WUPSButtonCombo_ComboStatus &outStatus); + + WUPSButtonCombo_Error DetectButtonCombo_Blocking(const WUPSButtonCombo_DetectButtonComboOptions &options, + WUPSButtonCombo_Buttons &outButtons); + +} // namespace WUPSButtonComboAPI +#endif \ No newline at end of file diff --git a/libraries/libwups/WUPSButtonCombo.cpp b/libraries/libwups/WUPSButtonCombo.cpp new file mode 100644 index 0000000..dee6a16 --- /dev/null +++ b/libraries/libwups/WUPSButtonCombo.cpp @@ -0,0 +1,103 @@ +#include "wups/button_combo/WUPSButtonCombo.h" + +#include +#include +#include + + +std::optional WUPSButtonCombo::Create(const WUPSButtonCombo_ComboOptions &options, + WUPSButtonCombo_ComboStatus &outStatus, + WUPSButtonCombo_Error &outError) noexcept { + WUPSButtonCombo_ComboHandle handle; + if (outError = WUPSButtonComboAPI_AddButtonCombo(&options, &handle, &outStatus); outError == WUPS_BUTTON_COMBO_ERROR_SUCCESS) { + return WUPSButtonCombo(handle); + } + return {}; +} + +WUPSButtonCombo WUPSButtonCombo::Create(const WUPSButtonCombo_ComboOptions &options, + WUPSButtonCombo_ComboStatus &outStatus) { + WUPSButtonCombo_Error error; + auto res = Create(options, outStatus, error); + if (!res) { + throw std::runtime_error{std::string("Failed to create button combo: ").append(WUPSButtonComboAPI_GetStatusStr(error))}; + } + return std::move(*res); +} + +WUPSButtonCombo::~WUPSButtonCombo() { + ReleaseButtonComboHandle(); +} + +void WUPSButtonCombo::ReleaseButtonComboHandle() { + if (mHandle != nullptr) { + if (const auto res = WUPSButtonComboAPI_RemoveButtonCombo(mHandle); res != WUPS_BUTTON_COMBO_ERROR_SUCCESS) { + OSReport("WUPSButtonCombo::ReleaseButtonComboHandle(): WUPSButtonComboAPI_RemoveButtonCombo for %08X returned: %s\n", mHandle, WUPSButtonComboAPI_GetStatusStr(res)); + } + mHandle = WUPSButtonCombo_ComboHandle(nullptr); + } +} + +WUPSButtonCombo::WUPSButtonCombo(WUPSButtonCombo &&src) noexcept { + ReleaseButtonComboHandle(); + + mHandle = src.mHandle; + + src.mHandle = WUPSButtonCombo_ComboHandle(nullptr); +} + +WUPSButtonCombo &WUPSButtonCombo::operator=(WUPSButtonCombo &&src) noexcept { + if (this != &src) { + ReleaseButtonComboHandle(); + + mHandle = src.mHandle; + + src.mHandle = WUPSButtonCombo_ComboHandle(nullptr); + } + return *this; +} + +[[nodiscard]] WUPSButtonCombo_ComboHandle WUPSButtonCombo::getHandle() const { + return mHandle; +} + +WUPSButtonCombo_Error WUPSButtonCombo::GetButtonComboStatus(WUPSButtonCombo_ComboStatus &outStatus) const { + return WUPSButtonComboAPI_GetButtonComboStatus(mHandle, &outStatus); +} + +[[nodiscard]] WUPSButtonCombo_Error WUPSButtonCombo::UpdateButtonComboMeta(const WUPSButtonCombo_MetaOptions &metaOptions) const { + return WUPSButtonComboAPI_UpdateButtonComboMeta(mHandle, &metaOptions); +} + +[[nodiscard]] WUPSButtonCombo_Error WUPSButtonCombo::UpdateButtonComboCallback(const WUPSButtonCombo_CallbackOptions &callbackOptions) const { + return WUPSButtonComboAPI_UpdateButtonComboCallback(mHandle, &callbackOptions); +} + +[[nodiscard]] WUPSButtonCombo_Error WUPSButtonCombo::UpdateControllerMask(const WUPSButtonCombo_ControllerTypes controllerMask, + WUPSButtonCombo_ComboStatus &outStatus) const { + return WUPSButtonComboAPI_UpdateControllerMask(mHandle, controllerMask, &outStatus); +} + +[[nodiscard]] WUPSButtonCombo_Error WUPSButtonCombo::UpdateButtonCombo(const WUPSButtonCombo_Buttons combo, + WUPSButtonCombo_ComboStatus &outStatus) const { + return WUPSButtonComboAPI_UpdateButtonCombo(mHandle, combo, &outStatus); +} + +[[nodiscard]] WUPSButtonCombo_Error WUPSButtonCombo::UpdateHoldDuration(const uint32_t holdDurationInFrames) const { + return WUPSButtonComboAPI_UpdateHoldDuration(mHandle, holdDurationInFrames); +} + +[[nodiscard]] WUPSButtonCombo_Error WUPSButtonCombo::GetButtonComboMeta(WUPSButtonCombo_MetaOptionsOut &outOptions) const { + return WUPSButtonComboAPI_GetButtonComboMeta(mHandle, &outOptions); +} + +WUPSButtonCombo_Error WUPSButtonCombo::GetButtonComboCallback(WUPSButtonCombo_CallbackOptions &outOptions) const { + return WUPSButtonComboAPI_GetButtonComboCallback(mHandle, &outOptions); +} + +WUPSButtonCombo_Error WUPSButtonCombo::GetButtonComboInfoEx(WUPSButtonCombo_ButtonComboInfoEx &outOptions) const { + return WUPSButtonComboAPI_GetButtonComboInfoEx(mHandle, &outOptions); +} + +WUPSButtonCombo::WUPSButtonCombo(const WUPSButtonCombo_ComboHandle handle) : mHandle(handle) { +} diff --git a/libraries/libwups/button_comboCPP.cpp b/libraries/libwups/button_comboCPP.cpp new file mode 100644 index 0000000..a7b5e87 --- /dev/null +++ b/libraries/libwups/button_comboCPP.cpp @@ -0,0 +1,161 @@ +#include +#include +#include + +namespace WUPSButtonComboAPI { + std::string_view GetStatusStr(const WUPSButtonCombo_Error status) { + return WUPSButtonComboAPI_GetStatusStr(status); + } + + std::optional CreateComboPressDownEx(const std::string_view label, + const WUPSButtonCombo_ControllerTypes controllerMask, + const WUPSButtonCombo_Buttons combo, + const WUPSButtonCombo_ComboCallback callback, + void *context, + const bool observer, + WUPSButtonCombo_ComboStatus &outStatus, + WUPSButtonCombo_Error &outError) noexcept { + WUPSButtonCombo_ComboOptions options = {}; + options.metaOptions.label = label.data(); + options.callbackOptions = {.callback = callback, .context = context}; + options.buttonComboOptions.type = observer ? WUPS_BUTTON_COMBO_COMBO_TYPE_PRESS_DOWN_OBSERVER : WUPS_BUTTON_COMBO_COMBO_TYPE_PRESS_DOWN; + options.buttonComboOptions.basicCombo.combo = combo; + options.buttonComboOptions.basicCombo.controllerMask = controllerMask; + + return WUPSButtonCombo::Create(options, outStatus, outError); + } + + std::optional CreateComboPressDown(const std::string_view label, + const WUPSButtonCombo_Buttons combo, + const WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus, + WUPSButtonCombo_Error &outError) noexcept { + return CreateComboPressDownEx(label, WUPS_BUTTON_COMBO_CONTROLLER_ALL, combo, callback, context, false, outStatus, outError); + } + + std::optional CreateComboPressDownObserver(const std::string_view label, + const WUPSButtonCombo_Buttons combo, + const WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus, + WUPSButtonCombo_Error &outError) noexcept { + return CreateComboPressDownEx(label, WUPS_BUTTON_COMBO_CONTROLLER_ALL, combo, callback, context, true, outStatus, outError); + } + + + std::optional CreateComboHoldEx(const std::string_view label, + const WUPSButtonCombo_ControllerTypes controllerMask, + const WUPSButtonCombo_Buttons combo, + const uint32_t holdDurationInMs, + const WUPSButtonCombo_ComboCallback callback, + void *context, + const bool observer, + WUPSButtonCombo_ComboStatus &outStatus, + WUPSButtonCombo_Error &outError) noexcept { + WUPSButtonCombo_ComboOptions options = {}; + options.metaOptions.label = label.data(); + options.callbackOptions = {.callback = callback, .context = context}; + options.buttonComboOptions.type = observer ? WUPS_BUTTON_COMBO_COMBO_TYPE_HOLD_OBSERVER : WUPS_BUTTON_COMBO_COMBO_TYPE_HOLD; + options.buttonComboOptions.basicCombo.combo = combo; + options.buttonComboOptions.basicCombo.controllerMask = controllerMask; + options.buttonComboOptions.optionalHoldForXMs = holdDurationInMs; + + return WUPSButtonCombo::Create(options, outStatus, outError); + } + + std::optional CreateComboHold(const std::string_view label, + const WUPSButtonCombo_Buttons combo, + const uint32_t holdDurationInMs, + const WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus, + WUPSButtonCombo_Error &outError) noexcept { + return CreateComboHoldEx(label, WUPS_BUTTON_COMBO_CONTROLLER_ALL, combo, holdDurationInMs, callback, context, false, outStatus, outError); + } + + std::optional CreateComboHoldObserver(const std::string_view label, + const WUPSButtonCombo_Buttons combo, + const uint32_t holdDurationInMs, + const WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus, + WUPSButtonCombo_Error &outError) noexcept { + return CreateComboHoldEx(label, WUPS_BUTTON_COMBO_CONTROLLER_ALL, combo, holdDurationInMs, callback, context, true, outStatus, outError); + } + + WUPSButtonCombo CreateComboPressDownEx(const std::string_view label, + const WUPSButtonCombo_ControllerTypes controllerMask, + const WUPSButtonCombo_Buttons combo, + const WUPSButtonCombo_ComboCallback callback, + void *context, + const bool observer, + WUPSButtonCombo_ComboStatus &outStatus) { + WUPSButtonCombo_Error error; + auto res = CreateComboPressDownEx(label, controllerMask, combo, callback, context, observer, outStatus, error); + if (!res) { + throw std::runtime_error{std::string("Failed to create press down ex button combo: ").append(WUPSButtonComboAPI_GetStatusStr(error))}; + } + return std::move(*res); + } + + WUPSButtonCombo CreatePressDown(const std::string_view label, + const WUPSButtonCombo_Buttons combo, + const WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus) { + return CreateComboPressDownEx(label, WUPS_BUTTON_COMBO_CONTROLLER_ALL, combo, callback, context, false, outStatus); + } + + WUPSButtonCombo CreatePressDownObserver(const std::string_view label, + const WUPSButtonCombo_Buttons combo, + const WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus) { + return CreateComboPressDownEx(label, WUPS_BUTTON_COMBO_CONTROLLER_ALL, combo, callback, context, true, outStatus); + } + + WUPSButtonCombo CreateComboHoldEx(const std::string_view label, + const WUPSButtonCombo_ControllerTypes controllerMask, + const WUPSButtonCombo_Buttons combo, + const uint32_t holdDurationInMs, + const WUPSButtonCombo_ComboCallback callback, + void *context, + const bool observer, + WUPSButtonCombo_ComboStatus &outStatus) { + WUPSButtonCombo_Error error; + auto res = CreateComboHoldEx(label, controllerMask, combo, holdDurationInMs, callback, context, observer, outStatus, error); + if (!res) { + throw std::runtime_error{std::string("Failed to create press down ex button combo: ").append(WUPSButtonComboAPI_GetStatusStr(error))}; + } + return std::move(*res); + } + + WUPSButtonCombo CreateComboHold(const std::string_view label, + const WUPSButtonCombo_Buttons combo, + const uint32_t holdDurationInMs, + const WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus) { + return CreateComboHoldEx(label, WUPS_BUTTON_COMBO_CONTROLLER_ALL, combo, holdDurationInMs, callback, context, false, outStatus); + } + + WUPSButtonCombo CreateComboHoldObserver(const std::string_view label, + const WUPSButtonCombo_Buttons combo, + const uint32_t holdDurationInMs, + const WUPSButtonCombo_ComboCallback callback, + void *context, + WUPSButtonCombo_ComboStatus &outStatus) { + return CreateComboHoldEx(label, WUPS_BUTTON_COMBO_CONTROLLER_ALL, combo, holdDurationInMs, callback, context, true, outStatus); + } + + WUPSButtonCombo_Error CheckComboAvailable(const WUPSButtonCombo_ButtonComboOptions &options, + WUPSButtonCombo_ComboStatus &outStatus) { + return WUPSButtonComboAPI_CheckComboAvailable(&options, &outStatus); + } + + WUPSButtonCombo_Error DetectButtonCombo_Blocking(const WUPSButtonCombo_DetectButtonComboOptions &options, + WUPSButtonCombo_Buttons &outButtons) { + return WUPSButtonComboAPI_DetectButtonCombo_Blocking(&options, &outButtons); + } +} // namespace WUPSButtonComboAPI \ No newline at end of file