Skip to content

Commit

Permalink
Introduce runtime normalization of gyroscope
Browse files Browse the repository at this point in the history
Config setting is added just in case - default value is good enough for almost every usecase, regardless of exact calibration's presence.
  • Loading branch information
v1993 committed Jan 27, 2022
1 parent 8b2a59e commit 618bfc0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ExampleConfig.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# GyroNormalizationFactor controls how quickly gyro drift is accounted for
# Default value of 50 should be good in 99%+ of cases, but rarely one may want to tweak it
[Linuxmotehook]
Port=26760
Orientation=sideways-left
SendButtons=false
GyroNormalizationFactor=50

# NunchuckStickCalibration is neutral x, y and minimal max offset from neutral x,y
# Supported orientation values: normal, sideways-left, sideways-right (likely not useful here), inverted
Expand Down
14 changes: 14 additions & 0 deletions src/Config.vala
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,20 @@ namespace Linuxmotehook {
}
}

private int gyro_normalization_factor_ = 50;
public int gyro_normalization_factor {
get { return gyro_normalization_factor_; }
set {
gyro_normalization_factor_ = value;
kfile.set_integer(MAIN_GROUP, "GyroNormalizationFactor", value);
}
}

construct {
kfile = new KeyFile();
kfile.set_list_separator(',');
// Note: this likely creates a circular reference because of lambdas
// Nobody really cares because we're single instance, but still
wiimote_configs = new Gee.HashMap<uint64?, WiimoteConfig>(
(key) => { return (uint)((key >> 32) ^ key); },
(key1, key2) => { return key1 == key2; }
Expand All @@ -103,6 +114,9 @@ namespace Linuxmotehook {
case "SendButtons":
send_buttons_ = kfile.get_boolean(MAIN_GROUP, key);
break;
case "GyroNormalizationFactor":
gyro_normalization_factor_ = kfile.get_integer(MAIN_GROUP, key);
break;
default:
warning("Unknown configuration key %s", key);
break;
Expand Down
3 changes: 2 additions & 1 deletion src/MainDevice.vala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ namespace Linuxmotehook {
dev_source.set_callback(cb);
dev_source.attach();

dev.set_mp_normalization(conf.gyro_calibration[0], conf.gyro_calibration[1], conf.gyro_calibration[2], 0);
var app_conf = new Config();
dev.set_mp_normalization(conf.gyro_calibration[0], conf.gyro_calibration[1], conf.gyro_calibration[2], app_conf.gyro_normalization_factor);
update_interfaces(true);
}

Expand Down

0 comments on commit 618bfc0

Please sign in to comment.