Display moving average of speed.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2017-06-24 19:07:20 +01:00
parent e68748a158
commit eba2cea5ca
2 changed files with 9 additions and 7 deletions

View file

@ -162,14 +162,16 @@ namespace
VideoRedrawScreen();
}
if (!DiskIsSpinning())
{
const auto end = std::chrono::steady_clock::now();
const auto diff = end - start;
const long us = std::chrono::duration_cast<std::chrono::microseconds>(diff).count();
g_relativeSpeed = double(us) / double(nExecutionPeriodUsec);
const double coeff = exp(-0.000001 * nExecutionPeriodUsec); // 0.36 after 1 second
g_relativeSpeed = g_relativeSpeed * coeff + double(us) / double(nExecutionPeriodUsec) * (1.0 - coeff);
if (!DiskIsSpinning())
{
if (us < nExecutionPeriodUsec)
{
usleep(nExecutionPeriodUsec - us);

View file

@ -150,7 +150,7 @@ namespace
}
double g_relativeSpeed = 0;
double g_relativeSpeed = 1.0;
void output(const char *fmt, ...)
{