Contiki-NG
Loading...
Searching...
No Matches
weather-meter.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016, Zolertia <http://www.zolertia.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 */
32/*---------------------------------------------------------------------------*/
33/**
34 * \addtogroup zoul-sensors
35 * @{
36 *
37 * \defgroup zoul-weather-meter-sensor Sparkfun's weather meter
38 * @{
39 *
40 * \file
41 * Weather meter header file
42 * \author
43 * Antonio Lignan <alinan@zolertia.com>
44 */
45/*---------------------------------------------------------------------------*/
46#include "lib/sensors.h"
47#include "dev/zoul-sensors.h"
48/* -------------------------------------------------------------------------- */
49#ifndef WEATHER_METER_H_
50#define WEATHER_METER_H_
51/* -------------------------------------------------------------------------- */
52/**
53 * \name Weather meter sensor return and operation values
54 * @{
55 */
56#define WEATHER_METER_RAIN_GAUGE 0x01
57#define WEATHER_METER_WIND_VANE 0x02
58#define WEATHER_METER_WIND_VANE_AVG_X 0x03
59#define WEATHER_METER_ANEMOMETER 0x04
60#define WEATHER_METER_ANEMOMETER_AVG 0x05
61#define WEATHER_METER_ANEMOMETER_AVG_X 0x06
62#define WEATHER_METER_ANEMOMETER_MAX 0x07
63
64/* Period (seconds) to calculate an average */
65#ifdef WEATHER_METER_CONF_AVG_PERIOD
66#define WEATHER_METER_AVG_PERIOD WEATHER_METER_CONF_AVG_PERIOD
67#else
68#define WEATHER_METER_AVG_PERIOD 120
69#endif
70
71#define WEATHER_METER_ACTIVE SENSORS_ACTIVE
72#define WEATHER_METER_ANEMOMETER_INT_OVER HW_INT_OVER_THRS
73#define WEATHER_METER_ANEMOMETER_INT_DIS HW_INT_DISABLE
74#define WEATHER_METER_RAIN_GAUGE_INT_OVER (HW_INT_OVER_THRS << 1)
75#define WEATHER_METER_RAIN_GAUGE_INT_DIS (HW_INT_DISABLE << 1)
76
77#define WEATHER_METER_SUCCESS 0
78#define WEATHER_METER_ERROR (-1)
79
80/* 2.4Km/h per tick, 2 per rotation */
81#define WEATHER_METER_ANEMOMETER_SPEED_1S (1200)
82
83/* 0.2794mm per tick */
84#define WEATHER_METER_AUX_RAIN_MM 2794
85
86/* Allows to select the return type: ticks or converted value (truncated) */
87#ifdef WEATHER_METER_RAIN_CONF_RETURN
88#define WEATHER_METER_RAIN_RETURN_TICKS WEATHER_METER_RAIN_CONF_RETURN
89#else
90#define WEATHER_METER_RAIN_RETURN_TICKS 1
91#endif
92/** @} */
93/* -------------------------------------------------------------------------- */
94/**
95 * \name Anemometer and rain gauge sensor interrupt callback macro
96 * @{
97 */
98#define WEATHER_METER_REGISTER_ANEMOMETER_INT(ptr) anemometer_int_callback = ptr;
99#define WEATHER_METER_REGISTER_RAIN_GAUGE_INT(ptr) rain_gauge_int_callback = ptr;
100extern void (*anemometer_int_callback)(uint16_t value);
101extern void (*rain_gauge_int_callback)(uint16_t value);
102/** @} */
103/* -------------------------------------------------------------------------- */
104/**
105 * \name Weather meter's anemometer default pin, port and interrupt vector
106 * @{
107 */
108#ifdef WEATHER_METER_CONF_ANEMOMETER_PIN
109#define ANEMOMETER_SENSOR_PIN WEATHER_METER_CONF_ANEMOMETER_PIN
110#else
111#define ANEMOMETER_SENSOR_PIN 1
112#endif
113#ifdef WEATHER_METER_CONF_ANEMOMETER_PORT
114#define ANEMOMETER_SENSOR_PORT WEATHER_METER_CONF_ANEMOMETER_PORT
115#else
116#define ANEMOMETER_SENSOR_PORT GPIO_D_NUM
117#endif
118#ifdef WEATHER_METER_CONF_ANEMOMETER_VECTOR
119#define ANEMOMETER_SENSOR_VECTOR WEATHER_METER_CONF_ANEMOMETER_VECTOR
120#else
121#define ANEMOMETER_SENSOR_VECTOR GPIO_D_IRQn
122#endif
123/** @} */
124/* -------------------------------------------------------------------------- */
125/**
126 * \name Weather meter's rain gauge default pin, port and interrupt vector
127 * @{
128 */
129#ifdef WEATHER_METER_CONF_RAIN_GAUGE_PIN
130#define RAIN_GAUGE_SENSOR_PIN WEATHER_METER_CONF_RAIN_GAUGE_PIN
131#else
132#define RAIN_GAUGE_SENSOR_PIN 2
133#endif
134#ifdef WEATHER_METER_CONF_RAIN_GAUGE_PORT
135#define RAIN_GAUGE_SENSOR_PORT WEATHER_METER_CONF_RAIN_GAUGE_PORT
136#else
137#define RAIN_GAUGE_SENSOR_PORT GPIO_D_NUM
138#endif
139#ifdef WEATHER_METER_CONF_RAIN_GAUGE_VECTOR
140#define RAIN_GAUGE_SENSOR_VECTOR WEATHER_METER_CONF_RAIN_GAUGE_VECTOR
141#else
142#define RAIN_GAUGE_SENSOR_VECTOR GPIO_D_IRQn
143#endif
144/** @} */
145/* -------------------------------------------------------------------------- */
146/**
147 * \name Weather meter's wind vane default ADCx pin (see board.h)
148 * @{
149 */
150#ifdef WEATHER_METER_CONF_RAIN_WIND_VANE_ADC
151#define WIND_VANE_ADC WEATHER_METER_CONF_RAIN_WIND_VANE_ADC
152#else
153#define WIND_VANE_ADC ZOUL_SENSORS_ADC3
154#endif
155/** @} */
156/* -------------------------------------------------------------------------- */
157#define WEATHER_METER_SENSOR "Sparkfun weather meter"
158/* -------------------------------------------------------------------------- */
159extern const struct sensors_sensor weather_meter;
160/* -------------------------------------------------------------------------- */
161#endif /* ifndef WEATHER_METER_H_ */
162/**
163 * @}
164 * @}
165 */
Implementation of a generic module controlling Zoul sensors.