/**************************************************************************
<MODULE NAME>
<FILENAME></FILENAME>
<HISTORY>
	<MODIFICATION>
		<DATE></DATE>
		<AUTHOR></AUTHOR>
		<DESCRIPTION>
		</DESCRIPTION>
	</MODIFICATION>
</HISTORY>
</MODULE NAME>
**************************************************************************/


/**************************************************************************
INCLUDE FILE
**************************************************************************/
#include <stdio.h>
#include <conio.h>
#include <CTYPE.H>

#include "..\comp\urneled\led.h"
#include "..\comp\keyboard\keydigiv.h"

/**************************************************************************
LOCAL VARIABLES
Always start with « static »-keyword
**************************************************************************/

/**************************************************************************
<METHOD>
	<CLASS>CKeyboardDigivote</CLASS>
	<NAME>CKeyboardDigivote</NAME>
	<TYPE> LOCAL  GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</ IO >
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
</METHOD>
**************************************************************************/
CKeyboardDigivote::CKeyboardDigivote()
{
	;
}


/**************************************************************************
<METHOD>
	<CLASS>CKeyboardDigivote</CLASS>
	<NAME>~CKeyboardDigivote</NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO>IN | OUT | INOUT</ IO >
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
</METHOD>
**************************************************************************/
CKeyboardDigivote::~CKeyboardDigivote()
{
	;
}

/**************************************************************************
<METHOD>
	<CLASS>CKeyboardDigivote</CLASS>
	<NAME></NAME>
	<TYPE>LOCAL | GLOBAL</TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</ IO >
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/
CKeyboard* CKeyboardDigivote::Instance(void)
{
	if(m_pcInst == NULL)
	{
		m_pcInst = new CKeyboardDigivote();
	}	
	return m_pcInst;
}

int CKeyboardDigivote::Kbhit(char color,int loop)
{
	static char cColor = -1;
	int iResult = 0;
	int i;
	for (i = 0; i < loop ; i--,i++,i++);
	iResult = ::kbhit();
	if(iResult != 0)
	{
		iResult = toupper(getch());
	}
	
	/*Set Led color*/
	if(cColor != color)
	{
		cColor = color;
		CLed::Inst()->SetLED(color);
	}
	return iResult;
}


int CKeyboardDigivote::Getch(char color) 
{
	char c;

	while((c = Kbhit(color,2000)) == 0)
	{
		;/* tant qu'on appuye pas sur une touche */ 
	}
	
	while(c == Kbhit(color,2000))
	{
		;/* tant qu'on appuye sur une touche */ 
	}


	return(c);
}