Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces 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 "pprzlink/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)
58 {
61 }
62 
64 {
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)
73 {
75 
76  if (pcf_status == PCF_SET_OE_LSB) {
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  } else if (pcf_status == PCF_SET_OE_MSB) {
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  } else if (pcf_status == PCF_IDLE) {
109  }
110  }
111 }
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint32_t pcf_direction
Definition: wind_gfi.c:54
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
transaction successfully finished by I2C driver
Definition: i2c.h:57
void wind_gfi_init(void)
Definition: wind_gfi.c:57
void wind_gfi_event(void)
Definition: wind_gfi.c:72
void wind_gfi_periodic(void)
Definition: wind_gfi.c:63
transaction set to done by user level
Definition: i2c.h:59
unsigned long uint32_t
Definition: types.h:18
struct i2c_transaction pcf_trans
Definition: wind_gfi.c:38
I2C transaction structure.
Definition: i2c.h:93
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
Definition: i2c.c:258
unsigned char uint8_t
Definition: types.h:14
bool i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction.
Definition: i2c.c:268
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
#define ZERO_OFFSET_DEGREES
Definition: wind_gfi.c:41
Architecture independent I2C (Inter-Integrated Circuit Bus) API.