Skip to content

Commit

Permalink
add continued_movement to formula
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Aug 4, 2024
1 parent 6d986d5 commit e164259
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
//

if (continued_movement()) {
delta_magnitude_ = absolute_magnitude_;
delta_magnitude_ = dm;
previous_absolute_magnitude_ = absolute_magnitude_;
} else {
// Ignore minor magnitude changes until a sufficient amount of change accumulates.
Expand Down Expand Up @@ -245,9 +245,11 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
xy_radian_(0.0),
xy_delta_magnitude_(0.0),
xy_absolute_magnitude_(0.0),
xy_continued_movement_(false),
wheels_radian_(0.0),
wheels_delta_magnitude_(0.0),
wheels_absolute_magnitude_(0.0) {
wheels_absolute_magnitude_(0.0),
wheels_continued_movement_(false) {
set_weak_core_configuration(weak_core_configuration);

xy_.values_updated.connect([this](void) {
Expand Down Expand Up @@ -415,6 +417,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
{"radian", xy_radian_},
{"delta_magnitude", xy_delta_magnitude_},
{"absolute_magnitude", xy_absolute_magnitude_},
{"continued_movement", xy_continued_movement_},
});
}

Expand All @@ -425,6 +428,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
{"radian", wheels_radian_},
{"delta_magnitude", wheels_delta_magnitude_},
{"absolute_magnitude", wheels_absolute_magnitude_},
{"continued_movement", wheels_continued_movement_},
});
}

Expand Down Expand Up @@ -466,36 +470,6 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche

void update_continued_movement_timer(continued_movement_mode mode,
std::chrono::milliseconds interval) {
xy_radian_ = xy_.get_radian();
xy_delta_magnitude_ = xy_.get_delta_magnitude();
xy_absolute_magnitude_ = xy_.get_absolute_magnitude();
if (continued_movement_mode_ == continued_movement_mode::xy &&
xy_.continued_movement()) {
// Add secondary stick absolute magnitude to magnitudes;
auto m = wheels_.get_absolute_magnitude();
xy_delta_magnitude_ += m;
xy_absolute_magnitude_ += m;
}

wheels_radian_ = wheels_.get_radian();
wheels_delta_magnitude_ = wheels_.get_delta_magnitude();
wheels_absolute_magnitude_ = wheels_.get_absolute_magnitude();
if (continued_movement_mode_ == continued_movement_mode::wheels &&
wheels_.continued_movement()) {
// Add secondary stick absolute magnitude to magnitudes;
auto m = xy_.get_absolute_magnitude();
wheels_delta_magnitude_ += m;
wheels_absolute_magnitude_ += m;
}

auto [x, y] = xy_hid_values();
x_value_.set_value(x);
y_value_.set_value(y);

auto [h, v] = wheels_hid_values();
horizontal_wheel_value_.set_value(h);
vertical_wheel_value_.set_value(v);

if (interval == std::chrono::milliseconds(0)) {
if (continued_movement_mode_ == continued_movement_mode::none) {
post_event(mode);
Expand Down Expand Up @@ -535,6 +509,38 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
}

void post_event(continued_movement_mode mode) {
xy_radian_ = xy_.get_radian();
xy_delta_magnitude_ = xy_.get_delta_magnitude();
xy_absolute_magnitude_ = xy_.get_absolute_magnitude();
xy_continued_movement_ = (continued_movement_mode_ == continued_movement_mode::xy);
if (continued_movement_mode_ == continued_movement_mode::xy &&
xy_.continued_movement()) {
// Add secondary stick absolute magnitude to magnitudes;
auto m = wheels_.get_absolute_magnitude();
xy_delta_magnitude_ += m;
xy_absolute_magnitude_ += m;
}

wheels_radian_ = wheels_.get_radian();
wheels_delta_magnitude_ = wheels_.get_delta_magnitude();
wheels_absolute_magnitude_ = wheels_.get_absolute_magnitude();
wheels_continued_movement_ = (continued_movement_mode_ == continued_movement_mode::wheels);
if (continued_movement_mode_ == continued_movement_mode::wheels &&
wheels_.continued_movement()) {
// Add secondary stick absolute magnitude to magnitudes;
auto m = xy_.get_absolute_magnitude();
wheels_delta_magnitude_ += m;
wheels_absolute_magnitude_ += m;
}

auto [x, y] = xy_hid_values();
x_value_.set_value(x);
y_value_.set_value(y);

auto [h, v] = wheels_hid_values();
horizontal_wheel_value_.set_value(h);
vertical_wheel_value_.set_value(v);

switch (mode) {
case continued_movement_mode::none:
break;
Expand Down Expand Up @@ -625,9 +631,11 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
double xy_radian_;
double xy_delta_magnitude_;
double xy_absolute_magnitude_;
double xy_continued_movement_;
double wheels_radian_;
double wheels_delta_magnitude_;
double wheels_absolute_magnitude_;
double wheels_continued_movement_;
};
} // namespace device_grabber_details
} // namespace grabber
Expand Down
9 changes: 5 additions & 4 deletions src/share/core_configuration/details/profile/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class device final {
var m:= 0;
if (absolute_magnitude < 1.0) {
if (continued_movement == false) {
m := delta_magnitude * 16;
} else if (absolute_magnitude < 1.5) {
m := absolute_magnitude * 8;
Expand All @@ -128,7 +128,7 @@ cos(radian) * m;
var m:= 0;
if (absolute_magnitude < 1.0) {
if (continued_movement == false) {
m := delta_magnitude * 16;
} else if (absolute_magnitude < 1.5) {
m := absolute_magnitude * 8;
Expand All @@ -150,7 +150,7 @@ sin(radian) * m;
var m := 0;
if (abs(cos(radian)) < abs(sin(radian))) {
if (absolute_magnitude < 1.0) {
if (continued_movement == false) {
m := delta_magnitude;
} else {
m := absolute_magnitude * 0.1;
Expand All @@ -169,7 +169,7 @@ sin(radian) * m;
var m := 0;
if (abs(cos(radian)) > abs(sin(radian))) {
if (absolute_magnitude < 1.0) {
if (continued_movement == false) {
m := delta_magnitude;
} else {
m := absolute_magnitude * 0.1;
Expand Down Expand Up @@ -519,6 +519,7 @@ cos(radian) * m;
{"radian", 0.0},
{"delta_magnitude", 0.1},
{"absolute_magnitude", 0.5},
{"continued_movement", 1.0},
});
return !std::isnan(value);
}
Expand Down

0 comments on commit e164259

Please sign in to comment.