//#include <windows.h>

#include "p_apps.h"
#include "PalmChip.h"
#include "p_dsp.h"

void HandleNumberKeys();
void HandleFunctionKeys();

BOOLEAN Ac97_bIVR;
XCHAR Ac97_bMuteInput;
XCHAR Key_pBuf[MAX_KEYBUF_LEN+1];
DCHAR Key_iLength;
BOOLEAN Key_bCopied;

BOOLEAN Line_b1S1OStatus = FALSE;

XCHAR Task_iTimer;
DCHAR Key_iCurrentID;

BOOLEAN Dtmf_bToneOn;
CCHAR _cCodecType[CODEC_MAX];

static XCHAR _pPrevKeyBuf[MAX_KEYBUF_LEN+1];
static XCHAR _iPrevKeyLength;

static volatile BOOLEAN _bKeyIndicated;
static volatile XCHAR _iKeyID;
volatile DCHAR Ac97_iDtmfCode;
volatile DSHORT Ac97_iDtmfDuration;
volatile BOOLEAN Slic_bDtmfFlag = FALSE;

BOOLEAN PIO_bHandsetUp, PIO_bHandFree;
BOOLEAN KeyIO_bIndicated;
BOOLEAN PIO_bIndicated;
XCHAR PIO_iHookFlashTimer;

CCHAR Dsp_cFrameLen[CODEC_NULL] = {G729_COMPRESSED, G7231_COMPRESSED, G711_LEN, G711_LEN, GSM610_LEN, ILBC_LEN};
volatile DCHAR Dsp_iType;

static PXCHAR _pTime;

void KeypadBackspace()
{
	DCHAR iLen;

	iLen = p_strlen_x(Key_pBuf);
	if (iLen)
	{
		iLen --;
		Key_pBuf[iLen] = 0;
	}
}

void KeypadStartup()
{
	_bKeyIndicated = FALSE;
	_iKeyID = KEYPAD_NULL;
	Key_iLength = 0;
	Key_pBuf[0] = 0;
	Key_bCopied = FALSE;

	PIO_bHandsetUp = FALSE;
	PIO_bHandFree = FALSE;
	PIO_iHookFlashTimer = 1;
}

void _HandleKeys(UCHAR iKeyID)
{
	if (IsUpgrading())	return;

	Task_iTimer = 0;
	Key_iCurrentID = iKeyID;
	if (Key_iCurrentID >= 'A' && Key_iCurrentID <= 'Z')
	{
		PIO_bIndicated = TRUE;
		HandleFunctionKeys();
	}
	else
	{
		KeyIO_bIndicated = TRUE;
		HandleNumberKeys();
	}
}

void KeypadClear()
{
	Key_iLength = 0;
	Key_pBuf[0] = 0;
}

void KeypadRun()
{
	if (!_bKeyIndicated)	return;

	_bKeyIndicated = FALSE;
	_HandleKeys(_iKeyID);
}

//Function used in palmtool simulation only
void KeypadIndicate(UCHAR iKeyID)
{
	_iKeyID = iKeyID;
	_bKeyIndicated = TRUE;
}

void SysSleep(ULONG lUSecond)
{
//	Sleep(20+lUSecond/1000);
}

void Led_On(UCHAR iIndex)
{
	if (iIndex)
	{
	}
}

void Led_Off(UCHAR iIndex)
{
	if (iIndex)
	{
	}
}

void SwitchPage(UCHAR iPage)
{
	if (iPage)
	{
	}
}

void DtmfPlayKey(UCHAR iKeyID)
{
	if (iKeyID)
	{
	}
}

void DtmfBusy()
{
}

void DtmfCongestion()
{
}

BOOLEAN DtmfPlayKeys()
{
	return TRUE;
}

void Ac97Stop()
{
}

void Ac97StartIVR()
{
}

void Ac97StopIVR()
{
}

void Ac97OutputVolHigher()
{
}

void Ac97OutputVolLower()
{
}

void Ac97OnHandsetChange()
{
}

void Ac97StartRing()
{
}

void Ac97StopRing()
{
}

#ifdef _USE_FXS
void SlicRingHandleTimer(UCHAR iTimer)
{
	if (iTimer)
	{
	}
}
#endif

void DtmfStopAll()
{
}

void DtmfStopRing()
{
}

void DtmfDialTone()
{
}

void Led_Blink(UCHAR iIndex)
{
	if (iIndex)
	{
	}
}

void L3ClockBlink()
{
}

void Ac97Start()
{
}

void Ac97SetInputVol()
{
}

void Ac97SetOutputVol()
{
}

void L3ClockOn()
{
}

void L3ClockOff()
{
}

void Cam_LedOn(UCHAR iIndex)
{
}

void Cam_LedOff(UCHAR iIndex)
{
}

void DtmfRing()
{
}

void SlicIdleMode()
{
}

void SlicOHTMode()
{
}

void SlicActiveMode()
{
}

void SlicStandbyMode()
{
}

void SwitchToFXO(BOOLEAN bFXO)		
{
	if (bFXO)
	{
	}
}

void L3DataOff()
{
}

void L3DataOn()
{
}