Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 "pprzlink/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)
53 {
55 }
56 
57 void humid_htm_start(void)
58 {
59  if (sys_time.nb_sec > 1) {
60  /* measurement request: wake up sensor, sample temperature/humidity */
63  }
64 }
65 
66 /* needs 18.5ms delay from measurement request */
67 void humid_htm_read(void)
68 {
69  if (htm_status == HTM_MR_OK) {
70  /* read humid and temp*/
73  }
74 }
75 
76 void humid_htm_event(void)
77 {
79  switch (htm_status) {
80 
81  case HTM_MR:
84  break;
85 
86  case HTM_READ_DATA:
87  /* check stale status */
88  if (((htm_trans.buf[0] >> 6) & 0x3) == 0) {
89  /* humidity */
90  humidhtm = ((htm_trans.buf[0] & 0x3F) << 8) | htm_trans.buf[1];
91  fhumidhtm = humidhtm / 163.83;
92  /* temperature */
93  temphtm = (htm_trans.buf[2] << 6) | (htm_trans.buf[3] >> 2);
94  ftemphtm = -40.00 + 0.01 * temphtm;
95  DOWNLINK_SEND_HTM_STATUS(DefaultChannel, DefaultDevice, &humidhtm, &temphtm, &fhumidhtm, &ftemphtm);
96  }
98  break;
99 
100  default:
102  break;
103  }
104  }
105 }
106 
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
bool 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:324
bool 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:334
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition: i2c.h:57
@ I2CTransDone
transaction set to done by user level
Definition: i2c.h:59
I2C transaction structure.
Definition: i2c.h:93
void humid_htm_event(void)
Definition: humid_htm_b71.c:76
uint8_t htm_status
Definition: humid_htm_b71.c:47
#define HTM_I2C_DEV
Definition: humid_htm_b71.c:41
uint16_t temphtm
Definition: humid_htm_b71.c:48
struct i2c_transaction htm_trans
Definition: humid_htm_b71.c:46
float fhumidhtm
Definition: humid_htm_b71.c:49
void humid_htm_init(void)
Definition: humid_htm_b71.c:52
uint16_t humidhtm
Definition: humid_htm_b71.c:48
void humid_htm_read(void)
Definition: humid_htm_b71.c:67
float ftemphtm
Definition: humid_htm_b71.c:49
#define HTM_SLAVE_ADDR
Definition: humid_htm_b71.c:44
void humid_htm_start(void)
Definition: humid_htm_b71.c:57
@ HTM_MR
Definition: humid_htm_b71.h:8
@ HTM_IDLE
Definition: humid_htm_b71.h:7
@ HTM_READ_DATA
Definition: humid_htm_b71.h:10
@ HTM_MR_OK
Definition: humid_htm_b71.h:9
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
Architecture independent timing functions.
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98