/*
 * battery_monitor.c
 *
 *  Created on: Dec 23, 2012
 *      Author: tkl
 */
#include "stddef.h"
#include "adc.h"
#include "battery_monitor.h"

//------------------------------------------------------------------------------
struct battery_monitor_voltage get_voltage(const struct battery_monitor *device)
{
	struct battery_monitor_voltage ret;
	ret.valid = false;
	if(NULL == device) {
		return ret;
	}
	adc_open(device->adc);
	ret.raw = adc_read(device->adc, device->timeout);
	adc_close(device->adc);
	ret.voltage = ret.raw * device->factor / device->divider + device->offset;
	ret.valid = true;
	return ret;
}
