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
humid_htm_b71.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Martin Mueller <martinmm@pfump.org>
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 
28 /* nice sensor but not very collaborative with others on the i2c bus */
29 
30 
32 
33 #include "mcu_periph/sys_time.h"
34 #include "mcu_periph/i2c.h"
35 #include "mcu_periph/uart.h"
36 #include "messages.h"
38 
39 #ifndef DOWNLINK_DEVICE
40 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
41 #endif
42 
43 #ifndef HTM_I2C_DEV
44 #define HTM_I2C_DEV i2c0
45 #endif
46 
47 #define HTM_SLAVE_ADDR 0x28
48 
53 
54 
55 void humid_htm_init(void) {
57 }
58 
59 void humid_htm_start( void ) {
60  if (sys_time.nb_sec > 1) {
61  /* measurement request: wake up sensor, sample temperature/humidity */
64  }
65 }
66 
67 /* needs 18.5ms delay from measurement request */
68 void humid_htm_read( void ) {
69  if (htm_status == HTM_MR_OK) {
70  /* read humid and temp*/
73  }
74 }
75 
76 void humid_htm_event( void ) {
78  switch (htm_status) {
79 
80  case HTM_MR:
83  break;
84 
85  case HTM_READ_DATA:
86  /* check stale status */
87  if (((htm_trans.buf[0] >> 6) & 0x3) == 0) {
88  /* humidity */
89  humidhtm = ((htm_trans.buf[0] & 0x3F) << 8) | htm_trans.buf[1];
90  fhumidhtm = humidhtm / 163.83;
91  /* temperature */
92  temphtm = (htm_trans.buf[2] << 6) | (htm_trans.buf[3] >> 2);
93  ftemphtm = -40.00 + 0.01 * temphtm;
94  DOWNLINK_SEND_HTM_STATUS(DefaultChannel, DefaultDevice, &humidhtm, &temphtm, &fhumidhtm, &ftemphtm);
95  }
97  break;
98 
99  default:
101  break;
102  }
103  }
104 }
105 
#define HTM_I2C_DEV
Definition: humid_htm_b71.c:44
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void humid_htm_init(void)
Definition: humid_htm_b71.c:55
uint16_t temphtm
Definition: humid_htm_b71.c:51
void humid_htm_event(void)
Definition: humid_htm_b71.c:76
void humid_htm_read(void)
Definition: humid_htm_b71.c:68
uint16_t humidhtm
Definition: humid_htm_b71.c:51
float ftemphtm
Definition: humid_htm_b71.c:52
float fhumidhtm
Definition: humid_htm_b71.c:52
#define HTM_SLAVE_ADDR
Definition: humid_htm_b71.c:47
Architecture independent timing functions.
bool_t i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Definition: i2c.c:85
enum I2CTransactionStatus status
Definition: i2c.h:83
void humid_htm_start(void)
Definition: humid_htm_b71.c:59
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:82
unsigned char uint8_t
Definition: types.h:14
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:69
struct i2c_transaction htm_trans
Definition: humid_htm_b71.c:49
uint8_t htm_status
Definition: humid_htm_b71.c:50
bool_t i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Definition: i2c.c:95
Architecture independent I2C (Inter-Integrated Circuit Bus) API.