BrickUp API Service for Docker version.

ir_NEC.cpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "IRremote.h"
  2. #include "IRremoteInt.h"
  3. //==============================================================================
  4. // N N EEEEE CCCC
  5. // NN N E C
  6. // N N N EEE C
  7. // N NN E C
  8. // N N EEEEE CCCC
  9. //==============================================================================
  10. #define NEC_BITS 32
  11. #define NEC_HDR_MARK 9000
  12. #define NEC_HDR_SPACE 4500
  13. #define NEC_BIT_MARK 560
  14. #define NEC_ONE_SPACE 1690
  15. #define NEC_ZERO_SPACE 560
  16. #define NEC_RPT_SPACE 2250
  17. //+=============================================================================
  18. #if SEND_NEC
  19. void IRsend::sendNEC (unsigned long data, int nbits)
  20. {
  21. // Set IR carrier frequency
  22. enableIROut(38);
  23. // Header
  24. mark(NEC_HDR_MARK);
  25. space(NEC_HDR_SPACE);
  26. // Data
  27. for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
  28. if (data & mask) {
  29. mark(NEC_BIT_MARK);
  30. space(NEC_ONE_SPACE);
  31. } else {
  32. mark(NEC_BIT_MARK);
  33. space(NEC_ZERO_SPACE);
  34. }
  35. }
  36. // Footer
  37. mark(NEC_BIT_MARK);
  38. space(0); // Always end with the LED off
  39. }
  40. #endif
  41. //+=============================================================================
  42. // NECs have a repeat only 4 items long
  43. //
  44. #if DECODE_NEC
  45. bool IRrecv::decodeNEC (decode_results *results)
  46. {
  47. long data = 0; // We decode in to here; Start with nothing
  48. int offset = 1; // Index in to results; Skip first entry!?
  49. // Check header "mark"
  50. if (!MATCH_MARK(results->rawbuf[offset], NEC_HDR_MARK)) return false ;
  51. offset++;
  52. // Check for repeat
  53. if ( (irparams.rawlen == 4)
  54. && MATCH_SPACE(results->rawbuf[offset ], NEC_RPT_SPACE)
  55. && MATCH_MARK (results->rawbuf[offset+1], NEC_BIT_MARK )
  56. ) {
  57. results->bits = 0;
  58. results->value = REPEAT;
  59. results->decode_type = NEC;
  60. return true;
  61. }
  62. // Check we have enough data
  63. if (irparams.rawlen < (2 * NEC_BITS) + 4) return false ;
  64. // Check header "space"
  65. if (!MATCH_SPACE(results->rawbuf[offset], NEC_HDR_SPACE)) return false ;
  66. offset++;
  67. // Build the data
  68. for (int i = 0; i < NEC_BITS; i++) {
  69. // Check data "mark"
  70. if (!MATCH_MARK(results->rawbuf[offset], NEC_BIT_MARK)) return false ;
  71. offset++;
  72. // Suppend this bit
  73. if (MATCH_SPACE(results->rawbuf[offset], NEC_ONE_SPACE )) data = (data << 1) | 1 ;
  74. else if (MATCH_SPACE(results->rawbuf[offset], NEC_ZERO_SPACE)) data = (data << 1) | 0 ;
  75. else return false ;
  76. offset++;
  77. }
  78. // Success
  79. results->bits = NEC_BITS;
  80. results->value = data;
  81. results->decode_type = NEC;
  82. return true;
  83. }
  84. #endif