Contiki 3.x
test-batv.c
Go to the documentation of this file.
1 /**
2  * \file
3  * Dummy contiki application that des nothing. Literally.
4  * Might be useful for relay only nodes.
5  */
6 #include <stdbool.h>
7 #include <stdio.h>
8 #include <math.h>
9 #include "contiki.h"
10 #include "ms-io.h"
11 
12 float floor2(float x){
13  if(x>=0.0f) return (float) ((int)x);
14  else return (float) ((int)x-1);
15 }
16 
17 PROCESS(do_nothing_process, "Process that does nothing");
18 
19 AUTOSTART_PROCESSES(&do_nothing_process);
20 
21 PROCESS_THREAD(do_nothing_process, ev, data) {
22  static struct etimer sample_timer;
23  static float bat_val;
24 
25  PROCESS_BEGIN();
26 
27  ms_init();
28  ms_sense_on();
29 
30  while (true) {
31  ms_get_batt(&bat_val);
32  float voltage = bat_val;
33 
34  float f1 = bat_val/1698;
35  int d1 = f1;
36  float f2 = f1 - d1;
37  int d2 = trunc(f2 * 10000);
38 
39 
40  printf("Batv Value: %f\n", bat_val);
41 
42  printf("Batv Value: %d.%d\n", d1, d2);
43 
44  printf("Approx Voltage: %ld.%02d\n\n", (long)voltage, (int)((voltage - floor2(voltage))*100) );
45 
46  etimer_set(&sample_timer, CLOCK_SECOND * 10);
47 
49  }
50 
51  PROCESS_END();
52 }
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
Definition: etimer.c:177
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition: process.h:273
A timer.
Definition: etimer.h:76
#define CLOCK_SECOND
A second, measured in system clock time.
Definition: clock.h:82
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
Definition: process.h:141
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120