Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
wind_gfi.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2010 Martin Mueller
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
32 #include "modules/meteo/wind_gfi.h"
33 
34 #include "mcu_periph/i2c.h"
35 #include "led.h"
36 #include "mcu_periph/uart.h"
37 #include "messages.h"
39 
41 
42 #ifndef ZERO_OFFSET_DEGREES
43 #define ZERO_OFFSET_DEGREES 45.
44 #endif
45 
46 #ifndef PCF_I2C_DEV
47 #define PCF_I2C_DEV i2c0
48 #endif
49 
50 /* PCF8575 address can be set through A0..A2, starting at 0x40 */
51 
52 #ifndef PCF_SLAVE_ADDR
53 #define PCF_SLAVE_ADDR 0x40
54 #endif
55 
58 
59 void wind_gfi_init(void) {
62 }
63 
64 void wind_gfi_periodic( void ) {
65  /* OE low, SEL high (for low data) */
66  pcf_trans.buf[0] = 0xFF;
67  pcf_trans.buf[1] = 0xBF;
70 }
71 
72 void wind_gfi_event( void ) {
74 
75  if (pcf_status == PCF_SET_OE_LSB) {
78  }
79  else if (pcf_status == PCF_READ_LSB) {
80  /* read lower byte direction info */
82 
83  /* OE low, SEL low (for high data) */
84  pcf_trans.buf[0] = 0xFF;
85  pcf_trans.buf[1] = 0x3F;
88  }
89  else if (pcf_status == PCF_SET_OE_MSB) {
92  }
93  else if (pcf_status == PCF_READ_MSB) {
94  float fpcf_direction;
95 
96  /* read higher byte direction info */
97  pcf_direction |= pcf_trans.buf[0] << 8;
98 
99  /* OE high, SEL high */
100  pcf_trans.buf[0] = 0xFF;
101  pcf_trans.buf[1] = 0xFF;
104 
105  /* 2048 digits per 360 degrees */
106  fpcf_direction = fmod((pcf_direction * (360./2048.)) + ZERO_OFFSET_DEGREES, 360.);
107 
108  DOWNLINK_SEND_TMP_STATUS(DefaultChannel, DefaultDevice, &pcf_direction, &fpcf_direction);
109  }
110  else if (pcf_status == PCF_IDLE) {
112  }
113  }
114 }
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define I2CReceive(_p, _t, _s_addr, _len)
Definition: i2c.h:140
uint32_t pcf_direction
Definition: wind_gfi.c:56
#define I2CTransmit(_p, _t, _s_addr, _len)
Definition: i2c.h:148
void wind_gfi_init(void)
Definition: wind_gfi.c:59
void wind_gfi_event(void)
Definition: wind_gfi.c:72
void wind_gfi_periodic(void)
Definition: wind_gfi.c:64
unsigned long uint32_t
Definition: types.h:18
struct i2c_transaction pcf_trans
Definition: wind_gfi.c:40
enum I2CTransactionStatus status
Definition: i2c.h:47
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
unsigned char uint8_t
Definition: types.h:14
arch independent LED (Light Emitting Diodes) API
#define PCF_I2C_DEV
Definition: wind_gfi.c:47
#define PCF_SLAVE_ADDR
Definition: wind_gfi.c:53
uint8_t pcf_status
Definition: wind_gfi.c:57
#define ZERO_OFFSET_DEGREES
Definition: wind_gfi.c:43