infrared_decoder_sirc.c 1.6 KB

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