mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-30 03:27:33 +08:00
add TronSens HTM-B71 humidity sensor
This commit is contained in:
+6
-1
@@ -754,8 +754,13 @@
|
|||||||
<field name="values" type="uint8[]" unit="none"/>
|
<field name="values" type="uint8[]" unit="none"/>
|
||||||
</message>
|
</message>
|
||||||
|
|
||||||
|
<message name="HTM_STATUS" id="115">
|
||||||
|
<field name="ihumid" type="uint16"/>
|
||||||
|
<field name="itemp" type="uint16"/>
|
||||||
|
<field name="humid" type="float" unit="rel_hum" format="%.2f"/>
|
||||||
|
<field name="temp" type="float" unit="deg_celsius" format="%.2f"/>
|
||||||
|
</message>
|
||||||
|
|
||||||
<!--115 is free -->
|
|
||||||
<!--116 is free -->
|
<!--116 is free -->
|
||||||
<!--117 is free -->
|
<!--117 is free -->
|
||||||
<!--118 is free -->
|
<!--118 is free -->
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<!DOCTYPE module SYSTEM "module.dtd">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
TronSens HTM-B71 humidity sensor (I2C)
|
||||||
|
@param HTM_I2C_DEV i2c device (default i2c0)
|
||||||
|
-->
|
||||||
|
|
||||||
|
<module name="humid_htm_b71" dir="meteo">
|
||||||
|
<header>
|
||||||
|
<file name="humid_htm_b71.h"/>
|
||||||
|
</header>
|
||||||
|
<init fun="humid_htm_init()"/>
|
||||||
|
<periodic fun="humid_htm_start()" freq="4" delay="10"/>
|
||||||
|
<periodic fun="humid_htm_read()" freq="4" delay="14"/>
|
||||||
|
<event fun="humid_htm_event()"/>
|
||||||
|
<makefile target="ap">
|
||||||
|
<file name="humid_htm_b71.c"/>
|
||||||
|
</makefile>
|
||||||
|
</module>
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Martin Mueller <martinmm@pfump.org>
|
||||||
|
*
|
||||||
|
* 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 humid_htm_b71.c
|
||||||
|
* \brief TronSens HTM-B71 humidity/temperature sensor i2c interface
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* nice sensor but not very collaborative with others on the i2c bus */
|
||||||
|
|
||||||
|
|
||||||
|
#include "modules/meteo/humid_htm_b71.h"
|
||||||
|
|
||||||
|
#include "sys_time.h"
|
||||||
|
#include "mcu_periph/i2c.h"
|
||||||
|
#include "mcu_periph/uart.h"
|
||||||
|
#include "messages.h"
|
||||||
|
#include "downlink.h"
|
||||||
|
|
||||||
|
#ifndef DOWNLINK_DEVICE
|
||||||
|
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HTM_I2C_DEV
|
||||||
|
#define HTM_I2C_DEV i2c0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define HTM_SLAVE_ADDR 0x28
|
||||||
|
|
||||||
|
struct i2c_transaction htm_trans;
|
||||||
|
uint8_t htm_status;
|
||||||
|
uint16_t humidhtm, temphtm;
|
||||||
|
float fhumidhtm, ftemphtm;
|
||||||
|
|
||||||
|
|
||||||
|
void humid_htm_init(void) {
|
||||||
|
htm_status = HTM_IDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void humid_htm_start( void ) {
|
||||||
|
if (cpu_time_sec > 1) {
|
||||||
|
/* measurement request: wake up sensor, sample temperature/humidity */
|
||||||
|
I2CTransmit(HTM_I2C_DEV, htm_trans, HTM_SLAVE_ADDR, 0);
|
||||||
|
htm_status = HTM_MR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* needs 18.5ms delay from measurement request */
|
||||||
|
void humid_htm_read( void ) {
|
||||||
|
if (htm_status == HTM_MR_OK) {
|
||||||
|
/* read humid and temp*/
|
||||||
|
htm_status = HTM_READ_DATA;
|
||||||
|
I2CReceive(HTM_I2C_DEV, htm_trans, HTM_SLAVE_ADDR, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void humid_htm_event( void ) {
|
||||||
|
if (htm_trans.status == I2CTransSuccess) {
|
||||||
|
switch (htm_status) {
|
||||||
|
|
||||||
|
case HTM_MR:
|
||||||
|
htm_status = HTM_MR_OK;
|
||||||
|
htm_trans.status = I2CTransDone;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HTM_READ_DATA:
|
||||||
|
/* check stale status */
|
||||||
|
if (((htm_trans.buf[0] >> 6) & 0x3) == 0) {
|
||||||
|
/* humidity */
|
||||||
|
humidhtm = ((htm_trans.buf[0] & 0x3F) << 8) | htm_trans.buf[1];
|
||||||
|
fhumidhtm = humidhtm / 163.83;
|
||||||
|
/* temperature */
|
||||||
|
temphtm = (htm_trans.buf[2] << 6) | (htm_trans.buf[3] >> 2);
|
||||||
|
ftemphtm = -40.00 + 0.01 * temphtm;
|
||||||
|
DOWNLINK_SEND_HTM_STATUS(DefaultChannel, &humidhtm, &temphtm, &fhumidhtm, &ftemphtm);
|
||||||
|
}
|
||||||
|
htm_trans.status = I2CTransDone;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
htm_trans.status = I2CTransDone;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef HUMID_HTM_H
|
||||||
|
#define HUMID_HTM_H
|
||||||
|
|
||||||
|
#include "std.h"
|
||||||
|
|
||||||
|
enum htm_type {
|
||||||
|
HTM_IDLE,
|
||||||
|
HTM_MR,
|
||||||
|
HTM_MR_OK,
|
||||||
|
HTM_READ_DATA
|
||||||
|
};
|
||||||
|
|
||||||
|
void humid_htm_init(void);
|
||||||
|
void humid_htm_start(void);
|
||||||
|
void humid_htm_read(void);
|
||||||
|
void humid_htm_event(void);
|
||||||
|
|
||||||
|
#endif // HUMID_HTM_H
|
||||||
|
|
||||||
Reference in New Issue
Block a user