From 26deac42d0abcac247b3514373f50e00857b2e00 Mon Sep 17 00:00:00 2001 From: Markus Zehnder Date: Sun, 20 Mar 2016 18:29:48 +0100 Subject: [PATCH] Add power on/off, keyboard modifier, more key mappings --- README.md | 51 +++--- src/IR_USB_Keyboard/Debug.h | 12 +- src/IR_USB_Keyboard/IR_USB_Keyboard.ino | 199 ++++++++++++++++-------- src/IR_USB_Keyboard/Panasonic.h | 35 ++++- src/IR_USB_Keyboard/Sony.h | 17 +- 5 files changed, 210 insertions(+), 104 deletions(-) rewrite README.md (70%) diff --git a/README.md b/README.md dissimilarity index 70% index 3cd51d5..5284031 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,26 @@ -# arduino-kodi-ir-keyboard / IRLremote + BootKeyboard branch -Kodi optimized infrared USB keyboard for an Asus Chromebox running openELEC. - -IR device: Logitech Harmony 880 with remote profile: 'Panasonic TV TX-43CXW754' - -Testing with: -- SparkFun Pro Micro, ATmega32u4 (5V, 16MHz) -- Arduino IDE 1.6.7 -- HID Project 2.4.3 -- IRLremote 1.7.4 - -Initial proof of concept with HID-Project instead of standard Keyboard library: -- Kodi control works pretty well already :-) -- key repeat works -- boot protocol mode works (tested on a MacMini) - -## Issues: -- Most promising branch yet :) -- IRLremote doesn't work with Logitech Plex Remote profile. Now (ab)using Panasonic TV TX-43CXW754 device template. -- Watch dog reset doesn't work, according to Google this is most likely an Arduino bootloader bug. - -## TODO: -- Power off / sleep / wakeup -- CTRL+D / CTRL+W key combinations for boot selection -- Chromebox hardware modification to control power toggle switch with Arduino +# arduino-kodi-ir-keyboard +(IRLremote + BootKeyboard branch) + +Kodi optimized infrared USB keyboard for an Asus Chromebox running openELEC. + +IR device: Logitech Harmony 880 with remote profile: 'Panasonic TV TX-43CXW754' + +Tested with: +- Arduino Leonardo & SparkFun Pro Micro, ATmega32u4 (5V, 16MHz) +- Arduino IDE 1.6.7 +- [HID Project](https://github.com/NicoHood/HID "HID Project") 2.4.3 +- [IRLremote](https://github.com/NicoHood/IRLremote "IRLremote") 1.7.4 + +## Features +- Full Kodi control (at least what I use ;) +- Power on / off with Chromebox hardware modification +- Key repeat +- Boot protocol mode (tested on a MacMini) + +## Issues +- Watch dog reset doesn't work, according to Google this is most likely an Arduino bootloader bug. +- KEY_QUOTE doesn't work with non-us keyboard layout + +## TODO +- CTRL+D / CTRL+W key commands for boot selection +- sleep / wakeup (IF openELEC supports it) diff --git a/src/IR_USB_Keyboard/Debug.h b/src/IR_USB_Keyboard/Debug.h index b2ba6e6..615bdc4 100644 --- a/src/IR_USB_Keyboard/Debug.h +++ b/src/IR_USB_Keyboard/Debug.h @@ -2,11 +2,15 @@ #define Debug_H #ifdef DEBUG_SKETCH - #define DEBUG_PRINT(...) Serial.print(__VA_ARGS__); - #define DEBUG_PRINTLN(...) Serial.println(__VA_ARGS__); + #ifndef DEBUG_OUT + // TODO enhance with 2nd serial port and LCD output + #define DEBUG_OUT Serial + #endif + #define DEBUG_PRINT(...) DEBUG_OUT.print(__VA_ARGS__); + #define DEBUG_PRINTLN(...) DEBUG_OUT.println(__VA_ARGS__); #else - #define DEBUG_PRINT(...) - #define DEBUG_PRINTLN(...) + #define DEBUG_PRINT(...) + #define DEBUG_PRINTLN(...) #endif #endif diff --git a/src/IR_USB_Keyboard/IR_USB_Keyboard.ino b/src/IR_USB_Keyboard/IR_USB_Keyboard.ino index 74819dd..75efd2c 100644 --- a/src/IR_USB_Keyboard/IR_USB_Keyboard.ino +++ b/src/IR_USB_Keyboard/IR_USB_Keyboard.ino @@ -25,29 +25,22 @@ SOFTWARE. /* IR to USB keyboard optimized for KODI openELEC running on Asus Chromebox. * IR device: Logitech Harmony 880 with remote profile: 'Panasonic TV TX-43CXW754' * - * Initial proof of concept. - * - * Testing with: - * - SparkFun Pro Micro, ATmega32u4 (5V, 16MHz) + * Tested with: + * - Arduino Leonardo & SparkFun Pro Micro, ATmega32u4 (5V, 16MHz) * - Arduino IDE 1.6.7 * - HID Project 2.4.3 * - IRLremote 1.7.4 * * ISSUES: - * - Most promising branch yet :) * - IRLremote doesn't work with Logitech Plex Remote profile. Now (ab)using Panasonic TV TX-43CXW754 device template. * - Watch dog reset doesn't work, according to Google this is most likely an Arduino bootloader bug. + * - IRLremote doesn't work with MattairTech MT-DB-U4 1.6.9-mt1 */ // --------GLOBAL FLAGS --------------- // enable debugging output over usb #define DEBUG_SKETCH //#define WATCHDOG -// hack for MattairTech MT-DB-U4 1.6.9-mt1 -#ifndef USB_EP_SIZE - #define USB_EP_SIZE USB_DEFAULT_EP_SIZE -#endif - // --------INCLUDES --------------- #ifdef WATCHDOG @@ -64,9 +57,15 @@ SOFTWARE. // pin assignments #define RECV_PIN 7 +#define POWER_SENSE_PIN 8 +#define POWER_BTN_PIN 9 + +// min 500ms hold time seems to be required (< 500ms was too short for power on) +#define POWER_BTN_HOLD_TIME 700 struct CodeMap { uint32_t irCommand; + uint8_t modifier; KeyboardKeycode keyCode; }; @@ -74,50 +73,70 @@ struct CodeMap { // My Logitech resends the first repeat after 40ms and afterwards every 110ms const int KEY_PRESS_TIME = 150; -// TODO not sure yet if a loop delay is required. With the IRRemote library it increased realibility... const int LOOP_DELAY = KEY_PRESS_TIME / 3; // IR code to key mapping +const uint8_t KEY_CTRL = 1; +const uint8_t KEY_ALT = 2; +const uint8_t KEY_SHIFT = 4; +const uint8_t KEY_GUI = 8; + // Kodi keyboard controls: http://kodi.wiki/view/Keyboard_controls const CodeMap irToKeyMap[] = { - {REMOTE_LEFT , KEY_LEFT_ARROW}, - {REMOTE_RIGHT , KEY_RIGHT_ARROW}, - {REMOTE_UP , KEY_UP_ARROW}, - {REMOTE_DOWN , KEY_DOWN_ARROW}, - {REMOTE_OK , KEY_RETURN}, - {REMOTE_ENTER , KEY_TAB}, // Fullscreen playback - {REMOTE_MENU , KEY_C}, - {REMOTE_BACK , KEY_BACKSPACE}, - {REMOTE_EXIT , KEY_ESC}, - {REMOTE_GUIDE , KEY_E}, - {REMOTE_INFO , KEY_I}, - {REMOTE_STOP , KEY_X}, - {REMOTE_PLAY , KEY_P}, - {REMOTE_PAUSE , KEY_SPACE}, - {REMOTE_REC , KEY_B}, - {REMOTE_REW , KEY_R}, - {REMOTE_FWD , KEY_F}, - {REMOTE_PREV , KEY_QUOTE}, // FIXME doesn't seem to work with non-us keyboard layout - {REMOTE_SKIP , KEY_PERIOD}, - {REMOTE_REPLAY, KEY_COMMA}, - {REMOTE_BLUE , KEY_T}, // toggle subtitles - {REMOTE_RED , KEY_W}, // Marked as watched / unwatched - {REMOTE_GREEN , KEY_S}, // Shutdown menu - {REMOTE_YELLOW, KEY_DELETE}, - {REMOTE_1 , KEY_1}, - {REMOTE_2 , KEY_2}, - {REMOTE_3 , KEY_3}, - {REMOTE_4 , KEY_4}, - {REMOTE_5 , KEY_5}, - {REMOTE_6 , KEY_6}, - {REMOTE_7 , KEY_7}, - {REMOTE_8 , KEY_8}, - {REMOTE_9 , KEY_9}, - {REMOTE_0 , KEY_0}, - -// TODO: -// CTRL + D -> boot ChromeOS -// CTRL + W -> boot openELEC + {REMOTE_LEFT , 0, KEY_LEFT_ARROW}, + {REMOTE_RIGHT , 0, KEY_RIGHT_ARROW}, + {REMOTE_UP , 0, KEY_UP_ARROW}, + {REMOTE_DOWN , 0, KEY_DOWN_ARROW}, + {REMOTE_OK , 0, KEY_RETURN}, + {REMOTE_ENTER , 0, KEY_TAB}, // Fullscreen playback + {REMOTE_MENU , 0, KEY_C}, + {REMOTE_CLEAR , 0, KEY_BACKSPACE}, + {REMOTE_EXIT , 0, KEY_ESC}, + {REMOTE_GUIDE , 0, KEY_E}, + {REMOTE_INFO , 0, KEY_I}, + {REMOTE_STOP , 0, KEY_X}, + {REMOTE_PLAY , 0, KEY_P}, + {REMOTE_PAUSE , 0, KEY_SPACE}, + {REMOTE_REC , 0, KEY_B}, + {REMOTE_REW , 0, KEY_R}, + {REMOTE_FWD , 0, KEY_F}, + {REMOTE_PREV , 0, KEY_QUOTE}, // FIXME doesn't seem to work with non-us keyboard layout + {REMOTE_SKIP , 0, KEY_PERIOD}, + {REMOTE_REPLAY , 0, KEY_COMMA}, + {REMOTE_SUBTITLE, 0, KEY_T}, // toggle subtitles + {REMOTE_BLUE , 0, KEY_O}, // Codec Info + {REMOTE_RED , 0, KEY_W}, // Marked as watched / unwatched + {REMOTE_GREEN , 0, KEY_S}, // shutdown / suspend / reboot menu + {REMOTE_YELLOW , 0, KEY_DELETE}, + {REMOTE_1 , 0, KEY_1}, + {REMOTE_2 , 0, KEY_2}, + {REMOTE_3 , 0, KEY_3}, + {REMOTE_4 , 0, KEY_4}, + {REMOTE_5 , 0, KEY_5}, + {REMOTE_6 , 0, KEY_6}, + {REMOTE_7 , 0, KEY_7}, + {REMOTE_8 , 0, KEY_8}, + {REMOTE_9 , 0, KEY_9}, + {REMOTE_0 , 0, KEY_0}, + {REMOTE_CH_UP , 0, KEY_PAGE_UP}, // PgUp / Skip to next queued video or next chapter if no videos are queued. / Increase Rating + {REMOTE_CH_DOWN , 0, KEY_PAGE_DOWN}, // PgDown / Skip to previous queued video or previous chapter if no videos are queued. / Decrease Rating + {REMOTE_ASPECT , 0, KEY_Z}, // Zoom/aspect ratio + {REMOTE_MUTE , 0, KEY_VOLUME_MUTE}, + {REMOTE_VOL_UP , 0, KEY_VOLUME_UP}, + {REMOTE_VOL_DOWN, 0, KEY_VOLUME_DOWN}, + {REMOTE_F1 , 0, KEY_A}, // Audio delay control + {REMOTE_F2 , 0, KEY_D}, // Move item down (Playlist editor & Favorites window) + {REMOTE_F3 , 0, KEY_U}, // Move item up (Playlist editor & Favorites window) + {REMOTE_F4 , 0, KEY_Q}, // Queue + {REMOTE_F5 , 0, KEY_V}, // Teletext / Visualisation settings + {REMOTE_F6 , 0, KEY_Y}, // Switch/choose player + {REMOTE_F7 , 0, KEY_HOME}, // Jump to the top of the menu + {REMOTE_REC , 0, KEY_PRINTSCREEN}, // Screenshot + + {REMOTE_ARROW_DOWN, KEY_CTRL, KEY_DOWN_ARROW}, // Move subtitles down + {REMOTE_ARROW_UP , KEY_CTRL, KEY_UP_ARROW}, // Move subtitles up + {REMOTE_F8 , KEY_CTRL, KEY_D}, // boot: ChromeOS TODO test... +//{REMOTE_F9 , KEY_CTRL, KEY_W}, // boot: openELEC TODO test... }; const int IR_KEY_MAP_SIZE = sizeof(irToKeyMap) / sizeof(CodeMap); @@ -141,6 +160,9 @@ void setup() { Serial.begin(115200); // afaik the baudrate is ignored on a 32u4 #endif DEBUG_PRINTLN("Chromebox_REMOTE_USB_Keyboard"); + + pinMode(POWER_SENSE_PIN, INPUT); + pinMode(POWER_BTN_PIN, OUTPUT); // initialize control over the keyboard: BootKeyboard.begin(); @@ -161,7 +183,7 @@ void loop() { //Test if watchdog interrupt enabled // http://forum.arduino.cc/index.php?topic=295345.msg2628807#msg2628807 if (WDTCSR & (1<