aboutsummaryrefslogtreecommitdiff
path: root/shared/util.h
blob: 8cb54c1e7b96ad05f386d0bc1176a6be961b92be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once

#include <stdint.h>

#define WS_MIN(a, b) (((a) < (b)) ? (a) : (b))
#define WS_MAX(a, b) (((a) > (b)) ? (a) : (b))

/** @brief take the log base 16 of `x` */
unsigned int ws_log16(unsigned int x);

#ifdef __cplusplus
extern "C" {
#endif

/** @brief convert 16-bit temperature value to uint8_t */
uint8_t ws_sensor_tmp_to_8(uint16_t temperature);
/** @brief convert 16-bit humidity value to uint8_t */
uint8_t ws_sensor_hum_to_8(uint16_t humidity);
/** @brief convert 16-bit atmospheric pressure value to uint8_t */
uint8_t ws_sensor_atm_to_8(uint16_t atmospheric_pressure);

/** @brief convert 8-bit temperature value back to float */
float ws_sensor_tmp_to_f(uint8_t temperature);
/** @brief convert 8-bit humidity value back to float */
float ws_sensor_hum_to_f(uint8_t humidity);
/** @brief convert 8-bit atmospheric pressure value back to float */
float ws_sensor_atm_to_f(uint8_t atmospheric_pressure);

#ifdef __cplusplus
}
#endif