Add extended TiltModel

This commit is contained in:
jpirnay
2026-05-11 16:29:40 +02:00
parent e035e4584b
commit 2b1dbb6737
17 changed files with 545 additions and 28 deletions
+31 -12
View File
@@ -2,6 +2,7 @@
#include <CrossPointSettings.h>
#include <GfxRenderer.h>
#include <HalTiltSensor.h>
#include <Logging.h>
#include <cstdint>
@@ -94,18 +95,36 @@ inline PageTurnResult detectPageTurn(const MappedInputManager& input) {
// Also suppress immediate page-turns if a double-click action is configured for the button,
// because the button event system delays short events until the double-click window expires.
using BA = CrossPointSettings::BUTTON_ACTION;
const bool prev = (SETTINGS.btnShortPageBack == BA::BTN_DEFAULT &&
!globalButtonEvents().hasDoubleAction(MappedInputManager::Button::PageBack) &&
input.wasReleased(MappedInputManager::Button::PageBack)) ||
(SETTINGS.btnShortLeft == BA::BTN_DEFAULT &&
!globalButtonEvents().hasDoubleAction(MappedInputManager::Button::Left) &&
input.wasReleased(MappedInputManager::Button::Left));
const bool next = (SETTINGS.btnShortPageForward == BA::BTN_DEFAULT &&
!globalButtonEvents().hasDoubleAction(MappedInputManager::Button::PageForward) &&
input.wasReleased(MappedInputManager::Button::PageForward)) ||
(SETTINGS.btnShortRight == BA::BTN_DEFAULT &&
!globalButtonEvents().hasDoubleAction(MappedInputManager::Button::Right) &&
input.wasReleased(MappedInputManager::Button::Right));
using TA = CrossPointSettings::TILT_GESTURE_ACTION;
const bool tiltNegative = SETTINGS.tiltPageTurn && halTiltSensor.wasTiltedBack();
const bool tiltPositive = SETTINGS.tiltPageTurn && halTiltSensor.wasTiltedForward();
bool tiltPrev = false;
bool tiltNext = false;
auto applyTiltAction = [&](uint8_t action) {
if (action == TA::TILT_ACT_NEXT_PAGE) {
tiltNext = true;
} else if (action == TA::TILT_ACT_PREV_PAGE) {
tiltPrev = true;
}
};
if (tiltPositive) {
applyTiltAction(SETTINGS.tiltPositiveAction);
}
if (tiltNegative) {
applyTiltAction(SETTINGS.tiltNegativeAction);
}
const bool prev = tiltPrev || ((SETTINGS.btnShortPageBack == BA::BTN_DEFAULT &&
!globalButtonEvents().hasDoubleAction(MappedInputManager::Button::PageBack) &&
input.wasReleased(MappedInputManager::Button::PageBack)) ||
(SETTINGS.btnShortLeft == BA::BTN_DEFAULT &&
!globalButtonEvents().hasDoubleAction(MappedInputManager::Button::Left) &&
input.wasReleased(MappedInputManager::Button::Left)));
const bool next = tiltNext || ((SETTINGS.btnShortPageForward == BA::BTN_DEFAULT &&
!globalButtonEvents().hasDoubleAction(MappedInputManager::Button::PageForward) &&
input.wasReleased(MappedInputManager::Button::PageForward)) ||
(SETTINGS.btnShortRight == BA::BTN_DEFAULT &&
!globalButtonEvents().hasDoubleAction(MappedInputManager::Button::Right) &&
input.wasReleased(MappedInputManager::Button::Right)));
return {prev, next};
}
@@ -196,6 +196,25 @@ void TxtReaderActivity::loop() {
return;
}
}
auto [prevTriggered, nextTriggered] = ReaderUtils::detectPageTurn(mappedInput);
if (!prevTriggered && !nextTriggered) {
return;
}
if (prevTriggered) {
if (currentPage > 0) {
currentPage--;
requestUpdate();
}
} else if (nextTriggered) {
if (currentPage < totalPages - 1) {
currentPage++;
requestUpdate();
} else {
finish();
}
}
}
void TxtReaderActivity::initializeReader() {
@@ -30,18 +30,13 @@ constexpr std::array<ButtonRow, 7> kButtonRows = {{
}};
// Find the SettingInfo for a given (button submenu, press kind) pair in the shared settings list.
const SettingInfo* findEntry(StrId submenu, StrId pressKind) {
const auto& list = getSettingsList();
std::string cellValue(StrId submenu, StrId pressKind) {
const auto list = getSettingsList();
auto it = std::find_if(list.begin(), list.end(), [submenu, pressKind](const SettingInfo& s) {
return s.submenu == submenu && s.nameId == pressKind && s.category == StrId::STR_CAT_CONTROLS;
});
return it != list.end() ? &*it : nullptr;
}
std::string cellValue(StrId submenu, StrId pressKind) {
const SettingInfo* s = findEntry(submenu, pressKind);
if (!s) return {};
return s->getDisplayValue();
if (it == list.end()) return {};
return it->getDisplayValue();
}
} // namespace
+10
View File
@@ -11,6 +11,8 @@
enum class SettingType { TOGGLE, ENUM, ACTION, VALUE, STRING };
enum class SettingDeviceTarget { BOTH, X3, X4 };
enum class SettingAction {
None,
RemapFrontButtons,
@@ -56,6 +58,7 @@ struct SettingInfo {
const char* key = nullptr; // JSON API key (nullptr for ACTION types)
StrId category = StrId::STR_NONE_OPT; // Category for web UI grouping
bool obfuscated = false; // Save/load via base64 obfuscation (passwords)
SettingDeviceTarget deviceTarget = SettingDeviceTarget::BOTH;
// Direct char[] string fields (for settings stored in CrossPointSettings)
size_t stringOffset = 0;
@@ -234,6 +237,13 @@ struct SettingInfo {
return *this;
}
// Restrict visibility of this setting to a specific hardware target.
// Default is BOTH when this method is not used.
SettingInfo& withDeviceTarget(SettingDeviceTarget target) {
deviceTarget = target;
return *this;
}
// For internal use by SettingsActivity: placeholder entry that launches the submenu.
static SettingInfo SubmenuEntry(StrId titleId) {
SettingInfo s;
+1 -1
View File
@@ -54,7 +54,7 @@ void SettingsActivity::onEnter() {
}
vec.push_back(s);
};
auto addToMoved = [](std::vector<SettingInfo>& vec, StrId& lastSub, SettingInfo&& s) {
auto addToMoved = [](std::vector<SettingInfo>& vec, StrId& lastSub, SettingInfo s) {
if (s.subcategory != StrId::STR_NONE_OPT && s.subcategory != lastSub) {
vec.push_back(SettingInfo::Separator(s.subcategory));
lastSub = s.subcategory;