3 #include "dev/adc1-sensor.h"
4 #include "dev/adc2-sensor.h"
5 #include "dev/batv-sensor.h"
7 #include "dev/event-sensor.h"
8 #include "mountainsensing/common/ms-io.h"
12 #include "dev/reset-sensor.h"
17 #define ADC_ACTIVATE_DELAY 10 //delay in ticks of the rtimer PLATFORM DEPENDANT!
22 #define EARLIEST_EPOCH 946684800
24 static void ms_radio_on(
void);
25 static void ms_radio_off(
void);
29 SENSE_EN_PORT(
SEL) &= ~BV(SENSE_EN_PIN);
30 SENSE_EN_PORT(DIR) |= BV(SENSE_EN_PIN);
31 SENSE_EN_PORT(REN) &= ~BV(SENSE_EN_PIN);
32 SENSE_EN_PORT(OUT) &= ~BV(SENSE_EN_PIN);
42 RADIO_EN_PORT(
SEL) &= ~BV(RADIO_EN_PIN);
43 RADIO_EN_PORT(DIR) |= BV(RADIO_EN_PIN);
44 RADIO_EN_PORT(REN) &= ~BV(RADIO_EN_PIN);
45 DEBUG(
"\tTurning on radio\n");
52 SENSORS_ACTIVATE(event_sensor);
55 void ms_radio_on(
void) {
56 DEBUG(
"Turning on radio\n");
57 RADIO_EN_PORT(OUT) |= BV(RADIO_EN_PIN);
60 void ms_radio_off(
void) {
61 DEBUG(
"Turning off radio\n");
62 RADIO_EN_PORT(OUT) &= ~BV(RADIO_EN_PIN);
65 void ms_sense_on(
void){
66 DEBUG(
"Turning on sense\n");
67 SENSE_EN_PORT(OUT) |= BV(SENSE_EN_PIN);
70 void ms_sense_off(
void){
71 DEBUG(
"Turning off sense\n");
72 SENSE_EN_PORT(OUT) &= ~BV(SENSE_EN_PIN);
75 bool ms_get_temp(
float *temp) {
80 bool ms_get_batt(
float *batt) {
83 SENSORS_ACTIVATE(batv_sensor);
85 while(RTIMER_CLOCK_LT(
RTIMER_NOW(), (t0 + (uint32_t) ADC_ACTIVATE_DELAY)));
86 *batt = (float)(batv_sensor.value(0)) / 184.06 - 0.2532;
87 SENSORS_DEACTIVATE(batv_sensor);
91 bool ms_get_time(uint32_t *seconds) {
102 bool ms_set_time(uint32_t seconds) {
116 bool ms_get_rain(uint32_t *rain) {
117 *rain = (uint32_t) event_sensor.value(1);
121 bool ms_get_adc1(uint32_t *adc1) {
123 SENSORS_ACTIVATE(adc1_sensor);
125 while(RTIMER_CLOCK_LT(
RTIMER_NOW(), (t0 + (uint32_t) ADC_ACTIVATE_DELAY)));
126 *adc1 = adc1_sensor.value(0);
127 SENSORS_DEACTIVATE(adc1_sensor);
131 bool ms_get_adc2(uint32_t *adc2) {
133 SENSORS_ACTIVATE(adc2_sensor);
135 while(RTIMER_CLOCK_LT(
RTIMER_NOW(), (t0 + (uint32_t) ADC_ACTIVATE_DELAY)));
136 *adc2 = adc2_sensor.value(0);
137 SENSORS_DEACTIVATE(adc2_sensor);
141 bool ms_get_acc(int32_t *x, int32_t *y, int32_t *z) {
146 bool ms_get_humid(
float *humid) {
151 bool ms_get_reboot(uint16_t *reboot) {
153 *reboot = reset_sensor.value(0);
157 bool ms_reset_reboot(
void) {
158 reset_counter_reset();
#define EARLIEST_EPOCH
Earliest time supported by the rtc - 2000/01/01 00:00:00.
#define RTIMER_NOW()
Get the current clock time.
Sensors for DS3231 (RTC with Temperature Sensor).
int ds3231_get_time(struct tm *t)
ds3231_get_time
Utility functions for operating on UTC times.
I2C communication device driver header file for Zolertia Z1 sensor node.
time_t tm_to_epoch(struct tm *const tmp)
Convert a tm struct to a UNIX epoch.
int ds3231_set_time(struct tm *t)
ds3231_set_time
int ds3231_temperature(void)
ds3231_temperature
void epoch_to_tm(const time_t *timer, struct tm *const tmp)
Convert a UNIX epoch to a tm struct.