Skip to content

Commit

Permalink
Use fixed number of samples for gyro calibration
Browse files Browse the repository at this point in the history
instead of fixed number of frames, otherwise we would stop calibrating
after just a handful of sensor updates when playing with an uncapped framerate
  • Loading branch information
andrei-drexler committed Aug 5, 2024
1 parent 4dc3bec commit c24fe16
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions Quake/in_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1395,10 +1395,15 @@ void IN_StartGyroCalibration (void)
updates_countdown = 300;
}

static void IN_UpdateGyroCalibration (void)
static qboolean IN_UpdateGyroCalibration (const float newsample[3])
{
if (!updates_countdown)
return;
return false;

gyro_accum[0] += newsample[0];
gyro_accum[1] += newsample[1];
gyro_accum[2] += newsample[2];
num_samples++;

updates_countdown--;
if (!updates_countdown)
Expand All @@ -1414,7 +1419,11 @@ static void IN_UpdateGyroCalibration (void)
gyro_calibration_z.value);

Con_Printf("Calibration finished\n");

return false;
}

return true;
}

qboolean IN_HasGyro (void)
Expand Down Expand Up @@ -1588,14 +1597,8 @@ void IN_SendKeyEvents (void)
float prev_yaw = gyro_yaw;
float prev_pitch = gyro_pitch;

if (updates_countdown)
{
gyro_accum[0] += event.csensor.data[0];
gyro_accum[1] += event.csensor.data[1];
gyro_accum[2] += event.csensor.data[2];
num_samples++;
if (IN_UpdateGyroCalibration (event.csensor.data))
break;
}

if (!gyro_turning_axis.value)
gyro_yaw = event.csensor.data[1] - gyro_calibration_y.value; // yaw
Expand Down Expand Up @@ -1638,7 +1641,5 @@ void IN_SendKeyEvents (void)
break;
}
}

IN_UpdateGyroCalibration ();
}

0 comments on commit c24fe16

Please sign in to comment.