Contiki 3.x
battery-monitor.c
1 #include "contiki.h"
2 #include "dev/battery-sensor.h"
3 #include "lib/sensors.h"
4 #include <stdio.h> /* For printf() */
5 /*---------------------------------------------------------------------------*/
6 PROCESS(battery_monitor_process, "Battery Voltage Monitor");
7 AUTOSTART_PROCESSES(&battery_monitor_process);
8 /*---------------------------------------------------------------------------*/
9 PROCESS_THREAD(battery_monitor_process, ev, data)
10 {
11  static struct etimer et;
12 
13  PROCESS_BEGIN();
14 
15  SENSORS_ACTIVATE(battery_sensor);
16 
17  while(1) {
18 
19  etimer_set(&et, CLOCK_SECOND * 2);
21  /*
22  * Battery voltage calculation formula
23  *
24  * V(Battery Voltage) = v(Voltage Reference) * 1024 / ADC
25  *
26  * Where:
27  * v = 1.223
28  *
29  */
30  printf("ADC value : %d\n", battery_sensor.value(0));
31  }
32  PROCESS_END();
33 }
34 /*---------------------------------------------------------------------------*/
int etimer_expired(struct etimer *et)
Check if an event timer has expired.
Definition: etimer.c:205
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition: process.h:273
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
Definition: process.h:157
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
Definition: etimer.c:177
A timer.
Definition: etimer.h:76
#define CLOCK_SECOND
A second, measured in system clock time.
Definition: clock.h:82