## Summary * Manually trigger GPIO update in File Browser mode * Previously just assumed that the GPIO data would update automatically (presumably via yield), the data is currently updated in the main loop (and now here as well during the middle of the processing loop). * This allows the back button to be correctly detected instead of only being checked once every 100ms or so for the button state. ## Additional Context * Fixes https://github.com/crosspoint-reader/crosspoint-reader/issues/579 --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Enhanced input state detection in the web server interface for more responsive and accurate user command recognition during high-frequency operations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
34 lines
932 B
C++
34 lines
932 B
C++
#pragma once
|
|
|
|
#include <HalGPIO.h>
|
|
|
|
class MappedInputManager {
|
|
public:
|
|
enum class Button { Back, Confirm, Left, Right, Up, Down, Power, PageBack, PageForward };
|
|
|
|
struct Labels {
|
|
const char* btn1;
|
|
const char* btn2;
|
|
const char* btn3;
|
|
const char* btn4;
|
|
};
|
|
|
|
explicit MappedInputManager(HalGPIO& gpio) : gpio(gpio) {}
|
|
|
|
void update() const { gpio.update(); }
|
|
bool wasPressed(Button button) const;
|
|
bool wasReleased(Button button) const;
|
|
bool isPressed(Button button) const;
|
|
bool wasAnyPressed() const;
|
|
bool wasAnyReleased() const;
|
|
unsigned long getHeldTime() const;
|
|
Labels mapLabels(const char* back, const char* confirm, const char* previous, const char* next) const;
|
|
// Returns the raw front button index that was pressed this frame (or -1 if none).
|
|
int getPressedFrontButton() const;
|
|
|
|
private:
|
|
HalGPIO& gpio;
|
|
|
|
bool mapButton(Button button, bool (HalGPIO::*fn)(uint8_t) const) const;
|
|
};
|