Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
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 
40 #ifndef HTM_I2C_DEV
41 #define HTM_I2C_DEV i2c0
42 #endif
43 
44 #define HTM_SLAVE_ADDR 0x28
45 
50 
51 
52 void humid_htm_init(void) {
54 }
55 
56 void humid_htm_start( void ) {
57  if (sys_time.nb_sec > 1) {
58  /* measurement request: wake up sensor, sample temperature/humidity */
61  }
62 }
63 
64 /* needs 18.5ms delay from measurement request */
65 void humid_htm_read( void ) {
66  if (htm_status == HTM_MR_OK) {
67  /* read humid and temp*/
70  }
71 }
72 
73 void humid_htm_event( void ) {
75  switch (htm_status) {
76 
77  case HTM_MR:
80  break;
81 
82  case HTM_READ_DATA:
83  /* check stale status */
84  if (((htm_trans.buf[0] >> 6) & 0x3) == 0) {
85  /* humidity */
86  humidhtm = ((htm_trans.buf[0] & 0x3F) << 8) | htm_trans.buf[1];
87  fhumidhtm = humidhtm / 163.83;
88  /* temperature */
89  temphtm = (htm_trans.buf[2] << 6) | (htm_trans.buf[3] >> 2);
90  ftemphtm = -40.00 + 0.01 * temphtm;
91  DOWNLINK_SEND_HTM_STATUS(DefaultChannel, DefaultDevice, &humidhtm, &temphtm, &fhumidhtm, &ftemphtm);
92  }
94  break;
95 
96  default:
98  break;
99  }
100  }
101 }
102 
#define HTM_I2C_DEV
Definition: humid_htm_b71.c:41
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
transaction successfully finished by I2C driver
Definition: i2c.h:57
void humid_htm_init(void)
Definition: humid_htm_b71.c:52
I2C transaction structure.
Definition: i2c.h:93
uint16_t temphtm
Definition: humid_htm_b71.c:48
void humid_htm_event(void)
Definition: humid_htm_b71.c:73
void humid_htm_read(void)
Definition: humid_htm_b71.c:65
uint16_t humidhtm
Definition: humid_htm_b71.c:48
float ftemphtm
Definition: humid_htm_b71.c:49
float fhumidhtm
Definition: humid_htm_b71.c:49
#define HTM_SLAVE_ADDR
Definition: humid_htm_b71.c:44
transaction set to done by user level
Definition: i2c.h:59
Architecture independent timing functions.
bool_t 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:238
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
void humid_htm_start(void)
Definition: humid_htm_b71.c:56
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
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:46
uint8_t htm_status
Definition: humid_htm_b71.c:47
bool_t 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:248
Architecture independent I2C (Inter-Integrated Circuit Bus) API.