infrared_decoder_samsung.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. uint8_t inverse_command_inverse = (uint8_t)~command_inverse;
  18. if((address1 == address2) && (command == inverse_command_inverse)) {
  19. decoder->message.command = command;
  20. decoder->message.address = address1;
  21. decoder->message.protocol = InfraredProtocolSamsung32;
  22. decoder->message.repeat = false;
  23. result = true;
  24. }
  25. return result;
  26. }
  27. // timings start from Space (delay between message and repeat)
  28. InfraredStatus infrared_decoder_samsung32_decode_repeat(InfraredCommonDecoder* decoder) {
  29. furi_assert(decoder);
  30. float preamble_tolerance = decoder->protocol->timings.preamble_tolerance;
  31. uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance;
  32. InfraredStatus status = InfraredStatusError;
  33. if(decoder->timings_cnt < 6) return InfraredStatusOk;
  34. if((decoder->timings[0] > INFRARED_SAMSUNG_REPEAT_PAUSE_MIN) &&
  35. (decoder->timings[0] < INFRARED_SAMSUNG_REPEAT_PAUSE_MAX) &&
  36. MATCH_TIMING(decoder->timings[1], INFRARED_SAMSUNG_REPEAT_MARK, preamble_tolerance) &&
  37. MATCH_TIMING(decoder->timings[2], INFRARED_SAMSUNG_REPEAT_SPACE, preamble_tolerance) &&
  38. MATCH_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance) &&
  39. MATCH_TIMING(decoder->timings[4], decoder->protocol->timings.bit1_space, bit_tolerance) &&
  40. MATCH_TIMING(decoder->timings[5], decoder->protocol->timings.bit1_mark, bit_tolerance)) {
  41. status = InfraredStatusReady;
  42. decoder->timings_cnt = 0;
  43. } else {
  44. status = InfraredStatusError;
  45. }
  46. return status;
  47. }
  48. void* infrared_decoder_samsung32_alloc(void) {
  49. return infrared_common_decoder_alloc(&protocol_samsung32);
  50. }
  51. InfraredMessage* infrared_decoder_samsung32_decode(void* decoder, bool level, uint32_t duration) {
  52. return infrared_common_decode(decoder, level, duration);
  53. }
  54. void infrared_decoder_samsung32_free(void* decoder) {
  55. infrared_common_decoder_free(decoder);
  56. }
  57. void infrared_decoder_samsung32_reset(void* decoder) {
  58. infrared_common_decoder_reset(decoder);
  59. }