BrickUp API Service for Docker version.

ir_Samsung.cpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "IRremote.h"
  2. #include "IRremoteInt.h"
  3. //==============================================================================
  4. // SSSS AAA MMM SSSS U U N N GGGG
  5. // S A A M M M S U U NN N G
  6. // SSS AAAAA M M M SSS U U N N N G GG
  7. // S A A M M S U U N NN G G
  8. // SSSS A A M M SSSS UUU N N GGG
  9. //==============================================================================
  10. #define SAMSUNG_BITS 32
  11. #define SAMSUNG_HDR_MARK 5000
  12. #define SAMSUNG_HDR_SPACE 5000
  13. #define SAMSUNG_BIT_MARK 560
  14. #define SAMSUNG_ONE_SPACE 1600
  15. #define SAMSUNG_ZERO_SPACE 560
  16. #define SAMSUNG_RPT_SPACE 2250
  17. //+=============================================================================
  18. #if SEND_SAMSUNG
  19. void IRsend::sendSAMSUNG (unsigned long data, int nbits)
  20. {
  21. // Set IR carrier frequency
  22. enableIROut(38);
  23. // Header
  24. mark(SAMSUNG_HDR_MARK);
  25. space(SAMSUNG_HDR_SPACE);
  26. // Data
  27. for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
  28. if (data & mask) {
  29. mark(SAMSUNG_BIT_MARK);
  30. space(SAMSUNG_ONE_SPACE);
  31. } else {
  32. mark(SAMSUNG_BIT_MARK);
  33. space(SAMSUNG_ZERO_SPACE);
  34. }
  35. }
  36. // Footer
  37. mark(SAMSUNG_BIT_MARK);
  38. space(0); // Always end with the LED off
  39. }
  40. #endif
  41. //+=============================================================================
  42. // SAMSUNGs have a repeat only 4 items long
  43. //
  44. #if DECODE_SAMSUNG
  45. bool IRrecv::decodeSAMSUNG (decode_results *results)
  46. {
  47. long data = 0;
  48. int offset = 1; // Skip first space
  49. // Initial mark
  50. if (!MATCH_MARK(results->rawbuf[offset], SAMSUNG_HDR_MARK)) return false ;
  51. offset++;
  52. // Check for repeat
  53. if ( (irparams.rawlen == 4)
  54. && MATCH_SPACE(results->rawbuf[offset], SAMSUNG_RPT_SPACE)
  55. && MATCH_MARK(results->rawbuf[offset+1], SAMSUNG_BIT_MARK)
  56. ) {
  57. results->bits = 0;
  58. results->value = REPEAT;
  59. results->decode_type = SAMSUNG;
  60. return true;
  61. }
  62. if (irparams.rawlen < (2 * SAMSUNG_BITS) + 4) return false ;
  63. // Initial space
  64. if (!MATCH_SPACE(results->rawbuf[offset++], SAMSUNG_HDR_SPACE)) return false ;
  65. for (int i = 0; i < SAMSUNG_BITS; i++) {
  66. if (!MATCH_MARK(results->rawbuf[offset++], SAMSUNG_BIT_MARK)) return false ;
  67. if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ONE_SPACE)) data = (data << 1) | 1 ;
  68. else if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ZERO_SPACE)) data = (data << 1) | 0 ;
  69. else return false ;
  70. offset++;
  71. }
  72. // Success
  73. results->bits = SAMSUNG_BITS;
  74. results->value = data;
  75. results->decode_type = SAMSUNG;
  76. return true;
  77. }
  78. #endif