34 #include "pprzlink/messages.h"
54 #define STATUS_REG_W 0x06
56 #define STATUS_REG_R 0x07
58 #define MEASURE_TEMP 0x03
60 #define MEASURE_HUMI 0x05
66 #define SHT_MEASURING_HUMID 1
67 #define SHT_MEASURING_TEMP 2
69 #if !defined SHT_DAT_GPIO || !defined SHT_SCK_GPIO
70 #error You need to define SHT_DAT_GPIO and SHT_SCK_GPIO
74 #define DATA_SET gpio_setup_input(SHT_DAT_GPIO)
75 #define DATA_CLR gpio_setup_output(SHT_DAT_GPIO)
77 #define DATA_IN gpio_get(SHT_DAT_GPIO)
81 #define SCK_SET gpio_set(SHT_SCK_GPIO)
82 #define SCK_CLR gpio_clear(SHT_SCK_GPIO)
108 for (i = 0x80; i > 0; i /= 2) {
129 for (i = 0x80; i > 0; i /= 2) {
131 if (
DATA_IN) { val = (val | i); }
178 for (i = 0; i < 9; i++) {
220 for (i = 0; i < 6665535; i++)
if (
DATA_IN == 0) {
break; }
265 const float C1 = -4.0;
266 const float C2 = 0.0405;
267 const float C3 = -0.0000028;
268 const float T1 = 0.01;
269 const float T2 = 0.00008;
279 t_C = t * 0.01 - 39.66;
280 rh_lin = C3 * rh * rh + C2 * rh +
C1;
281 rh_true = (t_C - 25) * (T1 + T2 * rh) + rh_lin;
282 if (rh_true > 100) { rh_true = 100; }
283 if (rh_true < 0.1) { rh_true = 0.1; }
311 log_sht_started =
false;
356 if (!log_sht_started) {
357 sdLogWriteLog(
pprzLogFile,
"SHT75: Humid(pct) Temp(degC) GPS_fix TOW(ms) Week Lat(1e7deg) Lon(1e7deg) HMSL(mm) gspeed(cm/s) course(1e7deg) climb(cm/s)\n");
358 log_sht_started =
true;
360 sdLogWriteLog(
pprzLogFile,
"sht75: %9.4f %9.4f %d %d %d %d %d %d %d %d %d\n",
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void humid_sht_init(void)
#define SHT_MEASURING_HUMID
void humid_sht_periodic(void)
#define DATA_SET
set data pin to input
static void gpio_clear(ioportid_t port, uint16_t pin)
Clear a gpio output to low level.
Some architecture independent helper functions for GPIOs.
#define DATA_CLR
set data pin to output
uint8_t s_write_byte(uint8_t value)
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
uint8_t s_write_statusreg(uint8_t *p_value)
uint8_t s_read_measure(uint16_t *p_value, uint8_t *p_checksum)
int32_t hmsl
height above mean sea level (MSL) in mm
uint32_t tow
GPS time of week in ms.
Device independent GPS code (interface)
#define SCK_SET
set clock pin to high
int32_t lon
in degrees*1e7
uint8_t s_read_byte(uint8_t ack)
uint8_t s_start_measure(uint8_t mode)
#define SHT_MEASURING_TEMP
uint8_t humid_sht_reset(void)
#define DefaultChannel
SITL.
void calc_sht(uint16_t hum, uint16_t tem, float *fhum, float *ftem)
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
uint8_t s_read_statusreg(uint8_t *p_value, uint8_t *p_checksum)
Common code for AP and FBW telemetry.
#define SCK_CLR
set clock pin to low
uint16_t gspeed
norm of 2d ground speed in cm/s
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
void s_connectionreset(void)
int32_t lat
in degrees*1e7
void gpio_setup_input(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs.
uint8_t s_measure(uint16_t *p_value, uint8_t *p_checksum, uint8_t mode)
struct NedCoor_i ned_vel
speed NED in cm/s
#define DATA_IN
get data pin
struct GpsState gps
global GPS state