//----------------------------------------------------
/**
	\file		photox.c

	\brief		Knihovna fotosenzoru
				<<< sens >>>

	\author		ConTeK s.r.o., Jakub Kastner
	\version	01.01
	\date		22.12.2015
*/
//----------------------------------------------------

#include "photox.h"
#include "appiodef.h"
#include "misc.h"

//----------------------------------------------------
/**
	\brief		Funkce pro obnoceni konstant

	\param		_ctx			kontext knihovny
				_ResPower		Vystupni proud [mA]
				_AmpfOffset		Offset zesilovace
*/
//----------------------------------------------------

void PhotoUpdateConstant( PHOTO_CTX * _ctx, float_t _ResPower, float_t _filtCoef,
						 float_t _ResLevel, float_t _Translevel)
{
	_ctx->ResPower = _ResPower;
	_ctx->FilterConstant = _filtCoef;

	_ctx->ResLevel = _ResLevel;
	_ctx->TransLevel = _Translevel;
}

//----------------------------------------------------
/**
	\brief		Funkce, navracejici hodnotu plamene

	\param		_ctx			kontext knihovny
	\return		TRUE	odpor <= nastavena hodnota
*/
//----------------------------------------------------

bool_t PhotoGetFire( PHOTO_CTX * _ctx )
{
	return _ctx->Res <= _ctx->ResLevel;
}


//----------------------------------------------------
/**
	\brief		Periodicky volaná funkce

	\param		_ctx			kontext knihovny
*/
//----------------------------------------------------

void PhotoTick( PHOTO_CTX * _ctx )
{
	float_t voltRes = KFilter( (sGetAInp(AI_PHOTORES) * VOLT_ON_DIV), _ctx->VoltRes, _ctx->FilterConstant);
	float_t voltTrans = KFilter( (sGetAInp(AI_PHOTOTRANS) * VOLT_ON_DIV), _ctx->VoltTrans, _ctx->FilterConstant);
	
	float_t Res = (voltRes) / _ctx->ResPower;
	_ctx->Res = Res;
	_ctx->VoltRes = voltRes;
	_ctx->VoltTrans = voltTrans;
}

//----------------------------------------------------
/**
	\brief		Inicializace knihovny

	\param		_ctx			kontext knihovny
*/
//----------------------------------------------------

void PhotoInit( PHOTO_CTX * _ctx )
{
	memset( _ctx, 0, sizeof( PHOTO_CTX ));
}

//----------------------------------------------------
/**
	\brief		Finalize knihovny

	\param		_ctx			kontext knihovny
*/
//----------------------------------------------------

void PhotoFinalize( PHOTO_CTX * _ctx )
{
	memset( _ctx, 0, sizeof( PHOTO_CTX ));
}

