irda_decoder_samsung.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <stdbool.h>
  2. #include <stdint.h>
  3. #include <furi.h>
  4. #include "../irda_i.h"
  5. static bool interpret_samsung32(IrdaCommonDecoder* decoder);
  6. static DecodeStatus decode_repeat_samsung32(IrdaCommonDecoder* decoder);
  7. static const IrdaCommonProtocolSpec protocol_samsung32 = {
  8. {
  9. IRDA_SAMSUNG_PREAMBULE_MARK,
  10. IRDA_SAMSUNG_PREAMBULE_SPACE,
  11. IRDA_SAMSUNG_BIT1_MARK,
  12. IRDA_SAMSUNG_BIT1_SPACE,
  13. IRDA_SAMSUNG_BIT0_MARK,
  14. IRDA_SAMSUNG_BIT0_SPACE,
  15. IRDA_SAMSUNG_PREAMBLE_TOLERANCE,
  16. IRDA_SAMSUNG_BIT_TOLERANCE,
  17. },
  18. 32,
  19. irda_common_decode_pdwm,
  20. interpret_samsung32,
  21. decode_repeat_samsung32,
  22. };
  23. static bool interpret_samsung32(IrdaCommonDecoder* decoder) {
  24. furi_assert(decoder);
  25. bool result = false;
  26. uint8_t address1 = decoder->data[0];
  27. uint8_t address2 = decoder->data[1];
  28. uint8_t command = decoder->data[2];
  29. uint8_t command_inverse = decoder->data[3];
  30. if ((address1 == address2) && (command == (uint8_t) ~command_inverse)) {
  31. decoder->message.command = command;
  32. decoder->message.address = address1;
  33. decoder->message.repeat = false;
  34. result = true;
  35. }
  36. return result;
  37. }
  38. // timings start from Space (delay between message and repeat)
  39. static DecodeStatus decode_repeat_samsung32(IrdaCommonDecoder* decoder) {
  40. furi_assert(decoder);
  41. float preamble_tolerance = decoder->protocol->timings.preamble_tolerance;
  42. uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance;
  43. DecodeStatus status = DecodeStatusError;
  44. if (decoder->timings_cnt < 6)
  45. return DecodeStatusOk;
  46. if ((decoder->timings[0] > IRDA_SAMSUNG_REPEAT_PAUSE_MIN)
  47. && (decoder->timings[0] < IRDA_SAMSUNG_REPEAT_PAUSE_MAX)
  48. && MATCH_PREAMBLE_TIMING(decoder->timings[1], IRDA_SAMSUNG_REPEAT_MARK, preamble_tolerance)
  49. && MATCH_PREAMBLE_TIMING(decoder->timings[2], IRDA_SAMSUNG_REPEAT_SPACE, preamble_tolerance)
  50. && MATCH_BIT_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance)
  51. && MATCH_BIT_TIMING(decoder->timings[4], decoder->protocol->timings.bit1_space, bit_tolerance)
  52. && MATCH_BIT_TIMING(decoder->timings[5], decoder->protocol->timings.bit1_mark, bit_tolerance)
  53. ) {
  54. status = DecodeStatusReady;
  55. decoder->timings_cnt = 0;
  56. } else {
  57. status = DecodeStatusError;
  58. }
  59. return status;
  60. }
  61. void* irda_decoder_samsung32_alloc(void) {
  62. return irda_common_decoder_alloc(&protocol_samsung32);
  63. }
  64. IrdaMessage* irda_decoder_samsung32_decode(void* decoder, bool level, uint32_t duration) {
  65. return irda_common_decode(decoder, level, duration);
  66. }
  67. void irda_decoder_samsung32_free(void* decoder) {
  68. irda_common_decoder_free(decoder);
  69. }
  70. void irda_decoder_samsung32_reset(void* decoder) {
  71. irda_common_decoder_reset(decoder);
  72. }