mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-02 13:27:32 +08:00
GFI wind dir/speed sensor module
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE module SYSTEM "module.dtd">
|
||||
|
||||
<module name="wind_gfi" dir="meteo">
|
||||
<header>
|
||||
<file name="wind_gfi.h"/>
|
||||
</header>
|
||||
<init fun="wind_gfi_init()"/>
|
||||
<periodic fun="wind_gfi_periodic()" freq="4" delay="2"/>
|
||||
<event fun="wind_gfi_event()"/>
|
||||
<makefile target="ap">
|
||||
<file name="wind_gfi.c"/>
|
||||
<define name="ZERO_OFFSET_DEGREES" value="56."/>
|
||||
</makefile>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2010 Martin Mueller
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/** \file wind_gfi.c
|
||||
* \brief GFI wind speed/direction sensor interface
|
||||
*
|
||||
* Uses HEDS-5540_A06, HCTL-2017_A00 and PCF8575.
|
||||
*/
|
||||
|
||||
|
||||
#include "wind_gfi.h"
|
||||
|
||||
#include "i2c.h"
|
||||
#include "led.h"
|
||||
#include "uart.h"
|
||||
#include "messages.h"
|
||||
#include "downlink.h"
|
||||
|
||||
struct i2c_transaction pcf_trans;
|
||||
|
||||
#ifndef ZERO_OFFSET_DEGREES
|
||||
#define ZERO_OFFSET_DEGREES 45.
|
||||
#endif
|
||||
|
||||
#ifndef PCF_I2C_DEV
|
||||
#define PCF_I2C_DEV i2c0
|
||||
#endif
|
||||
|
||||
/* PCF8575 address can be set through A0..A2, starting at 0x40 */
|
||||
|
||||
#ifndef PCF_SLAVE_ADDR
|
||||
#define PCF_SLAVE_ADDR 0x40
|
||||
#endif
|
||||
|
||||
uint32_t pcf_direction;
|
||||
uint8_t pcf_status;
|
||||
|
||||
void wind_gfi_init(void) {
|
||||
pcf_trans.status = I2CTransDone;
|
||||
pcf_status = PCF_IDLE;
|
||||
}
|
||||
|
||||
void wind_gfi_periodic( void ) {
|
||||
/* OE low, SEL high (for low data) */
|
||||
pcf_trans.buf[0] = 0xFF;
|
||||
pcf_trans.buf[1] = 0xBF;
|
||||
pcf_status = PCF_SET_OE_LSB;
|
||||
I2CTransmit(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2);
|
||||
}
|
||||
|
||||
void wind_gfi_event( void ) {
|
||||
if (pcf_trans.status == I2CTransSuccess) {
|
||||
|
||||
if (pcf_status == PCF_SET_OE_LSB) {
|
||||
pcf_status = PCF_READ_LSB;
|
||||
I2CReceive(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2);
|
||||
}
|
||||
else if (pcf_status == PCF_READ_LSB) {
|
||||
/* read lower byte direction info */
|
||||
pcf_direction = pcf_trans.buf[0];
|
||||
|
||||
/* OE low, SEL low (for high data) */
|
||||
pcf_trans.buf[0] = 0xFF;
|
||||
pcf_trans.buf[1] = 0x3F;
|
||||
pcf_status = PCF_SET_OE_MSB;
|
||||
I2CTransmit(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2);
|
||||
}
|
||||
else if (pcf_status == PCF_SET_OE_MSB) {
|
||||
pcf_status = PCF_READ_MSB;
|
||||
I2CReceive(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2);
|
||||
}
|
||||
else if (pcf_status == PCF_READ_MSB) {
|
||||
float fpcf_direction;
|
||||
|
||||
/* read higher byte direction info */
|
||||
pcf_direction |= pcf_trans.buf[0] << 8;
|
||||
|
||||
/* OE high, SEL high */
|
||||
pcf_trans.buf[0] = 0xFF;
|
||||
pcf_trans.buf[1] = 0xFF;
|
||||
pcf_status = PCF_IDLE;
|
||||
I2CTransmit(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2);
|
||||
|
||||
/* 2048 digits per 360 degrees */
|
||||
fpcf_direction = fmod((pcf_direction * (360./2048.)) + ZERO_OFFSET_DEGREES, 360.);
|
||||
|
||||
DOWNLINK_SEND_TMP_STATUS(DefaultChannel, &pcf_direction, &fpcf_direction);
|
||||
}
|
||||
else if (pcf_status == PCF_IDLE) {
|
||||
pcf_trans.status = I2CTransDone;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef WIND_GFI_H
|
||||
#define WIND_GFI_H
|
||||
|
||||
#include "std.h"
|
||||
|
||||
enum pcf_stat{
|
||||
PCF_IDLE,
|
||||
PCF_SET_OE_LSB,
|
||||
PCF_READ_LSB,
|
||||
PCF_SET_OE_MSB,
|
||||
PCF_READ_MSB
|
||||
};
|
||||
|
||||
void wind_gfi_init(void);
|
||||
void wind_gfi_periodic(void);
|
||||
void wind_gfi_event(void);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user