Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
humid_sht_uart.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2017 The Paparazzi team
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 
31 #include "std.h"
32 #include "mcu_periph/gpio.h"
33 #include "mcu_periph/uart.h"
34 #include "pprzlink/messages.h"
36 #include "humid_sht_uart.h"
37 
41 
42 void calc_sht(uint16_t hum, uint16_t tem, float *fhum , float *ftem);
44 
45 void calc_sht(uint16_t hum, uint16_t tem, float *fhum , float *ftem)
46 {
47  // calculates temperature [ C] and humidity [%RH]
48  // input : humi [Ticks] (12 bit)
49  // temp [Ticks] (14 bit)
50  // output: humi [%RH]
51  // temp [ C]
52 
53  const float C1 = -4.0; // for 12 Bit
54  const float C2 = 0.0405; // for 12 Bit
55  const float C3 = -0.0000028; // for 12 Bit
56  const float T1 = 0.01; // for 14 Bit @ 5V
57  const float T2 = 0.00008; // for 14 Bit @ 5V
58  float rh; // rh: Humidity [Ticks] 12 Bit
59  float t; // t: Temperature [Ticks] 14 Bit
60  float rh_lin; // rh_lin: Humidity linear
61  float rh_true; // rh_true: Temperature compensated humidity
62  float t_C; // t_C : Temperature [ C]
63 
64  rh = (float)hum; //converts integer to float
65  t = (float)tem; //converts integer to float
66 
67  t_C = t * 0.01 - 39.66; //calc. Temperature from ticks to [°C] @ 3.5V
68  rh_lin = C3 * rh * rh + C2 * rh + C1; //calc. Humidity from ticks to [%RH]
69  rh_true = (t_C - 25) * (T1 + T2 * rh) + rh_lin; //calc. Temperature compensated humidity [%RH]
70  if (rh_true > 100) { rh_true = 100; } //cut if the value is outside of
71  if (rh_true < 0.1) { rh_true = 0.1; } //the physical possible range
72  *ftem = t_C; //return temperature [ C]
73  *fhum = rh_true; //return humidity[%RH]
74 }
75 
77 {
78 }
79 
80 /* airspeed_otf_parse */
82 {
83  static uint8_t msg_cnt = 0;
84  static uint8_t data[6];
85  uint16_t i, chk = 0;
86 
87  if (msg_cnt > 0) {
88  data[msg_cnt++] = c;
89  if (msg_cnt == 6) {
90  tempsht = data[1] | (data[2] << 8);
91  humidsht = data[3] | (data[4] << 8);
92  for (i = 1; i < 5; i++)
93  chk += data[i];
94  if (data[5] == (chk & 0xFF)) {
96  DOWNLINK_SEND_SHT_STATUS(DefaultChannel, DefaultDevice, &humidsht, &tempsht, &fhumidsht, &ftempsht);
97  }
98  msg_cnt = 0;
99  }
100  }
101  else if (c == 0xFF)
102  msg_cnt = 1;
103 }
104 
106 {
107 }
108 
110 {
111  while (MetBuffer()) {
112  uint8_t ch = MetGetch();
114  }
115 }
c
VIC slots used for the LPC2148 define name e g gps UART1_VIC_SLOT e g modem SPI1_VIC_SLOT SPI1 in mcu_periph spi_arch c or spi_slave_hs_arch c(and some others not using the SPI peripheral yet..) I2C0_VIC_SLOT 8 mcu_periph/i2c_arch.c I2C1_VIC_SLOT 9 mcu_periph/i2c_arch.c USB_VIC_SLOT 10 usb
humid_sht_uart_parse
void humid_sht_uart_parse(uint8_t c)
Definition: humid_sht_uart.c:81
uint16_t
unsigned short uint16_t
Definition: types.h:16
humid_sht_uart_periodic
void humid_sht_uart_periodic(void)
Definition: humid_sht_uart.c:76
tempsht
uint16_t tempsht
Definition: humid_sht_uart.c:38
humid_sht_uart.h
calc_sht
void calc_sht(uint16_t hum, uint16_t tem, float *fhum, float *ftem)
Definition: humid_sht_uart.c:45
std.h
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
C2
@ C2
Definition: nav.c:588
uint8_t
unsigned char uint8_t
Definition: types.h:14
humid_sht_available
bool humid_sht_available
Definition: humid_sht_uart.c:40
humid_sht_uart_init
void humid_sht_uart_init(void)
Definition: humid_sht_uart.c:105
MetGetch
#define MetGetch()
Definition: humid_sht_uart.h:41
gpio.h
MetBuffer
#define MetBuffer()
Definition: humid_sht_uart.h:40
fhumidsht
float fhumidsht
Definition: humid_sht_uart.c:39
humid_sht_uart_event
void humid_sht_uart_event(void)
Definition: humid_sht_uart.c:109
ftempsht
float ftempsht
Definition: humid_sht_uart.c:39
C1
@ C1
Definition: nav.c:588
humidsht
uint16_t humidsht
!SITL
Definition: humid_sht_uart.c:38