//#include <proc/p32mx440f256h.h>

#include "TemperatureSensor.h"
#include "BoardCfg.h"
#include "TC77.h"
#include "timer.h"

void InitTempSensor()
{
	ActualTemp = 0xBAADBEEF;
	TimerStart(TEMP_SENSOR_REFRESH_TIMER,1000);
}

int TempSensorCheckAndConfigure()
{
	if(TC77Configure() == RET_OK)
	{
		ActualTemp = TC77GetActualTemp();
		return RET_OK;
	}
	
	return RET_ERROR;
}

float TempSensorGetTemp()
{
	return ActualTemp;
}

void TickTempSensor()
{
	if(IsTimerExpired(TEMP_SENSOR_REFRESH_TIMER))
	{
		ActualTemp = TC77GetActualTemp();
		TimerStart(TEMP_SENSOR_REFRESH_TIMER,1000);
//		printf("Temperature: %f\n",ActualTemp);
	}
}