#include <stdio.h>
#include <unistd.h>
#include <stdint.h>

#include "bike_store.h"
#include "bike_math.h"
#include "bike_measure.h"

#define True (1)

int main(int argc, char* argv[]) {
    bikeStoreMeasurement measurement;
    uint16_t min = 0, max = 0, average = 0;
    bikeDataType dataType;

    while (True) {
       measurement.speed = bikeMeasureSpeedInKmh();
       measurement.cadence = bikeMeasureCadenceInRpm();
       measurement.heartRate = bikeMeasureHeartRateInBpm();
       measurement.power = bikeMeasurePowerInWatt();

       bikeStoreAddMeasurement(measurement);

       dataType = BIKESPEED;
       min = bikeMathCalculateMinValue(dataType);
       max = bikeMathCalculateMaxValue(dataType);
       average = bikeMathCalculateAverageValue(dataType);
       printf("SPEED:\t%d, average = %d, min = %d, max = %d [km/h]\n", measurement.speed, average, min, max);

       dataType = BIKECADENCE;
       min = bikeMathCalculateMinValue(dataType);
       max = bikeMathCalculateMaxValue(dataType);
       average = bikeMathCalculateAverageValue(dataType);
       printf("CADENCE:\t%d, average = %d, min = %d, max = %d [rpm]\n", measurement.cadence, average, min, max);

       dataType = BIKEHEARTRATE;
       min = bikeMathCalculateMinValue(dataType);
       max = bikeMathCalculateMaxValue(dataType);
       average = bikeMathCalculateAverageValue(dataType);
       printf("HEART-RATE:\t%d, average = %d, min = %d, max = %d [hrm]\n", measurement.heartRate, average, min, max);

       dataType = BIKEPOWER;
       min = bikeMathCalculateMinValue(dataType);
       max = bikeMathCalculateMaxValue(dataType);
       average = bikeMathCalculateAverageValue(dataType);
       printf("POWER:\t%d, average = %d, min = %d, max = %d [watt]\n", measurement.power, average, min, max);
       printf("\n");

       sleep(1);
    }
}
