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