Skip to content

Commit dc40bff

Browse files
committed
Fix light reading on Cotech-367959 when no sensor installed (merbanan#2305)
1 parent b6ec3f8 commit dc40bff

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/devices/cotech_36_7959.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Also: SwitchDoc Labs Weather FT020T.
1616
Also: Sainlogic Weather Station WS019T
1717
Also: Sainlogic Weather Station FT0300
1818
Also: Ragova WiFi Weather Station FT-0310
19+
Also: NicetyMeter Weather Station 0366 (without Lux or UV index)
1920
2021
OOK modulated with Manchester encoding, halfbit-width 500 us.
2122
Message length is 112 bit, every second time it will transmit two identical messages, packet gap 5400 us.
@@ -46,6 +47,7 @@ Message layout
4647
- X : 8 bit: CRC, poly 0x31, init 0xc0
4748
*/
4849

50+
#include <stdbool.h>
4951
#include "decoder.h"
5052

5153
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)
106108

107109
float temp_c = (temp_raw - 400) * 0.1f;
108110

111+
// On models without a light sensor, the value read for UV index is out of bounds with its top bits set
112+
bool light_is_valid = ((uv & 0xf0) == 0);
113+
109114
/* clang-format off */
110115
data = data_make(
111116
"model", "", DATA_STRING, "Cotech-367959",
@@ -118,8 +123,8 @@ static int cotech_36_7959_decode(r_device *decoder, bitbuffer_t *bitbuffer)
118123
"wind_dir_deg", "Wind direction", DATA_INT, wind_dir,
119124
"wind_avg_m_s", "Wind", DATA_FORMAT, "%.1f m/s", DATA_DOUBLE, wind * 0.1f,
120125
"wind_max_m_s", "Gust", DATA_FORMAT, "%.1f m/s", DATA_DOUBLE, gust * 0.1f,
121-
"light_lux", "Light Intensity", DATA_FORMAT, "%u lux", DATA_INT, light_lux,
122-
"uv", "UV Index", DATA_FORMAT, "%u", DATA_INT, uv,
126+
"light_lux", "Light Intensity", DATA_COND, light_is_valid, DATA_FORMAT, "%u lux", DATA_INT, light_lux,
127+
"uv", "UV Index", DATA_COND, light_is_valid, DATA_FORMAT, "%u", DATA_INT, uv,
123128
"mic", "Integrity", DATA_STRING, "CRC",
124129
NULL);
125130
/* clang-format on */

0 commit comments

Comments
 (0)