Andrew Boyson / clock

Dependents:   oldheating gps motorhome heating

scan/scan.c

Committer:
andrewboyson
Date:
2018-12-04
Revision:
40:53666b1a5848
Parent:
39:5b594b1b6a0a

File content as of revision 40:53666b1a5848:

#include <stdint.h>
#include "hrtimer.h"

uint32_t ScanAverage = 0;
uint32_t ScanMinimum = 10000;
uint32_t ScanMaximum = 0;

void ScanMain()
{
    //Establish this scan time
    static uint32_t scanTimer = 0;

    bool firstScan = !scanTimer;

    uint32_t elapsed = HrTimerSinceRepetitive(&scanTimer);

    if (firstScan) return;

    //Average the scan time
    if (elapsed > ScanAverage) ScanAverage++;
    if (elapsed < ScanAverage) ScanAverage--;
    if (elapsed > ScanMaximum) ScanMaximum = elapsed;
    if (elapsed < ScanMaximum) ScanMaximum--;
    if (elapsed < ScanMinimum) ScanMinimum = elapsed;
}