Code improvement

This commit is contained in:
Jaby 2024-01-15 20:34:08 -05:00
parent bd1c662315
commit 2b371dc473
1 changed files with 7 additions and 10 deletions

View File

@ -13,7 +13,7 @@ namespace ScreenCenter {
struct ButtonWatcher {
enum struct State {
WentDown,
DownFor25000ms,
DownFor2500ms,
Unkown
};
@ -26,19 +26,16 @@ namespace ScreenCenter {
State check(GenericButton button) {
const auto controller = Periphery::get_primary_controller_as<Periphery::GenericController>();
if(controller.button.went_down(button)) {
if(!controller.button.was_down(button)) {
this->timer.reset();
if(controller.button.went_down(button)) {
return State::WentDown;
}
}
if(controller.button.was_down(button)) {
if(this->timer.is_expired_for(2500_ms)) {
return State::DownFor25000ms;
}
}
else {
this->timer.reset();
return State::DownFor2500ms;
}
return State::Unkown;
}
@ -96,7 +93,7 @@ namespace ScreenCenter {
static const auto handle_button = [](ButtonWatcher& button_state, GenericButton button, int16_t &dst, const int16_t mlp) {
switch(button_state.check(button)) {
case ButtonWatcher::State::WentDown:
case ButtonWatcher::State::DownFor25000ms:
case ButtonWatcher::State::DownFor2500ms:
dst += (1*mlp);
break;
}