STIMA  3
i2c-thr-config.h
Go to the documentation of this file.
1 
3 /*********************************************************************
4 Copyright (C) 2017 Marco Baldinetti <m.baldinetti@digiteco.it>
5 authors:
6 Paolo patruno <p.patruno@iperbole.bologna.it>
7 Marco Baldinetti <m.baldinetti@digiteco.it>
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of
12 the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 **********************************************************************/
22 
23 #ifndef _I2C_THR_CONFIG_H
24 #define _I2C_THR_CONFIG_H
25 
26 #include <sensors_config.h>
27 
28 /*********************************************************************
29 * MODULE
30 *********************************************************************/
35 #define MODULE_MAIN_VERSION (3)
36 
41 #define MODULE_MINOR_VERSION (6)
42 
47 #define MODULE_CONFIGURATION_VERSION (1)
48 
53 #if (USE_MODULE_THR)
54 #define MODULE_TYPE (STIMA_MODULE_TYPE_THR)
55 #elif (USE_MODULE_TH)
56 #define MODULE_TYPE (STIMA_MODULE_TYPE_TH)
57 #elif (USE_MODULE_RAIN)
58 #define MODULE_TYPE (STIMA_MODULE_TYPE_RAIN)
59 #endif
60 
61 /*********************************************************************
62 * CONFIGURATION
63 *********************************************************************/
68 #if (USE_MODULE_THR)
69 #define CONFIGURATION_DEFAULT_I2C_ADDRESS (I2C_THR_DEFAULT_ADDRESS)
70 
75 #define CONFIGURATION_DEFAULT_IS_ONESHOT (false)
76 
81 #define CONFIGURATION_DEFAULT_IS_CONTINUOUS (true)
82 
83 #elif (USE_MODULE_TH)
84 #define CONFIGURATION_DEFAULT_I2C_ADDRESS (I2C_THR_DEFAULT_ADDRESS)
85 
90 #define CONFIGURATION_DEFAULT_IS_ONESHOT (false)
91 
96 #define CONFIGURATION_DEFAULT_IS_CONTINUOUS (true)
97 
98 #elif (USE_MODULE_RAIN)
99 #define CONFIGURATION_DEFAULT_I2C_ADDRESS (I2C_RAIN_DEFAULT_ADDRESS)
100 
105 #define CONFIGURATION_DEFAULT_IS_ONESHOT (true)
106 
111 #define CONFIGURATION_DEFAULT_IS_CONTINUOUS (false)
112 
113 #endif
114 
119 #define CONFIGURATION_DEFAULT_TEMPERATURE_ADDRESS (I2C_THR_TEMPERATURE_DEFAULT_ADDRESS)
120 
125 #define CONFIGURATION_DEFAULT_HUMIDITY_ADDRESS (I2C_THR_HUMIDITY_DEFAULT_ADDRESS)
126 
131 #define CONFIGURATION_RESET_PIN (8)
132 
137 #define I2C_MAX_TIME (12)
138 
139 
140 
141 /*********************************************************************
142 * POWER DOWN
143 *********************************************************************/
148 #define USE_POWER_DOWN (true)
149 
154 #define DEBOUNCING_POWER_DOWN_TIME_MS (10)
155 
160 #define USE_TIMER_1 (true)
161 
162 /*********************************************************************
163 * WATCHDOG
164 *********************************************************************/
173 #define WDT_TIMER (WDTO_8S)
174 
175 /*********************************************************************
176 * TIMER1
177 *********************************************************************/
182 #if (F_CPU == 8000000L)
183 #define TIMER1_OVERFLOW_TIME_MS (8388)
184 #elif (F_CPU == 16000000L)
185 #define TIMER1_OVERFLOW_TIME_MS (4194)
186 #endif
187 
192 #define TIMER1_INTERRUPT_TIME_MS (4000)
193 
194 #if (TIMER1_INTERRUPT_TIME_MS > TIMER1_OVERFLOW_TIME_MS)
195 #error "TIMER1_INTERRUPT_TIME_MS must be <= TIMER1_OVERFLOW_TIME_MS"
196 #endif
197 
202 #define TIMER1_TCNT1_VALUE ((uint16_t)(0xFFFF - (float)(1.0 * 0xFFFF * TIMER1_INTERRUPT_TIME_MS / TIMER1_OVERFLOW_TIME_MS)))
203 
208 #define TIMER_COUNTER_VALUE_MAX_MS (SENSORS_SAMPLE_TIME_MS)
209 
210 /*********************************************************************
211 * TIPPING BUCKET RAIN GAUGE
212 *********************************************************************/
213 #if (USE_SENSOR_TBR)
218 #define TIPPING_BUCKET_PIN (2)
219 
220 
225 #define CONFIGURATION_DEFAULT_TIPPING_BUCKET_TIME_MS (50)
226 
231 #define CONFIGURATION_DEFAULT_RAIN_FOR_TIP (1)
232 
233 #endif
234 #define SDCARD_CHIP_SELECT_PIN (7)
239 
240 
244 #define SPI_SPEED (SD_SCK_MHZ(4))
245 
246 /*********************************************************************
247 * SENSORS
248 *********************************************************************/
249 
254 #define SENSOR_ERROR_COUNT_MAX (20)
255 
256 /*********************************************************************
257 * HUMIDITY AND TEMPERATURE SENSORS
258 *********************************************************************/
259 // observations with processing every 1-10 minutes (minutes for processing sampling)
260 // report every 5-60 minutes (> OBSERVATIONS_MINUTES)
261 
266 #define SENSORS_SAMPLE_TIME_MS (4000)
267 
272 #define OBSERVATION_SAMPLES_COUNT_MIN ((uint8_t)(OBSERVATIONS_MINUTES * 60 / ((uint8_t)(SENSORS_SAMPLE_TIME_MS / 1000))))
273 
274 #if ((OBSERVATIONS_MINUTES * 60) % (SENSORS_SAMPLE_TIME_MS / 1000) == 0)
279 #define OBSERVATION_SAMPLES_COUNT_MAX (OBSERVATION_SAMPLES_COUNT_MIN)
280 #else
285 #define OBSERVATION_SAMPLES_COUNT_MAX (OBSERVATION_SAMPLES_COUNT_MIN + 1)
286 #endif
287 
288 #define RMAP_REPORT_SAMPLE_VALID (true)
289 
290 #define RMAP_REPORT_SAMPLES_COUNT (STATISTICAL_DATA_COUNT * OBSERVATIONS_MINUTES * OBSERVATION_SAMPLES_COUNT_MAX)
291 
296 #define OBSERVATION_SAMPLE_ERROR_MAX ((uint16_t)(round(OBSERVATION_SAMPLES_COUNT_MAX - 2)))
297 #define OBSERVATION_SAMPLE_VALID_MIN ((uint16_t)(OBSERVATION_SAMPLES_COUNT_MAX - OBSERVATION_SAMPLE_ERROR_MAX))
298 
299 #define RMAP_REPORT_SAMPLE_ERROR_MAX ((uint16_t)(STATISTICAL_DATA_COUNT * OBSERVATION_SAMPLE_ERROR_MAX))
300 
301 #if (RMAP_REPORT_SAMPLE_VALID)
302 #define RMAP_REPORT_SAMPLE_VALID_MIN (OBSERVATION_SAMPLE_VALID_MIN)
303 #else
304 #define RMAP_REPORT_SAMPLE_VALID_MIN ((uint16_t)(STATISTICAL_DATA_COUNT * OBSERVATION_SAMPLE_VALID_MIN))
305 #endif
306 
307 #define RMAP_REPORT_ERROR_MAX ((uint16_t)(STATISTICAL_DATA_COUNT - 1))
308 #define RMAP_REPORT_VALID_MIN ((uint16_t)(STATISTICAL_DATA_COUNT - RMAP_REPORT_ERROR_MAX))
309 
310 #define SAMPLES_COUNT ((60000 / SENSORS_SAMPLE_TIME_MS * STATISTICAL_DATA_COUNT) + 10)
311 
312 #define RMAP_REPORT_INTERVAL_S (STATISTICAL_DATA_COUNT * OBSERVATIONS_MINUTES * 60.0)
313 
314 /*********************************************************************
315 * SENSORS
316 *********************************************************************/
321 #define USE_SENSORS_COUNT (USE_SENSOR_ADT + USE_SENSOR_HIH + USE_SENSOR_HYT + USE_SENSOR_TBR)
322 
323 #define USE_SENSOR_DRIVER_COUNT (USE_SENSOR_ADT + USE_SENSOR_HIH + USE_SENSOR_HYT)
324 
325 #if (USE_SENSORS_COUNT == 0)
326 #error No sensor used. Are you sure? If not, enable it in RmapConfig/sensors_config.h
327 #endif
328 
329 /*********************************************************************
330 * TASKS
331 *********************************************************************/
332 
337 #define SENSORS_RETRY_COUNT_MAX (2)
342 #define SENSORS_RETRY_DELAY_MS (100)
343 
344 #endif
#define SDCARD_CHIP_SELECT_PIN
Chip select for SDcard SPI.
Definition: i2c-thr-config.h:238