Paparazzi UAS  v5.18.0_stable
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 
htm_trans
struct i2c_transaction htm_trans
Definition: humid_htm_b71.c:46
uint16_t
unsigned short uint16_t
Definition: types.h:16
i2c_transaction::buf
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
htm_status
uint8_t htm_status
Definition: humid_htm_b71.c:47
humid_htm_b71.h
temphtm
uint16_t temphtm
Definition: humid_htm_b71.c:48
I2CTransSuccess
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition: i2c.h:57
HTM_MR_OK
@ HTM_MR_OK
Definition: humid_htm_b71.h:9
humid_htm_read
void humid_htm_read(void)
Definition: humid_htm_b71.c:67
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
i2c_transmit
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
fhumidhtm
float fhumidhtm
Definition: humid_htm_b71.c:49
HTM_I2C_DEV
#define HTM_I2C_DEV
Definition: humid_htm_b71.c:41
sys_time.h
Architecture independent timing functions.
uint8_t
unsigned char uint8_t
Definition: types.h:14
humid_htm_start
void humid_htm_start(void)
Definition: humid_htm_b71.c:57
i2c_transaction::status
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
humid_htm_event
void humid_htm_event(void)
Definition: humid_htm_b71.c:76
HTM_READ_DATA
@ HTM_READ_DATA
Definition: humid_htm_b71.h:10
i2c_transaction
I2C transaction structure.
Definition: i2c.h:93
HTM_MR
@ HTM_MR
Definition: humid_htm_b71.h:8
sys_time
Definition: sys_time.h:71
humidhtm
uint16_t humidhtm
Definition: humid_htm_b71.c:48
ftemphtm
float ftemphtm
Definition: humid_htm_b71.c:49
HTM_SLAVE_ADDR
#define HTM_SLAVE_ADDR
Definition: humid_htm_b71.c:44
I2CTransDone
@ I2CTransDone
transaction set to done by user level
Definition: i2c.h:59
humid_htm_init
void humid_htm_init(void)
Definition: humid_htm_b71.c:52
HTM_IDLE
@ HTM_IDLE
Definition: humid_htm_b71.h:7
sys_time::nb_sec
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
i2c.h
i2c_receive
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