infrared_encoder_rc6.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "infrared_protocol_rc6_i.h"
  2. #include <stdlib.h>
  3. #include <core/check.h>
  4. typedef struct InfraredEncoderRC6 {
  5. InfraredCommonEncoder* common_encoder;
  6. bool toggle_bit;
  7. } InfraredEncoderRC6;
  8. void infrared_encoder_rc6_reset(void* encoder_ptr, const InfraredMessage* message) {
  9. furi_assert(encoder_ptr);
  10. InfraredEncoderRC6* encoder = encoder_ptr;
  11. InfraredCommonEncoder* common_encoder = encoder->common_encoder;
  12. infrared_common_encoder_reset(common_encoder);
  13. uint32_t* data = (void*)common_encoder->data;
  14. *data |= 0x01; // start bit
  15. (void)*data; // 3 bits for mode == 0
  16. *data |= encoder->toggle_bit ? 0x10 : 0;
  17. *data |= reverse(message->address) << 5;
  18. *data |= reverse(message->command) << 13;
  19. common_encoder->bits_to_encode = common_encoder->protocol->databit_len[0];
  20. encoder->toggle_bit ^= 1;
  21. }
  22. InfraredStatus infrared_encoder_rc6_encode(void* encoder_ptr, uint32_t* duration, bool* level) {
  23. InfraredEncoderRC6* encoder = encoder_ptr;
  24. return infrared_common_encode(encoder->common_encoder, duration, level);
  25. }
  26. void* infrared_encoder_rc6_alloc(void) {
  27. InfraredEncoderRC6* encoder = malloc(sizeof(InfraredEncoderRC6));
  28. encoder->common_encoder = infrared_common_encoder_alloc(&infrared_protocol_rc6);
  29. encoder->toggle_bit = false;
  30. return encoder;
  31. }
  32. void infrared_encoder_rc6_free(void* encoder_ptr) {
  33. furi_assert(encoder_ptr);
  34. InfraredEncoderRC6* encoder = encoder_ptr;
  35. free(encoder->common_encoder);
  36. free(encoder);
  37. }
  38. InfraredStatus infrared_encoder_rc6_encode_manchester(
  39. InfraredCommonEncoder* common_encoder,
  40. uint32_t* duration,
  41. bool* polarity) {
  42. InfraredStatus status = InfraredStatusError;
  43. bool toggle_bit = (common_encoder->bits_encoded == 4);
  44. status = infrared_common_encode_manchester(common_encoder, duration, polarity);
  45. if(toggle_bit) *duration *= 2;
  46. return status;
  47. }