Skip to content

Commit

Permalink
WUPSConfigItemButtonCombo: Fix aborting combo detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Jan 4, 2025
1 parent 7b31373 commit 27b0d90
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions libraries/libwups/WUPSConfigItemButtonCombo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace {
return res;
}

bool checkForHold(ConfigItemButtonCombo *item) {
WUPSButtonCombo_Error checkForHold(ConfigItemButtonCombo *item) {
const auto oldCombo = item->currentButtonCombo;

auto buttonCombo = static_cast<WUPSButtonCombo_Buttons>(0);
Expand All @@ -99,35 +99,35 @@ namespace {
options.abortButtonCombo = item->detectAbortButton;
options.holdAbortForInMs = item->detectAbortHoldButtonInMs;
options.holdComboForInMs = item->detectComboHoldDurationInMs;
if (const auto res = WUPSButtonComboAPI_DetectButtonCombo_Blocking(&options, &buttonCombo); res != WUPS_BUTTON_COMBO_ERROR_SUCCESS) {
if (const auto res = WUPSButtonComboAPI_DetectButtonCombo_Blocking(&options, &buttonCombo); res != WUPS_BUTTON_COMBO_ERROR_SUCCESS && res != WUPS_BUTTON_COMBO_ERROR_ABORTED) {
OSReport("WUPSButtonComboAPI_DetectButtonCombo_Blocking returned %s\n", WUPSButtonComboAPI_GetStatusStr(res));
return false;
return res;
}

WUPSButtonCombo_ComboStatus status = WUPS_BUTTON_COMBO_COMBO_STATUS_INVALID_STATUS;
if (const auto res = WUPSButtonComboAPI_UpdateButtonCombo(item->comboHandle, buttonCombo, &status); res != WUPS_BUTTON_COMBO_ERROR_SUCCESS) {
OSReport("Failed to update combo info\n");
return false;
return WUPS_BUTTON_COMBO_ERROR_SUCCESS;
}
if (status != WUPS_BUTTON_COMBO_COMBO_STATUS_VALID) {
// (Try) to restore "old" button combo

if (WUPSButtonComboAPI_UpdateButtonCombo(item->comboHandle, oldCombo, &status) == WUPS_BUTTON_COMBO_ERROR_SUCCESS) {
OSReport("Failed to update combo info\n");
}
return false;
return WUPS_BUTTON_COMBO_ERROR_UNKNOWN_ERROR;
}

item->currentButtonCombo = buttonCombo;
return true;
return WUPS_BUTTON_COMBO_ERROR_SUCCESS;
}

int32_t getCurrentValueDisplayGeneric(void *context, bool isSelected, char *out_buf, int32_t out_size) {
auto *item = static_cast<ConfigItemButtonCombo *>(context);

WUPSButtonCombo_ComboStatus comboStatus = WUPS_BUTTON_COMBO_COMBO_STATUS_INVALID_STATUS;
if (const auto res = WUPSButtonComboAPI_GetButtonComboStatus(item->comboHandle, &comboStatus); res != WUPS_BUTTON_COMBO_ERROR_SUCCESS) {
OSReport("WUPSConfigItemButtonCombo_getCurrentValueDisplayGeneric: GetButtonComboStatus returned %d\n", WUPSButtonComboAPI_GetStatusStr(res));
OSReport("WUPSConfigItemButtonCombo_getCurrentValueDisplayGeneric: GetButtonComboStatus returned %s\n", WUPSButtonComboAPI_GetStatusStr(res));
}

switch (item->itemState) {
Expand All @@ -142,7 +142,7 @@ namespace {
snprintf(out_buf, out_size, "<Hold new combo for %dms; hold %s to abort>", item->detectAbortHoldButtonInMs, getButtonChar(item->detectAbortButton));
return 0;
}
if (checkForHold(item)) {
if (const auto res = checkForHold(item); res == WUPS_BUTTON_COMBO_ERROR_SUCCESS || res == WUPS_BUTTON_COMBO_ERROR_ABORTED) {
item->itemState = WUPS_CONFIG_ITEM_BUTTON_COMBO_STATE_NONE;
} else {
item->itemState = WUPS_CONFIG_ITEM_BUTTON_COMBO_STATE_PREPARE_FOR_HOLD;
Expand Down

0 comments on commit 27b0d90

Please sign in to comment.