Skip to content

Commit

Permalink
Add game_pad_stick_converter
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Sep 23, 2023
1 parent 0d814d6 commit c2d142e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/grabber/include/grabber/device_grabber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "constants.hpp"
#include "device_grabber_details/entry.hpp"
#include "device_grabber_details/fn_function_keys_manipulator_manager.hpp"
#include "device_grabber_details/game_pad_stick_converter.hpp"
#include "device_grabber_details/simple_modifications_manipulator_manager.hpp"
#include "event_tap_utility.hpp"
#include "filesystem_utility.hpp"
Expand Down Expand Up @@ -51,6 +52,8 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {
notification_message_manager_ = std::make_shared<notification_message_manager>(
constants::get_notification_message_file_path());

game_pad_stick_converter_ = std::make_shared<device_grabber_details::game_pad_stick_converter>();

simple_modifications_manipulator_manager_ = std::make_shared<device_grabber_details::simple_modifications_manipulator_manager>();
complex_modifications_manipulator_manager_ = std::make_shared<manipulator::manipulator_manager>();
fn_function_keys_manipulator_manager_ = std::make_shared<device_grabber_details::fn_function_keys_manipulator_manager>();
Expand Down Expand Up @@ -445,6 +448,8 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {
post_event_to_virtual_devices_manipulator_manager_ = nullptr;
virtual_hid_device_service_client_ = nullptr;

game_pad_stick_converter_ = nullptr;

notification_message_manager_ = nullptr;

hat_switch_converter::get_global_hat_switch_converter()->clear();
Expand Down Expand Up @@ -1111,6 +1116,8 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {

std::shared_ptr<event_queue::queue> merged_input_event_queue_;

std::shared_ptr<device_grabber_details::game_pad_stick_converter> game_pad_stick_converter_;

std::shared_ptr<device_grabber_details::simple_modifications_manipulator_manager> simple_modifications_manipulator_manager_;
std::shared_ptr<event_queue::queue> simple_modifications_applied_event_queue_;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include "types/device_id.hpp"
#include <memory>
#include <unordered_map>
#include <vector>

namespace krbn {
namespace grabber {
namespace device_grabber_details {
//
// game_pad_stick_converter takes value_arrived data as input and outputs poinitng motion.
// This conversion is necessary because it is difficult to use game pad sticks as natural pointing devices due to the following characteristics.
//
// - The game pad's stick only sends events when the value changes.
// We want the pointer to move while the stick is tilted, even if the value does not change.
// So we need to send events periodically with a timer.
// - The game pad's stick may send events slightly in the opposite direction when it is released and returns to neutral.
// This event should be properly ignored.
// - The game pad's stick may have a value in the neutral state. The deadzone must be properly set and ignored neutral values.
//
class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatcher_client {
public:
game_pad_stick_converter(void)
: dispatcher_client(),
timer_(*this) {
}

~game_pad_stick_converter(void) {
detach_from_dispatcher([this] {
timer_.stop();
});
}

void convert(std::shared_ptr<event_queue::queue> event_queue) {
}

private:
pqrs::dispatcher::extra::timer timer_;
};
} // namespace device_grabber_details
} // namespace grabber
} // namespace krbn

0 comments on commit c2d142e

Please sign in to comment.