Skip to content

Commit 435aad3

Browse files
committed
#3 - update signal for serialize/deserialize
1 parent 885c465 commit 435aad3

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

subghz/protocols/x10/x10.c

+31-30
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// last 8 bits are inverted from previous 8 bits.
3131
//
3232
// Format: SSSSXBXX ssssxbxx DBOQBXXX dboqbxxx
33-
// S - The serial number (Channel) is encoded in the first four bits that were sent.
33+
// S - The serial number (Channel) is encoded in the first four bits that were sent.
3434
// x - Unused bits
3535
// B - Bit 6 is set if the button should be button 9-16, instead of buttons 1-8.
3636
// DQ - The 1st bit of byte 3 is 1 if DIMMER. (bit 4=0 for BRIGHT, bit 4=1 for DIM)
@@ -119,14 +119,14 @@ void subghz_protocol_decoder_x10_reset(void* context) {
119119

120120
bool subghz_protocol_x10_validate(void* context) {
121121
furi_assert(context);
122-
122+
123123
SubGhzProtocolDecoderX10* instance = context;
124124
SubGhzBlockDecoder* decoder = &instance->decoder;
125-
uint64_t data = decoder->decode_data;
125+
uint64_t data = decoder->decode_data;
126126

127127
return decoder->decode_count_bit >= subghz_protocol_x10_const.min_count_bit_for_found &&
128-
((((data >> 24) ^ (data >> 16)) & 0xFF) == 0xFF) &&
129-
((((data >> 8) ^ (data )) & 0xFF) == 0xFF);
128+
((((data >> 24) ^ (data >> 16)) & 0xFF) == 0xFF) &&
129+
((((data >> 8) ^ (data )) & 0xFF) == 0xFF);
130130
}
131131

132132
void subghz_protocol_decoder_x10_feed(void* context, bool level, uint32_t duration) {
@@ -152,27 +152,27 @@ void subghz_protocol_decoder_x10_feed(void* context, bool level, uint32_t durati
152152
break;
153153
case X10DecoderStepSaveDuration:
154154
if(level) {
155-
if(DURATION_DIFF(duration, subghz_protocol_x10_const.te_short) <
156-
subghz_protocol_x10_const.te_delta) {
157-
if(instance->decoder.decode_count_bit ==
158-
subghz_protocol_x10_const.min_count_bit_for_found) {
159-
instance->decoder.parser_step = X10DecoderStepReset;
160-
if (subghz_protocol_x10_validate(context)) {
161-
FURI_LOG_E(TAG, "Decoded a signal!");
162-
instance->generic.data = instance->decoder.decode_data;
163-
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
155+
if(DURATION_DIFF(duration, subghz_protocol_x10_const.te_short) <
156+
subghz_protocol_x10_const.te_delta) {
157+
if(instance->decoder.decode_count_bit ==
158+
subghz_protocol_x10_const.min_count_bit_for_found) {
159+
instance->decoder.parser_step = X10DecoderStepReset;
160+
if (subghz_protocol_x10_validate(context)) {
161+
FURI_LOG_E(TAG, "Decoded a signal!");
162+
instance->generic.data = instance->decoder.decode_data;
163+
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
164164

165-
if(instance->base.callback)
166-
instance->base.callback(&instance->base, instance->base.context);
167-
}
168-
subghz_protocol_decoder_x10_reset(context);
169-
} else {
170-
instance->decoder.te_last = duration;
171-
instance->decoder.parser_step = X10DecoderStepCheckDuration;
172-
}
173-
} else {
174-
subghz_protocol_decoder_x10_reset(context);
175-
}
165+
if(instance->base.callback)
166+
instance->base.callback(&instance->base, instance->base.context);
167+
}
168+
subghz_protocol_decoder_x10_reset(context);
169+
} else {
170+
instance->decoder.te_last = duration;
171+
instance->decoder.parser_step = X10DecoderStepCheckDuration;
172+
}
173+
} else {
174+
subghz_protocol_decoder_x10_reset(context);
175+
}
176176
} else {
177177
subghz_protocol_decoder_x10_reset(context);
178178
}
@@ -218,7 +218,7 @@ uint8_t subghz_protocol_decoder_x10_get_hash_data(void* context) {
218218
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
219219
}
220220

221-
bool subghz_protocol_decoder_x10_serialize(
221+
SubGhzProtocolStatus subghz_protocol_decoder_x10_serialize(
222222
void* context,
223223
FlipperFormat* flipper_format,
224224
SubGhzRadioPreset* preset) {
@@ -227,7 +227,8 @@ bool subghz_protocol_decoder_x10_serialize(
227227
return subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
228228
}
229229

230-
bool subghz_protocol_decoder_x10_deserialize(void* context, FlipperFormat* flipper_format) {
230+
SubGhzProtocolStatus
231+
subghz_protocol_decoder_x10_deserialize(void* context, FlipperFormat* flipper_format) {
231232
furi_assert(context);
232233
SubGhzProtocolDecoderX10* instance = context;
233234
bool ret = false;
@@ -236,7 +237,7 @@ bool subghz_protocol_decoder_x10_deserialize(void* context, FlipperFormat* flipp
236237
break;
237238
}
238239
if(instance->generic.data_count_bit !=
239-
subghz_protocol_x10_const.min_count_bit_for_found) {
240+
subghz_protocol_x10_const.min_count_bit_for_found) {
240241
FURI_LOG_E(TAG, "Wrong number of bits in key");
241242
break;
242243
}
@@ -255,8 +256,8 @@ void subghz_protocol_decoder_x10_get_string(void* context, FuriString* output) {
255256

256257
uint32_t code_button = 1 + (
257258
((instance->generic.btn&0x10) >> 4) |
258-
((instance->generic.btn&0x8) >> 2) |
259-
((instance->generic.btn&0x40)>>4) |
259+
((instance->generic.btn&0x8) >> 2) |
260+
((instance->generic.btn&0x40)>>4) |
260261
((instance->generic.btn&4)<<1));
261262

262263
char* code_action = (instance->generic.btn & 0x20) == 0x20 ? "Off" : "On";

subghz/protocols/x10/x10.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ uint8_t subghz_protocol_decoder_x10_get_hash_data(void* context);
5959
* @param context Pointer to a SubGhzProtocolDecoderX10 instance
6060
* @param flipper_format Pointer to a FlipperFormat instance
6161
* @param preset The modulation on which the signal was received, SubGhzRadioPreset
62-
* @return true On success
62+
* @return SubGhzProtocolStatus
6363
*/
64-
bool subghz_protocol_decoder_x10_serialize(
64+
SubGhzProtocolStatus subghz_protocol_decoder_x10_serialize(
6565
void* context,
6666
FlipperFormat* flipper_format,
6767
SubGhzRadioPreset* preset);
@@ -70,9 +70,10 @@ bool subghz_protocol_decoder_x10_serialize(
7070
* Deserialize data SubGhzProtocolDecoderX10.
7171
* @param context Pointer to a SubGhzProtocolDecoderX10 instance
7272
* @param flipper_format Pointer to a FlipperFormat instance
73-
* @return true On success
73+
* @return SubGhzProtocolStatus
7474
*/
75-
bool subghz_protocol_decoder_x10_deserialize(void* context, FlipperFormat* flipper_format);
75+
SubGhzProtocolStatus
76+
subghz_protocol_decoder_x10_deserialize(void* context, FlipperFormat* flipper_format);
7677

7778
/**
7879
* Getting a textual representation of the received data.

0 commit comments

Comments
 (0)