/* VectorNav HSI Calibration Library v1.0.0.2
 *
 * Copyright (c) 2018 VectorNav Technologies, LLC
 *
 * This source code is proprietary to and copyrighted by VectorNav Technologies, LLC and is
 * available solely under license from VectorNav. All rights reserved. If you do not have a
 * license to use this source code from VectorNav, any use hereof is strictly prohibited by
 * U.S. law and other applicable law. This source code is restricted for use solely with the
 * products of VectorNav and as otherwise set forth in any agreement with VectorNav. Any
 * disclosure of this source code to the public or to any third party is also prohibited.
 */
#ifndef _VNTIME_H_
#define _VNTIME_H_

#include "vncompiler.h"
#include "vnint.h"
#include "vnenum.h"

#if VN_WINDOWS_BASED

  /* Disable some warnings for Visual Studio with -Wall. */
  #if defined(_MSC_VER)
    #pragma warning(push)
    #pragma warning(disable:4668)
    #pragma warning(disable:4820)
    #pragma warning(disable:4255)
  #endif

  #include <Windows.h>

  #if defined(_MSC_VER)
    #pragma warning(pop)
  #endif

#endif

#ifdef __cplusplus
extern "C" {
#endif

/** \brief Provides simple timing capabilities. */
struct VnStopwatch
{
  #if VN_WINDOWS_BASED
  double pcFrequency;
  __int64 counterStart;
  #elif VN_UNIX_BASED
  double clockStart;
  #endif
};

#ifndef __cplusplus
typedef struct VnStopwatch VnStopwatch_t;
#endif

/** \brief Initializes and starts a stopwatch.
 * \param[in] stopwatch The VnStopwatch to initialize and start.
 * \return Any errors encountered. */
enum VnError
VnStopwatch_initializeAndStart(
    struct VnStopwatch *stopwatch);

/** \brief Resets the stopwatch's timing.
 * \param[in] stopwatch The associated VnStopwatch.
 * \return Any errors encountered. */
enum VnError
VnStopwatch_reset(
    struct VnStopwatch *stopwatch);

/** \brief Determines the number of milliseconds elapsed since the last reset
 *      of the stopwatch.
 * \param[in] stopwatch The associated VnStopwatch.
 * \param[out] elapsedMs The elapsed time in milliseconds.
 * \return Any errors encountered. */
enum VnError
VnStopwatch_elapsedMs(
    struct VnStopwatch *stopwatch,
    float *elapsedMs);

#ifdef __cplusplus
}
#endif

#endif
