infrared_decoder_samsung.c 2.5 KB

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