IRremote.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * IRremote
  3. * Version 0.1 July, 2009
  4. * Copyright 2009 Ken Shirriff
  5. * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.htm http://arcfn.com
  6. * Edited by Mitra to add new controller SANYO
  7. *
  8. * Interrupt code based on NECIRrcv by Joe Knapp
  9. * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
  10. * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/
  11. *
  12. * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
  13. */
  14. #ifndef IRremote_h
  15. #define IRremote_h
  16. // The following are compile-time library options.
  17. // If you change them, recompile the library.
  18. // If DEBUG is defined, a lot of debugging output will be printed during decoding.
  19. // TEST must be defined for the IRtest unittests to work. It will make some
  20. // methods virtual, which will be slightly slower, which is why it is optional.
  21. // #define DEBUG
  22. // #define TEST
  23. // Results returned from the decoder
  24. class decode_results {
  25. public:
  26. int decode_type; // NEC, SONY, RC5, UNKNOWN
  27. unsigned int panasonicAddress; // This is only used for decoding Panasonic data
  28. unsigned long value; // Decoded value
  29. int bits; // Number of bits in decoded value
  30. volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks
  31. int rawlen; // Number of records in rawbuf.
  32. };
  33. // Values for decode_type
  34. #define NEC 1
  35. #define SONY 2
  36. #define RC5 3
  37. #define RC6 4
  38. #define DISH 5
  39. #define SHARP 6
  40. #define PANASONIC 7
  41. #define JVC 8
  42. #define SANYO 9
  43. #define MITSUBISHI 10
  44. #define UNKNOWN -1
  45. // Decoded value for NEC when a repeat code is received
  46. #define REPEAT 0xffffffff
  47. // main class for receiving IR
  48. class IRrecv
  49. {
  50. public:
  51. IRrecv(int recvpin);
  52. void blink13(int blinkflag);
  53. int decode(decode_results *results);
  54. void enableIRIn();
  55. void resume();
  56. private:
  57. // These are called by decode
  58. int getRClevel(decode_results *results, int *offset, int *used, int t1);
  59. long decodeNEC(decode_results *results);
  60. long decodeSony(decode_results *results);
  61. long decodeSanyo(decode_results *results);
  62. long decodeMitsubishi(decode_results *results);
  63. long decodeRC5(decode_results *results);
  64. long decodeRC6(decode_results *results);
  65. long decodePanasonic(decode_results *results);
  66. long decodeJVC(decode_results *results);
  67. long decodeHash(decode_results *results);
  68. int compare(unsigned int oldval, unsigned int newval);
  69. }
  70. ;
  71. // Only used for testing; can remove virtual for shorter code
  72. #ifdef TEST
  73. #define VIRTUAL virtual
  74. #else
  75. #define VIRTUAL
  76. #endif
  77. class IRsend
  78. {
  79. public:
  80. IRsend() {}
  81. void sendNEC(unsigned long data, int nbits);
  82. void sendSony(unsigned long data, int nbits);
  83. // Neither Sanyo nor Mitsubishi send is implemented yet
  84. // void sendSanyo(unsigned long data, int nbits);
  85. // void sendMitsubishi(unsigned long data, int nbits);
  86. void sendRaw(unsigned int buf[], int len, int hz);
  87. void sendRC5(unsigned long data, int nbits);
  88. void sendRC6(unsigned long data, int nbits);
  89. void sendDISH(unsigned long data, int nbits);
  90. void sendSharp(unsigned long data, int nbits);
  91. void sendPanasonic(unsigned int address, unsigned long data);
  92. void sendJVC(unsigned long data, int nbits, int repeat); // *Note instead of sending the REPEAT constant if you want the JVC repeat signal sent, send the original code value and change the repeat argument from 0 to 1. JVC protocol repeats by skipping the header NOT by sending a separate code value like NEC does.
  93. // private:
  94. void enableIROut(int khz);
  95. VIRTUAL void mark(int usec);
  96. VIRTUAL void space(int usec);
  97. }
  98. ;
  99. // Some useful constants
  100. #define USECPERTICK 50 // microseconds per clock interrupt tick
  101. #define RAWBUF 100 // Length of raw duration buffer
  102. // Marks tend to be 100us too long, and spaces 100us too short
  103. // when received due to sensor lag.
  104. #define MARK_EXCESS 100
  105. #endif