Skip to content

Commit

Permalink
Add game_pad_stick_release_detection_threshold_milliseconds_,game_pad…
Browse files Browse the repository at this point in the history
…_stick_stroke_acceleration_measurement_duration_milliseconds_
  • Loading branch information
tekezo committed Oct 19, 2023
1 parent ebd300f commit 8ccd7d3
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/share/core_configuration/details/profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,52 @@ class profile final {
}
}

int get_device_game_pad_stick_release_detection_threshold_milliseconds(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
if (auto value = d.get_game_pad_stick_release_detection_threshold_milliseconds()) {
return *value;
}
}
}
return device::game_pad_stick_release_detection_threshold_milliseconds_default_value;
}

void set_device_game_pad_stick_release_detection_threshold_milliseconds(const device_identifiers& identifiers,
std::optional<int> value) {
add_device(identifiers);

for (auto&& device : devices_) {
if (device.get_identifiers() == identifiers) {
device.set_game_pad_stick_release_detection_threshold_milliseconds(value);
return;
}
}
}

int get_device_game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
if (auto value = d.get_game_pad_stick_stroke_acceleration_measurement_duration_milliseconds()) {
return *value;
}
}
}
return device::game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_default_value;
}

void set_device_game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_(const device_identifiers& identifiers,
std::optional<int> value) {
add_device(identifiers);

for (auto&& device : devices_) {
if (device.get_identifiers() == identifiers) {
device.set_game_pad_stick_stroke_acceleration_measurement_duration_milliseconds(value);
return;
}
}
}

double get_device_game_pad_xy_stick_deadzone(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
Expand Down
39 changes: 39 additions & 0 deletions src/share/core_configuration/details/profile/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace core_configuration {
namespace details {
class device final {
public:
static constexpr int game_pad_stick_release_detection_threshold_milliseconds_default_value = 100;
static constexpr int game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_default_value = 50;

static constexpr double game_pad_xy_stick_deadzone_default_value = 0.1;
static constexpr double game_pad_wheels_stick_deadzone_default_value = 0.1;

Expand Down Expand Up @@ -137,6 +140,16 @@ class device final {

game_pad_swap_sticks_ = value.get<bool>();

} else if (key == "game_pad_stick_release_detection_threshold_milliseconds") {
pqrs::json::requires_number(value, "`" + key + "`");

game_pad_stick_release_detection_threshold_milliseconds_ = value.get<int>();

} else if (key == "game_pad_stick_stroke_acceleration_measurement_duration_milliseconds") {
pqrs::json::requires_number(value, "`" + key + "`");

game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_ = value.get<int>();

} else if (key == "game_pad_xy_stick_deadzone") {
pqrs::json::requires_number(value, "`" + key + "`");

Expand Down Expand Up @@ -239,6 +252,12 @@ class device final {
j["mouse_swap_xy"] = mouse_swap_xy_;
j["mouse_swap_wheels"] = mouse_swap_wheels_;
j["game_pad_swap_sticks"] = game_pad_swap_sticks_;
if (game_pad_stick_release_detection_threshold_milliseconds_ != std::nullopt) {
j["game_pad_stick_release_detection_threshold_milliseconds"] = *game_pad_stick_release_detection_threshold_milliseconds_;
}
if (game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_ != std::nullopt) {
j["game_pad_stick_stroke_acceleration_measurement_duration_milliseconds"] = *game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_;
}
if (game_pad_xy_stick_deadzone_ != std::nullopt) {
j["game_pad_xy_stick_deadzone"] = *game_pad_xy_stick_deadzone_;
}
Expand Down Expand Up @@ -371,6 +390,24 @@ class device final {
coordinate_between_properties();
}

std::optional<int> get_game_pad_stick_release_detection_threshold_milliseconds(void) const {
return game_pad_stick_release_detection_threshold_milliseconds_;
}
void set_game_pad_stick_release_detection_threshold_milliseconds(std::optional<int> value) {
game_pad_stick_release_detection_threshold_milliseconds_ = value;

coordinate_between_properties();
}

std::optional<int> get_game_pad_stick_stroke_acceleration_measurement_duration_milliseconds(void) const {
return game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_;
}
void set_game_pad_stick_stroke_acceleration_measurement_duration_milliseconds(std::optional<int> value) {
game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_ = value;

coordinate_between_properties();
}

std::optional<double> get_game_pad_xy_stick_deadzone(void) const {
return game_pad_xy_stick_deadzone_;
}
Expand Down Expand Up @@ -525,6 +562,8 @@ class device final {
bool mouse_swap_xy_;
bool mouse_swap_wheels_;
bool game_pad_swap_sticks_;
std::optional<int> game_pad_stick_release_detection_threshold_milliseconds_;
std::optional<int> game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_;
std::optional<double> game_pad_xy_stick_deadzone_;
std::optional<double> game_pad_wheels_stick_deadzone_;
std::optional<std::string> game_pad_xy_stick_interval_milliseconds_formula_;
Expand Down
4 changes: 4 additions & 0 deletions tests/src/core_configuration/src/device_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ void run_device_test(void) {
{"mouse_flip_x", true},
{"mouse_swap_wheels", true},
{"game_pad_swap_sticks", true},
{"game_pad_stick_release_detection_threshold_milliseconds", 200},
{"game_pad_stick_stroke_acceleration_measurement_duration_milliseconds", 100},
{"game_pad_xy_stick_deadzone", 0.08},
{"game_pad_wheels_stick_deadzone", 0.08},
{"game_pad_xy_stick_interval_milliseconds_formula", "20"},
Expand Down Expand Up @@ -396,6 +398,8 @@ void run_device_test(void) {
}},
{"ignore", true},
{"game_pad_swap_sticks", true},
{"game_pad_stick_release_detection_threshold_milliseconds", 200},
{"game_pad_stick_stroke_acceleration_measurement_duration_milliseconds", 100},
{"game_pad_xy_stick_deadzone", 0.08},
{"game_pad_wheels_stick_deadzone", 0.08},
{"game_pad_xy_stick_interval_milliseconds_formula", "20"},
Expand Down

0 comments on commit 8ccd7d3

Please sign in to comment.