Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | // hardwarekeyboard.cpp - HardwareKeyboard object |
| 2 | // Shell file used for most devices. A custom hardwarekeyboard.cpp is needed for devices with a hardware keyboard. |
| 3 | |
| 4 | #include <stdarg.h> |
| 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <string.h> |
| 8 | #include <fcntl.h> |
| 9 | #include <sys/reboot.h> |
| 10 | #include <sys/stat.h> |
| 11 | #include <sys/time.h> |
| 12 | #include <sys/mman.h> |
| 13 | #include <sys/types.h> |
| 14 | #include <sys/ioctl.h> |
| 15 | #include <time.h> |
| 16 | #include <unistd.h> |
| 17 | #include <stdlib.h> |
| 18 | |
| 19 | #include <string> |
| 20 | |
| 21 | extern "C" { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 22 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 23 | #include "../minuitwrp/minui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | #include "rapidxml.hpp" |
| 27 | #include "objects.hpp" |
| 28 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 29 | HardwareKeyboard::HardwareKeyboard(void) |
| 30 | { |
| 31 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 32 | } |
| 33 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 34 | HardwareKeyboard::~HardwareKeyboard() |
| 35 | { |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 36 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 37 | } |
| 38 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 39 | int HardwareKeyboard::KeyDown(int key_code) |
| 40 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 41 | mPressedKeys.insert(key_code); |
| 42 | PageManager::NotifyKey(key_code, true); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 43 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 44 | LOGERR("HardwareKeyboard::KeyDown %i\n", key_code); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 45 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 46 | return 0; // 0 = no key repeat anything else turns on key repeat |
| 47 | } |
| 48 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 49 | int HardwareKeyboard::KeyUp(int key_code) |
| 50 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 51 | std::set<int>::iterator itr = mPressedKeys.find(key_code); |
| 52 | if(itr != mPressedKeys.end()) |
| 53 | { |
| 54 | mPressedKeys.erase(itr); |
| 55 | PageManager::NotifyKey(key_code, false); |
| 56 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 57 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 58 | LOGERR("HardwareKeyboard::KeyUp %i\n", key_code); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 59 | #endif |
| 60 | return 0; |
| 61 | } |
| 62 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 63 | int HardwareKeyboard::KeyRepeat(void) |
| 64 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 65 | /* |
| 66 | * Uncomment when key repeats are sent somewhere. |
| 67 | * std::set<int>::iterator itr = mPressedKeys.find(key_code); |
| 68 | * if(itr != mPressedKeys.end()) |
| 69 | * { |
| 70 | * Send repeats somewhere, don't remove itr from mPressedKeys |
| 71 | * } |
| 72 | */ |
| 73 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 74 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 75 | LOGERR("HardwareKeyboard::KeyRepeat\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 76 | #endif |
| 77 | return 0; |
| 78 | } |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 79 | |
| 80 | void HardwareKeyboard::ConsumeKeyRelease(int key) |
| 81 | { |
| 82 | mPressedKeys.erase(key); |
| 83 | } |