Skip to content

Commit

Permalink
Update game_pad_stick_converter.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Oct 2, 2023
1 parent 1dced9b commit b384ecb
Showing 1 changed file with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
active_ = value;
}

int integer_value(void) const {
int xy_value(void) const {
// The logical value range of Karabiner-DriverKit-VirtualHIDPointing is -127 ... 127.
auto divider = 50.0;
auto result = static_cast<int>(stick_value_ / divider);
Expand All @@ -91,14 +91,36 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
return result;
}

std::chrono::milliseconds interval(void) const {
int wheel_value(void) const {
// The logical value range of Karabiner-DriverKit-VirtualHIDPointing is -127 ... 127.
int result = std::signbit(stick_value_) ? -1 : 1;
return result;
}

std::chrono::milliseconds xy_interval(void) const {
if (std::abs(stick_value_) == 0.0) {
return std::chrono::milliseconds(0);
}

return std::chrono::milliseconds(20);
}

std::chrono::milliseconds wheel_interval(void) const {
if (std::abs(stick_value_) == 0.0) {
return std::chrono::milliseconds(0);
}

if (std::abs(stick_value_) > 500.0) {
return std::chrono::milliseconds(50);
}

if (std::abs(stick_value_) > 250.0) {
return std::chrono::milliseconds(75);
}

return std::chrono::milliseconds(100);
}

void add_event(CFIndex logical_max,
CFIndex logical_min,
CFIndex integer_value) {
Expand Down Expand Up @@ -380,15 +402,15 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
void emit_x_event(const device_id device_id,
event_origin event_origin) {
auto get_interval = [](const state& s) {
return s.x.interval();
return s.x.xy_interval();
};

auto unset_active = [](state& s) {
s.x.set_active(false);
};

auto make_pointing_motion = [](const state& s) {
return pointing_motion(s.x.integer_value(),
return pointing_motion(s.x.xy_value(),
0,
0,
0);
Expand All @@ -404,7 +426,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
void emit_y_event(const device_id device_id,
event_origin event_origin) {
auto get_interval = [](const state& s) {
return s.y.interval();
return s.y.xy_interval();
};

auto unset_active = [](state& s) {
Expand All @@ -413,7 +435,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche

auto make_pointing_motion = [](const state& s) {
return pointing_motion(0,
s.y.integer_value(),
s.y.xy_value(),
0,
0);
};
Expand All @@ -428,7 +450,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
void emit_vertical_wheel_event(const device_id device_id,
event_origin event_origin) {
auto get_interval = [](const state& s) {
return s.vertical_wheel.interval();
return s.vertical_wheel.wheel_interval();
};

auto unset_active = [](state& s) {
Expand All @@ -438,7 +460,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
auto make_pointing_motion = [](const state& s) {
return pointing_motion(0,
0,
-s.vertical_wheel.integer_value(),
-s.vertical_wheel.wheel_value(),
0);
};

Expand All @@ -452,7 +474,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
void emit_horizontal_wheel_event(const device_id device_id,
event_origin event_origin) {
auto get_interval = [](const state& s) {
return s.horizontal_wheel.interval();
return s.horizontal_wheel.wheel_interval();
};

auto unset_active = [](state& s) {
Expand All @@ -463,7 +485,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
return pointing_motion(0,
0,
0,
s.horizontal_wheel.integer_value());
s.horizontal_wheel.wheel_value());
};

emit_event(device_id,
Expand Down

0 comments on commit b384ecb

Please sign in to comment.