Code improvement
This commit is contained in:
parent
bd1c662315
commit
2b371dc473
|
@ -13,7 +13,7 @@ namespace ScreenCenter {
|
||||||
struct ButtonWatcher {
|
struct ButtonWatcher {
|
||||||
enum struct State {
|
enum struct State {
|
||||||
WentDown,
|
WentDown,
|
||||||
DownFor25000ms,
|
DownFor2500ms,
|
||||||
Unkown
|
Unkown
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,19 +26,16 @@ namespace ScreenCenter {
|
||||||
State check(GenericButton button) {
|
State check(GenericButton button) {
|
||||||
const auto controller = Periphery::get_primary_controller_as<Periphery::GenericController>();
|
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();
|
this->timer.reset();
|
||||||
return State::WentDown;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(controller.button.was_down(button)) {
|
if(controller.button.went_down(button)) {
|
||||||
if(this->timer.is_expired_for(2500_ms)) {
|
return State::WentDown;
|
||||||
return State::DownFor25000ms;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
if(this->timer.is_expired_for(2500_ms)) {
|
||||||
this->timer.reset();
|
return State::DownFor2500ms;
|
||||||
}
|
}
|
||||||
return State::Unkown;
|
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) {
|
static const auto handle_button = [](ButtonWatcher& button_state, GenericButton button, int16_t &dst, const int16_t mlp) {
|
||||||
switch(button_state.check(button)) {
|
switch(button_state.check(button)) {
|
||||||
case ButtonWatcher::State::WentDown:
|
case ButtonWatcher::State::WentDown:
|
||||||
case ButtonWatcher::State::DownFor25000ms:
|
case ButtonWatcher::State::DownFor2500ms:
|
||||||
dst += (1*mlp);
|
dst += (1*mlp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue