Stick Calibration Examples
These examples use the exported GPC3 math and I/O functions directly.
Simple Deadzone
gpc
function fix32 deadzone_axis(fix32 value, fix32 zone) {
if (abs(value) < zone) {
return 0.0;
}
return value;
}
main {
set_val(STICK_1_X, deadzone_axis(get_val(STICK_1_X), 8.0));
set_val(STICK_1_Y, deadzone_axis(get_val(STICK_1_Y), 8.0));
set_val(STICK_2_X, deadzone_axis(get_val(STICK_2_X), 8.0));
set_val(STICK_2_Y, deadzone_axis(get_val(STICK_2_Y), 8.0));
}Sensitivity Boost
gpc
fix32 stick_scale = 1.20;
main {
fix32 x = get_val(STICK_1_X) * stick_scale;
fix32 y = get_val(STICK_1_Y) * stick_scale;
set_val(STICK_1_X, clamp(x, -100.0, 100.0));
set_val(STICK_1_Y, clamp(y, -100.0, 100.0));
}Precision Mode
gpc
fix32 normal_scale = 1.00;
fix32 precision_scale = 0.70;
main {
fix32 scale = normal_scale;
if (get_val(BUTTON_9) > 50) {
scale = precision_scale;
}
set_val(STICK_1_X, clamp(get_val(STICK_1_X) * scale, -100.0, 100.0));
set_val(STICK_1_Y, clamp(get_val(STICK_1_Y) * scale, -100.0, 100.0));
}Invert Y Axis
gpc
main {
set_val(STICK_1_Y, get_val(STICK_1_Y) * -1.0);
}Response Curve
Higher curve values make small movements softer and large movements stronger.
gpc
function fix32 curve_axis(fix32 value, fix32 curve) {
fix32 sign = 1.0;
if (value < 0.0) {
sign = -1.0;
}
fix32 normalized = abs(value) / 100.0;
return clamp(pow(normalized, curve) * 100.0 * sign, -100.0, 100.0);
}
main {
set_val(STICK_1_X, curve_axis(get_val(STICK_1_X), 1.40));
set_val(STICK_1_Y, curve_axis(get_val(STICK_1_Y), 1.40));
}Stick Swap
gpc
main {
fix32 right_x = get_val(STICK_1_X);
fix32 right_y = get_val(STICK_1_Y);
fix32 left_x = get_val(STICK_2_X);
fix32 left_y = get_val(STICK_2_Y);
set_val(STICK_1_X, left_x);
set_val(STICK_1_Y, left_y);
set_val(STICK_2_X, right_x);
set_val(STICK_2_Y, right_y);
}Drift Compensation
gpc
fix32 drift_x = 3.0;
fix32 drift_y = -2.0;
main {
fix32 x = get_val(STICK_1_X) - drift_x;
fix32 y = get_val(STICK_1_Y) - drift_y;
set_val(STICK_1_X, clamp(x, -100.0, 100.0));
set_val(STICK_1_Y, clamp(y, -100.0, 100.0));
}Smoothing
gpc
fix32 smooth_x = 0.0;
fix32 smooth_y = 0.0;
fix32 amount = 0.25;
main {
smooth_x = lerp(smooth_x, get_val(STICK_1_X), amount);
smooth_y = lerp(smooth_y, get_val(STICK_1_Y), amount);
set_val(STICK_1_X, smooth_x);
set_val(STICK_1_Y, smooth_y);
}Notes
- Start with small changes and verify them in Device Monitor.
- Clamp scaled stick output to
-100through100. - Put tuning values at the top of the file so users can adjust them safely.