mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
Merge branch 'crosspoint-reader:master' into master
This commit is contained in:
commit
b9ce83799a
@ -2,97 +2,73 @@
|
|||||||
|
|
||||||
#include "CrossPointSettings.h"
|
#include "CrossPointSettings.h"
|
||||||
|
|
||||||
decltype(InputManager::BTN_BACK) MappedInputManager::mapButton(const Button button) const {
|
namespace {
|
||||||
|
using ButtonIndex = uint8_t;
|
||||||
|
|
||||||
|
struct FrontLayoutMap {
|
||||||
|
ButtonIndex back;
|
||||||
|
ButtonIndex confirm;
|
||||||
|
ButtonIndex left;
|
||||||
|
ButtonIndex right;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SideLayoutMap {
|
||||||
|
ButtonIndex pageBack;
|
||||||
|
ButtonIndex pageForward;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Order matches CrossPointSettings::FRONT_BUTTON_LAYOUT.
|
||||||
|
constexpr FrontLayoutMap kFrontLayouts[] = {
|
||||||
|
{InputManager::BTN_BACK, InputManager::BTN_CONFIRM, InputManager::BTN_LEFT, InputManager::BTN_RIGHT},
|
||||||
|
{InputManager::BTN_LEFT, InputManager::BTN_RIGHT, InputManager::BTN_BACK, InputManager::BTN_CONFIRM},
|
||||||
|
{InputManager::BTN_CONFIRM, InputManager::BTN_LEFT, InputManager::BTN_BACK, InputManager::BTN_RIGHT},
|
||||||
|
{InputManager::BTN_BACK, InputManager::BTN_CONFIRM, InputManager::BTN_RIGHT, InputManager::BTN_LEFT},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Order matches CrossPointSettings::SIDE_BUTTON_LAYOUT.
|
||||||
|
constexpr SideLayoutMap kSideLayouts[] = {
|
||||||
|
{InputManager::BTN_UP, InputManager::BTN_DOWN},
|
||||||
|
{InputManager::BTN_DOWN, InputManager::BTN_UP},
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
bool MappedInputManager::mapButton(const Button button, bool (InputManager::*fn)(uint8_t) const) const {
|
||||||
const auto frontLayout = static_cast<CrossPointSettings::FRONT_BUTTON_LAYOUT>(SETTINGS.frontButtonLayout);
|
const auto frontLayout = static_cast<CrossPointSettings::FRONT_BUTTON_LAYOUT>(SETTINGS.frontButtonLayout);
|
||||||
const auto sideLayout = static_cast<CrossPointSettings::SIDE_BUTTON_LAYOUT>(SETTINGS.sideButtonLayout);
|
const auto sideLayout = static_cast<CrossPointSettings::SIDE_BUTTON_LAYOUT>(SETTINGS.sideButtonLayout);
|
||||||
|
const auto& front = kFrontLayouts[frontLayout];
|
||||||
|
const auto& side = kSideLayouts[sideLayout];
|
||||||
|
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case Button::Back:
|
case Button::Back:
|
||||||
switch (frontLayout) {
|
return (inputManager.*fn)(front.back);
|
||||||
case CrossPointSettings::LEFT_RIGHT_BACK_CONFIRM:
|
|
||||||
return InputManager::BTN_LEFT;
|
|
||||||
case CrossPointSettings::LEFT_BACK_CONFIRM_RIGHT:
|
|
||||||
return InputManager::BTN_CONFIRM;
|
|
||||||
case CrossPointSettings::BACK_CONFIRM_LEFT_RIGHT:
|
|
||||||
/* fall through */
|
|
||||||
case CrossPointSettings::BACK_CONFIRM_RIGHT_LEFT:
|
|
||||||
/* fall through */
|
|
||||||
default:
|
|
||||||
return InputManager::BTN_BACK;
|
|
||||||
}
|
|
||||||
case Button::Confirm:
|
case Button::Confirm:
|
||||||
switch (frontLayout) {
|
return (inputManager.*fn)(front.confirm);
|
||||||
case CrossPointSettings::LEFT_RIGHT_BACK_CONFIRM:
|
|
||||||
return InputManager::BTN_RIGHT;
|
|
||||||
case CrossPointSettings::LEFT_BACK_CONFIRM_RIGHT:
|
|
||||||
return InputManager::BTN_LEFT;
|
|
||||||
case CrossPointSettings::BACK_CONFIRM_LEFT_RIGHT:
|
|
||||||
/* fall through */
|
|
||||||
case CrossPointSettings::BACK_CONFIRM_RIGHT_LEFT:
|
|
||||||
/* fall through */
|
|
||||||
default:
|
|
||||||
return InputManager::BTN_CONFIRM;
|
|
||||||
}
|
|
||||||
case Button::Left:
|
case Button::Left:
|
||||||
switch (frontLayout) {
|
return (inputManager.*fn)(front.left);
|
||||||
case CrossPointSettings::LEFT_RIGHT_BACK_CONFIRM:
|
|
||||||
/* fall through */
|
|
||||||
case CrossPointSettings::LEFT_BACK_CONFIRM_RIGHT:
|
|
||||||
return InputManager::BTN_BACK;
|
|
||||||
case CrossPointSettings::BACK_CONFIRM_RIGHT_LEFT:
|
|
||||||
return InputManager::BTN_RIGHT;
|
|
||||||
case CrossPointSettings::BACK_CONFIRM_LEFT_RIGHT:
|
|
||||||
/* fall through */
|
|
||||||
default:
|
|
||||||
return InputManager::BTN_LEFT;
|
|
||||||
}
|
|
||||||
case Button::Right:
|
case Button::Right:
|
||||||
switch (frontLayout) {
|
return (inputManager.*fn)(front.right);
|
||||||
case CrossPointSettings::LEFT_RIGHT_BACK_CONFIRM:
|
|
||||||
return InputManager::BTN_CONFIRM;
|
|
||||||
case CrossPointSettings::BACK_CONFIRM_RIGHT_LEFT:
|
|
||||||
return InputManager::BTN_LEFT;
|
|
||||||
case CrossPointSettings::BACK_CONFIRM_LEFT_RIGHT:
|
|
||||||
/* fall through */
|
|
||||||
case CrossPointSettings::LEFT_BACK_CONFIRM_RIGHT:
|
|
||||||
/* fall through */
|
|
||||||
default:
|
|
||||||
return InputManager::BTN_RIGHT;
|
|
||||||
}
|
|
||||||
case Button::Up:
|
case Button::Up:
|
||||||
return InputManager::BTN_UP;
|
return (inputManager.*fn)(InputManager::BTN_UP);
|
||||||
case Button::Down:
|
case Button::Down:
|
||||||
return InputManager::BTN_DOWN;
|
return (inputManager.*fn)(InputManager::BTN_DOWN);
|
||||||
case Button::Power:
|
case Button::Power:
|
||||||
return InputManager::BTN_POWER;
|
return (inputManager.*fn)(InputManager::BTN_POWER);
|
||||||
case Button::PageBack:
|
case Button::PageBack:
|
||||||
switch (sideLayout) {
|
return (inputManager.*fn)(side.pageBack);
|
||||||
case CrossPointSettings::NEXT_PREV:
|
|
||||||
return InputManager::BTN_DOWN;
|
|
||||||
case CrossPointSettings::PREV_NEXT:
|
|
||||||
/* fall through */
|
|
||||||
default:
|
|
||||||
return InputManager::BTN_UP;
|
|
||||||
}
|
|
||||||
case Button::PageForward:
|
case Button::PageForward:
|
||||||
switch (sideLayout) {
|
return (inputManager.*fn)(side.pageForward);
|
||||||
case CrossPointSettings::NEXT_PREV:
|
|
||||||
return InputManager::BTN_UP;
|
|
||||||
case CrossPointSettings::PREV_NEXT:
|
|
||||||
/* fall through */
|
|
||||||
default:
|
|
||||||
return InputManager::BTN_DOWN;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return InputManager::BTN_BACK;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MappedInputManager::wasPressed(const Button button) const { return inputManager.wasPressed(mapButton(button)); }
|
bool MappedInputManager::wasPressed(const Button button) const { return mapButton(button, &InputManager::wasPressed); }
|
||||||
|
|
||||||
bool MappedInputManager::wasReleased(const Button button) const { return inputManager.wasReleased(mapButton(button)); }
|
bool MappedInputManager::wasReleased(const Button button) const {
|
||||||
|
return mapButton(button, &InputManager::wasReleased);
|
||||||
|
}
|
||||||
|
|
||||||
bool MappedInputManager::isPressed(const Button button) const { return inputManager.isPressed(mapButton(button)); }
|
bool MappedInputManager::isPressed(const Button button) const { return mapButton(button, &InputManager::isPressed); }
|
||||||
|
|
||||||
bool MappedInputManager::wasAnyPressed() const { return inputManager.wasAnyPressed(); }
|
bool MappedInputManager::wasAnyPressed() const { return inputManager.wasAnyPressed(); }
|
||||||
|
|
||||||
|
|||||||
@ -25,5 +25,6 @@ class MappedInputManager {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
InputManager& inputManager;
|
InputManager& inputManager;
|
||||||
decltype(InputManager::BTN_BACK) mapButton(Button button) const;
|
|
||||||
|
bool mapButton(Button button, bool (InputManager::*fn)(uint8_t) const) const;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -170,14 +170,21 @@ void EpubReaderActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool prevReleased = mappedInput.wasReleased(MappedInputManager::Button::PageBack) ||
|
// When long-press chapter skip is disabled, turn pages on press instead of release.
|
||||||
mappedInput.wasReleased(MappedInputManager::Button::Left);
|
const bool usePressForPageTurn = !SETTINGS.longPressChapterSkip;
|
||||||
const bool nextReleased = mappedInput.wasReleased(MappedInputManager::Button::PageForward) ||
|
const bool prevTriggered = usePressForPageTurn ? (mappedInput.wasPressed(MappedInputManager::Button::PageBack) ||
|
||||||
(SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::PAGE_TURN &&
|
mappedInput.wasPressed(MappedInputManager::Button::Left))
|
||||||
mappedInput.wasReleased(MappedInputManager::Button::Power)) ||
|
: (mappedInput.wasReleased(MappedInputManager::Button::PageBack) ||
|
||||||
mappedInput.wasReleased(MappedInputManager::Button::Right);
|
mappedInput.wasReleased(MappedInputManager::Button::Left));
|
||||||
|
const bool powerPageTurn = SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::PAGE_TURN &&
|
||||||
|
mappedInput.wasReleased(MappedInputManager::Button::Power);
|
||||||
|
const bool nextTriggered = usePressForPageTurn
|
||||||
|
? (mappedInput.wasPressed(MappedInputManager::Button::PageForward) || powerPageTurn ||
|
||||||
|
mappedInput.wasPressed(MappedInputManager::Button::Right))
|
||||||
|
: (mappedInput.wasReleased(MappedInputManager::Button::PageForward) || powerPageTurn ||
|
||||||
|
mappedInput.wasReleased(MappedInputManager::Button::Right));
|
||||||
|
|
||||||
if (!prevReleased && !nextReleased) {
|
if (!prevTriggered && !nextTriggered) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +202,7 @@ void EpubReaderActivity::loop() {
|
|||||||
// We don't want to delete the section mid-render, so grab the semaphore
|
// We don't want to delete the section mid-render, so grab the semaphore
|
||||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||||
nextPageNumber = 0;
|
nextPageNumber = 0;
|
||||||
currentSpineIndex = nextReleased ? currentSpineIndex + 1 : currentSpineIndex - 1;
|
currentSpineIndex = nextTriggered ? currentSpineIndex + 1 : currentSpineIndex - 1;
|
||||||
section.reset();
|
section.reset();
|
||||||
xSemaphoreGive(renderingMutex);
|
xSemaphoreGive(renderingMutex);
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
@ -208,7 +215,7 @@ void EpubReaderActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prevReleased) {
|
if (prevTriggered) {
|
||||||
if (section->currentPage > 0) {
|
if (section->currentPage > 0) {
|
||||||
section->currentPage--;
|
section->currentPage--;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -110,21 +110,28 @@ void TxtReaderActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool prevReleased = mappedInput.wasReleased(MappedInputManager::Button::PageBack) ||
|
// When long-press chapter skip is disabled, turn pages on press instead of release.
|
||||||
mappedInput.wasReleased(MappedInputManager::Button::Left);
|
const bool usePressForPageTurn = !SETTINGS.longPressChapterSkip;
|
||||||
const bool nextReleased = mappedInput.wasReleased(MappedInputManager::Button::PageForward) ||
|
const bool prevTriggered = usePressForPageTurn ? (mappedInput.wasPressed(MappedInputManager::Button::PageBack) ||
|
||||||
(SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::PAGE_TURN &&
|
mappedInput.wasPressed(MappedInputManager::Button::Left))
|
||||||
mappedInput.wasReleased(MappedInputManager::Button::Power)) ||
|
: (mappedInput.wasReleased(MappedInputManager::Button::PageBack) ||
|
||||||
mappedInput.wasReleased(MappedInputManager::Button::Right);
|
mappedInput.wasReleased(MappedInputManager::Button::Left));
|
||||||
|
const bool powerPageTurn = SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::PAGE_TURN &&
|
||||||
|
mappedInput.wasReleased(MappedInputManager::Button::Power);
|
||||||
|
const bool nextTriggered = usePressForPageTurn
|
||||||
|
? (mappedInput.wasPressed(MappedInputManager::Button::PageForward) || powerPageTurn ||
|
||||||
|
mappedInput.wasPressed(MappedInputManager::Button::Right))
|
||||||
|
: (mappedInput.wasReleased(MappedInputManager::Button::PageForward) || powerPageTurn ||
|
||||||
|
mappedInput.wasReleased(MappedInputManager::Button::Right));
|
||||||
|
|
||||||
if (!prevReleased && !nextReleased) {
|
if (!prevTriggered && !nextTriggered) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prevReleased && currentPage > 0) {
|
if (prevTriggered && currentPage > 0) {
|
||||||
currentPage--;
|
currentPage--;
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
} else if (nextReleased && currentPage < totalPages - 1) {
|
} else if (nextTriggered && currentPage < totalPages - 1) {
|
||||||
currentPage++;
|
currentPage++;
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -111,14 +111,21 @@ void XtcReaderActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool prevReleased = mappedInput.wasReleased(MappedInputManager::Button::PageBack) ||
|
// When long-press chapter skip is disabled, turn pages on press instead of release.
|
||||||
mappedInput.wasReleased(MappedInputManager::Button::Left);
|
const bool usePressForPageTurn = !SETTINGS.longPressChapterSkip;
|
||||||
const bool nextReleased = mappedInput.wasReleased(MappedInputManager::Button::PageForward) ||
|
const bool prevTriggered = usePressForPageTurn ? (mappedInput.wasPressed(MappedInputManager::Button::PageBack) ||
|
||||||
(SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::PAGE_TURN &&
|
mappedInput.wasPressed(MappedInputManager::Button::Left))
|
||||||
mappedInput.wasReleased(MappedInputManager::Button::Power)) ||
|
: (mappedInput.wasReleased(MappedInputManager::Button::PageBack) ||
|
||||||
mappedInput.wasReleased(MappedInputManager::Button::Right);
|
mappedInput.wasReleased(MappedInputManager::Button::Left));
|
||||||
|
const bool powerPageTurn = SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::PAGE_TURN &&
|
||||||
|
mappedInput.wasReleased(MappedInputManager::Button::Power);
|
||||||
|
const bool nextTriggered = usePressForPageTurn
|
||||||
|
? (mappedInput.wasPressed(MappedInputManager::Button::PageForward) || powerPageTurn ||
|
||||||
|
mappedInput.wasPressed(MappedInputManager::Button::Right))
|
||||||
|
: (mappedInput.wasReleased(MappedInputManager::Button::PageForward) || powerPageTurn ||
|
||||||
|
mappedInput.wasReleased(MappedInputManager::Button::Right));
|
||||||
|
|
||||||
if (!prevReleased && !nextReleased) {
|
if (!prevTriggered && !nextTriggered) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,14 +139,14 @@ void XtcReaderActivity::loop() {
|
|||||||
const bool skipPages = SETTINGS.longPressChapterSkip && mappedInput.getHeldTime() > skipPageMs;
|
const bool skipPages = SETTINGS.longPressChapterSkip && mappedInput.getHeldTime() > skipPageMs;
|
||||||
const int skipAmount = skipPages ? 10 : 1;
|
const int skipAmount = skipPages ? 10 : 1;
|
||||||
|
|
||||||
if (prevReleased) {
|
if (prevTriggered) {
|
||||||
if (currentPage >= static_cast<uint32_t>(skipAmount)) {
|
if (currentPage >= static_cast<uint32_t>(skipAmount)) {
|
||||||
currentPage -= skipAmount;
|
currentPage -= skipAmount;
|
||||||
} else {
|
} else {
|
||||||
currentPage = 0;
|
currentPage = 0;
|
||||||
}
|
}
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
} else if (nextReleased) {
|
} else if (nextTriggered) {
|
||||||
currentPage += skipAmount;
|
currentPage += skipAmount;
|
||||||
if (currentPage >= xtc->getPageCount()) {
|
if (currentPage >= xtc->getPageCount()) {
|
||||||
currentPage = xtc->getPageCount(); // Allow showing "End of book"
|
currentPage = xtc->getPageCount(); // Allow showing "End of book"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user