IR-PC-HID-Remote.ino 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. //------------------------------------------------------------------------------
  2. // Include the IRremote library header
  3. //
  4. #include <IRremote.h>
  5. #include <HID-Project.h> // HID-Project 2.8.2
  6. bool sendHID = true;
  7. // ATTENTION - set ALL debug and useSerial to false in normal usage
  8. // as sending over Serial blocks the Arduino Leonardo unless a terminal application is connected!
  9. bool debug = false;
  10. bool debug2 = false;
  11. bool useSerial = false;
  12. // global conf vars
  13. unsigned int holdButton_releaseTimeout = 120;
  14. #define BTN_1 1
  15. #define BTN_2 2
  16. #define BTN_3 3
  17. #define BTN_4 4
  18. #define BTN_5 5
  19. #define BTN_6 6
  20. #define BTN_7 7
  21. #define BTN_8 8
  22. #define BTN_9 9
  23. #define BTN_0 10
  24. #define BTN_PLAY 11
  25. #define BTN_PAUSE 12
  26. #define BTN_STOP 13
  27. #define BTN_REC 14
  28. #define BTN_REWD 15
  29. #define BTN_FFWD 16
  30. #define BTN_PREV 17
  31. #define BTN_NEXT 18
  32. #define BTN_LEFT 20
  33. #define BTN_RIGHT 21
  34. #define BTN_UP 22
  35. #define BTN_DOWN 23
  36. #define BTN_OK_ENTER 24
  37. #define BTN_BACK 25
  38. #define BTN_MENU 26
  39. #define BTN_HOME 27
  40. #define BTN_RED 30
  41. #define BTN_GREEN 31
  42. #define BTN_YELLOW 32
  43. #define BTN_BLUE 33
  44. #define BTN_STATUS 34
  45. #define BTN_RETURN 35
  46. #define BTN_SETUP 36
  47. #define BTN_GUIDE 37
  48. #define BTN_RADIO 38
  49. #define BTN_PREVCH 39
  50. #define BTN_CH_DOWN 40
  51. #define BTN_CH_UP 41
  52. #define BTN_VOL_DOWN 42
  53. #define BTN_VOL_UP 43
  54. #define BTN_MUTE 44
  55. #define BTN_POWER 45
  56. #define BTN_TV 46
  57. #define BTN_VIDEOS 47
  58. #define BTN_MUSIC 48
  59. #define BTN_PICTURES 49
  60. #define BTN_STAR 50
  61. #define BTN_HASH 51
  62. #define BTN_PAGE_UP 60
  63. #define BTN_PAGE_DOWN 61
  64. #define BTN_CONTEXT 62
  65. #define BTN_INFO 63
  66. #define BTN_DUMMY 255
  67. // Button Modes
  68. #define BUTTONMODE_ONCE 0
  69. #define BUTTONMODE_REPEAT 1
  70. #define BUTTONMODE_HOLD 2
  71. // Remote Types
  72. #define REMOTETYPE_RC5 0
  73. #define REMOTETYPE_RC6 1
  74. // global vars
  75. unsigned long lastNECcode;
  76. unsigned long lastReceivedMillis;
  77. unsigned long holdButton_lastTriggeredMillis = 0;
  78. //------------------------------------------------------------------------------
  79. // Tell IRremote which Arduino pin is connected to the IR Receiver (TSOP4838)
  80. //
  81. int recvPin = 2;
  82. IRrecv irrecv(recvPin);
  83. //+=============================================================================
  84. // Configure the Arduino
  85. //
  86. void setup ( )
  87. {
  88. if(useSerial || debug || debug2) Serial.begin(115200);
  89. BootKeyboard.begin();
  90. Consumer.begin();
  91. System.begin();
  92. irrecv.enableIRIn(); // Start the receiver
  93. }
  94. //+=============================================================================
  95. // Dump out the decode_results structure.
  96. //
  97. void dumpInfo (decode_results *results)
  98. {
  99. // Check if the buffer overflowed
  100. // if (results->overflow) {
  101. // Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWLEN");
  102. // return;
  103. // }
  104. if (debug) {
  105. if ((results->decode_type != UNKNOWN && results->bits > 0) && debug2) {
  106. if (useSerial) {
  107. Serial.println();
  108. Serial.println();
  109. Serial.print(F("RECEIVED: "));
  110. encoding(results);
  111. Serial.print(";0x");
  112. ircode(results);
  113. Serial.print(";");
  114. Serial.print(results->bits, DEC);
  115. Serial.println();
  116. }
  117. }
  118. }
  119. // RC5 CODES
  120. if (results->decode_type == RC5 && results->bits == 12) {
  121. // RC5 code
  122. // 3 bytes, start byte for this device is 0xF or 0x7 depending on toggle bit
  123. uint8_t _currRC5Code = results->value ^ 0xF00;
  124. uint8_t _currRC5Pref = ( _currRC5Code ^ results->value ) >> 8;
  125. if (debug) {
  126. Serial.print(F(" _currRC5Code=0x"));
  127. Serial.print(_currRC5Code, HEX);
  128. Serial.print(F(" _currRC5Pref=0x"));
  129. Serial.println(_currRC5Pref, HEX);
  130. }
  131. // Hauppauge Remote
  132. if (_currRC5Code == 0xBD) { // POWER
  133. //handleButton_RCx(BTN_POWER, BUTTONMODE_REPEAT, _currRC5Pref, REMOTETYPE_RC5);
  134. handlePowerButton();
  135. }
  136. else if (_currRC5Code == 0x90) { // VOL+
  137. //handleButton_RCx(BTN_VOL_UP, BUTTONMODE_REPEAT, _currRC5Pref, REMOTETYPE_RC5);
  138. handleButton_RCx(BTN_VOL_UP, BUTTONMODE_HOLD, _currRC5Pref, REMOTETYPE_RC5);
  139. }
  140. else if (_currRC5Code == 0x91) { // VOL-
  141. //handleButton_RCx(BTN_VOL_DOWN, BUTTONMODE_REPEAT, _currRC5Pref, REMOTETYPE_RC5);
  142. handleButton_RCx(BTN_VOL_DOWN, BUTTONMODE_HOLD, _currRC5Pref, REMOTETYPE_RC5);
  143. }
  144. else if (_currRC5Code == 0xB2) { // REWIND
  145. //handleButton_RCx(BTN_REWD, BUTTONMODE_REPEAT, _currRC5Pref, REMOTETYPE_RC5);
  146. //handleButton_RCx(BTN_REWD, BUTTONMODE_HOLD, _currRC5Pref, REMOTETYPE_RC5);
  147. handleButton_RCx(BTN_REWD, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  148. }
  149. else if (_currRC5Code == 0xB4) { // FAST_FORWARD
  150. //handleButton_RCx(BTN_FFWD, BUTTONMODE_REPEAT, _currRC5Pref, REMOTETYPE_RC5);
  151. //handleButton_RCx(BTN_FFWD, BUTTONMODE_HOLD, _currRC5Pref, REMOTETYPE_RC5);
  152. handleButton_RCx(BTN_FFWD, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  153. }
  154. else if (_currRC5Code == 0xA1) { // CH- used as page down
  155. handleButton_RCx(BTN_CH_DOWN, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  156. }
  157. else if (_currRC5Code == 0xA0) { // CH+ used as page up
  158. handleButton_RCx(BTN_CH_UP, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  159. }
  160. else if (_currRC5Code == 0x94) { // ARROW UP
  161. //handleButton_RCx(BTN_UP, BUTTONMODE_REPEAT, _currRC5Pref, REMOTETYPE_RC5);
  162. handleButton_RCx(BTN_UP, BUTTONMODE_HOLD, _currRC5Pref, REMOTETYPE_RC5);
  163. }
  164. else if (_currRC5Code == 0x95) { // ARROW DOWN
  165. //handleButton_RCx(BTN_DOWN, BUTTONMODE_REPEAT, _currRC5Pref, REMOTETYPE_RC5);
  166. handleButton_RCx(BTN_DOWN, BUTTONMODE_HOLD, _currRC5Pref, REMOTETYPE_RC5);
  167. }
  168. else if (_currRC5Code == 0x96) { // ARROW LEFT
  169. //handleButton_RCx(BTN_LEFT, BUTTONMODE_REPEAT, _currRC5Pref, REMOTETYPE_RC5);
  170. handleButton_RCx(BTN_LEFT, BUTTONMODE_HOLD, _currRC5Pref, REMOTETYPE_RC5);
  171. }
  172. else if (_currRC5Code == 0x97) { // ARROW RIGHT
  173. //handleButton_RCx(BTN_RIGHT, BUTTONMODE_REPEAT, _currRC5Pref, REMOTETYPE_RC5);
  174. handleButton_RCx(BTN_RIGHT, BUTTONMODE_HOLD, _currRC5Pref, REMOTETYPE_RC5);
  175. }
  176. else if (_currRC5Code == 0xA5) { // OK
  177. //handleButton_RCx(BTN_OK_ENTER, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  178. handleButton_RCx(BTN_OK_ENTER, BUTTONMODE_HOLD, _currRC5Pref, REMOTETYPE_RC5);
  179. }
  180. else if (_currRC5Code == 0x9F) { // BACK/EXIT
  181. //handleButton_RCx(BTN_BACK, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  182. handleButton_RCx(BTN_BACK, BUTTONMODE_HOLD, _currRC5Pref, REMOTETYPE_RC5);
  183. }
  184. else if (_currRC5Code == 0x8D) { // i/MENU
  185. handleButton_RCx(BTN_MENU, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  186. }
  187. else if (_currRC5Code == 0x92) { // PREV.CH
  188. handleButton_RCx(BTN_CONTEXT, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  189. }
  190. else if (_currRC5Code == 0x8F) { // MUTE
  191. handleButton_RCx(BTN_MUTE, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  192. }
  193. else if (_currRC5Code == 0xBB) { // HOME/GO
  194. //handleButton_RCx(BTN_HOME, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  195. handleTaskSwitchButton();
  196. }
  197. else if (_currRC5Code == 0x9C) { // TV
  198. handleButton_RCx(BTN_TV, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  199. }
  200. else if (_currRC5Code == 0x98) { // VIDEOS
  201. handleButton_RCx(BTN_VIDEOS, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  202. }
  203. else if (_currRC5Code == 0x99) { // MUSIC
  204. handleButton_RCx(BTN_MUSIC, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  205. }
  206. else if (_currRC5Code == 0x9A) { // PICTURES
  207. handleButton_RCx(BTN_PICTURES, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  208. }
  209. else if (_currRC5Code == 0x9B) { // GUIDE
  210. handleButton_RCx(BTN_GUIDE, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  211. }
  212. else if (_currRC5Code == 0x8C) { // RADIO
  213. handleButton_RCx(BTN_RADIO, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  214. }
  215. else if (_currRC5Code == 0xB7) { // REC
  216. handleButton_RCx(BTN_REC, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  217. }
  218. else if (_currRC5Code == 0xB6) { // STOP
  219. handleButton_RCx(BTN_STOP, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  220. }
  221. else if (_currRC5Code == 0xB5) { // PLAY
  222. handleButton_RCx(BTN_PLAY, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  223. }
  224. else if (_currRC5Code == 0xB0) { // PAUSE
  225. handleButton_RCx(BTN_PAUSE, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  226. }
  227. else if (_currRC5Code == 0xA4) { // PREV
  228. handleButton_RCx(BTN_PREV, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  229. }
  230. else if (_currRC5Code == 0x9E) { // NEXT
  231. handleButton_RCx(BTN_NEXT, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  232. }
  233. else if (_currRC5Code == 0x81) { // 1
  234. handleButton_RCx(BTN_1, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  235. }
  236. else if (_currRC5Code == 0x82) { // 2
  237. handleButton_RCx(BTN_2, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  238. }
  239. else if (_currRC5Code == 0x83) { // 3
  240. handleButton_RCx(BTN_3, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  241. }
  242. else if (_currRC5Code == 0x84) { // 4
  243. handleButton_RCx(BTN_4, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  244. }
  245. else if (_currRC5Code == 0x85) { // 5
  246. handleButton_RCx(BTN_5, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  247. }
  248. else if (_currRC5Code == 0x86) { // 6
  249. handleButton_RCx(BTN_6, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  250. }
  251. else if (_currRC5Code == 0x87) { // 7
  252. handleButton_RCx(BTN_7, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  253. }
  254. else if (_currRC5Code == 0x88) { // 8
  255. handleButton_RCx(BTN_8, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  256. }
  257. else if (_currRC5Code == 0x89) { // 9
  258. handleButton_RCx(BTN_9, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  259. }
  260. else if (_currRC5Code == 0x80) { // 0
  261. handleButton_RCx(BTN_0, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  262. }
  263. else if (_currRC5Code == 0x8A) { // *
  264. handleButton_RCx(BTN_STAR, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  265. }
  266. else if (_currRC5Code == 0x8E) { // #
  267. handleButton_RCx(BTN_HASH, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  268. }
  269. else if (_currRC5Code == 0x8B) { // RED
  270. handleButton_RCx(BTN_RED, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  271. }
  272. else if (_currRC5Code == 0xAE) { // GREEN
  273. handleButton_RCx(BTN_GREEN, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  274. }
  275. else if (_currRC5Code == 0xB8) { // YELLOW
  276. handleButton_RCx(BTN_YELLOW, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  277. }
  278. else if (_currRC5Code == 0xA9) { // BLUE
  279. handleButton_RCx(BTN_BLUE, BUTTONMODE_ONCE, _currRC5Pref, REMOTETYPE_RC5);
  280. }
  281. } // END RC5 CODES
  282. // SONY CODES
  283. else if (results->decode_type == SONY && results->bits == 12) {
  284. // DENON RC-1014 REMOTE, Mode AUDIO/CD, MEDIA KEYS (set to SONY CD Player)
  285. if (results->value == 0x9D1) { // PAUSE
  286. handleButton(BTN_PAUSE, false);
  287. }
  288. else if (results->value == 0xCD1) { // REWD
  289. handleButton(BTN_REWD, true);
  290. }
  291. else if (results->value == 0x2D1) { // FFWD
  292. handleButton(BTN_FFWD, true);
  293. }
  294. else if (results->value == 0xD1) { // PREV
  295. handleButton(BTN_PREV, false);
  296. }
  297. else if (results->value == 0x8D1) { // NEXT
  298. handleButton(BTN_NEXT, false);
  299. }
  300. else if (results->value == 0x4D1) { // PLAY
  301. handleButton(BTN_PLAY, false);
  302. }
  303. else if (results->value == 0x1D1) { // STOP
  304. handleButton(BTN_STOP, false);
  305. }
  306. } // END SONY CODES
  307. // RC6 CODES
  308. else if (results->decode_type == RC6 && results->bits == 20) {
  309. unsigned int _currRC6Code = results->value ^ 0xF0000;
  310. uint8_t _currRC6Pref = ( _currRC6Code ^ results->value ) >> 16;
  311. if (debug) {
  312. Serial.print(F(" _currRC6Code=0x"));
  313. Serial.print(_currRC6Code, HEX);
  314. Serial.print(F(" _currRC6Pref=0x"));
  315. Serial.println(_currRC6Pref, HEX);
  316. }
  317. // Pioneer Remote in BD mode, configured code preset to Sat-PVR/Philips 6139 (RC6 code)
  318. // with the most important buttons available.
  319. // Missing buttons configured using learning function, which does not work well with RCx format due to the toggle bit,
  320. // so i used an old unused IR remote with NEC code for these, which will be OK for non-repeating buttons.
  321. if (_currRC6Code == 0x270C) { // POWER (of SOURCE)
  322. //handleButton_RCx(BTN_POWER, BUTTONMODE_REPEAT, _currRC6Pref, REMOTETYPE_RC6);
  323. handlePowerButton();
  324. }
  325. else if (_currRC6Code == 0x275C) { // OK/ENTER
  326. //handleButton_RCx(BTN_OK_ENTER, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  327. handleButton_RCx(BTN_OK_ENTER, BUTTONMODE_HOLD, _currRC6Pref, REMOTETYPE_RC6);
  328. }
  329. else if (_currRC6Code == 0x2783) { // RETURN/BACK - bottom right at control pad
  330. //handleButton_RCx(BTN_BACK, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  331. handleButton_RCx(BTN_BACK, BUTTONMODE_HOLD, _currRC6Pref, REMOTETYPE_RC6);
  332. }
  333. else if (_currRC6Code == 0x275A) { // LEFT
  334. //handleButton_RCx(BTN_LEFT, BUTTONMODE_REPEAT, _currRC6Pref, REMOTETYPE_RC6);
  335. handleButton_RCx(BTN_LEFT, BUTTONMODE_HOLD, _currRC6Pref, REMOTETYPE_RC6);
  336. }
  337. else if (_currRC6Code == 0x275B) { // RIGHT
  338. //handleButton_RCx(BTN_RIGHT, BUTTONMODE_REPEAT, _currRC6Pref, REMOTETYPE_RC6);
  339. handleButton_RCx(BTN_RIGHT, BUTTONMODE_HOLD, _currRC6Pref, REMOTETYPE_RC6);
  340. }
  341. else if (_currRC6Code == 0x2758) { // UP
  342. //handleButton_RCx(BTN_UP, BUTTONMODE_REPEAT, _currRC6Pref, REMOTETYPE_RC6);
  343. handleButton_RCx(BTN_UP, BUTTONMODE_HOLD, _currRC6Pref, REMOTETYPE_RC6);
  344. }
  345. else if (_currRC6Code == 0x2759) { // DOWN
  346. //handleButton_RCx(BTN_DOWN, BUTTONMODE_REPEAT, _currRC6Pref, REMOTETYPE_RC6);
  347. handleButton_RCx(BTN_DOWN, BUTTONMODE_HOLD, _currRC6Pref, REMOTETYPE_RC6);
  348. }
  349. else if (_currRC6Code == 0x27CC) { // HOME MENU - bottom left at control pad
  350. handleButton_RCx(BTN_MENU, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  351. }
  352. else if (_currRC6Code == 0x2743) { // X - AUDIO PARAMETER - top left at control pad
  353. //handleButton_RCx(BTN_HOME, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  354. handleTaskSwitchButton();
  355. }
  356. else if (_currRC6Code == 0x2754) { // VIDEO PARAMETER - top right at control pad
  357. //handleButton_RCx(BTN_MENU, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  358. handleButton_RCx(BTN_CONTEXT, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  359. }
  360. else if (_currRC6Code == 0x2771) { // PLAY
  361. handleButton_RCx(BTN_PLAY, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  362. }
  363. else if (_currRC6Code == 0x276F) { // PAUSE
  364. handleButton_RCx(BTN_PAUSE, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  365. }
  366. else if (_currRC6Code == 0x276E) { // STOP
  367. handleButton_RCx(BTN_STOP, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  368. }
  369. else if (_currRC6Code == 0x276D) { // PREVIOUS
  370. handleButton_RCx(BTN_PREV, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  371. }
  372. else if (_currRC6Code == 0x2770) { // NEXT
  373. handleButton_RCx(BTN_NEXT, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  374. }
  375. else if (_currRC6Code == 0x2701) { // 1
  376. handleButton_RCx(BTN_1, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  377. }
  378. else if (_currRC6Code == 0x2702) { // 2
  379. handleButton_RCx(BTN_2, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  380. }
  381. else if (_currRC6Code == 0x2703) { // 3
  382. handleButton_RCx(BTN_3, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  383. }
  384. else if (_currRC6Code == 0x2704) { // 4
  385. handleButton_RCx(BTN_4, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  386. }
  387. else if (_currRC6Code == 0x2705) { // 5
  388. handleButton_RCx(BTN_5, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  389. }
  390. else if (_currRC6Code == 0x2706) { // 6
  391. handleButton_RCx(BTN_6, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  392. }
  393. else if (_currRC6Code == 0x2707) { // 7
  394. handleButton_RCx(BTN_7, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  395. }
  396. else if (_currRC6Code == 0x2708) { // 8
  397. handleButton_RCx(BTN_8, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  398. }
  399. else if (_currRC6Code == 0x2709) { // 9
  400. handleButton_RCx(BTN_9, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  401. }
  402. else if (_currRC6Code == 0x2700) { // 0
  403. handleButton_RCx(BTN_0, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  404. }
  405. else if (_currRC6Code == 0x2720) { // CH+
  406. handleButton_RCx(BTN_CH_UP, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  407. }
  408. else if (_currRC6Code == 0x2721) { // CH-
  409. handleButton_RCx(BTN_CH_DOWN, BUTTONMODE_ONCE, _currRC6Pref, REMOTETYPE_RC6);
  410. }
  411. // Buttons in NEC CODE due to limitations of this RC:
  412. // RED
  413. // GREEN
  414. // YELLOW
  415. // BLUE
  416. // REWIND
  417. // FAST FORWARD
  418. // ./CLR
  419. // CLASS/ENTER
  420. // AUDIO
  421. // INFO/DISP
  422. } // END RC6 CODES
  423. // NEC CODES - used also for Pioneer remote codes here (Pioneer code consists of 2 NEC codes and is not directly supported by Arduino IRRemote.h)
  424. else if (results->decode_type == NEC && results->bits == 32) {
  425. // Pioneer Remote in BD mode, configured code preset to Sat-PVR/Philips 6139 (RC6 code)
  426. // -> missing/unused buttons "learned" with codes in NEC format
  427. if (results->value == 0x4FF18E7) { // RED
  428. handleButton(BTN_RED, false);
  429. }
  430. else if (results->value == 0x4FF02FD) { // GREEN
  431. handleButton(BTN_GREEN, false);
  432. }
  433. else if (results->value == 0x4FF827D) { // YELLOW
  434. handleButton(BTN_YELLOW, false);
  435. }
  436. else if (results->value == 0x4FF38C7) { // BLUE
  437. handleButton(BTN_BLUE, false);
  438. }
  439. else if (results->value == 0x4FFB847) { // REWIND
  440. handleButton(BTN_REWD, false);
  441. }
  442. else if (results->value == 0x4FF08F7) { // FAST FORWARD
  443. handleButton(BTN_FFWD, false);
  444. }
  445. else if (results->value == 0x4FF6897) { // ./CLR
  446. //handleButton(BTN_, false);
  447. }
  448. else if (results->value == 0x4FF9867) { // CLASS/ENTER
  449. handleButton(BTN_OK_ENTER, false);
  450. }
  451. else if (results->value == 0x4FFF807) { // AUDIO
  452. //handleButton(BTN_, false);
  453. }
  454. else if (results->value == 0x4FF7887) { // DISPLAY/INFO
  455. handleButton(BTN_INFO, false);
  456. }
  457. // Pioneer Codes - here we have to take 2 received codes into account, so we check against the last received that we stored in a global variable then ;-)
  458. // // Pioneer 2238 code for BD ---- NOT UNUSED ANY MORE
  459. // if (lastNECcode == 0xD52A34CB && results->value == 0xF50AC639) { // LEFT
  460. // handleButton(BTN_LEFT, true);
  461. // }
  462. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A26D9) { // RIGHT
  463. // handleButton(BTN_RIGHT, true);
  464. // }
  465. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A4FB0) { // UP
  466. // handleButton(BTN_UP, true);
  467. // }
  468. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50ACF30) { // DOWN
  469. // handleButton(BTN_DOWN, true);
  470. // }
  471. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50AF708) { // ENTER + CLASS ENTER
  472. // handleButton(BTN_OK_ENTER, false);
  473. // }
  474. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A3DC2) { // POWER
  475. // //handleButton(BTN_POWER, false);
  476. // handlePowerButton();
  477. // }
  478. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A2DD2) { // AUDIO PARAMETER - top left at control pad
  479. // //handleButton(BTN_, false);
  480. // }
  481. // else if (lastNECcode == 0xD52A54AB && results->value == 0xF50A3CC3) { // VIDEO PARAMETER - top right at control pad
  482. // //handleButton(BTN_, false);
  483. // }
  484. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A0DF2) { // HOME MENU - bottom left at control pad
  485. // handleButton(BTN_MENU, false);
  486. // }
  487. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A2FD0) { // RETURN - bottom right at control pad
  488. // handleButton(BTN_BACK, false);
  489. // }
  490. // else if (lastNECcode == 0xD52A54AB && results->value == 0xF50A26D9) { // RED
  491. // handleButton(BTN_RED, false);
  492. // }
  493. // else if (lastNECcode == 0xD52A54AB && results->value == 0xF50AA659) { // GREEN
  494. // handleButton(BTN_GREEN, false);
  495. // }
  496. // else if (lastNECcode == 0xD52A54AB && results->value == 0xF50A1FE0) { // YELLOW
  497. // handleButton(BTN_YELLOW, false);
  498. // }
  499. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A9D62) { // BLUE
  500. // handleButton(BTN_BLUE, false);
  501. // }
  502. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A57A8) { // REWIND
  503. // handleButton(BTN_REWD, true);
  504. // }
  505. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A9768) { // FFWD
  506. // handleButton(BTN_FFWD, true);
  507. // }
  508. // else if (lastNECcode == 0xD52A44BB && results->value == 0xD52A44BB) { // PLAY
  509. // handleButton(BTN_PLAY, false);
  510. // }
  511. // else if (lastNECcode == 0xD52AE41B && results->value == 0xD52AE41B) { // PREVIOUS
  512. // handleButton(BTN_PREV, false);
  513. // }
  514. // else if (lastNECcode == 0xD52AC43B && results->value == 0xD52AC43B) { // PAUSE
  515. // handleButton(BTN_PAUSE, false);
  516. // }
  517. // else if (lastNECcode == 0xD52A04FB && results->value == 0xD52A04FB) { // STOP
  518. // handleButton(BTN_STOP, false);
  519. // }
  520. // else if (lastNECcode == 0xD52A649B && results->value == 0xD52A649B) { // NEXT TRACK
  521. // handleButton(BTN_NEXT, false);
  522. // }
  523. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A05FA) { // 0
  524. // handleButton(BTN_0, false);
  525. // }
  526. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A857A) { // 1
  527. // handleButton(BTN_1, false);
  528. // }
  529. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A45BA) { // 2
  530. // handleButton(BTN_2, false);
  531. // }
  532. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50AC53A) { // 3
  533. // handleButton(BTN_3, false);
  534. // }
  535. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A25DA) { // 4
  536. // handleButton(BTN_4, false);
  537. // }
  538. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50AA55A) { // 5
  539. // handleButton(BTN_5, false);
  540. // }
  541. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A659A) { // 6
  542. // handleButton(BTN_6, false);
  543. // }
  544. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50AE51A) { // 7
  545. // handleButton(BTN_7, false);
  546. // }
  547. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A15EA) { // 8
  548. // handleButton(BTN_8, false);
  549. // }
  550. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A956A) { // 9
  551. // handleButton(BTN_9, false);
  552. // }
  553. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50A7D82) { // AUDIO
  554. // //handleButton(BTN_POWER, false);
  555. // }
  556. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50AC738) { // DISP/INFO
  557. // //handleButton(BTN_POWER, false);
  558. // }
  559. // else if (lastNECcode == 0xD52A54AB && results->value == 0xF50A7689) { // CH_UP
  560. // handleButton(BTN_CH_UP, false);
  561. // }
  562. // else if (lastNECcode == 0xD52A54AB && results->value == 0xF50AF609) { // CH_DOWN
  563. // handleButton(BTN_CH_DOWN, false);
  564. // }
  565. // else if (lastNECcode == 0xD52A34CB && results->value == 0xF50AA758) { // ./CLR/D.ACCESS
  566. // //handleButton(BTN_POWER, false);
  567. // }
  568. // remember last NEC code
  569. lastNECcode = results->value;
  570. } // END NEC CODES
  571. }
  572. //+=============================================================================
  573. // The repeating section of the code
  574. //
  575. void loop ( )
  576. {
  577. decode_results results; // Somewhere to store the results
  578. if (irrecv.decode(&results)) { // Grab an IR code
  579. dumpInfo(&results); // Output the results (if not in ignore time window)
  580. irrecv.resume(); // Prepare for the next value
  581. }
  582. handlePowerButton_loop();
  583. handleTaskSwitchButton_loop();
  584. handleHoldButtons_loop(); // release all keys after timeout
  585. }