Skip to content

Commit dc25708

Browse files
committed
Fix Hideki Gust speed by Udo Kirsten
1 parent c359f71 commit dc25708

File tree

1 file changed

+53
-41
lines changed

1 file changed

+53
-41
lines changed

src/devices/hideki.c

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,29 @@ Hideki Temperature, Humidity, Wind, Rain sensor.
1313
The received bits are inverted.
1414
1515
Every 8 bits are stuffed with a (even) parity bit.
16-
The payload (excluding the header) has an byte parity (XOR) check
17-
The payload (excluding the header) has CRC-8, poly 0x07 init 0x00 check
18-
The payload bytes are reflected (LSB first / LSB last) after the CRC check
16+
The payload (excluding the header) has an byte parity (XOR) check.
17+
The payload (excluding the header) has CRC-8, poly 0x07 init 0x00 check.
18+
The payload bytes are reflected (LSB first / LSB last) after the CRC check.
1919
20-
11111001 0 11110101 0 01110011 1 01111010 1 11001100 0 01000011 1 01000110 1 00111111 0 00001001 0 00010111 0
21-
SYNC+HEAD P RC cha P LEN P Nr.? P .1° 1° P 10° BV P 1% 10% P ? P XOR P CRC P
20+
Temp:
21+
22+
11111001 0 11110101 0 01110011 1 01111010 1 11001100 0 01000011 1 01000110 1 00111111 0 00001001 0 00010111 0
23+
SYNC+HEAD P RC cha P LEN P Nr.? P .1° 1° P 10° BV P 1% 10% P ? P XOR P CRC P
2224
2325
TS04:
24-
00000000 11111111 22222222 33333333 44444444 55555555 66666666 77777777 88888888 99999999
25-
SYNC+HEAD cha RC LEN Nr.? 1° .1° VB 10° 10% 1% ? XOR CRC
26+
27+
00000000 11111111 22222222 33333333 44444444 55555555 66666666 77777777 88888888 99999999
28+
SYNC+HEAD cha RC LEN Nr.? 1° .1° VB 10° 10% 1% ? XOR CRC
2629
2730
Wind:
28-
00000000 11111111 22222222 33333333 44444444 55555555 66666666 77777777 88888888 99999999 AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
29-
SYNC+HEAD cha RC LEN Nr.? 1° .1° VB 10° 1° .1° VB 10° 1W .1W .1G 10W 10G 1G w° AA XOR CRC
31+
32+
00000000 11111111 22222222 33333333 44444444 55555555 66666666 77777777 88888888 99999999 AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
33+
SYNC+HEAD cha RC LEN Nr.? 1° .1° VB 10° 1° .1° VB 10° 1W .1W .1G 10W 10G 1G w° AA XOR CRC
3034
3135
Rain:
32-
00000000 11111111 22222222 33333333 44444444 55555555 66666666 77777777 88888888
33-
SYNC+HEAD cha RC B LEN Nr.? RAIN_L RAIN_H 0x66 XOR CRC
36+
37+
00000000 11111111 22222222 33333333 44444444 55555555 66666666 77777777 88888888
38+
SYNC+HEAD cha RC B LEN Nr.? RAIN_L RAIN_H 0x66 XOR CRC
3439
3540
*/
3641

@@ -69,10 +74,10 @@ static int hideki_ts04_callback(r_device *decoder, bitbuffer_t *bitbuffer)
6974
// Strip (unstuff) and check parity bit
7075
// TODO: refactor to util function
7176
for (int i = 0; i < unstuffed_len; ++i) {
72-
unsigned int offset = i/8;
73-
packet[i] = (b[i+offset] << (i%8)) | (b[i+offset+1] >> (8 - i%8));
77+
unsigned int offset = i / 8;
78+
packet[i] = (b[i + offset] << (i % 8)) | (b[i + offset + 1] >> (8 - i % 8));
7479
// check parity
75-
uint8_t parity = (b[i+offset+1] >> (7 - i%8)) & 1;
80+
uint8_t parity = (b[i + offset + 1] >> (7 - i % 8)) & 1;
7681
if (parity != parity8(packet[i])) {
7782
if (decoder->verbose)
7883
fprintf(stderr, "%s: Parity error at %d\n", __func__, i);
@@ -127,6 +132,7 @@ static int hideki_ts04_callback(r_device *decoder, bitbuffer_t *bitbuffer)
127132

128133
if (sensortype == HIDEKI_TS04) {
129134
humidity = ((packet[6] & 0xF0) >> 4) * 10 + (packet[6] & 0x0F);
135+
/* clang-format off */
130136
data = data_make(
131137
"model", "", DATA_STRING, _X("Hideki-TS04","HIDEKI TS04 sensor"),
132138
_X("id","rc"), "Rolling Code", DATA_INT, rc,
@@ -136,17 +142,19 @@ static int hideki_ts04_callback(r_device *decoder, bitbuffer_t *bitbuffer)
136142
"humidity", "Humidity", DATA_FORMAT, "%u %%", DATA_INT, humidity,
137143
"mic", "Integrity", DATA_STRING, "CRC",
138144
NULL);
145+
/* clang-format on */
139146
decoder_output_data(decoder, data);
140147
return 1;
141148
}
142149
if (sensortype == HIDEKI_WIND) {
143150
int const wd[] = { 0, 15, 13, 14, 9, 10, 12, 11, 1, 2, 4, 3, 8, 7, 5, 6 };
144151
wind_direction = wd[((packet[11] & 0xF0) >> 4)] * 225;
145152
wind_speed = (packet[9] & 0x0F) * 100 + (packet[8] >> 4) * 10 + (packet[8] & 0x0F);
146-
gust_speed = (packet[10] & 0xF0) * 100 + (packet[10] >> 4) * 10 + (packet[9] >> 4);
153+
gust_speed = (packet[10] >> 4) * 100 + (packet[10] & 0x0F) * 10 + (packet[9] >> 4);
147154
int const ad[] = { 0, 1, -1, 2 }; // i.e. None, CW, CCW, invalid
148155
wind_approach = ad[(packet[11] >> 2) & 0x03];
149156

157+
/* clang-format off */
150158
data = data_make(
151159
"model", "", DATA_STRING, _X("Hideki-Wind","HIDEKI Wind sensor"),
152160
_X("id","rc"), "Rolling Code", DATA_INT, rc,
@@ -159,10 +167,12 @@ static int hideki_ts04_callback(r_device *decoder, bitbuffer_t *bitbuffer)
159167
_X("wind_dir_deg","wind_direction"), "Wind Direction", DATA_FORMAT, "%.01f", DATA_DOUBLE, wind_direction * 0.1f,
160168
"mic", "Integrity", DATA_STRING, "CRC",
161169
NULL);
170+
/* clang-format on */
162171
decoder_output_data(decoder, data);
163172
return 1;
164173
}
165174
if (sensortype == HIDEKI_TEMP) {
175+
/* clang-format off */
166176
data = data_make(
167177
"model", "", DATA_STRING, _X("Hideki-Temperature","HIDEKI Temperature sensor"),
168178
_X("id","rc"), "Rolling Code", DATA_INT, rc,
@@ -171,13 +181,15 @@ static int hideki_ts04_callback(r_device *decoder, bitbuffer_t *bitbuffer)
171181
"temperature_C", "Temperature", DATA_FORMAT, "%.01f C", DATA_DOUBLE, temp * 0.1f,
172182
"mic", "Integrity", DATA_STRING, "CRC",
173183
NULL);
184+
/* clang-format on */
174185
decoder_output_data(decoder, data);
175186
return 1;
176187
}
177188
if (sensortype == HIDEKI_RAIN) {
178189
rain_units = (packet[5] << 8) | packet[4];
179190
battery_ok = (packet[2] >> 6) & 1;
180191

192+
/* clang-format off */
181193
data = data_make(
182194
"model", "", DATA_STRING, _X("Hideki-Rain","HIDEKI Rain sensor"),
183195
_X("id","rc"), "Rolling Code", DATA_INT, rc,
@@ -186,6 +198,7 @@ static int hideki_ts04_callback(r_device *decoder, bitbuffer_t *bitbuffer)
186198
"rain_mm", "Rain", DATA_FORMAT, "%.01f mm", DATA_DOUBLE, rain_units * 0.7f,
187199
"mic", "Integrity", DATA_STRING, "CRC",
188200
NULL);
201+
/* clang-format on */
189202
decoder_output_data(decoder, data);
190203
return 1;
191204
}
@@ -194,33 +207,32 @@ static int hideki_ts04_callback(r_device *decoder, bitbuffer_t *bitbuffer)
194207
}
195208

196209
static char *output_fields[] = {
197-
"model",
198-
"rc", // TODO: delete this
199-
"id",
200-
"channel",
201-
"battery",
202-
"temperature_C",
203-
"humidity",
204-
"wind_speed_mph", // TODO: remove this
205-
"gust_speed_mph", // TODO: remove this
206-
"wind_avg_mi_h",
207-
"wind_max_mi_h",
208-
"wind_approach",
209-
"wind_direction", // TODO: remove this
210-
"wind_dir_deg",
211-
"rain_mm",
212-
"mic",
213-
NULL,
210+
"model",
211+
"rc", // TODO: delete this
212+
"id",
213+
"channel",
214+
"battery",
215+
"temperature_C",
216+
"humidity",
217+
"wind_speed_mph", // TODO: remove this
218+
"gust_speed_mph", // TODO: remove this
219+
"wind_avg_mi_h",
220+
"wind_max_mi_h",
221+
"wind_approach",
222+
"wind_direction", // TODO: remove this
223+
"wind_dir_deg",
224+
"rain_mm",
225+
"mic",
226+
NULL,
214227
};
215228

216229
r_device hideki_ts04 = {
217-
.name = "HIDEKI TS04 Temperature, Humidity, Wind and Rain Sensor",
218-
.modulation = OOK_PULSE_DMC,
219-
.short_width = 520, // half-bit width 520 us
220-
.long_width = 1040, // bit width 1040 us
221-
.reset_limit = 4000,
222-
.tolerance = 240,
223-
.decode_fn = &hideki_ts04_callback,
224-
.disabled = 0,
225-
.fields = output_fields,
230+
.name = "HIDEKI TS04 Temperature, Humidity, Wind and Rain Sensor",
231+
.modulation = OOK_PULSE_DMC,
232+
.short_width = 520, // half-bit width 520 us
233+
.long_width = 1040, // bit width 1040 us
234+
.reset_limit = 4000,
235+
.tolerance = 240,
236+
.decode_fn = &hideki_ts04_callback,
237+
.fields = output_fields,
226238
};

0 commit comments

Comments
 (0)