Code improvement
This commit is contained in:
parent
459dad9ed5
commit
548b808056
|
@ -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();
|
||||
return State::WentDown;
|
||||
}
|
||||
|
||||
if(controller.button.was_down(button)) {
|
||||
if(this->timer.is_expired_for(2500_ms)) {
|
||||
return State::DownFor25000ms;
|
||||
if(controller.button.went_down(button)) {
|
||||
return State::WentDown;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
this->timer.reset();
|
||||
if(this->timer.is_expired_for(2500_ms)) {
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue