mirror of
https://github.com/Lorenzooone/cc3dsfs.git
synced 2026-04-25 07:27:53 -05:00
Fix possible issue with enter vs. extra enter
This commit is contained in:
parent
9de1e687ae
commit
ea3ae3a56c
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
class ExtraButton {
|
||||
public:
|
||||
void initialize(int pi_value, int id, sf::Keyboard::Key corresponding_key, bool is_power, float first_re_press_time, float later_re_press_time);
|
||||
void initialize(int pi_value, int id, sf::Keyboard::Key corresponding_key, bool is_power, float first_re_press_time, float later_re_press_time, bool use_pud_up);
|
||||
int get_pi_value();
|
||||
void poll(std::queue<SFEvent> &events_queue);
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -99,7 +99,9 @@ private:
|
|||
HeldTime touch_right_click_action;
|
||||
HeldTime touch_action;
|
||||
HeldTime pgdown_action;
|
||||
HeldTime extra_pgdown_action;
|
||||
HeldTime enter_action;
|
||||
HeldTime extra_enter_action;
|
||||
HeldTime right_click_action;
|
||||
HeldTime controller_button_action;
|
||||
bool consumed_touch_long_press;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ struct out_rect_data {
|
|||
};
|
||||
|
||||
struct SFEvent {
|
||||
SFEvent(sf::Event::EventType type, sf::Keyboard::Key code, uint32_t unicode, uint32_t joystickId, uint32_t joy_button, sf::Joystick::Axis axis, float position, sf::Mouse::Button mouse_button, int mouse_x, int mouse_y, bool poweroff_cmd) : type(type), code(code), unicode(unicode), joystickId(joystickId), joy_button(joy_button), axis(axis), position(position), mouse_button(mouse_button), mouse_x(mouse_x), mouse_y(mouse_y), poweroff_cmd(poweroff_cmd) {}
|
||||
SFEvent(sf::Event::EventType type, sf::Keyboard::Key code, uint32_t unicode, uint32_t joystickId, uint32_t joy_button, sf::Joystick::Axis axis, float position, sf::Mouse::Button mouse_button, int mouse_x, int mouse_y, bool poweroff_cmd, bool is_extra) : type(type), code(code), unicode(unicode), joystickId(joystickId), joy_button(joy_button), axis(axis), position(position), mouse_button(mouse_button), mouse_x(mouse_x), mouse_y(mouse_y), poweroff_cmd(poweroff_cmd), is_extra(is_extra) {}
|
||||
|
||||
sf::Event::EventType type;
|
||||
sf::Keyboard::Key code;
|
||||
|
|
@ -26,12 +26,13 @@ struct SFEvent {
|
|||
int mouse_x;
|
||||
int mouse_y;
|
||||
bool poweroff_cmd;
|
||||
bool is_extra;
|
||||
};
|
||||
|
||||
void joystick_axis_poll(std::queue<SFEvent> &events_queue);
|
||||
JoystickDirection get_joystick_direction(uint32_t joystickId, sf::Joystick::Axis axis, float position);
|
||||
JoystickAction get_joystick_action(uint32_t joystickId, uint32_t joy_button);
|
||||
void init_extra_buttons_poll(int page_up_id, int page_down_id, int enter_id, int power_id);
|
||||
void init_extra_buttons_poll(int page_up_id, int page_down_id, int enter_id, int power_id, bool use_pud_up);
|
||||
void end_extra_buttons_poll();
|
||||
void extra_buttons_poll(std::queue<SFEvent> &events_queue);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
static ExtraButton pi_page_up, pi_page_down, pi_enter, pi_power;
|
||||
|
||||
void ExtraButton::initialize(int pi_value, int id, sf::Keyboard::Key corresponding_key, bool is_power, float first_re_press_time, float later_re_press_time) {
|
||||
void ExtraButton::initialize(int pi_value, int id, sf::Keyboard::Key corresponding_key, bool is_power, float first_re_press_time, float later_re_press_time, bool use_pud_up) {
|
||||
this->pi_value = pi_value;
|
||||
this->id = id;
|
||||
this->is_power = is_power;
|
||||
|
|
@ -18,7 +18,10 @@ void ExtraButton::initialize(int pi_value, int id, sf::Keyboard::Key correspondi
|
|||
this->later_re_press_time = later_re_press_time;
|
||||
#ifdef RASPI
|
||||
set_mode(this->pi_value, this->id, PI_INPUT);
|
||||
set_pull_up_down(this->pi_value, this->id, PI_PUD_UP);
|
||||
if(use_pud_up)
|
||||
set_pull_up_down(this->pi_value, this->id, PI_PUD_UP);
|
||||
else
|
||||
set_pull_up_down(this->pi_value, this->id, PI_PUD_DOWN);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -67,18 +70,18 @@ void ExtraButton::poll(std::queue<SFEvent> &events_queue) {
|
|||
}
|
||||
else
|
||||
this->started = false;
|
||||
events_queue.emplace(event_kind, this->corresponding_key, 0, 0, 0, sf::Joystick::Axis::X, 0, sf::Mouse::Left, 0, 0, this->is_power);
|
||||
events_queue.emplace(event_kind, this->corresponding_key, 0, 0, 0, sf::Joystick::Axis::X, 0, sf::Mouse::Left, 0, 0, this->is_power, true);
|
||||
}
|
||||
|
||||
void init_extra_buttons_poll(int page_up_id, int page_down_id, int enter_id, int power_id) {
|
||||
void init_extra_buttons_poll(int page_up_id, int page_down_id, int enter_id, int power_id, bool use_pud_up) {
|
||||
int pi_value = -1;
|
||||
#ifdef RASPI
|
||||
pi_value = pigpio_start(NULL, NULL);
|
||||
#endif
|
||||
pi_page_up.initialize(pi_value, page_up_id, sf::Keyboard::PageUp, false, 0.5, 0.03);
|
||||
pi_page_down.initialize(pi_value, page_down_id, sf::Keyboard::PageDown, false, 0.5, 0.03);
|
||||
pi_enter.initialize(pi_value, enter_id, sf::Keyboard::Enter, false, 0.5, 0.075);
|
||||
pi_power.initialize(pi_value, power_id, sf::Keyboard::Escape, true, 30.0, 30.0);
|
||||
pi_page_up.initialize(pi_value, page_up_id, sf::Keyboard::PageUp, false, 0.5, 0.03, use_pud_up);
|
||||
pi_page_down.initialize(pi_value, page_down_id, sf::Keyboard::PageDown, false, 0.5, 0.03, use_pud_up);
|
||||
pi_enter.initialize(pi_value, enter_id, sf::Keyboard::Enter, false, 0.5, 0.075, use_pud_up);
|
||||
pi_power.initialize(pi_value, power_id, sf::Keyboard::Escape, true, 30.0, 30.0, use_pud_up);
|
||||
}
|
||||
|
||||
void end_extra_buttons_poll() {
|
||||
|
|
|
|||
|
|
@ -329,11 +329,17 @@ bool WindowScreen::common_poll(SFEvent &event_data) {
|
|||
this->set_close(0);
|
||||
break;
|
||||
case sf::Keyboard::Enter:
|
||||
check_held_reset_key(true, this->enter_action);
|
||||
if(event_data.is_extra)
|
||||
check_held_reset(true, this->extra_enter_action);
|
||||
else
|
||||
check_held_reset_key(true, this->enter_action);
|
||||
consumed = false;
|
||||
break;
|
||||
case sf::Keyboard::PageDown:
|
||||
check_held_reset_key(true, this->pgdown_action);
|
||||
if(event_data.is_extra)
|
||||
check_held_reset(true, this->extra_pgdown_action);
|
||||
else
|
||||
check_held_reset_key(true, this->pgdown_action);
|
||||
consumed = false;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -344,11 +350,17 @@ bool WindowScreen::common_poll(SFEvent &event_data) {
|
|||
case sf::Event::KeyReleased:
|
||||
switch(event_data.code) {
|
||||
case sf::Keyboard::Enter:
|
||||
check_held_reset_key(false, this->enter_action);
|
||||
if(event_data.is_extra)
|
||||
check_held_reset(false, this->extra_enter_action);
|
||||
else
|
||||
check_held_reset_key(false, this->enter_action);
|
||||
consumed = false;
|
||||
break;
|
||||
case sf::Keyboard::PageDown:
|
||||
check_held_reset_key(false, this->pgdown_action);
|
||||
if(event_data.is_extra)
|
||||
check_held_reset(false, this->extra_pgdown_action);
|
||||
else
|
||||
check_held_reset_key(false, this->pgdown_action);
|
||||
consumed = false;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -1394,6 +1406,10 @@ bool WindowScreen::query_reset_request() {
|
|||
return true;
|
||||
if(check_held_diff(curr_time, this->pgdown_action) > this->bad_resolution_timeout)
|
||||
return true;
|
||||
if(check_held_diff(curr_time, this->extra_enter_action) > this->bad_resolution_timeout)
|
||||
return true;
|
||||
if(check_held_diff(curr_time, this->extra_pgdown_action) > this->bad_resolution_timeout)
|
||||
return true;
|
||||
if(check_held_diff(curr_time, this->controller_button_action) > this->bad_resolution_timeout)
|
||||
return true;
|
||||
if(check_held_diff(curr_time, this->touch_action) > this->bad_resolution_timeout)
|
||||
|
|
@ -1405,6 +1421,8 @@ void WindowScreen::reset_held_times() {
|
|||
check_held_reset(false, this->right_click_action);
|
||||
check_held_reset(false, this->enter_action);
|
||||
check_held_reset(false, this->pgdown_action);
|
||||
check_held_reset(false, this->extra_enter_action);
|
||||
check_held_reset(false, this->extra_pgdown_action);
|
||||
check_held_reset(false, this->controller_button_action);
|
||||
check_held_reset(false, this->touch_action);
|
||||
}
|
||||
|
|
@ -1429,7 +1447,7 @@ void WindowScreen::poll_window() {
|
|||
mouse_x = event.mouseMove.x;
|
||||
mouse_y = event.mouseMove.y;
|
||||
}
|
||||
events_queue.emplace(event.type, event.key.code, event.text.unicode, joystickId, event.joystickButton.button, event.joystickMove.axis, 0.0, event.mouseButton.button, mouse_x, mouse_y, false);
|
||||
events_queue.emplace(event.type, event.key.code, event.text.unicode, joystickId, event.joystickButton.button, event.joystickMove.axis, 0.0, event.mouseButton.button, mouse_x, mouse_y, false, false);
|
||||
}
|
||||
if(this->m_win.hasFocus()) {
|
||||
check_held_reset(sf::Mouse::isButtonPressed(sf::Mouse::Right), this->right_click_action);
|
||||
|
|
@ -1453,10 +1471,10 @@ void WindowScreen::poll_window() {
|
|||
auto curr_time = std::chrono::high_resolution_clock::now();
|
||||
const std::chrono::duration<double> diff = curr_time - this->touch_right_click_action.start_time;
|
||||
if(diff.count() > this->touch_long_press_timer) {
|
||||
events_queue.emplace(sf::Event::MouseButtonPressed, sf::Keyboard::Backspace, 0, 0, 0, sf::Joystick::Axis::X, 0.0, sf::Mouse::Right, touch_pos.x, touch_pos.y, false);
|
||||
events_queue.emplace(sf::Event::MouseButtonPressed, sf::Keyboard::Backspace, 0, 0, 0, sf::Joystick::Axis::X, 0.0, sf::Mouse::Right, touch_pos.x, touch_pos.y, false, false);
|
||||
this->touch_right_click_action.start_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
events_queue.emplace(sf::Event::MouseButtonPressed, sf::Keyboard::Backspace, 0, 0, 0, sf::Joystick::Axis::X, 0.0, sf::Mouse::Left, touch_pos.x, touch_pos.y, false);
|
||||
events_queue.emplace(sf::Event::MouseButtonPressed, sf::Keyboard::Backspace, 0, 0, 0, sf::Joystick::Axis::X, 0.0, sf::Mouse::Left, touch_pos.x, touch_pos.y, false, false);
|
||||
}
|
||||
joystick_axis_poll(this->events_queue);
|
||||
extra_buttons_poll(this->events_queue);
|
||||
|
|
|
|||
|
|
@ -423,6 +423,7 @@ int main(int argc, char **argv) {
|
|||
int page_down_id = -1;
|
||||
int enter_id = -1;
|
||||
int power_id = -1;
|
||||
bool use_pud_up = true;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if(parse_existence_arg(i, argv, mono_app, true, "--mono_app"))
|
||||
continue;
|
||||
|
|
@ -435,19 +436,22 @@ int main(int argc, char **argv) {
|
|||
continue;
|
||||
if(parse_int_arg(i, argc, argv, power_id, "--pi_power"))
|
||||
continue;
|
||||
if(parse_existence_arg(i, argv, use_pud_up, false, "--pi_pud_down"))
|
||||
continue;
|
||||
#endif
|
||||
std::cout << "Help:" << std::endl;
|
||||
std::cout << " --mono_app Enables special mode for when only this application" << std::endl;
|
||||
std::cout << " should run on the system. Disabled by default." << std::endl;
|
||||
std::cout << " --mono_app Enables special mode for when only this application" << std::endl;
|
||||
std::cout << " should run on the system. Disabled by default." << std::endl;
|
||||
#ifdef RASPI
|
||||
std::cout << " --pi_select ID Specifies ID for the select GPIO button." << std::endl;
|
||||
std::cout << " --pi_menu ID Specifies ID for the menu GPIO button." << std::endl;
|
||||
std::cout << " --pi_enter ID Specifies ID for the enter GPIO button." << std::endl;
|
||||
std::cout << " --pi_power ID Specifies ID for the poweroff GPIO button." << std::endl;
|
||||
std::cout << " --pi_pud_down Sets the pull-up GPIO mode to down. Default is up." << std::endl;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
init_extra_buttons_poll(page_up_id, page_down_id, enter_id, power_id);
|
||||
init_extra_buttons_poll(page_up_id, page_down_id, enter_id, power_id, use_pud_up);
|
||||
AudioData audio_data;
|
||||
audio_data.reset();
|
||||
CaptureData* capture_data = new CaptureData;
|
||||
|
|
|
|||
|
|
@ -367,7 +367,7 @@ void joystick_axis_poll(std::queue<SFEvent> &events_queue) {
|
|||
for(int j = 0; j < sf::Joystick::AxisCount; j++) {
|
||||
sf::Joystick::Axis axis = sf::Joystick::Axis(sf::Joystick::Axis::X + j);
|
||||
if(sf::Joystick::hasAxis(i, axis))
|
||||
events_queue.emplace(sf::Event::JoystickMoved, sf::Keyboard::Backspace, 0, i, 0, axis, sf::Joystick::getAxisPosition(i, axis), sf::Mouse::Left, 0, 0, false);
|
||||
events_queue.emplace(sf::Event::JoystickMoved, sf::Keyboard::Backspace, 0, i, 0, axis, sf::Joystick::getAxisPosition(i, axis), sf::Mouse::Left, 0, 0, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user