PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ir_Whynter.cpp 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "IRremote.h"
  2. #include "IRremoteInt.h"
  3. //==============================================================================
  4. // W W H H Y Y N N TTTTT EEEEE RRRRR
  5. // W W H H Y Y NN N T E R R
  6. // W W W HHHHH Y N N N T EEE RRRR
  7. // W W W H H Y N NN T E R R
  8. // WWW H H Y N N T EEEEE R R
  9. //==============================================================================
  10. #define WHYNTER_BITS 32
  11. #define WHYNTER_HDR_MARK 2850
  12. #define WHYNTER_HDR_SPACE 2850
  13. #define WHYNTER_BIT_MARK 750
  14. #define WHYNTER_ONE_MARK 750
  15. #define WHYNTER_ONE_SPACE 2150
  16. #define WHYNTER_ZERO_MARK 750
  17. #define WHYNTER_ZERO_SPACE 750
  18. //+=============================================================================
  19. #if SEND_WHYNTER
  20. void IRsend::sendWhynter (unsigned long data, int nbits)
  21. {
  22. // Set IR carrier frequency
  23. enableIROut(38);
  24. // Start
  25. mark(WHYNTER_ZERO_MARK);
  26. space(WHYNTER_ZERO_SPACE);
  27. // Header
  28. mark(WHYNTER_HDR_MARK);
  29. space(WHYNTER_HDR_SPACE);
  30. // Data
  31. for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
  32. if (data & mask) {
  33. mark(WHYNTER_ONE_MARK);
  34. space(WHYNTER_ONE_SPACE);
  35. } else {
  36. mark(WHYNTER_ZERO_MARK);
  37. space(WHYNTER_ZERO_SPACE);
  38. }
  39. }
  40. // Footer
  41. mark(WHYNTER_ZERO_MARK);
  42. space(WHYNTER_ZERO_SPACE); // Always end with the LED off
  43. }
  44. #endif
  45. //+=============================================================================
  46. #if DECODE_WHYNTER
  47. bool IRrecv::decodeWhynter (decode_results *results)
  48. {
  49. long data = 0;
  50. int offset = 1; // skip initial space
  51. // Check we have the right amount of data
  52. if (irparams.rawlen < (2 * WHYNTER_BITS) + 6) return false ;
  53. // Sequence begins with a bit mark and a zero space
  54. if (!MATCH_MARK (results->rawbuf[offset++], WHYNTER_BIT_MARK )) return false ;
  55. if (!MATCH_SPACE(results->rawbuf[offset++], WHYNTER_ZERO_SPACE)) return false ;
  56. // header mark and space
  57. if (!MATCH_MARK (results->rawbuf[offset++], WHYNTER_HDR_MARK )) return false ;
  58. if (!MATCH_SPACE(results->rawbuf[offset++], WHYNTER_HDR_SPACE)) return false ;
  59. // data bits
  60. for (int i = 0; i < WHYNTER_BITS; i++) {
  61. if (!MATCH_MARK(results->rawbuf[offset++], WHYNTER_BIT_MARK)) return false ;
  62. if (MATCH_SPACE(results->rawbuf[offset], WHYNTER_ONE_SPACE )) data = (data << 1) | 1 ;
  63. else if (MATCH_SPACE(results->rawbuf[offset], WHYNTER_ZERO_SPACE)) data = (data << 1) | 0 ;
  64. else return false ;
  65. offset++;
  66. }
  67. // trailing mark
  68. if (!MATCH_MARK(results->rawbuf[offset], WHYNTER_BIT_MARK)) return false ;
  69. // Success
  70. results->bits = WHYNTER_BITS;
  71. results->value = data;
  72. results->decode_type = WHYNTER;
  73. return true;
  74. }
  75. #endif