#include "config.h"
#include "scaling.h"
#include "util.h"

uint16_t current_to_dac(float amps)
{
	float tmp;
	uint16_t dacc;

	tmp = 32768 * (1 + amps / 20);
	if (tmp < 0)
		tmp = 0;
	if (tmp > 65535)
		tmp = 65535;
	dacc = (uint16_t)(tmp + 0.5);

	return dacc;
}

float dac_to_current(uint16_t dacv)
{
	float amps;
	amps = dacv * (20.0 / 32768.0) - 20.0;
 	return amps;
}

float adc12_to_current(int16_t picv)
{
	float amps;

	if (picv < 0)
		picv = 0;
	if (picv > 2047)
		picv = 2047;
	
	amps = (1024.0 - picv) / 3522.6;
	return amps;
}
