infrared_decoder_sirc.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "common/infrared_common_i.h"
  2. #include "infrared.h"
  3. #include "infrared_protocol_defs_i.h"
  4. #include <stdbool.h>
  5. #include <stdint.h>
  6. #include <furi.h>
  7. #include "../infrared_i.h"
  8. InfraredMessage* infrared_decoder_sirc_check_ready(void* ctx) {
  9. return infrared_common_decoder_check_ready(ctx);
  10. }
  11. bool infrared_decoder_sirc_interpret(InfraredCommonDecoder* decoder) {
  12. furi_assert(decoder);
  13. uint32_t* data = (void*)&decoder->data[0];
  14. uint16_t address = 0;
  15. uint8_t command = 0;
  16. InfraredProtocol protocol = InfraredProtocolUnknown;
  17. if(decoder->databit_cnt == 12) {
  18. address = (*data >> 7) & 0x1F;
  19. command = *data & 0x7F;
  20. protocol = InfraredProtocolSIRC;
  21. } else if(decoder->databit_cnt == 15) {
  22. address = (*data >> 7) & 0xFF;
  23. command = *data & 0x7F;
  24. protocol = InfraredProtocolSIRC15;
  25. } else if(decoder->databit_cnt == 20) {
  26. address = (*data >> 7) & 0x1FFF;
  27. command = *data & 0x7F;
  28. protocol = InfraredProtocolSIRC20;
  29. } else {
  30. return false;
  31. }
  32. decoder->message.protocol = protocol;
  33. decoder->message.address = address;
  34. decoder->message.command = command;
  35. /* SIRC doesn't specify repeat detection */
  36. decoder->message.repeat = false;
  37. return true;
  38. }
  39. void* infrared_decoder_sirc_alloc(void) {
  40. return infrared_common_decoder_alloc(&protocol_sirc);
  41. }
  42. InfraredMessage* infrared_decoder_sirc_decode(void* decoder, bool level, uint32_t duration) {
  43. return infrared_common_decode(decoder, level, duration);
  44. }
  45. void infrared_decoder_sirc_free(void* decoder) {
  46. infrared_common_decoder_free(decoder);
  47. }
  48. void infrared_decoder_sirc_reset(void* decoder) {
  49. infrared_common_decoder_reset(decoder);
  50. }