feat: Make page turn naturally follow orientation (#2023)

This commit is contained in:
Jackson
2026-05-19 23:13:27 +03:00
committed by GitHub
parent b69111bea5
commit beb7876ccf
27 changed files with 48 additions and 9 deletions
+2
View File
@@ -240,6 +240,8 @@ bool CrossPointSettings::loadFromBinaryFile() {
if (++settingsRead >= fileSettingsCount) break;
serialization::readPod(inputFile, embeddedStyle);
if (++settingsRead >= fileSettingsCount) break;
serialization::readPod(inputFile, frontButtonFollowOrientation);
if (++settingsRead >= fileSettingsCount) break;
} while (false);
if (frontButtonMappingRead) {
+1
View File
@@ -192,6 +192,7 @@ class CrossPointSettings {
// Button layouts (front layout retained for migration only)
uint8_t frontButtonLayout = BACK_CONFIRM_LEFT_RIGHT;
uint8_t sideButtonLayout = PREV_NEXT;
uint8_t frontButtonFollowOrientation = 0;
// Front button remap (logical -> hardware)
// Used by MappedInputManager to translate logical buttons into physical front buttons.
uint8_t frontButtonBack = FRONT_HW_BACK;
+10 -3
View File
@@ -68,6 +68,13 @@ unsigned long MappedInputManager::getHeldTime() const { return gpio.getHeldTime(
MappedInputManager::Labels MappedInputManager::mapLabels(const char* back, const char* confirm, const char* previous,
const char* next) const {
// Swap previous/next labels to match the page turn direction swap in INVERTED and LANDSCAPE_CCW.
const bool swapLabels =
SETTINGS.frontButtonFollowOrientation && (SETTINGS.orientation == CrossPointSettings::INVERTED ||
SETTINGS.orientation == CrossPointSettings::LANDSCAPE_CCW);
const char* leftLabel = swapLabels ? next : previous;
const char* rightLabel = swapLabels ? previous : next;
// Build the label order based on the configured hardware mapping.
auto labelForHardware = [&](uint8_t hw) -> const char* {
// Compare against configured logical roles and return the matching label.
@@ -78,10 +85,10 @@ MappedInputManager::Labels MappedInputManager::mapLabels(const char* back, const
return confirm;
}
if (hw == SETTINGS.frontButtonLeft) {
return previous;
return leftLabel;
}
if (hw == SETTINGS.frontButtonRight) {
return next;
return rightLabel;
}
return "";
};
@@ -106,4 +113,4 @@ int MappedInputManager::getPressedFrontButton() const {
return HalGPIO::BTN_RIGHT;
}
return -1;
}
}
+2
View File
@@ -163,6 +163,8 @@ inline std::vector<SettingInfo> getSettingsList(const SdCardFontRegistry* regist
// --- Controls ---
SettingInfo::Enum(StrId::STR_SIDE_BTN_LAYOUT, &CrossPointSettings::sideButtonLayout,
{StrId::STR_PREV_NEXT, StrId::STR_NEXT_PREV}, "sideButtonLayout", StrId::STR_CAT_CONTROLS),
SettingInfo::Toggle(StrId::STR_FRONT_BTN_FOLLOW_ORIENTATION, &CrossPointSettings::frontButtonFollowOrientation,
"frontButtonFollowOrientation", StrId::STR_CAT_CONTROLS),
SettingInfo::Enum(StrId::STR_LONG_PRESS_BEHAVIOR, &CrossPointSettings::longPressButtonBehavior,
{StrId::STR_LONG_PRESS_BEHAVIOR_OFF, StrId::STR_LONG_PRESS_BEHAVIOR_SKIP,
StrId::STR_LONG_PRESS_BEHAVIOR_ORIENTATION},
+11 -6
View File
@@ -41,16 +41,21 @@ inline PageTurnResult detectPageTurn(const MappedInputManager& input) {
const bool usePress = SETTINGS.longPressButtonBehavior == SETTINGS.OFF;
const bool tiltNext = SETTINGS.tiltPageTurn && halTiltSensor.wasTiltedForward();
const bool tiltPrev = SETTINGS.tiltPageTurn && halTiltSensor.wasTiltedBack();
const bool prev = tiltPrev || (usePress ? (input.wasPressed(MappedInputManager::Button::PageBack) ||
input.wasPressed(MappedInputManager::Button::Left))
: (input.wasReleased(MappedInputManager::Button::PageBack) ||
input.wasReleased(MappedInputManager::Button::Left)));
const bool swapFront =
SETTINGS.frontButtonFollowOrientation && (SETTINGS.orientation == CrossPointSettings::INVERTED ||
SETTINGS.orientation == CrossPointSettings::LANDSCAPE_CCW);
const auto prevButton = swapFront ? MappedInputManager::Button::Right : MappedInputManager::Button::Left;
const auto nextButton = swapFront ? MappedInputManager::Button::Left : MappedInputManager::Button::Right;
const bool prev =
tiltPrev ||
(usePress ? (input.wasPressed(MappedInputManager::Button::PageBack) || input.wasPressed(prevButton))
: (input.wasReleased(MappedInputManager::Button::PageBack) || input.wasReleased(prevButton)));
const bool powerTurn = SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::PAGE_TURN &&
input.wasReleased(MappedInputManager::Button::Power);
const bool next = tiltNext || (usePress ? (input.wasPressed(MappedInputManager::Button::PageForward) || powerTurn ||
input.wasPressed(MappedInputManager::Button::Right))
input.wasPressed(nextButton))
: (input.wasReleased(MappedInputManager::Button::PageForward) || powerTurn ||
input.wasReleased(MappedInputManager::Button::Right)));
input.wasReleased(nextButton)));
return {prev, next, tiltPrev || tiltNext};
}