engine_control/source/firmware/kernel/driver/battery_monitor.c

26 lines
617 B
C
Raw Normal View History

2016-07-23 05:59:54 +00:00
/*
* 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;
}