diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-10-30 17:22:54 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-10-30 17:22:54 +0100 |
commit | d629902140406ac26fa65c1a7d559e6f1798206f (patch) | |
tree | 345bdcc0866312ec1af5480e25a205fff5bc5be2 /shared/util.c | |
parent | 64d742443bfacf5b1fad29f44642780b623f9a15 (diff) |
add sensor range en/decoding functions
Diffstat (limited to 'shared/util.c')
-rw-r--r-- | shared/util.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/shared/util.c b/shared/util.c index ea972b0..648631a 100644 --- a/shared/util.c +++ b/shared/util.c @@ -4,4 +4,28 @@ unsigned int ws_log16(unsigned int x) { unsigned int l = 0; while (x >>= 4) ++l; // bitshift right by 4 until x == 0 return l; -}
\ No newline at end of file +} + +uint8_t ws_sensor_tmp_to_8(uint16_t temperature) { + return temperature / 256; +} + +uint8_t ws_sensor_hum_to_8(uint16_t humidity) { + return humidity / 256; +} + +uint8_t ws_sensor_atm_to_8(uint16_t atmospheric_pressure) { + return atmospheric_pressure / 256; +} + +float ws_sensor_tmp_to_f(uint8_t temperature) { + return ((175.72 * temperature) / 256.0) - 46.85; +} + +float ws_sensor_hum_to_f(uint8_t humidity) { + return ((125.0 * humidity) / 256.0) - 6.0; +} + +float ws_sensor_atm_to_f(uint8_t atmospheric_pressure) { + return ((20.0 * atmospheric_pressure) / 256.0) + 990.0; // datasheet no? +} |