Open Sint  3.4-2
anemometer.h
Go to the documentation of this file.
1 /* This file is part of OpenSint
2  * Copyright (C) 2005-2012 Enrico Rossi
3  *
4  * OpenSint is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * OpenSint is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
20 #ifndef ANEMOMETER_H_
21 #define ANEMOMETER_H_
22 
23 #include "davis.h"
24 #include "lacrosse.h"
25 
27 #define ANE_DAVIS 1
28 #define ANE_LACROSSE 2
29 #define ANE_AUTO 99
30 
31 /*
32  If We want to use the media value at run (x) as
33  the first element of run (x+1).
34  This lead to a wrong value into the 2 first run from the
35  power up.
36  */
37 
38 #define MEDIA_NEXT_CYCLE
39 
40 enum wind_dir {
41  NORTH,
42  NORTH_EAST,
43  EAST,
44  SOUTH_EAST,
45  SOUTH,
46  SOUTH_WEST,
47  WEST,
48  NORTH_WEST
49 };
50 
51 enum wind_tendency {
52  INCREASE,
53  DECREASE,
54  STABLE
55 };
56 
57 struct complex {
58  double x;
59  double y;
60 };
61 
62 struct wind_array {
63  /*
64  Volatile stuff, used into ISR
65  flag: boolean used by ISR to tell to main there is a new
66  data (speed and direction) to be elaborated.
67  speed_rt: number of pulse x round detected.
68  angle_rt: 0-359 degrees detected
69  */
70  volatile uint8_t flag;
71  volatile int speed_rt;
72  volatile int angle_rt;
73 
74  /* wind elements speed 0-359 degrees */
75  int speed, vmin, vmax, angle;
76  enum wind_dir direction;
77  enum wind_tendency tendency;
78 
79  /* real time elements */
80  int vmin_rt, vmax_rt;
81  struct complex vector_rt, media_rt;
82  uint8_t counter_rt;
83 
84  /* Type of anemometer: 0 for lacrosse */
85  uint8_t sensor;
86 
87  /* LaCrosse data
88  [00000100][0000bbbb][000vvvvvvvvvvvv][0000cccc]
89  */
90  uint8_t lacrosse_head, lacrosse_chksum;
91  uint8_t lacrosse_bearing, lacrosse_nbearing;
92  uint16_t lacrosse_speed, lacrosse_nspeed;
93  uint8_t lacrosse_chkok; /* calculated checksum*/
94  uint8_t lacrosse_loop; /* max number of failed reading */
95 };
96 
98 struct wind_array *wind;
99 
100 uint8_t anemometer_adjust(struct wind_array *wind);
101 void anemometer_init(void);
102 enum wind_dir get_wind_direction(int direction);
103 void anemometer_start(struct wind_array *wind);
104 void anemometer_stop(struct wind_array *wind);
105 uint8_t anemometer_eeread(void);
106 void anemometer_eesave(uint8_t sensor);
107 
108 #endif
struct wind_array * wind
Definition: anemometer.h:98
void anemometer_start(struct wind_array *wind)
enable the anemometer and start storing value.
Definition: anemometer.c:43
Definition: anemometer.h:62
davis specific functions
void anemometer_stop(struct wind_array *wind)
disable the anemometer.
Definition: anemometer.c:50
void anemometer_init(void)
initialize the anemometer. allocate the memory for the wind struct, read from eeprom which wind senso...
Definition: anemometer.c:101
Definition: anemometer.h:57
uint8_t anemometer_eeread(void)
Read which wind sensor is stored into the EEPROM.
Definition: anemometer.c:82
uint8_t anemometer_adjust(struct wind_array *wind)
apply correction to wind value if needed.
Definition: anemometer.c:34
enum wind_dir get_wind_direction(int direction)
return standard direction from encoder.
Definition: anemometer.c:129