From: Markus Zehnder Date: Sat, 5 Mar 2016 20:08:31 +0000 (+0100) Subject: add watchdog and debug options X-Git-Url: http://git.hcoop.net/clinton/arduino-kodi-ir-keyboard.git/commitdiff_plain/82bb42637017d4b6b5970af61b73bca112e4aae0 add watchdog and debug options --- diff --git a/README.md b/README.md index cc11a34..084e7a8 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,15 @@ -# arduino-kodi-ir-keyboard +# arduino-kodi-ir-keyboard / BootKeyboard branch Kodi optimized infrared USB keyboard for an Asus Chromebox running openELEC. IR device: Logitech Harmony 880 with remote profile: 'Plex Player' -Tested with SparkFun Pro Micro, ATmega32u4 (5V, 16MHz) +Testing with: +- SparkFun Pro Micro, ATmega32u4 (5V, 16MHz) +- MattairTech MT-DB-U4 (ATmega 32U4), 16MHZ 5V, CDC_HID + +Arduino IDE 1.6.7 +HID Project 2.4.3 +IRRemote 2.0.1 Initial proof of concept with HID-Project instead of standard Keyboard library: - Kodi control works pretty well already :-) @@ -11,10 +17,11 @@ Initial proof of concept with HID-Project instead of standard Keyboard library: - boot protocol mode works (tested on a MacMini) ## Issues: -- Sketch doesn't always start after power up!? - Needs more testing... +- Stability issues: program hangs within 0..60 minutes + (Watch dog reset didn't work either, according to Google this is most likely a bootloader bug) ## TODO: +- Stable operation: continue testing with an Arduino Leonardo - Power off / sleep / wakeup - CTRL+D / CTRL+W key combinations for boot selection - Chromebox hardware modification to control power toggle switch with Arduino diff --git a/src/IR_USB_Keyboard/Debug.h b/src/IR_USB_Keyboard/Debug.h new file mode 100644 index 0000000..b2ba6e6 --- /dev/null +++ b/src/IR_USB_Keyboard/Debug.h @@ -0,0 +1,12 @@ +#ifndef Debug_H +#define Debug_H + +#ifdef DEBUG_SKETCH + #define DEBUG_PRINT(...) Serial.print(__VA_ARGS__); + #define DEBUG_PRINTLN(...) Serial.println(__VA_ARGS__); +#else + #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 9e66b42..ed58482 100644 --- a/src/IR_USB_Keyboard/IR_USB_Keyboard.ino +++ b/src/IR_USB_Keyboard/IR_USB_Keyboard.ino @@ -24,7 +24,13 @@ SOFTWARE. /* IR to USB keyboard optimized for KODI openELEC running on Asus Chromebox. * IR device: Logitech Harmony 880 with remote profile: 'Plex Player' - * Tested with SparkFun Pro Micro, ATmega32u4 (5V, 16MHz) + * Testing with: + * - SparkFun Pro Micro, ATmega32u4 (5V, 16MHz) + * - MattairTech MT-DB-U4 (ATmega 32U4), 16MHZ 5V, CDC_HID + * + * Arduino IDE 1.6.7 + * HID Project 2.4.3 + * IRRemote 2.0.1 * * Initial proof of concept: * - Kodi control works pretty well already :-) @@ -32,22 +38,35 @@ SOFTWARE. * - boot protocol mode works (tested on a MacMini) * * ISSUES: - * - Sketch doesn't always start after power up!? - * Needs more testing... + * - Stability issues: program hangs within 0..60 minutes + * (Watch dog reset didn't work either, according to Google this is most likely a bootloader bug) * * TODO: + * - Stable operation: continue testing with an Arduino Leonardo * - Power off / sleep / wakeup * - CTRL+D / CTRL+W key combinations for boot selection on the Asus Chromebox * - Chromebox hardware modification to control power toggle switch with Arduino */ +#ifdef WATCHDOG + #include +#endif + +// hack for MattairTech MT-DB-U4 1.6.9-mt1 +#ifndef USB_EP_SIZE + #define USB_EP_SIZE USB_DEFAULT_EP_SIZE +#endif + #include #include +//#define DEBUG_SKETCH +#include "Debug.h" + // --------CONSTANTS --------------- // pin assignments -#define RECV_PIN 7 +#define RECV_PIN 20 struct CodeMap { unsigned long irCode; @@ -173,19 +192,45 @@ unsigned long timeKeyDown = 0; // time of key press initiation void setup() { // open debug console + #ifndef DEBUG Serial.begin(115200); // afaik the baudrate is ignored on a 32u4 - Serial.println("Chromebox_IR_USB_Keyboard"); + #endif + DEBUG_PRINTLN("Chromebox_IR_USB_Keyboard"); // initialize control over the keyboard: BootKeyboard.begin(); // Start the receiver irrecv.enableIRIn(); + +#ifdef WATCHDOG + // enable watch dog + // maybe this solves the frequent hangs on the Pro Micro... + wdt_enable(WDTO_1S); +#endif } //======================================== void loop() { +#ifdef WATCHDOG + //Test if watchdog interrupt enabled + // http://forum.arduino.cc/index.php?topic=295345.msg2628807#msg2628807 + if (WDTCSR & (1<