Skip to content

Commit

Permalink
Show gyro calibration progress
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-drexler committed Aug 5, 2024
1 parent c24fe16 commit 51bdbd3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Quake/in_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ static float gyro_yaw = 0.f, gyro_pitch = 0.f, gyro_raw_mag = 0.f;
static float gyro_center_frac = 0.f, gyro_center_amount = 0.f;

// used for gyro calibration
#define GYRO_CALIBRATION_SAMPLES 300
static float gyro_accum[3] = {0.f, 0.f, 0.f};
static unsigned int num_samples = 0;
static unsigned int updates_countdown = 0;

static qboolean gyro_present = false;
Expand Down Expand Up @@ -1391,8 +1391,7 @@ void IN_StartGyroCalibration (void)
gyro_accum[1] = 0.0;
gyro_accum[2] = 0.0;

num_samples = 0;
updates_countdown = 300;
updates_countdown = GYRO_CALIBRATION_SAMPLES;
}

static qboolean IN_UpdateGyroCalibration (const float newsample[3])
Expand All @@ -1403,12 +1402,11 @@ static qboolean IN_UpdateGyroCalibration (const float newsample[3])
gyro_accum[0] += newsample[0];
gyro_accum[1] += newsample[1];
gyro_accum[2] += newsample[2];
num_samples++;

updates_countdown--;
if (!updates_countdown)
{
const float inverseSamples = 1.f / num_samples;
const float inverseSamples = 1.f / GYRO_CALIBRATION_SAMPLES;
Cvar_SetValue("gyro_calibration_x", gyro_accum[0] * inverseSamples);
Cvar_SetValue("gyro_calibration_y", gyro_accum[1] * inverseSamples);
Cvar_SetValue("gyro_calibration_z", gyro_accum[2] * inverseSamples);
Expand Down Expand Up @@ -1480,6 +1478,11 @@ qboolean IN_IsCalibratingGyro (void)
return updates_countdown != 0;
}

float IN_GetGyroCalibrationProgress (void)
{
return (GYRO_CALIBRATION_SAMPLES - updates_countdown) / (float) GYRO_CALIBRATION_SAMPLES;
}

static float IN_FilterGyroSample (float prev, float cur)
{
float thresh = DEG2RAD (gyro_noise_thresh.value);
Expand Down
1 change: 1 addition & 0 deletions Quake/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ qboolean IN_HasGyro (void);
float IN_GetRawGyroMagnitude (void);
void IN_StartGyroCalibration (void);
qboolean IN_IsCalibratingGyro (void);
float IN_GetGyroCalibrationProgress (void);

float IN_GetRawLookMagnitude (void);
float IN_GetRawMoveMagnitude (void);
Expand Down
7 changes: 7 additions & 0 deletions Quake/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -3102,6 +3102,8 @@ void M_Menu_Calibration_f (void)

void M_Calibration_Draw (void)
{
char anim[16];
int i, progress;
int y = 72;

switch (calibration_state)
Expand All @@ -3117,7 +3119,12 @@ void M_Calibration_Draw (void)
break;

case CALIBRATION_IN_ROGRESS:
progress = IN_GetGyroCalibrationProgress () * (Q_COUNTOF (anim) - 1);
for (i = 0; i < (int) Q_COUNTOF (anim) - 1; i++)
anim[i] = i < progress ? '.'|0x80 : '.';
anim[i] = '\0';
M_PrintAligned (160, y, ALIGN_CENTER, "Calibrating, please wait...");
M_PrintAligned (160, y + 16, ALIGN_CENTER, anim);
if (!IN_IsCalibratingGyro ())
calibration_state = CALIBRATION_FINISHED;
break;
Expand Down

0 comments on commit 51bdbd3

Please sign in to comment.