
#include "LibAlrBx.h"
#include "..\comp\TypePc\TypePc.h"
#include "..\comp\AlarmBox\AlrBxDig.h"
#include "..\comp\AlarmBox\AlrBxJit.h"
#include "..\comp\File\CFile.h"


int InitLibrary(void)
{
	return 1;
}

int InitAlarmBox(int iTypePc)
{
	int iResult = 0;
	switch(iTypePc)
	{
		case CTypePc::eJiteMavVer1:
		case CTypePc::eJiteMavVer2:
			CAlarmBoxJites::Instance();
			break;
		case CTypePc::eDigivotMav1:
		case CTypePc::eDigivotMav2:
			CAlarmBoxDigivot::Instance();
			break;
		default :
			iResult = -1;
			break;
	}
	return iResult;
}

void FreeResource()
{
	CAlarmBox::DestroyInst();
}

int GetStatus(void)
{
	int iResult = -1;
	if(CAlarmBox::Inst() != NULL)
		iResult = (int) CAlarmBox::Inst()->GetStatus();
	return iResult;
}

void SetGreenLed(void)
{
	if(CAlarmBox::Inst() != NULL)
		CAlarmBox::Inst()->SetGreenLed();
}

void SetRedLed(void)
{
	if(CAlarmBox::Inst() != NULL)
		CAlarmBox::Inst()->SetRedLed();
}

void SetLeds(void)
{
	if(CAlarmBox::Inst() != NULL)
		CAlarmBox::Inst()->SetLeds();
}

void ResetLeds(void)
{
	if(CAlarmBox::Inst() != NULL)
		CAlarmBox::Inst()->ResetLeds();
}

unsigned char ButtonPressed(int iSeconds)
{
	unsigned char  ucResult = 0;
	if(CAlarmBox::Inst() != NULL)
		ucResult = CAlarmBox::Inst()->ButtonPressed(iSeconds);
	return ucResult;
}


s_PcType LoadDefinitionFile(void)
{
    int iRep = 0;
	s_PcType sResult;
    CTypePc hPcType;

    CFile hFile("c:\\PcType.dat","r");
    iRep = hFile.Read((void*) &hPcType, sizeof(hPcType));
	if(iRep >= 0)
	{
		sResult.iPcType = (int)hPcType.GetPcType();
		sResult.iLigthPenType = (int)hPcType.GetLightPenType();
		sResult.iMgCardType = (int)hPcType.GetMagCardType();
		sResult.iStatus = 0;
	}
	else
	{
		sResult.iStatus = iRep;
	}
    return sResult;
}