Advertisement
Fyrilin

IRremote_full.h

Oct 6th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  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. * LG added by Darryl Smith (based on the JVC protocol)
  14. * Whynter A/C ARC-110WD added by Francesco Meschia
  15. */
  16.  
  17. #ifndef IRremote_h
  18. #define IRremote_h
  19.  
  20. // The following are compile-time library options.
  21. // If you change them, recompile the library.
  22. // If DEBUG is defined, a lot of debugging output will be printed during decoding.
  23. // TEST must be defined for the IRtest unittests to work. It will make some
  24. // methods virtual, which will be slightly slower, which is why it is optional.
  25. //#define DEBUG
  26. // #define TEST
  27.  
  28. // Results returned from the decoder
  29. class decode_results {
  30. public:
  31. int decode_type; // NEC, SONY, RC5, UNKNOWN
  32. union { // This is used for decoding Panasonic and Sharp data
  33. unsigned int panasonicAddress;
  34. unsigned int sharpAddress;
  35. };
  36. unsigned long value; // Decoded value
  37. int bits; // Number of bits in decoded value
  38. volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks
  39. int rawlen; // Number of records in rawbuf.
  40. };
  41.  
  42. // Send types
  43. #define IRsendNEC
  44. #define IRsendCISCO
  45. #define IRsendSONY
  46. #define IRsendRC5
  47. #define IRsendRC6
  48. #define IRsendDISH
  49. #define IRsendSHARP
  50. #define IRsendPANASONIC
  51. #define IRsendJVC
  52. #define IRsendSANYO
  53. #define IRsendMITSUBISHI
  54. #define IRsendSAMSUNG
  55. #define IRsendRAW
  56.  
  57. // Values for decode_type
  58. #define NEC 1
  59. #define SONY 2
  60. #define RC5 3
  61. #define RC6 4
  62. #define DISH 5
  63. #define SHARP 6
  64. #define PANASONIC 7
  65. #define JVC 8
  66. #define SANYO 9
  67. #define MITSUBISHI 10
  68. #define SAMSUNG 11
  69. #define LG 12
  70. #define WHYNTER 13
  71. #define AIWA_RC_T501 14
  72. #define CISCO 20
  73. #define UNKNOWN -1
  74.  
  75. // Decoded value for NEC when a repeat code is received
  76. #define REPEAT 0xffffffff
  77.  
  78. // main class for receiving IR
  79. class IRrecv
  80. {
  81. public:
  82. IRrecv(int recvpin);
  83. void blink13(int blinkflag);
  84. int decode(decode_results *results);
  85. void enableIRIn();
  86. void resume();
  87. private:
  88. // These are called by decode
  89. int getRClevel(decode_results *results, int *offset, int *used, int t1);
  90. #ifdef NEC
  91. long decodeNEC(decode_results *results);
  92. #endif
  93. #ifdef CISCO
  94. long decodeCISCO(decode_results *results);
  95. #endif
  96. #ifdef SONY
  97. long decodeSony(decode_results *results);
  98. #endif
  99. #ifdef SANYO
  100. long decodeSanyo(decode_results *results);
  101. #endif
  102. #ifdef MITSUBISHI
  103. long decodeMitsubishi(decode_results *results);
  104. #endif
  105. #ifdef RC5
  106. long decodeRC5(decode_results *results);
  107. #endif
  108. #ifdef RC6
  109. long decodeRC6(decode_results *results);
  110. #endif
  111. #ifdef PANASONIC
  112. long decodePanasonic(decode_results *results);
  113. #endif
  114. #ifdef LG
  115. long decodeLG(decode_results *results);
  116. #endif
  117. #ifdef JVC
  118. long decodeJVC(decode_results *results);
  119. #endif
  120. #ifdef SAMSUNG
  121. long decodeSAMSUNG(decode_results *results);
  122. #endif
  123.  
  124. #ifdef WHYNTER
  125. long decodeWhynter(decode_results *results);
  126. #endif
  127.  
  128. #ifdef AIWA_RC_T501
  129. long decodeAiwaRCT501(decode_results *results);
  130. #endif
  131.  
  132. long decodeHash(decode_results *results);
  133. int compare(unsigned int oldval, unsigned int newval);
  134.  
  135. } ;
  136.  
  137. // Only used for testing; can remove virtual for shorter code
  138. #ifdef TEST
  139. #define VIRTUAL virtual
  140. #else
  141. #define VIRTUAL
  142. #endif
  143.  
  144. class IRsend
  145. {
  146. public:
  147. IRsend() {}
  148. void sendRaw(unsigned int buf[], int len, int hz);
  149. void sendRC5(unsigned long data, int nbits);
  150. void sendRC6(unsigned long data, int nbits);
  151.  
  152. #ifdef WHYNTER
  153. void sendWhynter(unsigned long data, int nbits);
  154. #endif
  155. #ifdef NEC
  156. void sendNEC(unsigned long data, int nbits);
  157. #endif
  158. #ifdef CISCO
  159. void sendCISCO(unsigned long data, int nbits);
  160. #endif
  161. #ifdef SONY
  162. void sendSony(unsigned long data, int nbits);
  163. // Neither Sanyo nor Mitsubishi send is implemented yet
  164. // void sendSanyo(unsigned long data, int nbits);
  165. // void sendMitsubishi(unsigned long data, int nbits);
  166. #endif
  167.  
  168. #ifdef DISH
  169. void sendDISH(unsigned long data, int nbits);
  170. #endif
  171. #ifdef SHARP
  172. void sendSharp(unsigned int address, unsigned int command);
  173. void sendSharpRaw(unsigned long data, int nbits);
  174. #endif
  175. #ifdef IRsendSHARP
  176. void sendSharp(unsigned long data, int nbits);
  177. #endif
  178. #ifdef PANASONIC
  179. void sendPanasonic(unsigned int address, unsigned long data);
  180. #endif
  181. #ifdef JVC
  182. 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.
  183. void sendAiwaRCT501(int code);
  184. // private:
  185. #endif
  186. #ifdef SAMSUNG
  187. void sendSAMSUNG(unsigned long data, int nbits);
  188. #endif
  189. void enableIROut(int khz);
  190. VIRTUAL void mark(int usec);
  191. VIRTUAL void space(int usec);
  192. } ;
  193.  
  194. // Some useful constants
  195.  
  196. #define USECPERTICK 50 // microseconds per clock interrupt tick
  197. #define RAWBUF 100 // Length of raw duration buffer
  198.  
  199. // Marks tend to be 100us too long, and spaces 100us too short
  200. // when received due to sensor lag.
  201. #define MARK_EXCESS 100
  202.  
  203. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement