PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

IRremote.h 11KB

hace 3 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. //******************************************************************************
  2. // IRremote
  3. // Version 2.0.1 June, 2015
  4. // Copyright 2009 Ken Shirriff
  5. // For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
  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. #ifndef IRremote_h
  17. #define IRremote_h
  18. //------------------------------------------------------------------------------
  19. // The ISR header contains several useful macros the user may wish to use
  20. //
  21. #include "IRremoteInt.h"
  22. //------------------------------------------------------------------------------
  23. // Supported IR protocols
  24. // Each protocol you include costs memory and, during decode, costs time
  25. // Disable (set to 0) all the protocols you do not need/want!
  26. //
  27. #define DECODE_RC5 1
  28. #define SEND_RC5 1
  29. #define DECODE_RC6 1
  30. #define SEND_RC6 1
  31. #define DECODE_NEC 1
  32. #define SEND_NEC 1
  33. #define DECODE_SONY 1
  34. #define SEND_SONY 1
  35. #define DECODE_PANASONIC 1
  36. #define SEND_PANASONIC 1
  37. #define DECODE_JVC 1
  38. #define SEND_JVC 1
  39. #define DECODE_SAMSUNG 1
  40. #define SEND_SAMSUNG 1
  41. #define DECODE_WHYNTER 1
  42. #define SEND_WHYNTER 1
  43. #define DECODE_AIWA_RC_T501 1
  44. #define SEND_AIWA_RC_T501 1
  45. #define DECODE_LG 1
  46. #define SEND_LG 1
  47. #define DECODE_SANYO 1
  48. #define SEND_SANYO 0 // NOT WRITTEN
  49. #define DECODE_MITSUBISHI 1
  50. #define SEND_MITSUBISHI 0 // NOT WRITTEN
  51. #define DECODE_DISH 0 // NOT WRITTEN
  52. #define SEND_DISH 1
  53. #define DECODE_SHARP 0 // NOT WRITTEN
  54. #define SEND_SHARP 1
  55. #define DECODE_DENON 1
  56. #define SEND_DENON 1
  57. #define DECODE_PRONTO 0 // This function doe not logically make sense
  58. #define SEND_PRONTO 1
  59. #define DECODE_LEGO_PF 0 // NOT WRITTEN
  60. #define SEND_LEGO_PF 1
  61. //------------------------------------------------------------------------------
  62. // When sending a Pronto code we request to send either the "once" code
  63. // or the "repeat" code
  64. // If the code requested does not exist we can request to fallback on the
  65. // other code (the one we did not explicitly request)
  66. //
  67. // I would suggest that "fallback" will be the standard calling method
  68. // The last paragraph on this page discusses the rationale of this idea:
  69. // http://www.remotecentral.com/features/irdisp2.htm
  70. //
  71. #define PRONTO_ONCE false
  72. #define PRONTO_REPEAT true
  73. #define PRONTO_FALLBACK true
  74. #define PRONTO_NOFALLBACK false
  75. //------------------------------------------------------------------------------
  76. // An enumerated list of all supported formats
  77. // You do NOT need to remove entries from this list when disabling protocols!
  78. //
  79. typedef
  80. enum {
  81. UNKNOWN = -1,
  82. UNUSED = 0,
  83. RC5,
  84. RC6,
  85. NEC,
  86. SONY,
  87. PANASONIC,
  88. JVC,
  89. SAMSUNG,
  90. WHYNTER,
  91. AIWA_RC_T501,
  92. LG,
  93. SANYO,
  94. MITSUBISHI,
  95. DISH,
  96. SHARP,
  97. DENON,
  98. PRONTO,
  99. LEGO_PF,
  100. }
  101. decode_type_t;
  102. //------------------------------------------------------------------------------
  103. // Set DEBUG to 1 for lots of lovely debug output
  104. //
  105. #define DEBUG 0
  106. //------------------------------------------------------------------------------
  107. // Debug directives
  108. //
  109. #if DEBUG
  110. # define DBG_PRINT(...) Serial.print(__VA_ARGS__)
  111. # define DBG_PRINTLN(...) Serial.println(__VA_ARGS__)
  112. #else
  113. # define DBG_PRINT(...)
  114. # define DBG_PRINTLN(...)
  115. #endif
  116. //------------------------------------------------------------------------------
  117. // Mark & Space matching functions
  118. //
  119. int MATCH (int measured, int desired) ;
  120. int MATCH_MARK (int measured_ticks, int desired_us) ;
  121. int MATCH_SPACE (int measured_ticks, int desired_us) ;
  122. //------------------------------------------------------------------------------
  123. // Results returned from the decoder
  124. //
  125. class decode_results
  126. {
  127. public:
  128. decode_type_t decode_type; // UNKNOWN, NEC, SONY, RC5, ...
  129. unsigned int address; // Used by Panasonic & Sharp [16-bits]
  130. unsigned long value; // Decoded value [max 32-bits]
  131. int bits; // Number of bits in decoded value
  132. volatile unsigned int *rawbuf; // Raw intervals in 50uS ticks
  133. int rawlen; // Number of records in rawbuf
  134. int overflow; // true iff IR raw code too long
  135. };
  136. //------------------------------------------------------------------------------
  137. // Decoded value for NEC when a repeat code is received
  138. //
  139. #define REPEAT 0xFFFFFFFF
  140. //------------------------------------------------------------------------------
  141. // Main class for receiving IR
  142. //
  143. class IRrecv
  144. {
  145. public:
  146. IRrecv (int recvpin) ;
  147. IRrecv (int recvpin, int blinkpin);
  148. void blink13 (int blinkflag) ;
  149. int decode (decode_results *results) ;
  150. void enableIRIn ( ) ;
  151. bool isIdle ( ) ;
  152. void resume ( ) ;
  153. private:
  154. long decodeHash (decode_results *results) ;
  155. int compare (unsigned int oldval, unsigned int newval) ;
  156. //......................................................................
  157. # if (DECODE_RC5 || DECODE_RC6)
  158. // This helper function is shared by RC5 and RC6
  159. int getRClevel (decode_results *results, int *offset, int *used, int t1) ;
  160. # endif
  161. # if DECODE_RC5
  162. bool decodeRC5 (decode_results *results) ;
  163. # endif
  164. # if DECODE_RC6
  165. bool decodeRC6 (decode_results *results) ;
  166. # endif
  167. //......................................................................
  168. # if DECODE_NEC
  169. bool decodeNEC (decode_results *results) ;
  170. # endif
  171. //......................................................................
  172. # if DECODE_SONY
  173. bool decodeSony (decode_results *results) ;
  174. # endif
  175. //......................................................................
  176. # if DECODE_PANASONIC
  177. bool decodePanasonic (decode_results *results) ;
  178. # endif
  179. //......................................................................
  180. # if DECODE_JVC
  181. bool decodeJVC (decode_results *results) ;
  182. # endif
  183. //......................................................................
  184. # if DECODE_SAMSUNG
  185. bool decodeSAMSUNG (decode_results *results) ;
  186. # endif
  187. //......................................................................
  188. # if DECODE_WHYNTER
  189. bool decodeWhynter (decode_results *results) ;
  190. # endif
  191. //......................................................................
  192. # if DECODE_AIWA_RC_T501
  193. bool decodeAiwaRCT501 (decode_results *results) ;
  194. # endif
  195. //......................................................................
  196. # if DECODE_LG
  197. bool decodeLG (decode_results *results) ;
  198. # endif
  199. //......................................................................
  200. # if DECODE_SANYO
  201. bool decodeSanyo (decode_results *results) ;
  202. # endif
  203. //......................................................................
  204. # if DECODE_MITSUBISHI
  205. bool decodeMitsubishi (decode_results *results) ;
  206. # endif
  207. //......................................................................
  208. # if DECODE_DISH
  209. bool decodeDish (decode_results *results) ; // NOT WRITTEN
  210. # endif
  211. //......................................................................
  212. # if DECODE_SHARP
  213. bool decodeSharp (decode_results *results) ; // NOT WRITTEN
  214. # endif
  215. //......................................................................
  216. # if DECODE_DENON
  217. bool decodeDenon (decode_results *results) ;
  218. # endif
  219. //......................................................................
  220. # if DECODE_LEGO_PF
  221. bool decodeLegoPowerFunctions (decode_results *results) ;
  222. # endif
  223. } ;
  224. //------------------------------------------------------------------------------
  225. // Main class for sending IR
  226. //
  227. class IRsend
  228. {
  229. public:
  230. IRsend () { }
  231. void custom_delay_usec (unsigned long uSecs);
  232. void enableIROut (int khz) ;
  233. void mark (unsigned int usec) ;
  234. void space (unsigned int usec) ;
  235. void sendRaw (const unsigned int buf[], unsigned int len, unsigned int hz) ;
  236. //......................................................................
  237. # if SEND_RC5
  238. void sendRC5 (unsigned long data, int nbits) ;
  239. # endif
  240. # if SEND_RC6
  241. void sendRC6 (unsigned long data, int nbits) ;
  242. # endif
  243. //......................................................................
  244. # if SEND_NEC
  245. void sendNEC (unsigned long data, int nbits) ;
  246. # endif
  247. //......................................................................
  248. # if SEND_SONY
  249. void sendSony (unsigned long data, int nbits) ;
  250. # endif
  251. //......................................................................
  252. # if SEND_PANASONIC
  253. void sendPanasonic (unsigned int address, unsigned long data) ;
  254. # endif
  255. //......................................................................
  256. # if SEND_JVC
  257. // JVC does NOT repeat by sending a separate code (like NEC does).
  258. // The JVC protocol repeats by skipping the header.
  259. // To send a JVC repeat signal, send the original code value
  260. // and set 'repeat' to true
  261. void sendJVC (unsigned long data, int nbits, bool repeat) ;
  262. # endif
  263. //......................................................................
  264. # if SEND_SAMSUNG
  265. void sendSAMSUNG (unsigned long data, int nbits) ;
  266. # endif
  267. //......................................................................
  268. # if SEND_WHYNTER
  269. void sendWhynter (unsigned long data, int nbits) ;
  270. # endif
  271. //......................................................................
  272. # if SEND_AIWA_RC_T501
  273. void sendAiwaRCT501 (int code) ;
  274. # endif
  275. //......................................................................
  276. # if SEND_LG
  277. void sendLG (unsigned long data, int nbits) ;
  278. # endif
  279. //......................................................................
  280. # if SEND_SANYO
  281. void sendSanyo ( ) ; // NOT WRITTEN
  282. # endif
  283. //......................................................................
  284. # if SEND_MISUBISHI
  285. void sendMitsubishi ( ) ; // NOT WRITTEN
  286. # endif
  287. //......................................................................
  288. # if SEND_DISH
  289. void sendDISH (unsigned long data, int nbits) ;
  290. # endif
  291. //......................................................................
  292. # if SEND_SHARP
  293. void sendSharpRaw (unsigned long data, int nbits) ;
  294. void sendSharp (unsigned int address, unsigned int command) ;
  295. # endif
  296. //......................................................................
  297. # if SEND_DENON
  298. void sendDenon (unsigned long data, int nbits) ;
  299. # endif
  300. //......................................................................
  301. # if SEND_PRONTO
  302. void sendPronto (char* code, bool repeat, bool fallback) ;
  303. # endif
  304. //......................................................................
  305. # if SEND_LEGO_PF
  306. void sendLegoPowerFunctions (uint16_t data, bool repeat = true) ;
  307. # endif
  308. } ;
  309. #endif