diff --git a/include/buttoncombo/api.h b/include/buttoncombo/api.h
index a07712c..cd8a91c 100644
--- a/include/buttoncombo/api.h
+++ b/include/buttoncombo/api.h
@@ -7,19 +7,30 @@ extern "C" {
#endif
/**
- * Returns a ButtonComboModule_Status as a string
- * @param status
- * @return String representation of a given status
+ * This function returns a string representation of the provided ButtonComboModule_Error.
+ *
+ * @param status The status to get the string representation for.
+ * @return A pointer to a string describing the provided status.
**/
const char *ButtonComboModule_GetStatusStr(ButtonComboModule_Error status);
/**
- * Returns a ButtonComboModule_ControllerTypes as a string
- * @param controller
- * @return String representation of a given controller
+ * This function returns a string representation of the provided ButtonComboModule_ControllerTypes.
+ *
+ * @param controller The controller to get the string representation for.
+ * @return A pointer to a string describing the provided controller.
**/
const char *ButtonComboModule_GetControllerTypeStr(ButtonComboModule_ControllerTypes controller);
+/**
+ * This function returns a string representation of the provided ButtonComboModule_ComboStatus.
+ *
+ * @param status The combo status to get the string representation for.
+ * @return A pointer to a string describing the provided combo status.
+**/
+const char *ButtonComboModule_GetComboStatusStr(ButtonComboModule_ComboStatus status);
+
+
/**
* This function has to be called before any other function of this lib (except ButtonComboModule_GetVersion) can be used.
*
@@ -51,82 +62,329 @@ ButtonComboModule_Error ButtonComboModule_DeInitLibrary();
ButtonComboModule_Error ButtonComboModule_GetVersion(ButtonComboModule_APIVersion *outVersion);
-ButtonComboModule_Error ButtonComboModule_AddButtonComboSimplePressDownEx(const char *label,
- ButtonComboModule_Buttons buttonCombo,
- ButtonComboModule_ControllerTypes controllerMask,
+/**
+ * Creates a button combo which triggers a callback if this combo is detected.
+ *
+ * **Requires ButtonComboModule API version 1 or higher**
+ *
+ * This function takes a generic `ButtonComboModule_ComboOptions` which defines how the combo should be checked.
+ *
+ * Depending on the given type, the combo will either check for holding (for X ms) or pressing a button on for a given
+ * controller mask. The type also defines if it's an "observer" or not. Observers won't check for combo conflicts.
+ *
+ * If the given type is not an `observer` and any other (valid) button combination overlaps with new combo, then the
+ * `outStatus` will be set to `BUTTON_COMBO_MODULE_COMBO_STATUS_VALID` and the combo will be inactive. The original
+ * ButtonCombo which had the combo first won't be affected at all.
+ * In conflict state the callback will not be triggered even if the combination is pressed. If `observer` is set to
+ * "true", the combo won't check for conflicts.
+ *
+ * To resolve a BUTTON_COMBO_MODULE_COMBO_STATUS_VALID combo state you **always** have to update combo information
+ * via @ButtonComboModule_UpdateControllerMask or @ButtonComboModule_UpdateButtonCombo. The state won't update itself,
+ * even it the combo has no conflicts in a later point in time (e.g. due to other conflicting combos being removed in the meantime)
+ *
+ * Conflict example (only relevant if combo type is not an observer):
+ * It's not possible to add any new valid button combo containing "L+R" (e.g. "X+L+R"), if there already is a button
+ * combination "L+R". Furthermore, it's also not possible to add a "L" or "R" combo if there already is a button
+ * combination "L+R".
+ *
+ * See @ButtonComboModule_RemoveButtonCombo to remove an added button combo.
+ *
+ * @param options options of this button combo
+ * @param outHandle The handle of the button combo will be stored here on success. Must not be nullptr.
+ * @param outStatus (optional) The status of the combo will be stored here. Only if the status is BUTTON_COMBO_MODULE_COMBO_STATUS_VALID the combo is valid. Can be NULL.
+ * @return Returns BUTTON_COMBO_MODULE_ERROR_SUCCESS on success. Please check the outStatus as well.
+*/
+ButtonComboModule_Error ButtonComboModule_AddButtonCombo(const ButtonComboModule_ComboOptions *options,
+ ButtonComboModule_ComboHandle *outHandle,
+ ButtonComboModule_ComboStatus *outStatus);
+
+/**
+ * Creates a "PressDown" button combo which triggers a callback when given combo for a given controller has been pressed
+ *
+ * **Requires ButtonComboModule API version 1 or higher**
+ *
+ * See @ButtonComboModule_AddButtonCombo for detailed information about button combos.
+ * See @ButtonComboModule_RemoveButtonCombo to remove the added button combo.
+ *
+ * @param label label of the button combo
+ * @param controllerMask Mask of controllers which should be checked. Must not be empty.
+ * @param combo Combo which should be checked. Must not be empty
+ * @param callback Callback that will be called if a button combo is detected. Must not be nullptr.
+ * @param context Context for the callback. Can be nullptr.
+ * @param observer Defines if this combo should check for conflicts. Set it to "true" to be an observer and ignore conflicts.
+ * @param outHandle The handle of the button combo will be stored here on success. Must not be nullptr.
+ * @param outStatus (optional) The status of the combo will be stored here. Only if the status is BUTTON_COMBO_MODULE_COMBO_STATUS_VALID the combo is valid. Can be NULL.
+ * @return Returns BUTTON_COMBO_MODULE_ERROR_SUCCESS on success. Please check the outStatus as well.
+*/
+ButtonComboModule_Error ButtonComboModule_AddButtonComboPressDownEx(const char *label,
+ ButtonComboModule_ControllerTypes controllerMask,
+ ButtonComboModule_Buttons combo,
+ ButtonComboModule_ComboCallback callback,
+ void *context,
+ bool observer,
+ ButtonComboModule_ComboHandle *outHandle,
+ ButtonComboModule_ComboStatus *outStatus);
+/**
+ * Wrapper for `ButtonComboModule_AddButtonComboPressDownEx` with
+ * - `observer` set to "true"
+ * - `controllerMask` set to "BUTTON_COMBO_MODULE_CONTROLLER_ALL"
+ *
+ * **Requires ButtonComboModule API version 1 or higher**
+ *
+ * See: @ButtonComboModule_AddButtonComboPressDownEx for more information.
+*/
+ButtonComboModule_Error ButtonComboModule_AddButtonComboPressDown(const char *label,
+ ButtonComboModule_Buttons combo,
+ ButtonComboModule_ComboCallback callback,
+ void *context,
+ ButtonComboModule_ComboHandle *outHandle,
+ ButtonComboModule_ComboStatus *outStatus);
+
+/**
+ * Wrapper for `ButtonComboModule_AddButtonComboPressDownEx` with
+ * - `observer` set to "true"
+ * - `controllerMask` set to "BUTTON_COMBO_MODULE_CONTROLLER_ALL"
+ *
+ * **Requires ButtonComboModule API version 1 or higher**
+ *
+ * See: @ButtonComboModule_AddButtonComboPressDownEx for more information.
+ */
+ButtonComboModule_Error ButtonComboModule_AddButtonComboPressDownObserver(const char *label,
+ ButtonComboModule_Buttons combo,
ButtonComboModule_ComboCallback callback,
void *context,
- ButtonComboModule_ComboHandle *handleOut);
+ ButtonComboModule_ComboHandle *outHandle,
+ ButtonComboModule_ComboStatus *outStatus);
-ButtonComboModule_Error ButtonComboModule_AddButtonComboSimplePressDown(const char *label,
- ButtonComboModule_Buttons buttonCombo,
- ButtonComboModule_ComboCallback callback,
- void *context,
- ButtonComboModule_ComboHandle *handleOut);
-ButtonComboModule_Error ButtonComboModule_AddButtonComboSimpleHold(const char *label,
- ButtonComboModule_Buttons buttonCombo,
- uint32_t holdDurationInMs,
- ButtonComboModule_ComboCallback callback,
- void *context,
- ButtonComboModule_ComboHandle *handleOut);
+/**
+ * Creates a "Hold" button combo which triggers a callback when given combo for a given controller has been hold for X ms
+ *
+ * **Requires ButtonComboModule API version 1 or higher**
+ *
+ * See @ButtonComboModule_AddButtonCombo for detailed information about button combos.
+ * See @ButtonComboModule_RemoveButtonCombo to remove the added button combo.
+ *
+ * @param label label of the button combo
+ * @param controllerMask Mask of controllers which should be checked. Must not be empty.
+ * @param combo Combo which should be checked. Must not be empty
+ * @param holdDurationInMs Defines how long the button combination need to be hold down. Must not be 0.
+ * @param callback Callback that will be called if a button combo is detected. Must not be nullptr.
+ * @param context Context for the callback. Can be nullptr.
+ * @param observer Defines if this combo should check for conflicts. Set it to "true" to be an observer and ignore conflicts.
+ * @param outHandle The handle of the button combo will be stored here on success. Must not be nullptr.
+ * @param outStatus (optional) The status of the combo will be stored here. Only if the status is BUTTON_COMBO_MODULE_COMBO_STATUS_VALID the combo is valid. Can be NULL.
+ * @return Returns BUTTON_COMBO_MODULE_ERROR_SUCCESS on success. Please check the outStatus as well.
+ */
+ButtonComboModule_Error ButtonComboModule_AddButtonComboHoldEx(const char *label,
+ ButtonComboModule_ControllerTypes controllerMask,
+ ButtonComboModule_Buttons combo,
+ uint32_t holdDurationInMs,
+ ButtonComboModule_ComboCallback callback,
+ void *context,
+ bool observer,
+ ButtonComboModule_ComboHandle *outHandle,
+ ButtonComboModule_ComboStatus *outStatus);
/**
- * Registers a button combo.
- *
- * Requires ButtonComboModule API version 1 or higher
- * @param options pointer which holds information about button combo that should be added
- * @param outHandle pointer where the handle of the added combo will be written to
- * @param outStatus pointer where the status of this combo will be written to
- *
- * @return BUTTON_COMBO_MODULE_ERROR_SUCCESS: The API version has been store in the version ptr.
- * BUTTON_COMBO_MODULE_ERROR_LIB_UNINITIALIZED: Library was not initialized. Call ButtonComboModule_InitLibrary() before using this function.
- * BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_COMMAND: Command not supported by the currently loaded ButtonComboModule version.
- * BUTTON_COMBO_MODULE_ERROR_INVALID_ARGUMENT: Invalid input pointers or values.
- * BUTTON_COMBO_MODULE_ERROR_INCOMPATIBLE_OPTIONS_VERSION: Invalid input pointers or values.
- * BUTTON_COMBO_MODULE_ERROR_UNKNOWN_ERROR: Adding the button combo failed.
-**/
-ButtonComboModule_Error ButtonComboModule_AddButtonCombo(const ButtonComboModule_ComboOptions *options,
- ButtonComboModule_ComboHandle *outHandle,
- ButtonComboModule_ComboStatus *outStatus);
+ * Wrapper for `ButtonComboModule_AddButtonComboHoldEx` with
+ * - `observer` set to "false"
+ * - `controllerMask` set to "BUTTON_COMBO_MODULE_CONTROLLER_ALL"
+ *
+ * **Requires ButtonComboModule API version 1 or higher**
+ *
+ * See: @ButtonComboModule_AddButtonComboHoldEx for more information.
+*/
+ButtonComboModule_Error ButtonComboModule_AddButtonComboHold(const char *label,
+ ButtonComboModule_Buttons combo,
+ uint32_t holdDurationInMs,
+ ButtonComboModule_ComboCallback callback,
+ void *context,
+ ButtonComboModule_ComboHandle *outHandle,
+ ButtonComboModule_ComboStatus *outStatus);
+
+/**
+ * Wrapper for `ButtonComboModule_AddButtonComboHoldEx` with
+ * - `observer` set to "true"
+ * - `controllerMask` set to "BUTTON_COMBO_MODULE_CONTROLLER_ALL"
+ *
+ * **Requires ButtonComboModule API version 1 or higher**
+ *
+ * See: @ButtonComboModule_AddButtonComboHoldEx for more information.
+*/
+ButtonComboModule_Error ButtonComboModule_AddButtonComboHoldObserver(const char *label,
+ ButtonComboModule_Buttons combo,
+ uint32_t holdDurationInMs,
+ ButtonComboModule_ComboCallback callback,
+ void *context,
+ ButtonComboModule_ComboHandle *outHandle,
+ ButtonComboModule_ComboStatus *outStatus);
+/**
+* Removes a button combo for the given handle.
+*
+* **Requires ButtonComboModule API version 1 or higher**
+*
+* @param handle handle of the button combo that should be removed.
+* @return Returns BUTTON_COMBO_MODULE_ERROR_SUCCESS on success.
+*/
ButtonComboModule_Error ButtonComboModule_RemoveButtonCombo(ButtonComboModule_ComboHandle handle);
+/**
+ * Gets a button combo status for the given handle.
+ *
+ * **Requires ButtonComboModule API version 1 or higher**
+ *
+ * @param handle Handle of the button combo
+ * @param outStatus The status of the combo will be stored here.
+ * @return Returns BUTTON_COMBO_MODULE_ERROR_SUCCESS on success.
+ */
ButtonComboModule_Error ButtonComboModule_GetButtonComboStatus(ButtonComboModule_ComboHandle handle,
ButtonComboModule_ComboStatus *outStatus);
+/**
+* Updates the meta options for the given handle
+*
+* **Requires ButtonComboModule API version 1 or higher**
+*
+* @param handle Handle of the button
+* @param metaOptions new meta options
+* @return Returns BUTTON_COMBO_MODULE_ERROR_SUCCESS on success.
+*/
ButtonComboModule_Error ButtonComboModule_UpdateButtonComboMeta(ButtonComboModule_ComboHandle handle,
- const ButtonComboModule_MetaOptions *options);
+ const ButtonComboModule_MetaOptions *metaOptions);
+/**
+* Updates the callback and context for the given handle
+*
+* **Requires ButtonComboModule API version 1 or higher**
+*
+* @param handle Handle of the button combo
+* @param callbackOptions new callback options
+* @return Returns BUTTON_COMBO_MODULE_ERROR_SUCCESS on success.
+*/
ButtonComboModule_Error ButtonComboModule_UpdateButtonComboCallback(ButtonComboModule_ComboHandle handle,
- const ButtonComboModule_CallbackOptions *options);
+ const ButtonComboModule_CallbackOptions *callbackOptions);
+/**
+* Updates the controller mask for the given handle
+*
+* **Requires ButtonComboModule API version 1 or higher**
+*
+* This will also re-check for conflicts and updates the combo status
+*
+* @param handle Handle of the button combo
+* @param controllerMask new controller mask. must not be empty
+* @param outStatus the new combo status after setting the mask will be written here.
+* @return Returns BUTTON_COMBO_MODULE_ERROR_SUCCESS on success.
+*/
ButtonComboModule_Error ButtonComboModule_UpdateControllerMask(ButtonComboModule_ComboHandle handle,
ButtonComboModule_ControllerTypes controllerMask,
ButtonComboModule_ComboStatus *outStatus);
+/**
+* Updates the combo for the given handle
+*
+* **Requires ButtonComboModule API version 1 or higher**
+*
+* This will also re-check for conflicts and updates the combo status
+*
+* @param handle Handle of the button combo
+* @param combo new combo. must not be empty.
+* @param outStatus the new combo status after setting the mask will be written here.
+* @return Returns BUTTON_COMBO_MODULE_ERROR_SUCCESS on success.
+*/
ButtonComboModule_Error ButtonComboModule_UpdateButtonCombo(ButtonComboModule_ComboHandle handle,
ButtonComboModule_Buttons combo,
ButtonComboModule_ComboStatus *outStatus);
+/**
+* Updates hold duration for a given handle
+*
+* **Requires ButtonComboModule API version 1 or higher**
+*
+* This only possible to "Hold"-button combos.
+*
+* @param handle Handle of the button combo
+* @param holdDurationInMs the new hold duration in milliseconds
+* @return Returns BUTTON_COMBO_MODULE_ERROR_SUCCESS on success.
+*/
ButtonComboModule_Error ButtonComboModule_UpdateHoldDuration(ButtonComboModule_ComboHandle handle,
uint32_t holdDurationInMs);
+/**
+* Returns the current metadata for the given handle
+*
+* @param handle Handle of the button combo
+* @param outOptions struct where the result will be written to. Must not be nullptr.
+* @return Returns BUTTON_COMBO_MODULE_ERROR_SUCCESS on success.
+*/
ButtonComboModule_Error ButtonComboModule_GetButtonComboMeta(ButtonComboModule_ComboHandle handle,
ButtonComboModule_MetaOptionsOut *outOptions);
+/**
+* Returns the current callback and context for the given handle
+*
+* **Requires ButtonComboModule API version 1 or higher**
+*
+* @param handle Handle of the button combo
+* @param outOptions struct where the result will be written to. Must not be nullptr.
+* @return Returns BUTTON_COMBO_MODULE_ERROR_SUCCESS on success.
+*/
ButtonComboModule_Error ButtonComboModule_GetButtonComboCallback(ButtonComboModule_ComboHandle handle,
ButtonComboModule_CallbackOptions *outOptions);
+/**
+* Returns the information about the controller mask and combo for the given handle
+*
+* **Requires ButtonComboModule API version 1 or higher**
+*
+* @param handle Handle of the button combo
+* @param outOptions struct where the result will be written to. Must not be nullptr.
+* @return Returns BUTTON_COMBO_MODULE_ERROR_SUCCESS on success.
+*/
ButtonComboModule_Error ButtonComboModule_GetButtonComboInfoEx(ButtonComboModule_ComboHandle handle,
ButtonComboModule_ButtonComboInfoEx *outOptions);
+/**
+* Helper function to check the combo status for a given button combo option struct.
+*
+* **Requires ButtonComboModule API version 1 or higher**
+*
+* This can be used to check if a certain button combination is still "free" and won't cause any conflicts.
+*
+* The input for this function is a "ButtonComboModule_ButtonComboOptions" struct ptr. Fill in the values like this:
+* `controllerMask` - Mask of which controllers would be checked for the button combo.
+* `combo` - The button combo that should be checked.
+*
+* @param options Holds information about how the button combo should be detected.
+* @param outStatus On success this will store the status of provided combo options.
+* @return Returns "BUTTON_COMBO_MODULE_ERROR_SUCCESS" on success
+**/
ButtonComboModule_Error ButtonComboModule_CheckComboAvailable(const ButtonComboModule_ButtonComboOptions *options,
ButtonComboModule_ComboStatus *outStatus);
-
+/**
+* Helper function to detect a pressed button combo.
+*
+* **Requires ButtonComboModule API version 1 or higher**
+*
+* This function is blocking the current thread until it return, call it in an appropriate place.
+*
+* The input for this function is a "ButtonComboModule_DetectButtonComboOptions" struct ptr. Fill in the values like this:
+* `controllerMask` - Mask of which controller should be checked for a button combo. Must not be empty
+* `holdComboForInMs` - Defines how many ms a combo needs to be hold to be detected as a combo
+* `holdAbortForInMs` - Defines how many ms the abort combo needs to be hold so the detection will be aborted.
+* `abortButtonCombo` - Defines the combo that will trigger an abort.
+*
+* The abort button combo is checked on all controller, if they are not part of the `controllerMask`
+*
+* @param options Holds information about how the button combo should be detected.
+* @param outButtons The detected button combo will be stored here if the functions returns BUTTON_COMBO_MODULE_ERROR_SUCCESS.
+* @return Returns "BUTTON_COMBO_MODULE_ERROR_SUCCESS" on success, and "BUTTON_COMBO_MODULE_ERROR_ABORTED" if the detection was aborted.
+**/
ButtonComboModule_Error ButtonComboModule_DetectButtonCombo_Blocking(const ButtonComboModule_DetectButtonComboOptions *options,
- ButtonComboModule_Buttons *outButtonCombo);
+ ButtonComboModule_Buttons *outButtons);
#ifdef __cplusplus
}
@@ -134,15 +392,82 @@ ButtonComboModule_Error ButtonComboModule_DetectButtonCombo_Blocking(const Butto
#ifdef __cplusplus
-#include "ButtonCombo.h"
+#include
#include
#include
namespace ButtonComboModule {
- std::string_view GetStatusStr(ButtonComboModule_Error status);
-
- std::string_view GetControllerTypeStr(ButtonComboModule_ControllerTypes controller);
-
+ /**
+ * Wrapper for @ButtonComboModule_GetStatusStr
+ **/
+ const char *GetStatusStr(ButtonComboModule_Error status);
+
+ /**
+ * Wrapper for @ButtonComboModule_GetControllerTypeStr
+ **/
+ const char *GetControllerTypeStr(ButtonComboModule_ControllerTypes controller);
+
+ /**
+ * Wrapper for @ButtonComboModule_GetComboStatusStr
+ **/
+ const char *GetComboStatusStr(ButtonComboModule_ComboStatus status);
+
+ /**
+ * Creates a button combo which triggers a callback if this combo is detected.
+ *
+ * This function takes a generic `ButtonComboModule_ComboOptions` which defines how the combo should be checked.
+ *
+ * Depending on the given type, the combo will either check for holding (for X ms) or pressing a button on for a given
+ * controller mask. The type also defines if it's an "observer" or not. Observers won't check for combo conflicts.
+ *
+ * If the given type is not an `observer` and any other (valid) button combination overlaps with new combo, then the
+ * `outStatus` will be set to `BUTTON_COMBO_MODULE_COMBO_STATUS_CONFLICT` and the combo will be inactive. The original
+ * ButtonCombo which had the combo first won't be affected at all.
+ * In conflict state the callback will not be triggered even if the combination is pressed. If `observer` is set to
+ * "true", the combo won't check for conflicts.
+ *
+ * To resolve a BUTTON_COMBO_MODULE_COMBO_STATUS_CONFLICT combo state you **always** have to update combo information
+ * via @ButtonCombo::UpdateControllerMask or @ButtonCombo::UpdateButtonCombo. The state won't update itself,
+ * even it the combo has no conflicts in a later point in time (e.g. due to other conflicting combos being removed in the meantime)
+ *
+ * Conflict example (only relevant if combo type is not an observer):
+ * It's not possible to add any new valid button combo containing "L+R" (e.g. "X+L+R"), if there already is a button
+ * combination "L+R". Furthermore, it's also not possible to add a "L" or "R" combo if there already is a button
+ * combination "L+R".
+ *
+ * @param options options of this button combo
+ * @param outStatus (optional) The status of the combo will be stored here. Only if the status is BUTTON_COMBO_MODULE_COMBO_STATUS_VALID the combo is valid.
+ * @param outError The error of this operation will be stored here. Only if the error is BUTTON_COMBO_MODULE_ERROR_SUCCESS creating the combo was successful.
+ * @return An optional `ButtonCombo` object if the combo registration succeeds; otherwise, an empty optional.
+ */
+ std::optional CreateComboEx(const ButtonComboModule_ComboOptions &options,
+ ButtonComboModule_ComboStatus &outStatus,
+ ButtonComboModule_Error &outError) noexcept;
+
+ /**
+ * Creates a button combo which triggers a callback if this combo is detected.
+ *
+ * This function creates a "PressDown"-combo. This means the callback is triggered once the combo is pressed down
+ * on one of the provided controllers. The provided controller mask can be a combination of any
+ * `ButtonComboModule_ControllerTypes` values.
+ *
+ * The "observer" parameter defines if this button combo should check for conflicts with other button combos.
+ *
+ * See @CreateComboEx for more information.
+ *
+ * The returned objected will automatically remove the button combo in the destructor. Make sure to keep it around
+ * along as the button combo should be valid! You have to use `std::move` to move it around.
+ *
+ * @param label Label of this button combo
+ * @param controllerMask Mask of controllers which should be checked. Must not be empty.
+ * @param combo Combination which should be checked. Must not be empty.
+ * @param callback Callback that will be called if a button combo is detected. Must not be nullptr.
+ * @param context Context for the callback. Can be nullptr.
+ * @param observer Defines if this combo should check for conflicts. Set to "true" to be an observer and ignore conflicts.
+ * @param outStatus The status of the combo will be stored here. Only if the status is BUTTON_COMBO_MODULE_COMBO_STATUS_VALID the combo is valid.
+ * @param outError The error of this operation will be stored here. Only if the error is BUTTON_COMBO_MODULE_ERROR_SUCCESS creating the combo was successful.
+ * @return An optional `ButtonCombo` object if the combo registration succeeds; otherwise, an empty optional.
+ */
std::optional CreateComboPressDownEx(std::string_view label,
ButtonComboModule_ControllerTypes controllerMask,
ButtonComboModule_Buttons combo,
@@ -152,6 +477,15 @@ namespace ButtonComboModule {
ButtonComboModule_ComboStatus &outStatus,
ButtonComboModule_Error &outError) noexcept;
+ /**
+ * Wrapper for `CreateComboPressDownEx` with `observer` set to "false" and `controllerMask` set to
+ * "BUTTON_COMBO_MODULE_CONTROLLER_ALL"
+ *
+ * See: @CreateComboPressDownEx for more information.
+ *
+ * The returned objected will automatically remove the button combo in the destructor. Make sure to keep it around
+ * along as the button combo should be valid! You have to use `std::move` to move it around.
+ */
std::optional CreateComboPressDown(std::string_view label,
ButtonComboModule_Buttons combo,
ButtonComboModule_ComboCallback callback,
@@ -159,6 +493,15 @@ namespace ButtonComboModule {
ButtonComboModule_ComboStatus &outStatus,
ButtonComboModule_Error &outError) noexcept;
+ /**
+ * Wrapper for `CreateComboPressDownEx` with `observer` set to "true" and `controllerMask` set to
+ * "BUTTON_COMBO_MODULE_CONTROLLER_ALL"
+ *
+ * See: @CreateComboPressDownEx for more information.
+ *
+ * The returned objected will automatically remove the button combo in the destructor. Make sure to keep it around
+ * along as the button combo should be valid! You have to use `std::move` to move it around.
+ */
std::optional CreateComboPressDownObserver(std::string_view label,
ButtonComboModule_Buttons combo,
ButtonComboModule_ComboCallback callback,
@@ -166,6 +509,30 @@ namespace ButtonComboModule {
ButtonComboModule_ComboStatus &outStatus,
ButtonComboModule_Error &outError) noexcept;
+ /**
+ * Creates a button combo which triggers a callback if a given button Combination has been hold for given duration.
+ *
+ * This function creates a "Hold"-combo. This means the callback is triggered once the combo is hold for a given duration
+ * on one of the provided controllers. The provided controller mask can be a combination of any `ButtonComboModule_ControllerTypes` values.
+ *
+ * The "observer" parameter defines if this button combo should check for conflicts with other button combos.
+ *
+ * See: @CreateComboEx for more information about the details.
+ *
+ * The returned objected will automatically remove the button combo in the destructor. Make sure to keep it around
+ * along as the button combo should be valid! You have to use `std::move` to move it around.
+ *
+ * @param label Label of this button combo
+ * @param controllerMask Mask of controllers which should be checked. Must not be empty.
+ * @param combo Combination which should be checked. Must not be empty.
+ * @param holdDurationInMs Defines how long the button combination need to be hold down. Must not be 0.
+ * @param callback Callback that will be called if a button combo is detected. Must not be nullptr.
+ * @param context Context for the callback
+ * @param observer Defines if this combo should check for conflicts. Set to "true" to be an observer and ignore conflicts.
+ * @param outStatus The status of the combo will be stored here. Only if the status is BUTTON_COMBO_MODULE_COMBO_STATUS_VALID the combo is valid. Must not be nullptr.
+ * @param outError The error of this operation will be stored here. Only if the error is BUTTON_COMBO_MODULE_ERROR_SUCCESS creating the combo was successful. Must not be nullptr.
+ * @return An optional `ButtonCombo` object if the combo registration succeeds; otherwise, an empty optional.
+ */
std::optional CreateComboHoldEx(std::string_view label,
ButtonComboModule_ControllerTypes controllerMask,
ButtonComboModule_Buttons combo,
@@ -176,6 +543,15 @@ namespace ButtonComboModule {
ButtonComboModule_ComboStatus &outStatus,
ButtonComboModule_Error &outError) noexcept;
+ /**
+ * Wrapper for `CreateComboHoldEx` with `observer` set to "false" and `controllerMask` set to
+ * "BUTTON_COMBO_MODULE_CONTROLLER_ALL"
+ *
+ * See: @CreateComboHoldEx for more information.
+ *
+ * The returned objected will automatically remove the button combo in the destructor. Make sure to keep it around
+ * along as the button combo should be valid! You have to use `std::move` to move it around.
+ */
std::optional CreateComboHold(std::string_view label,
ButtonComboModule_Buttons combo,
uint32_t holdDurationInMs,
@@ -184,6 +560,15 @@ namespace ButtonComboModule {
ButtonComboModule_ComboStatus &outStatus,
ButtonComboModule_Error &outError) noexcept;
+ /**
+ * Wrapper for `CreateComboHoldEx` with `observer` set to "true" and `controllerMask` set to
+ * "BUTTON_COMBO_MODULE_CONTROLLER_ALL"
+ *
+ * See: @CreateComboHoldEx for more information.
+ *
+ * The returned objected will automatically remove the button combo in the destructor. Make sure to keep it around
+ * along as the button combo should be valid! You have to use `std::move` to move it around.
+ */
std::optional CreateComboHoldObserver(std::string_view label,
ButtonComboModule_Buttons combo,
uint32_t holdDurationInMs,
@@ -192,7 +577,9 @@ namespace ButtonComboModule {
ButtonComboModule_ComboStatus &outStatus,
ButtonComboModule_Error &outError) noexcept;
-
+ /**
+ * Same as @CreateComboEx, but throwing an exception on error instead of returning an optional.
+ */
ButtonCombo CreateComboPressDownEx(std::string_view label,
ButtonComboModule_ControllerTypes controllerMask,
ButtonComboModule_Buttons combo,
@@ -200,19 +587,25 @@ namespace ButtonComboModule {
void *context,
bool observer,
ButtonComboModule_ComboStatus &outStatus);
-
+ /**
+ * Same as @CreateComboEx, but throwing an exception on error instead of returning an optional.
+ */
ButtonCombo CreateComboPressDown(std::string_view label,
ButtonComboModule_Buttons combo,
ButtonComboModule_ComboCallback callback,
void *context,
ButtonComboModule_ComboStatus &outStatus);
-
+ /**
+ * Same as @CreateComboPressDownObserver, but throwing an exception on error instead of returning an optional.
+ */
ButtonCombo CreateComboPressDownObserver(std::string_view label,
ButtonComboModule_Buttons combo,
ButtonComboModule_ComboCallback callback,
void *context,
ButtonComboModule_ComboStatus &outStatus);
-
+ /**
+ * Same as @CreateComboHoldEx, but throwing an exception on error instead of returning an optional.
+ */
ButtonCombo CreateComboHoldEx(std::string_view label,
ButtonComboModule_ControllerTypes controllerMask,
ButtonComboModule_Buttons combo,
@@ -221,23 +614,34 @@ namespace ButtonComboModule {
void *context,
bool observer,
ButtonComboModule_ComboStatus &outStatus);
-
+ /**
+ * Same as @CreateComboHold, but throwing an exception on error instead of returning an optional.
+ */
ButtonCombo CreateComboHold(std::string_view label,
ButtonComboModule_Buttons combo,
uint32_t holdDurationInMs,
ButtonComboModule_ComboCallback callback,
void *context,
ButtonComboModule_ComboStatus &outStatus);
-
+ /**
+ * Same as @CreateComboHoldObserver, but throwing an exception on error instead of returning an optional.
+ */
ButtonCombo CreateComboHoldObserver(std::string_view label,
ButtonComboModule_Buttons combo,
uint32_t holdDurationInMs,
ButtonComboModule_ComboCallback callback,
void *context,
ButtonComboModule_ComboStatus &outStatus);
+
+ /**
+ * See @ButtonComboModule_CheckComboAvailable
+ */
ButtonComboModule_Error CheckComboAvailable(const ButtonComboModule_ButtonComboOptions &options,
ButtonComboModule_ComboStatus &outStatus);
+ /**
+ * See @ButtonComboModule_DetectButtonCombo_Blocking
+ */
ButtonComboModule_Error DetectButtonCombo_Blocking(const ButtonComboModule_DetectButtonComboOptions &options,
ButtonComboModule_Buttons &outButtons);
} // namespace ButtonComboModule
diff --git a/include/buttoncombo/defines.h b/include/buttoncombo/defines.h
index eeef442..3870be9 100644
--- a/include/buttoncombo/defines.h
+++ b/include/buttoncombo/defines.h
@@ -41,13 +41,13 @@ typedef enum ButtonComboModule_Buttons {
BCMPAD_BUTTON_TV = 0x00010000,
//! The reserved bit
BCMPAD_BUTTON_RESERVED_BIT = 0x80000,
- //! The 1 button
+ //! The 1 button on the wiimote (exclusive to Wiimotes)
BCMPAD_BUTTON_1 = 0x0001,
- //! The 2 button
+ //! The 2 button on the wiimote (exclusive to Wiimotes)
BCMPAD_BUTTON_2 = 0x0002,
- //! The C button
+ //! The C button on the nunchuck (exclusive to Wiimotes)
BCMPAD_BUTTON_C = 0x100000,
- //! The Z button
+ //! The Z button on the nunchuck (exclusive to Wiimotes)
BCMPAD_BUTTON_Z = 0x200000,
} ButtonComboModule_Buttons;
WUT_ENUM_BITMASK_TYPE(ButtonComboModule_Buttons);
@@ -111,17 +111,17 @@ typedef struct ButtonComboModule_ComboHandle {
typedef int32_t ButtonComboModule_APIVersion;
typedef enum ButtonComboModule_ComboType {
- BUTTON_COMBO_MODULE_TYPE_INVALID = 0,
- BUTTON_COMBO_MODULE_TYPE_HOLD = 1, // Does check for conflicts
- BUTTON_COMBO_MODULE_TYPE_PRESS_DOWN = 2, // Does check for conflicts
- BUTTON_COMBO_MODULE_TYPE_HOLD_OBSERVER = 3, // Does not check for conflicts
- BUTTON_COMBO_MODULE_TYPE_PRESS_DOWN_OBSERVER = 4, // Does not check for conflicts
+ BUTTON_COMBO_MODULE_COMBO_TYPE_INVALID = 0,
+ BUTTON_COMBO_MODULE_COMBO_TYPE_HOLD = 1, // Checks if a combo has been hold for X ms. Does check for conflicts
+ BUTTON_COMBO_MODULE_COMBO_TYPE_HOLD_OBSERVER = 2, // Checks if a combo has been hold for X ms. Does not check for conflicts
+ BUTTON_COMBO_MODULE_COMBO_TYPE_PRESS_DOWN = 3, // Checks if a combo has been pressed down on a controller. Does check for conflicts
+ BUTTON_COMBO_MODULE_COMBO_TYPE_PRESS_DOWN_OBSERVER = 4, // Checks if a combo has been pressed down on a controller. Does not check for conflicts
} ButtonComboModule_ComboType;
typedef enum ButtonComboModule_ComboStatus {
- BUTTON_COMBO_MODULE_COMBO_STATUS_INVALID_STATUS = 0,
- BUTTON_COMBO_MODULE_COMBO_STATUS_VALID = 1,
- BUTTON_COMBO_MODULE_COMBO_STATUS_CONFLICT = 2,
+ BUTTON_COMBO_MODULE_COMBO_STATUS_INVALID_STATUS = 0, // Invalid status, this only happens on errors.
+ BUTTON_COMBO_MODULE_COMBO_STATUS_VALID = 1, // The Combo is valid and active
+ BUTTON_COMBO_MODULE_COMBO_STATUS_CONFLICT = 2, // The Combo is already used by a different combo. Update to combo by updating the combo or controller mask.
} ButtonComboModule_ComboStatus;
typedef struct ButtonComboModule_DetectButtonComboOptions {
@@ -131,13 +131,31 @@ typedef struct ButtonComboModule_DetectButtonComboOptions {
ButtonComboModule_Buttons abortButtonCombo;
} ButtonComboModule_DetectButtonComboOptions;
+/**
+ * @typedef ButtonComboModule_ComboCallback
+ * @brief Callback function type for handling button combo events.
+ *
+ * This callback is invoked when a button combo is triggered.
+ *
+ * @param triggeredBy
+ * The type of controller that triggered the button combination.
+ * See @ref ButtonComboModule_ControllerTypes for possible values.
+ *
+ * @param handle
+ * A handle representing the button combo that was triggered.
+ * This can be used to identify the specific combo that invoked the callback.
+ *
+ * @param context
+ * A user-defined context pointer passed during the setup of the callback.
+ * This can be used to provide additional information or state relevant to the callback.
+ */
typedef void (*ButtonComboModule_ComboCallback)(ButtonComboModule_ControllerTypes triggeredBy, ButtonComboModule_ComboHandle handle, void *context);
#define BUTTON_COMBO_MODULE_COMBO_OPTIONS_VERSION 1
#define BUTTON_COMBO_MODULE_API_VERSION_ERROR (-0xFF)
typedef struct ButtonComboModule_MetaOptions {
- const char *label;
+ const char *label; // Label that identifies a button combo, currently only used for debugging
} ButtonComboModule_MetaOptions;
typedef struct ButtonComboModule_MetaOptionsOut {
@@ -146,24 +164,24 @@ typedef struct ButtonComboModule_MetaOptionsOut {
} ButtonComboModule_MetaOptionsOut;
typedef struct ButtonComboModule_CallbackOptions {
- ButtonComboModule_ComboCallback callback;
- void *context;
+ ButtonComboModule_ComboCallback callback; // Must not be NULL. Defines which callback should be called once a combo is detected
+ void *context; // Passed into the callback when it's triggered. Can be NULL
} ButtonComboModule_CallbackOptions;
typedef struct ButtonComboModule_ButtonComboOptions {
- ButtonComboModule_ControllerTypes controllerMask;
- ButtonComboModule_Buttons combo;
+ ButtonComboModule_ControllerTypes controllerMask; // Defines a mask for which controller should be checked. Must not be empty.
+ ButtonComboModule_Buttons combo; // Defines which combo should be detected.Note : Not all button are available on all controllers.Must not be empty.
} ButtonComboModule_ButtonComboOptions;
typedef struct ButtonComboModule_ButtonComboInfoEx {
- ButtonComboModule_ComboType type;
- ButtonComboModule_ButtonComboOptions basicCombo;
- uint32_t optionalHoldForXMs;
+ ButtonComboModule_ComboType type; // Defines the type of the combo AND if it will check for conflicts.
+ ButtonComboModule_ButtonComboOptions basicCombo; // Defines which combo should be checked on which controller
+ uint32_t optionalHoldForXMs; // Only mandatory if the type is set to COMBO_TYPE_HOLD or COMBO_TYPE_HOLD_OBSERVER
} ButtonComboModule_ButtonComboInfoEx;
typedef struct ButtonComboModule_ComboOptions {
- int version;
- ButtonComboModule_MetaOptions metaOptions;
- ButtonComboModule_CallbackOptions callbackOptions;
- ButtonComboModule_ButtonComboInfoEx buttonComboOptions;
+ int version; // Has to be set to BUTTON_COMBO_MODULE_COMBO_OPTIONS_VERSION
+ ButtonComboModule_MetaOptions metaOptions; // Defines the meta information about the combo e.g. the label
+ ButtonComboModule_CallbackOptions callbackOptions; // Defines the callback that should be called once the combo is detected
+ ButtonComboModule_ButtonComboInfoEx buttonComboOptions; // Defines how and when which combo should be detected
} ButtonComboModule_ComboOptions;
\ No newline at end of file
diff --git a/source/ButtonCombo.cpp b/source/ButtonCombo.cpp
index 587bc5e..a9651d4 100644
--- a/source/ButtonCombo.cpp
+++ b/source/ButtonCombo.cpp
@@ -6,6 +6,7 @@
#include
namespace ButtonComboModule {
+
std::optional ButtonCombo::Create(const ButtonComboModule_ComboOptions &options,
ButtonComboModule_ComboStatus &outStatus,
ButtonComboModule_Error &outError) noexcept {
diff --git a/source/cppApi.cpp b/source/cppApi.cpp
index dc96913..12b5dd0 100644
--- a/source/cppApi.cpp
+++ b/source/cppApi.cpp
@@ -6,14 +6,24 @@
#include
namespace ButtonComboModule {
- std::string_view GetStatusStr(const ButtonComboModule_Error status) {
+ const char *GetStatusStr(const ButtonComboModule_Error status) {
return ButtonComboModule_GetStatusStr(status);
}
- std::string_view GetControllerTypeStr(const ButtonComboModule_ControllerTypes controller) {
+ const char *GetControllerTypeStr(const ButtonComboModule_ControllerTypes controller) {
return ButtonComboModule_GetControllerTypeStr(controller);
}
+ const char *GetComboStatusStr(const ButtonComboModule_ComboStatus status) {
+ return ButtonComboModule_GetComboStatusStr(status);
+ }
+
+ std::optional CreateComboEx(const ButtonComboModule_ComboOptions &options,
+ ButtonComboModule_ComboStatus &outStatus,
+ ButtonComboModule_Error &outError) noexcept {
+ return ButtonCombo::Create(options, outStatus, outError);
+ }
+
std::optional CreateComboPressDownEx(const std::string_view label,
const ButtonComboModule_ControllerTypes controllerMask,
const ButtonComboModule_Buttons combo,
@@ -23,9 +33,10 @@ namespace ButtonComboModule {
ButtonComboModule_ComboStatus &outStatus,
ButtonComboModule_Error &outError) noexcept {
ButtonComboModule_ComboOptions options = {};
+ options.version = BUTTON_COMBO_MODULE_COMBO_OPTIONS_VERSION;
options.metaOptions.label = label.data();
options.callbackOptions = {.callback = callback, .context = context};
- options.buttonComboOptions.type = observer ? BUTTON_COMBO_MODULE_TYPE_PRESS_DOWN_OBSERVER : BUTTON_COMBO_MODULE_TYPE_PRESS_DOWN;
+ options.buttonComboOptions.type = observer ? BUTTON_COMBO_MODULE_COMBO_TYPE_PRESS_DOWN_OBSERVER : BUTTON_COMBO_MODULE_COMBO_TYPE_PRESS_DOWN;
options.buttonComboOptions.basicCombo.combo = combo;
options.buttonComboOptions.basicCombo.controllerMask = controllerMask;
@@ -61,9 +72,10 @@ namespace ButtonComboModule {
ButtonComboModule_ComboStatus &outStatus,
ButtonComboModule_Error &outError) noexcept {
ButtonComboModule_ComboOptions options = {};
+ options.version = BUTTON_COMBO_MODULE_COMBO_OPTIONS_VERSION;
options.metaOptions.label = label.data();
options.callbackOptions = {.callback = callback, .context = context};
- options.buttonComboOptions.type = observer ? BUTTON_COMBO_MODULE_TYPE_HOLD_OBSERVER : BUTTON_COMBO_MODULE_TYPE_HOLD;
+ options.buttonComboOptions.type = observer ? BUTTON_COMBO_MODULE_COMBO_TYPE_HOLD_OBSERVER : BUTTON_COMBO_MODULE_COMBO_TYPE_HOLD;
options.buttonComboOptions.basicCombo.combo = combo;
options.buttonComboOptions.basicCombo.controllerMask = controllerMask;
options.buttonComboOptions.optionalHoldForXMs = holdDurationInMs;
@@ -91,6 +103,11 @@ namespace ButtonComboModule {
return CreateComboHoldEx(label, BUTTON_COMBO_MODULE_CONTROLLER_ALL, combo, holdDurationInMs, callback, context, true, outStatus, outError);
}
+ ButtonCombo CreateComboEx(const ButtonComboModule_ComboOptions &options,
+ ButtonComboModule_ComboStatus &outStatus) {
+ return ButtonCombo::Create(options, outStatus);
+ }
+
ButtonCombo CreateComboPressDownEx(const std::string_view label,
const ButtonComboModule_ControllerTypes controllerMask,
const ButtonComboModule_Buttons combo,
diff --git a/source/utils.cpp b/source/utils.cpp
index 69e4310..7c30ee5 100644
--- a/source/utils.cpp
+++ b/source/utils.cpp
@@ -87,6 +87,18 @@ const char *ButtonComboModule_GetControllerTypeStr(const ButtonComboModule_Contr
return "";
}
+const char *ButtonComboModule_GetComboStatusStr(ButtonComboModule_ComboStatus status) {
+ switch (status) {
+ case BUTTON_COMBO_MODULE_COMBO_STATUS_INVALID_STATUS:
+ return "BUTTON_COMBO_MODULE_COMBO_STATUS_INVALID_STATUS";
+ case BUTTON_COMBO_MODULE_COMBO_STATUS_VALID:
+ return "BUTTON_COMBO_MODULE_COMBO_STATUS_VALID";
+ case BUTTON_COMBO_MODULE_COMBO_STATUS_CONFLICT:
+ return "BUTTON_COMBO_MODULE_COMBO_STATUS_CONFLICT";
+ }
+ return "BUTTON_COMBO_MODULE_COMBO_STATUS_INVALID_STATUS";
+}
+
ButtonComboModule_Error ButtonComboModule_InitLibrary() {
if (sLibInitDone) {
return BUTTON_COMBO_MODULE_ERROR_SUCCESS;
@@ -189,66 +201,6 @@ ButtonComboModule_Error ButtonComboModule_GetVersion(ButtonComboModule_APIVersio
return sBCMGetVersionFn(outVersion);
}
-namespace {
- ButtonComboModule_ComboOptions getBaseComboOptions(const char *label,
- const ButtonComboModule_ComboCallback callback,
- void *context) {
- ButtonComboModule_ComboOptions comboOptions = {};
- comboOptions.version = BUTTON_COMBO_MODULE_COMBO_OPTIONS_VERSION;
- comboOptions.metaOptions.label = label;
- comboOptions.callbackOptions.callback = callback;
- comboOptions.callbackOptions.context = context;
- return comboOptions;
- }
-} // namespace
-
-ButtonComboModule_Error ButtonComboModule_AddButtonComboSimplePressDownEx(
- const char *label,
- const ButtonComboModule_Buttons buttonCombo,
- const ButtonComboModule_ControllerTypes controllerMask,
- const ButtonComboModule_ComboCallback callback,
- void *context,
- ButtonComboModule_ComboHandle *outHandle,
- ButtonComboModule_ComboStatus *outStatus) {
- ButtonComboModule_ComboOptions options = getBaseComboOptions(label, callback, context);
- options.buttonComboOptions.type = BUTTON_COMBO_MODULE_TYPE_PRESS_DOWN;
- options.buttonComboOptions.basicCombo.combo = buttonCombo;
- options.buttonComboOptions.basicCombo.controllerMask = controllerMask;
-
- return ButtonComboModule_AddButtonCombo(&options, outHandle, outStatus);
-}
-
-ButtonComboModule_Error ButtonComboModule_AddButtonComboSimplePressDown(
- const char *label,
- const ButtonComboModule_Buttons buttonCombo,
- const ButtonComboModule_ComboCallback callback,
- void *context,
- ButtonComboModule_ComboHandle *handleOut) {
- return ButtonComboModule_AddButtonComboSimplePressDownEx(label,
- buttonCombo,
- BUTTON_COMBO_MODULE_CONTROLLER_ALL,
- callback,
- context,
- handleOut);
-}
-
-ButtonComboModule_Error ButtonComboModule_AddButtonComboSimpleHold(
- const char *label,
- const ButtonComboModule_Buttons buttonCombo,
- const uint32_t holdDurationInMs,
- const ButtonComboModule_ComboCallback callback,
- void *context,
- ButtonComboModule_ComboHandle *outHandle,
- ButtonComboModule_ComboStatus *outStatus) {
- ButtonComboModule_ComboOptions options = getBaseComboOptions(label, callback, context);
- options.buttonComboOptions.type = BUTTON_COMBO_MODULE_TYPE_HOLD;
- options.buttonComboOptions.basicCombo.combo = buttonCombo;
- options.buttonComboOptions.basicCombo.controllerMask = BUTTON_COMBO_MODULE_CONTROLLER_ALL;
- options.buttonComboOptions.optionalHoldForXMs = holdDurationInMs;
-
- return ButtonComboModule_AddButtonCombo(&options, outHandle, outStatus);
-}
-
ButtonComboModule_Error ButtonComboModule_AddButtonCombo(const ButtonComboModule_ComboOptions *options,
ButtonComboModule_ComboHandle *outHandle,
ButtonComboModule_ComboStatus *outStatus) {
@@ -259,13 +211,96 @@ ButtonComboModule_Error ButtonComboModule_AddButtonCombo(const ButtonComboModule
return BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_COMMAND;
}
- if (outHandle == nullptr) {
+ if (options == nullptr || outHandle == nullptr) {
return BUTTON_COMBO_MODULE_ERROR_INVALID_ARGUMENT;
}
+ if (options->version != BUTTON_COMBO_MODULE_COMBO_OPTIONS_VERSION) {
+ return BUTTON_COMBO_MODULE_ERROR_INCOMPATIBLE_OPTIONS_VERSION;
+ }
return sBCMAddButtonComboFn(options, outHandle, outStatus);
}
+
+ButtonComboModule_Error ButtonComboModule_AddButtonComboPressDownEx(const char *label,
+ const ButtonComboModule_ControllerTypes controllerMask,
+ const ButtonComboModule_Buttons combo,
+ const ButtonComboModule_ComboCallback callback,
+ void *context,
+ const bool observer,
+ ButtonComboModule_ComboHandle *outHandle,
+ ButtonComboModule_ComboStatus *outStatus) {
+ ButtonComboModule_ComboOptions options = {};
+ options.version = BUTTON_COMBO_MODULE_COMBO_OPTIONS_VERSION;
+ options.metaOptions.label = label;
+ options.callbackOptions = {.callback = callback, .context = context};
+ options.buttonComboOptions.type = observer ? BUTTON_COMBO_MODULE_COMBO_TYPE_PRESS_DOWN_OBSERVER : BUTTON_COMBO_MODULE_COMBO_TYPE_PRESS_DOWN;
+ options.buttonComboOptions.basicCombo.combo = combo;
+ options.buttonComboOptions.basicCombo.controllerMask = controllerMask;
+ options.buttonComboOptions.optionalHoldForXMs = 0;
+
+ return ButtonComboModule_AddButtonCombo(&options, outHandle, outStatus);
+}
+
+ButtonComboModule_Error ButtonComboModule_AddButtonComboPressDown(const char *label,
+ const ButtonComboModule_Buttons combo,
+ const ButtonComboModule_ComboCallback callback,
+ void *context,
+ ButtonComboModule_ComboHandle *outHandle,
+ ButtonComboModule_ComboStatus *outStatus) {
+ return ButtonComboModule_AddButtonComboPressDownEx(label, BUTTON_COMBO_MODULE_CONTROLLER_ALL, combo, callback, context, false, outHandle, outStatus);
+}
+
+ButtonComboModule_Error ButtonComboModule_AddButtonComboPressDownObserver(const char *label,
+ const ButtonComboModule_Buttons combo,
+ const ButtonComboModule_ComboCallback callback,
+ void *context,
+ ButtonComboModule_ComboHandle *outHandle,
+ ButtonComboModule_ComboStatus *outStatus) {
+ return ButtonComboModule_AddButtonComboPressDownEx(label, BUTTON_COMBO_MODULE_CONTROLLER_ALL, combo, callback, context, true, outHandle, outStatus);
+}
+
+ButtonComboModule_Error ButtonComboModule_AddButtonComboHoldEx(const char *label,
+ const ButtonComboModule_ControllerTypes controllerMask,
+ const ButtonComboModule_Buttons combo,
+ const uint32_t holdDurationInMs,
+ const ButtonComboModule_ComboCallback callback,
+ void *context,
+ const bool observer,
+ ButtonComboModule_ComboHandle *outHandle,
+ ButtonComboModule_ComboStatus *outStatus) {
+ ButtonComboModule_ComboOptions options = {};
+ options.version = BUTTON_COMBO_MODULE_COMBO_OPTIONS_VERSION;
+ options.metaOptions.label = label;
+ options.callbackOptions = {.callback = callback, .context = context};
+ options.buttonComboOptions.type = observer ? BUTTON_COMBO_MODULE_COMBO_TYPE_HOLD_OBSERVER : BUTTON_COMBO_MODULE_COMBO_TYPE_HOLD;
+ options.buttonComboOptions.basicCombo.combo = combo;
+ options.buttonComboOptions.basicCombo.controllerMask = controllerMask;
+ options.buttonComboOptions.optionalHoldForXMs = holdDurationInMs;
+
+ return ButtonComboModule_AddButtonCombo(&options, outHandle, outStatus);
+}
+
+ButtonComboModule_Error ButtonComboModule_AddButtonComboHold(const char *label,
+ const ButtonComboModule_Buttons combo,
+ const uint32_t holdDurationInMs,
+ const ButtonComboModule_ComboCallback callback,
+ void *context,
+ ButtonComboModule_ComboHandle *outHandle,
+ ButtonComboModule_ComboStatus *outStatus) {
+ return ButtonComboModule_AddButtonComboHoldEx(label, BUTTON_COMBO_MODULE_CONTROLLER_ALL, combo, holdDurationInMs, callback, context, false, outHandle, outStatus);
+}
+
+ButtonComboModule_Error ButtonComboModule_AddButtonComboHoldObserver(const char *label,
+ const ButtonComboModule_Buttons combo,
+ const uint32_t holdDurationInMs,
+ const ButtonComboModule_ComboCallback callback,
+ void *context,
+ ButtonComboModule_ComboHandle *outHandle,
+ ButtonComboModule_ComboStatus *outStatus) {
+ return ButtonComboModule_AddButtonComboHoldEx(label, BUTTON_COMBO_MODULE_CONTROLLER_ALL, combo, holdDurationInMs, callback, context, true, outHandle, outStatus);
+}
+
ButtonComboModule_Error ButtonComboModule_RemoveButtonCombo(const ButtonComboModule_ComboHandle handle) {
if (sButtonComboModuleVersion == BUTTON_COMBO_MODULE_API_VERSION_ERROR) {
return BUTTON_COMBO_MODULE_ERROR_LIB_UNINITIALIZED;
@@ -274,7 +309,7 @@ ButtonComboModule_Error ButtonComboModule_RemoveButtonCombo(const ButtonComboMod
return BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_COMMAND;
}
- if (handle == 0) {
+ if (handle == nullptr) {
return BUTTON_COMBO_MODULE_ERROR_INVALID_ARGUMENT;
}
@@ -291,7 +326,7 @@ ButtonComboModule_Error ButtonComboModule_GetButtonComboStatus(const ButtonCombo
return BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_COMMAND;
}
- if (handle == 0 || outStatus == nullptr) {
+ if (handle == nullptr || outStatus == nullptr) {
return BUTTON_COMBO_MODULE_ERROR_INVALID_ARGUMENT;
}
@@ -300,7 +335,7 @@ ButtonComboModule_Error ButtonComboModule_GetButtonComboStatus(const ButtonCombo
ButtonComboModule_Error ButtonComboModule_UpdateButtonComboMeta(const ButtonComboModule_ComboHandle handle,
- const ButtonComboModule_MetaOptions *options) {
+ const ButtonComboModule_MetaOptions *metaOptions) {
if (sButtonComboModuleVersion == BUTTON_COMBO_MODULE_API_VERSION_ERROR) {
return BUTTON_COMBO_MODULE_ERROR_LIB_UNINITIALIZED;
}
@@ -308,15 +343,15 @@ ButtonComboModule_Error ButtonComboModule_UpdateButtonComboMeta(const ButtonComb
return BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_COMMAND;
}
- if (handle == 0 || options == nullptr) {
+ if (handle == nullptr || metaOptions == nullptr) {
return BUTTON_COMBO_MODULE_ERROR_INVALID_ARGUMENT;
}
- return sBCMUpdateButtonComboMeta(handle, options);
+ return sBCMUpdateButtonComboMeta(handle, metaOptions);
}
ButtonComboModule_Error ButtonComboModule_UpdateButtonComboCallback(const ButtonComboModule_ComboHandle handle,
- const ButtonComboModule_CallbackOptions *options) {
+ const ButtonComboModule_CallbackOptions *callbackOptions) {
if (sButtonComboModuleVersion == BUTTON_COMBO_MODULE_API_VERSION_ERROR) {
return BUTTON_COMBO_MODULE_ERROR_LIB_UNINITIALIZED;
}
@@ -324,11 +359,11 @@ ButtonComboModule_Error ButtonComboModule_UpdateButtonComboCallback(const Button
return BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_COMMAND;
}
- if (handle == 0 || options == nullptr) {
+ if (handle == nullptr || callbackOptions == nullptr) {
return BUTTON_COMBO_MODULE_ERROR_INVALID_ARGUMENT;
}
- return sBCMUpdateButtonComboCallback(handle, options);
+ return sBCMUpdateButtonComboCallback(handle, callbackOptions);
}
ButtonComboModule_Error ButtonComboModule_UpdateControllerMask(const ButtonComboModule_ComboHandle handle,
@@ -341,12 +376,13 @@ ButtonComboModule_Error ButtonComboModule_UpdateControllerMask(const ButtonCombo
return BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_COMMAND;
}
- if (handle == 0) {
+ if (handle == nullptr) {
return BUTTON_COMBO_MODULE_ERROR_INVALID_ARGUMENT;
}
return sBCMUpdateControllerMask(handle, controllerMask, outStatus);
}
+
ButtonComboModule_Error ButtonComboModule_UpdateButtonCombo(const ButtonComboModule_ComboHandle handle,
const ButtonComboModule_Buttons combo,
ButtonComboModule_ComboStatus *outStatus) {
@@ -357,7 +393,7 @@ ButtonComboModule_Error ButtonComboModule_UpdateButtonCombo(const ButtonComboMod
return BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_COMMAND;
}
- if (handle == 0) {
+ if (handle == nullptr) {
return BUTTON_COMBO_MODULE_ERROR_INVALID_ARGUMENT;
}
@@ -373,7 +409,7 @@ ButtonComboModule_Error ButtonComboModule_UpdateHoldDuration(const ButtonComboMo
return BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_COMMAND;
}
- if (handle == 0) {
+ if (handle == nullptr) {
return BUTTON_COMBO_MODULE_ERROR_INVALID_ARGUMENT;
}
@@ -389,7 +425,7 @@ ButtonComboModule_Error ButtonComboModule_GetButtonComboMeta(const ButtonComboMo
return BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_COMMAND;
}
- if (handle == 0 || outOptions == nullptr) {
+ if (handle == nullptr || outOptions == nullptr) {
return BUTTON_COMBO_MODULE_ERROR_INVALID_ARGUMENT;
}
@@ -405,7 +441,7 @@ ButtonComboModule_Error ButtonComboModule_GetButtonComboCallback(const ButtonCom
return BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_COMMAND;
}
- if (handle == 0 || outOptions == nullptr) {
+ if (handle == nullptr || outOptions == nullptr) {
return BUTTON_COMBO_MODULE_ERROR_INVALID_ARGUMENT;
}
@@ -421,7 +457,7 @@ ButtonComboModule_Error ButtonComboModule_GetButtonComboInfoEx(const ButtonCombo
return BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_COMMAND;
}
- if (handle == 0 || outOptions == nullptr) {
+ if (handle == nullptr || outOptions == nullptr) {
return BUTTON_COMBO_MODULE_ERROR_INVALID_ARGUMENT;
}
@@ -445,7 +481,7 @@ ButtonComboModule_Error ButtonComboModule_CheckComboAvailable(const ButtonComboM
}
ButtonComboModule_Error ButtonComboModule_DetectButtonCombo_Blocking(const ButtonComboModule_DetectButtonComboOptions *options,
- ButtonComboModule_Buttons *outButtonCombo) {
+ ButtonComboModule_Buttons *outButtons) {
if (sButtonComboModuleVersion == BUTTON_COMBO_MODULE_API_VERSION_ERROR) {
return BUTTON_COMBO_MODULE_ERROR_LIB_UNINITIALIZED;
}
@@ -453,9 +489,9 @@ ButtonComboModule_Error ButtonComboModule_DetectButtonCombo_Blocking(const Butto
return BUTTON_COMBO_MODULE_ERROR_UNSUPPORTED_COMMAND;
}
- if (options == nullptr || outButtonCombo == nullptr) {
+ if (options == nullptr || outButtons == nullptr) {
return BUTTON_COMBO_MODULE_ERROR_INVALID_ARGUMENT;
}
- return sBCMDetectButtonComboBlocking(options, outButtonCombo);
+ return sBCMDetectButtonComboBlocking(options, outButtons);
}
\ No newline at end of file