Contiki 2.5
board-mbxxx.c
1 /*#include PLATFORM_HEADER
2 #include BOARD_HEADER
3 #include "hal/micro/micro-common.h"
4 #include "hal/micro/cortexm3/micro-common.h"*/
5 
6 #include "dev/button-sensor.h"
7 #include "dev/temperature-sensor.h"
8 #include "dev/acc-sensor.h"
9 
10 static uint8_t sensors_status;
11 
12 #define BUTTON_STATUS_ACTIVE (1 << 0)
13 #define TEMP_STATUS_ACTIVE (1 << 1)
14 #define ACC_STATUS_ACTIVE (1 << 2)
15 
16 /* Remember state of sensors (if active or not), in order to
17  * resume their original state after calling powerUpSensors().
18  * Useful when entering in sleep mode, since all system
19  * peripherals have to be reinitialized. */
20 
21 void sensorsPowerDown(){
22 
23  sensors_status = 0;
24 
25  if(button_sensor.status(SENSORS_READY)){
26  sensors_status |= BUTTON_STATUS_ACTIVE;
27  }
28  if(temperature_sensor.status(SENSORS_READY)){
29  sensors_status |= TEMP_STATUS_ACTIVE;
30  }
31  if(acc_sensor.status(SENSORS_READY)){
32  sensors_status |= ACC_STATUS_ACTIVE;
33  // Power down accelerometer to save power
34  SENSORS_DEACTIVATE(acc_sensor);
35  }
36 }
37 
38 /**/
39 void sensorsPowerUp(){
40 
41  button_sensor.configure(SENSORS_HW_INIT, 0);
42  temperature_sensor.configure(SENSORS_HW_INIT, 0);
43  acc_sensor.configure(SENSORS_HW_INIT, 0);
44 
45  if(sensors_status & BUTTON_STATUS_ACTIVE){
46  SENSORS_ACTIVATE(button_sensor);
47  }
48  if(sensors_status & TEMP_STATUS_ACTIVE){
49  SENSORS_ACTIVATE(temperature_sensor);
50  }
51  if(sensors_status & ACC_STATUS_ACTIVE){
52  SENSORS_ACTIVATE(acc_sensor);
53  }
54 }