#include <windows.h>
#include "..\\..\\interfaces\\madVRTestPattern.h"

// ***************************************************************

double GrayRamp[11][3] =
  { {0.0, 0.0, 0.0}, {0.1, 0.1, 0.1}, {0.2, 0.2, 0.2}, {0.3, 0.3, 0.3},
    {0.4, 0.4, 0.4}, {0.5, 0.5, 0.5}, {0.6, 0.6, 0.6}, {0.7, 0.7, 0.7},
    {0.8, 0.8, 0.8}, {0.9, 0.9, 0.9}, {1.0, 1.0, 1.0} };

void MeasureTestPattern()
{
  // replace "Sleep()" with your measurement code
  Sleep(1000);
}

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
  if (!madVR_IsAvailable())
    MessageBox(0, "madVR network dll not found.", "Error", MB_ICONERROR);
  else
    if (madVR_ConnectDialog())
    {
      madVR_Disable3dlut();
      madVR_SetOsdText(L"measuring display, please wait...");
      madVR_SetBackground(22, 0x808080);
      madVR_ShowProgressBar(_countof(GrayRamp));
      for (int i1 = 0; i1 < _countof(GrayRamp); i1++)
      {
        if (!madVR_ShowRGB(GrayRamp[i1][0], GrayRamp[i1][1], GrayRamp[i1][2]))
        {
          MessageBox(0, "Test pattern failure.", "Error", MB_ICONERROR);
          break;
        }
        // sleep a bit to work around display input latency
        Sleep(50);
        MeasureTestPattern();
      }
      madVR_Disconnect();
    }

  return true;
}
