Fix light reading on Cotech-367959 when no sensor installed ()

This commit is contained in:
obones 2023-01-11 18:55:53 +01:00 committed by GitHub
parent 023a52d593
commit 2cd5623c9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,7 @@ Also: SwitchDoc Labs Weather FT020T.
Also: Sainlogic Weather Station WS019T
Also: Sainlogic Weather Station FT0300
Also: Ragova WiFi Weather Station FT-0310
Also: NicetyMeter Weather Station 0366 (without Lux or UV index)
OOK modulated with Manchester encoding, halfbit-width 500 us.
Message length is 112 bit, every second time it will transmit two identical messages, packet gap 5400 us.
@ -46,6 +47,7 @@ Message layout
- X : 8 bit: CRC, poly 0x31, init 0xc0
*/
#include <stdbool.h>
#include "decoder.h"
static int cotech_36_7959_decode(r_device *decoder, bitbuffer_t *bitbuffer)
@ -106,6 +108,9 @@ static int cotech_36_7959_decode(r_device *decoder, bitbuffer_t *bitbuffer)
float temp_c = (temp_raw - 400) * 0.1f;
// On models without a light sensor, the value read for UV index is out of bounds with its top bits set
bool light_is_valid = ((uv & 0xf0) == 0);
/* clang-format off */
data = data_make(
"model", "", DATA_STRING, "Cotech-367959",
@ -118,8 +123,8 @@ static int cotech_36_7959_decode(r_device *decoder, bitbuffer_t *bitbuffer)
"wind_dir_deg", "Wind direction", DATA_INT, wind_dir,
"wind_avg_m_s", "Wind", DATA_FORMAT, "%.1f m/s", DATA_DOUBLE, wind * 0.1f,
"wind_max_m_s", "Gust", DATA_FORMAT, "%.1f m/s", DATA_DOUBLE, gust * 0.1f,
"light_lux", "Light Intensity", DATA_FORMAT, "%u lux", DATA_INT, light_lux,
"uv", "UV Index", DATA_FORMAT, "%u", DATA_INT, uv,
"light_lux", "Light Intensity", DATA_COND, light_is_valid, DATA_FORMAT, "%u lux", DATA_INT, light_lux,
"uv", "UV Index", DATA_COND, light_is_valid, DATA_FORMAT, "%u", DATA_INT, uv,
"mic", "Integrity", DATA_STRING, "CRC",
NULL);
/* clang-format on */