Skip to content

Commit 8863e5e

Browse files
HilariousCowslouken
authored andcommitted
Made the maximum noise during accelerometer noise profiling a define, in terms of "G"
Also removed a // comment which was causing the build to error.
1 parent 6bfc545 commit 8863e5e

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

test/gamepadutils.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,8 +1786,7 @@ void RenderGyroDriftCalibrationButton(GyroDisplay *ctx, GamepadDisplay *gamepad_
17861786
SetGamepadButtonArea(start_calibration_button, &recalibrate_button_area);
17871787
RenderGamepadButton(start_calibration_button);
17881788

1789-
const float flAbsoluteMaxAccelerationG = 0.125f;
1790-
bool bExtremeNoise = ctx->accelerometer_noise_sq > (flAbsoluteMaxAccelerationG * flAbsoluteMaxAccelerationG);
1789+
bool bExtremeNoise = ctx->accelerometer_noise_sq > ACCELEROMETER_MAX_NOISE_G_SQ;
17911790
/* Explicit warning message if we detect too much movement */
17921791
if (ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_OFF) {
17931792

@@ -1803,10 +1802,9 @@ void RenderGyroDriftCalibrationButton(GyroDisplay *ctx, GamepadDisplay *gamepad_
18031802
if (ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_NOISE_PROFILING
18041803
|| ctx->current_calibration_phase == GYRO_CALIBRATION_PHASE_DRIFT_PROFILING)
18051804
{
1806-
float flAbsoluteNoiseFraction = SDL_clamp(ctx->accelerometer_noise_sq / (flAbsoluteMaxAccelerationG * flAbsoluteMaxAccelerationG), 0.0f, 1.0f);
1807-
float flAbsoluteToleranceFraction = SDL_clamp(ctx->accelerometer_noise_tolerance_sq / (flAbsoluteMaxAccelerationG * flAbsoluteMaxAccelerationG), 0.0f, 1.0f);
1805+
float flAbsoluteNoiseFraction = SDL_clamp(ctx->accelerometer_noise_sq / ACCELEROMETER_MAX_NOISE_G_SQ, 0.0f, 1.0f);
1806+
float flAbsoluteToleranceFraction = SDL_clamp(ctx->accelerometer_noise_tolerance_sq / ACCELEROMETER_MAX_NOISE_G_SQ, 0.0f, 1.0f);
18081807
float flRelativeNoiseFraction = SDL_clamp(ctx->accelerometer_noise_sq / ctx->accelerometer_noise_tolerance_sq, 0.0f, 1.0f);
1809-
bool bTooMuchNoise = (flAbsoluteNoiseFraction == 1.0f);
18101808

18111809
float noise_bar_height = gamepad_display->button_height;
18121810
SDL_FRect noise_bar_rect;
@@ -1815,12 +1813,10 @@ void RenderGyroDriftCalibrationButton(GyroDisplay *ctx, GamepadDisplay *gamepad_
18151813
noise_bar_rect.w = recalibrate_button_area.w;
18161814
noise_bar_rect.h = noise_bar_height;
18171815

1818-
//SDL_strlcpy(label_text, "Place GamePad On Table", sizeof(label_text));
18191816
SDL_snprintf(label_text, sizeof(label_text), "Noise Tolerance: %3.3fG ", SDL_sqrtf(ctx->accelerometer_noise_tolerance_sq) );
18201817
SDLTest_DrawString(ctx->renderer, recalibrate_button_area.x, recalibrate_button_area.y + recalibrate_button_area.h + new_line_height * 2, label_text);
18211818

18221819
/* Adjust the noise bar rectangle based on the accelerometer noise value */
1823-
18241820
float noise_bar_fill_width = flAbsoluteNoiseFraction * noise_bar_rect.w; /* Scale the width based on the noise value */
18251821
SDL_FRect noise_bar_fill_rect;
18261822
noise_bar_fill_rect.x = noise_bar_rect.x + (noise_bar_rect.w - noise_bar_fill_width) * 0.5f;
@@ -1848,6 +1844,7 @@ void RenderGyroDriftCalibrationButton(GyroDisplay *ctx, GamepadDisplay *gamepad_
18481844
SDL_RenderRect(ctx->renderer, &noise_bar_rect); /* draw the outline rectangle */
18491845

18501846
/* Explicit warning message if we detect too much movement */
1847+
bool bTooMuchNoise = (flAbsoluteNoiseFraction == 1.0f);
18511848
if (bTooMuchNoise) {
18521849
SDL_strlcpy(label_text, "Place GamePad Down!", sizeof(label_text));
18531850
SDLTest_DrawString(ctx->renderer, recalibrate_button_area.x, noise_bar_rect.y + noise_bar_rect.h + new_line_height, label_text);

test/gamepadutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ extern void DestroyGamepadButton(GamepadButton *ctx);
145145

146146
/* This is used as the initial noise tolernace threshold. It's set very close to zero to avoid divide by zero while we're evaluating the noise profile. Each controller may have a very different noise profile.*/
147147
#define ACCELEROMETER_NOISE_THRESHOLD 1e-6f
148-
148+
#define ACCELEROMETER_MAX_NOISE_G_SQ ( 0.125f * 0.125f )
149149
/* Gyro Calibration Phases */
150150
typedef enum
151151
{

0 commit comments

Comments
 (0)