blob: d8cdfd45affa9d80f4700cc924bdf73a5222834d [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001// 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
21extern "C" {
Dees_Troy2673cec2013-04-02 20:22:16 +000022#include "../twcommon.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040023#include "../minuitwrp/minui.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040024}
25
26#include "rapidxml.hpp"
27#include "objects.hpp"
28
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020029HardwareKeyboard::HardwareKeyboard(void)
30{
31
Dees_Troy51a0e822012-09-05 15:24:24 -040032}
33
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020034HardwareKeyboard::~HardwareKeyboard()
35{
Matt Mowerfb1c4ff2014-04-16 13:43:36 -050036
Dees_Troy51a0e822012-09-05 15:24:24 -040037}
38
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020039int HardwareKeyboard::KeyDown(int key_code)
40{
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010041 mPressedKeys.insert(key_code);
42 PageManager::NotifyKey(key_code, true);
Dees_Troy51a0e822012-09-05 15:24:24 -040043#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +000044 LOGERR("HardwareKeyboard::KeyDown %i\n", key_code);
Dees_Troy51a0e822012-09-05 15:24:24 -040045#endif
Dees_Troy51a0e822012-09-05 15:24:24 -040046 return 0; // 0 = no key repeat anything else turns on key repeat
47}
48
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020049int HardwareKeyboard::KeyUp(int key_code)
50{
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010051 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_Troy51a0e822012-09-05 15:24:24 -040057#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +000058 LOGERR("HardwareKeyboard::KeyUp %i\n", key_code);
Dees_Troy51a0e822012-09-05 15:24:24 -040059#endif
60 return 0;
61}
62
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020063int HardwareKeyboard::KeyRepeat(void)
64{
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010065 /*
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_Troy51a0e822012-09-05 15:24:24 -040074#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +000075 LOGERR("HardwareKeyboard::KeyRepeat\n");
Dees_Troy51a0e822012-09-05 15:24:24 -040076#endif
77 return 0;
78}
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010079
80void HardwareKeyboard::ConsumeKeyRelease(int key)
81{
82 mPressedKeys.erase(key);
83}