#include "stdafx.h"
#include "ADSmartIO.h"
#include "windows.h"

#define MIN	0
#define MAX 255

int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPTSTR    lpCmdLine,
					int       nCmdShow)
{
	int rampValue			= 0;
	ADSmartIO *smartIOCtrl	= 0;	

	RETAILMSG (TRUE, (L"Backlight On/Off/RampUP/RampDown test version 720020-11154\r\n"));

	smartIOCtrl = new ADSmartIO;
	if (smartIOCtrl == NULL)
	{
		RETAILMSG (TRUE, (L"Out of memory\r\n"));
		return -1;
	}

	for (int i=0; i<50; i++)
	{
		RETAILMSG (TRUE, (L"Ramping down backlight\r\n"));
		for (rampValue=MIN; rampValue<=MAX; rampValue+=5)
		{
			(*smartIOCtrl).SetBacklightPwm (rampValue);
			Sleep (500);
		}

		RETAILMSG (TRUE, (L"Ramping up backlight\r\n"));
		for (rampValue=MAX; rampValue>=MIN; rampValue-=5)
		{
			(*smartIOCtrl).SetBacklightPwm (rampValue);
			Sleep (500);
		}

		RETAILMSG (TRUE, (L"Turn off backlight\r\n"));
		(*smartIOCtrl).SetBacklightState (false);
		Sleep (5000);

		RETAILMSG (TRUE, (L"Turn on backlight\r\n"));
		(*smartIOCtrl).SetBacklightState (true);
		Sleep (5000);
	}

	RETAILMSG (TRUE, (L"Finished backlight testing\r\n"));
	delete smartIOCtrl;
	return 0;
}

