Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
humid_htm_b71.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2011 Martin Mueller <martinmm@pfump.org>
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
30 /* nice sensor but not very collaborative with others on the i2c bus */
31 
32 
34 
35 #include "mcu_periph/sys_time.h"
36 #include "mcu_periph/i2c.h"
37 #include "mcu_periph/uart.h"
38 #include "messages.h"
40 
41 #ifndef DOWNLINK_DEVICE
42 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
43 #endif
44 
45 #ifndef HTM_I2C_DEV
46 #define HTM_I2C_DEV i2c0
47 #endif
48 
49 #define HTM_SLAVE_ADDR 0x28
50 
55 
56 
57 void humid_htm_init(void) {
59 }
60 
61 void humid_htm_start( void ) {
62  if (cpu_time_sec > 1) {
63  /* measurement request: wake up sensor, sample temperature/humidity */
66  }
67 }
68 
69 /* needs 18.5ms delay from measurement request */
70 void humid_htm_read( void ) {
71  if (htm_status == HTM_MR_OK) {
72  /* read humid and temp*/
75  }
76 }
77 
78 void humid_htm_event( void ) {
80  switch (htm_status) {
81 
82  case HTM_MR:
85  break;
86 
87  case HTM_READ_DATA:
88  /* check stale status */
89  if (((htm_trans.buf[0] >> 6) & 0x3) == 0) {
90  /* humidity */
91  humidhtm = ((htm_trans.buf[0] & 0x3F) << 8) | htm_trans.buf[1];
92  fhumidhtm = humidhtm / 163.83;
93  /* temperature */
94  temphtm = (htm_trans.buf[2] << 6) | (htm_trans.buf[3] >> 2);
95  ftemphtm = -40.00 + 0.01 * temphtm;
96  DOWNLINK_SEND_HTM_STATUS(DefaultChannel, DefaultDevice, &humidhtm, &temphtm, &fhumidhtm, &ftemphtm);
97  }
99  break;
100 
101  default:
103  break;
104  }
105  }
106 }
107 
#define HTM_I2C_DEV
Definition: humid_htm_b71.c:46
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define I2CReceive(_p, _t, _s_addr, _len)
Definition: i2c.h:140
void humid_htm_init(void)
Definition: humid_htm_b71.c:57
#define I2CTransmit(_p, _t, _s_addr, _len)
Definition: i2c.h:148
uint16_t temphtm
Definition: humid_htm_b71.c:53
void humid_htm_event(void)
Definition: humid_htm_b71.c:78
void humid_htm_read(void)
Definition: humid_htm_b71.c:70
#define cpu_time_sec
Definition: sys_time.h:64
uint16_t humidhtm
Definition: humid_htm_b71.c:53
float ftemphtm
Definition: humid_htm_b71.c:54
float fhumidhtm
Definition: humid_htm_b71.c:54
#define HTM_SLAVE_ADDR
Definition: humid_htm_b71.c:49
Architecture independent timing functions.
enum I2CTransactionStatus status
Definition: i2c.h:47
void humid_htm_start(void)
Definition: humid_htm_b71.c:61
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
unsigned char uint8_t
Definition: types.h:14
struct i2c_transaction htm_trans
Definition: humid_htm_b71.c:51
uint8_t htm_status
Definition: humid_htm_b71.c:52