//---------------------------------------------------------------------------
#include <stdio.h>
#include <conio.h>
#include <mem.h>
#include <dos.h>

#pragma hdrstop

#ifndef linux
#include "..\..\core\api.h"
#else
#include "../../core/api.h"
#endif // linux
//---------------------------------------------------------------------------


          
tGetBoardName GetBoardName;
tReadGPIOEvent ReadGPIOEvent;

void __cdecl DebugOut(char *Text)
{
	printf("%s",Text);
}

unsigned int Events[8];

int main(int argc, char* argv[])
{
char * Name;
unsigned char Val;
int i;

	
	Proc_DebugOut=DebugOut;
	memset(Events,0,sizeof(Events));
	
	if (KT_API_Open(sfDISK))
	{
		printf("KTAPI Verion %d.%03d.%d.%d",KT_API->VersionMajor,KT_API->VersionMinor,KT_API->Build,KT_API->Type);
		
		if ( KT_API_GetFunction("GetBoardName",&GetBoardName))
		{	
			GetBoardName(&Name);
			printf(" - %s",Name);		
		}
		
		if (OS_String[0]!=0x00)
		{
			printf(" (%s)",OS_String);		
		}
		
		printf("\n");
		
		
		
		if ( KT_API_GetFunction("ReadGPIOEvent",&ReadGPIOEvent))
		{
			Val=0;
			// Reset events
			ReadGPIOEvent(&Val);
			printf("\n");
			
			while(!kbhit())
			{
				ReadGPIOEvent(&Val);
				
				for(i=0;i<8;i++)
				{
					if ((Val&(1<<i))!=0)
					{
						Events[i]++;
					}
					
					printf("%8d ",Events[i]);
				}
				printf("\r");
				delay(1);
			}
		}		
		else
		{
			printf("ReadGPIOEvent not supportede on this board\n");
		}

		KT_API_Close();
	}


	return 0;
}
//---------------------------------------------------------------------------
