From 80a408526fb0bb87a3bf46336196469ce959d29d Mon Sep 17 00:00:00 2001 From: kasunch Date: Wed, 24 Feb 2010 09:13:56 +0000 Subject: [PATCH] Adding an example application for battery sensor --- platform/micaz/apps/battery-monitor.c | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 platform/micaz/apps/battery-monitor.c diff --git a/platform/micaz/apps/battery-monitor.c b/platform/micaz/apps/battery-monitor.c new file mode 100644 index 000000000..be4599458 --- /dev/null +++ b/platform/micaz/apps/battery-monitor.c @@ -0,0 +1,34 @@ +#include "contiki.h" +#include "dev/battery-sensor.h" +#include "lib/sensors.h" +#include /* For printf() */ +/*---------------------------------------------------------------------------*/ +PROCESS(battery_monitor_process, "Battery Voltage Monitor"); +AUTOSTART_PROCESSES(&battery_monitor_process); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(battery_monitor_process, ev, data) +{ + static struct etimer et; + + PROCESS_BEGIN(); + + SENSORS_ACTIVATE(battery_sensor); + + while(1) { + + etimer_set(&et, CLOCK_SECOND * 2); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + /* + * Battery voltage calculation formula + * + * V(Battery Voltage) = v(Voltage Reference) * 1024 / ADC + * + * Where: + * v = 1.223 + * + */ + printf("ADC value : %d\n", battery_sensor.value(0)); + } + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/