Contiki 3.x
ms-io-arch.c
1 #include "clock.h"
2 #include "mountainsensing/common/ms-io.h"
3 #include "dev/sht25.h"
4 #include "dev/battery-sensor.h"
5 #include "i2cmaster.h"
6 #include "adxl345.h"
7 #include "dev/reset-sensor.h"
8 
9 //#define DEBUG_ON
11 
12 /**
13  * Get the accelerometer reading from a single axis.
14  * This will enable and disable i2c as required.
15  */
16 static int16_t get_acc(enum ADXL345_AXIS axis);
17 
18 void ms_init(void) {
19  // We don't need to do anything
20 }
21 
22 void ms_sense_on(void) {
23  // We don't need to do anything
24 }
25 
26 void ms_sense_off(void) {
27  // We don't need to do anything
28 }
29 
30 bool ms_get_temp(float *temp) {
31  SENSORS_ACTIVATE(sht25);
32  *temp = ((float) sht25.value(SHT25_VAL_TEMP)) / 100;
33  SENSORS_DEACTIVATE(sht25);
34  return true;
35 }
36 
37 bool ms_get_humid(float *humid) {
38  SENSORS_ACTIVATE(sht25);
39  *humid = ((float) sht25.value(SHT25_VAL_HUM)) / 100;
40  SENSORS_DEACTIVATE(sht25);
41  return true;
42 }
43 
44 bool ms_get_batt(float *batt) {
45  SENSORS_ACTIVATE(battery_sensor);
46  *batt = (float) battery_sensor.value(0);
47  SENSORS_DEACTIVATE(battery_sensor);
48  return true;
49 }
50 
51 bool ms_get_time(uint32_t *seconds) {
52  *seconds = (uint32_t) clock_seconds();
53  return true;
54 }
55 
56 bool ms_set_time(uint32_t seconds) {
57  clock_set_seconds((unsigned long) seconds);
58  return true;
59 }
60 
61 bool ms_get_acc(int32_t *x, int32_t *y, int32_t *z) {
62  *x = get_acc(X_AXIS);
63  *y = get_acc(Z_AXIS);
64  *z = get_acc(Z_AXIS);
65  return true;
66 }
67 
68 int16_t get_acc(enum ADXL345_AXIS axis) {
69  i2c_enable();
70  int16_t acc = accm_read_axis(axis);
71  i2c_disable();
72  return acc;
73 }
74 
75 bool ms_get_adc1(uint32_t *adc1) {
76  return false;
77 }
78 
79 bool ms_get_adc2(uint32_t *adc2) {
80  return false;
81 }
82 
83 bool ms_get_rain(uint32_t *rain) {
84  return false;
85 }
86 
87 bool ms_get_reboot(uint16_t *reboot) {
88  // Param is ignored by the reset sensor
89  *reboot = reset_sensor.value(0);
90  return true;
91 }
92 
93 bool ms_reset_reboot(void) {
94  reset_counter_reset();
95  return true;
96 }
Debug helpers.
void i2c_disable(void)
Configure serial controller in disabled mode.
Definition: i2c.c:76
void i2c_enable(void)
Configure serial controller in I2C mode and set I2C speed.
Definition: i2c.c:52
CCIF unsigned long clock_seconds(void)
Get the current value of the platform seconds.
Definition: clock.c:54
void clock_set_seconds(unsigned long sec)
Set the value of the platform seconds.
Definition: clock.c:147