| 34 | void ButtonRemapActivity::onExit() { Activity::onExit(); } |
| 35 | |
| 36 | void ButtonRemapActivity::loop() { |
| 37 | // Clear any temporary warning after its timeout. |
| 38 | if (errorUntil > 0 && millis() > errorUntil) { |
| 39 | errorMessage.clear(); |
| 40 | errorUntil = 0; |
| 41 | requestUpdate(); |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | // Side buttons: |
| 46 | // - Up: reset mapping to defaults and exit. |
| 47 | // - Down: cancel without saving. |
| 48 | if (mappedInput.wasPressed(MappedInputManager::Button::Up)) { |
| 49 | // Persist default mapping immediately so the user can recover quickly. |
| 50 | SETTINGS.frontButtonBack = CrossPointSettings::FRONT_HW_BACK; |
| 51 | SETTINGS.frontButtonConfirm = CrossPointSettings::FRONT_HW_CONFIRM; |
| 52 | SETTINGS.frontButtonLeft = CrossPointSettings::FRONT_HW_LEFT; |
| 53 | SETTINGS.frontButtonRight = CrossPointSettings::FRONT_HW_RIGHT; |
| 54 | SETTINGS.saveToFile(); |
| 55 | finish(); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | if (mappedInput.wasPressed(MappedInputManager::Button::Down)) { |
| 60 | // Exit without changing settings. |
| 61 | finish(); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | { |
| 66 | // Make sure UI done rendering before accepting another assignment. |
| 67 | // This avoids rapid double-presses that can advance the step without a visible redraw. |
| 68 | RenderLock lock(*this); |
| 69 | |
| 70 | // Wait for a front button press to assign to the current role. |
| 71 | const int pressedButton = mappedInput.getPressedFrontButton(); |
| 72 | if (pressedButton < 0) { |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | // Update temporary mapping and advance the remap step. |
| 77 | // Only accept the press if this hardware button isn't already assigned elsewhere. |
| 78 | if (!validateUnassigned(static_cast<uint8_t>(pressedButton))) { |
| 79 | requestUpdate(); |
| 80 | return; |
| 81 | } |
| 82 | tempMapping[currentStep] = static_cast<uint8_t>(pressedButton); |
| 83 | currentStep++; |
| 84 | |
| 85 | if (currentStep >= kRoleCount) { |
| 86 | // All roles assigned; save to settings and exit. |
| 87 | applyTempMapping(); |
| 88 | SETTINGS.saveToFile(); |
| 89 | finish(); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | requestUpdate(); |
nothing calls this directly
no test coverage detected