infrared_decoder_samsung.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "infrared_protocol_samsung_i.h"
  2. #include <core/check.h>
  3. InfraredMessage* infrared_decoder_samsung32_check_ready(void* ctx) {
  4. return infrared_common_decoder_check_ready(ctx);
  5. }
  6. bool infrared_decoder_samsung32_interpret(InfraredCommonDecoder* decoder) {
  7. furi_assert(decoder);
  8. bool result = false;
  9. uint8_t address1 = decoder->data[0];
  10. uint8_t address2 = decoder->data[1];
  11. uint8_t command = decoder->data[2];
  12. uint8_t command_inverse = decoder->data[3];
  13. uint8_t inverse_command_inverse = (uint8_t)~command_inverse;
  14. if((address1 == address2) && (command == inverse_command_inverse)) {
  15. decoder->message.command = command;
  16. decoder->message.address = address1;
  17. decoder->message.protocol = InfraredProtocolSamsung32;
  18. decoder->message.repeat = false;
  19. result = true;
  20. }
  21. return result;
  22. }
  23. // timings start from Space (delay between message and repeat)
  24. InfraredStatus infrared_decoder_samsung32_decode_repeat(InfraredCommonDecoder* decoder) {
  25. furi_assert(decoder);
  26. float preamble_tolerance = decoder->protocol->timings.preamble_tolerance;
  27. uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance;
  28. InfraredStatus status = InfraredStatusError;
  29. if(decoder->timings_cnt < 6) return InfraredStatusOk;
  30. if((decoder->timings[0] > INFRARED_SAMSUNG_REPEAT_PAUSE_MIN) &&
  31. (decoder->timings[0] < INFRARED_SAMSUNG_REPEAT_PAUSE_MAX) &&
  32. MATCH_TIMING(decoder->timings[1], INFRARED_SAMSUNG_REPEAT_MARK, preamble_tolerance) &&
  33. MATCH_TIMING(decoder->timings[2], INFRARED_SAMSUNG_REPEAT_SPACE, preamble_tolerance) &&
  34. MATCH_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance) &&
  35. MATCH_TIMING(decoder->timings[4], decoder->protocol->timings.bit1_space, bit_tolerance) &&
  36. MATCH_TIMING(decoder->timings[5], decoder->protocol->timings.bit1_mark, bit_tolerance)) {
  37. status = InfraredStatusReady;
  38. decoder->timings_cnt = 0;
  39. } else {
  40. status = InfraredStatusError;
  41. }
  42. return status;
  43. }
  44. void* infrared_decoder_samsung32_alloc(void) {
  45. return infrared_common_decoder_alloc(&infrared_protocol_samsung32);
  46. }
  47. InfraredMessage* infrared_decoder_samsung32_decode(void* decoder, bool level, uint32_t duration) {
  48. return infrared_common_decode(decoder, level, duration);
  49. }
  50. void infrared_decoder_samsung32_free(void* decoder) {
  51. infrared_common_decoder_free(decoder);
  52. }
  53. void infrared_decoder_samsung32_reset(void* decoder) {
  54. infrared_common_decoder_reset(decoder);
  55. }