Paparazzi UAS  v7.0_unstable
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 }
Some architecture independent helper functions for GPIOs.
void humid_sht_uart_periodic(void)
uint16_t humidsht
!SITL
void humid_sht_uart_event(void)
void calc_sht(uint16_t hum, uint16_t tem, float *fhum, float *ftem)
float fhumidsht
void humid_sht_uart_parse(uint8_t c)
bool humid_sht_available
float ftempsht
void humid_sht_uart_init(void)
uint16_t tempsht
SHTxx sensor interface.
#define MetBuffer()
#define MetGetch()
@ C2
Definition: nav.c:617
@ C1
Definition: nav.c:617
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