Use pulses instead of frame based movement
This commit is contained in:
parent
2b371dc473
commit
5f0e8a9212
|
@ -10,32 +10,43 @@ namespace ScreenCenter {
|
||||||
using namespace JabyEngine;
|
using namespace JabyEngine;
|
||||||
using GenericButton = Periphery::GenericController::Button;
|
using GenericButton = Periphery::GenericController::Button;
|
||||||
|
|
||||||
struct ButtonWatcher {
|
struct ButtonPulser {
|
||||||
|
static constexpr auto StartTime = 2500_ms;
|
||||||
|
static constexpr auto PulseTime = 100_ms;
|
||||||
|
|
||||||
enum struct State {
|
enum struct State {
|
||||||
WentDown,
|
WentDown,
|
||||||
DownFor2500ms,
|
Pulse,
|
||||||
Unkown
|
Unkown
|
||||||
};
|
};
|
||||||
|
|
||||||
SimpleTimer<uint16_t> timer;
|
SimpleTimer<uint8_t> timer;
|
||||||
|
uint8_t pulse_time;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
this->timer.reset();
|
this->timer.reset();
|
||||||
|
this->pulse_time = StartTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
ButtonPulser::setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
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.was_down(button)) {
|
if(!controller.button.was_down(button)) {
|
||||||
this->timer.reset();
|
ButtonPulser::reset();
|
||||||
|
|
||||||
if(controller.button.went_down(button)) {
|
if(controller.button.went_down(button)) {
|
||||||
return State::WentDown;
|
return State::WentDown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this->timer.is_expired_for(2500_ms)) {
|
if(this->timer.is_expired_for(this->pulse_time)) {
|
||||||
return State::DownFor2500ms;
|
this->pulse_time = PulseTime;
|
||||||
|
this->timer.reset();
|
||||||
|
|
||||||
|
return State::Pulse;
|
||||||
}
|
}
|
||||||
return State::Unkown;
|
return State::Unkown;
|
||||||
}
|
}
|
||||||
|
@ -49,8 +60,9 @@ namespace ScreenCenter {
|
||||||
static constexpr uint16_t ScanlinesV = 240;
|
static constexpr uint16_t ScanlinesV = 240;
|
||||||
#endif //JABYENGINE_PAL
|
#endif //JABYENGINE_PAL
|
||||||
|
|
||||||
static const auto frame = Frame::create();
|
static const auto frame = Frame::create();
|
||||||
static ButtonWatcher button_watcher[4];
|
|
||||||
|
static ButtonPulser button_pulse[4];
|
||||||
static void (*update)() = nullptr;
|
static void (*update)() = nullptr;
|
||||||
static int16_t offset_x = 0;
|
static int16_t offset_x = 0;
|
||||||
static int16_t offset_y = 0;
|
static int16_t offset_y = 0;
|
||||||
|
@ -90,10 +102,10 @@ namespace ScreenCenter {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_interactive() {
|
static void update_interactive() {
|
||||||
static const auto handle_button = [](ButtonWatcher& button_state, GenericButton button, int16_t &dst, const int16_t mlp) {
|
static const auto handle_button = [](ButtonPulser& button_pulse, GenericButton button, int16_t &dst, const int16_t mlp) {
|
||||||
switch(button_state.check(button)) {
|
switch(button_pulse.check(button)) {
|
||||||
case ButtonWatcher::State::WentDown:
|
case ButtonPulser::State::WentDown:
|
||||||
case ButtonWatcher::State::DownFor2500ms:
|
case ButtonPulser::State::Pulse:
|
||||||
dst += (1*mlp);
|
dst += (1*mlp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -108,10 +120,10 @@ namespace ScreenCenter {
|
||||||
|
|
||||||
const auto controller = Periphery::get_primary_controller_as<Periphery::GenericController>();
|
const auto controller = Periphery::get_primary_controller_as<Periphery::GenericController>();
|
||||||
|
|
||||||
handle_button(button_watcher[0], GenericButton::Left, offset_x, -1);
|
handle_button(button_pulse[0], GenericButton::Left, offset_x, -1);
|
||||||
handle_button(button_watcher[1], GenericButton::Right, offset_x, 1);
|
handle_button(button_pulse[1], GenericButton::Right, offset_x, 1);
|
||||||
handle_button(button_watcher[2], GenericButton::Up, offset_y, -1);
|
handle_button(button_pulse[2], GenericButton::Up, offset_y, -1);
|
||||||
handle_button(button_watcher[3], GenericButton::Down, offset_y, 1);
|
handle_button(button_pulse[3], GenericButton::Down, offset_y, 1);
|
||||||
|
|
||||||
auto cursor = FontWriter::update(CenterPoint);
|
auto cursor = FontWriter::update(CenterPoint);
|
||||||
FontWriter::bios_font_writer.write(cursor, ModeStr, TVModeStr);
|
FontWriter::bios_font_writer.write(cursor, ModeStr, TVModeStr);
|
||||||
|
@ -124,8 +136,8 @@ namespace ScreenCenter {
|
||||||
static void setup() {
|
static void setup() {
|
||||||
Shared::back_menu.reset();
|
Shared::back_menu.reset();
|
||||||
|
|
||||||
for(auto& button : button_watcher) {
|
for(auto& pulse : button_pulse) {
|
||||||
button.setup();
|
pulse.setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
update = update_enter_state;
|
update = update_enter_state;
|
||||||
|
|
Loading…
Reference in New Issue