From a725f63418fd8a295f21fe20ef319638c40d9b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Tue, 14 Sep 2004 16:21:31 +0000 Subject: [PATCH] Added AT keyboard mapping git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8937 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../input_server/devices/keyboard/Jamfile | 2 + .../devices/keyboard/KeyboardInputDevice.cpp | 346 +++++++++++++++++- .../devices/keyboard/KeyboardInputDevice.h | 5 +- 3 files changed, 343 insertions(+), 10 deletions(-) diff --git a/src/add-ons/input_server/devices/keyboard/Jamfile b/src/add-ons/input_server/devices/keyboard/Jamfile index 047fe414c4..e8c6d89abc 100644 --- a/src/add-ons/input_server/devices/keyboard/Jamfile +++ b/src/add-ons/input_server/devices/keyboard/Jamfile @@ -1,5 +1,7 @@ SubDir OBOS_TOP src add-ons input_server devices keyboard ; +UsePrivateHeaders input ; + Addon keyboard : input_server/devices : KeyboardInputDevice.cpp Keymap.cpp diff --git a/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp b/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp index 17c3c6ceb5..8c7974e995 100644 --- a/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp +++ b/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp @@ -38,8 +38,10 @@ #if DEBUG inline void LOG(const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); \ fputs(buf, KeyboardInputDevice::sLogFile); fflush(KeyboardInputDevice::sLogFile); } + #define LOG_ERR(text...) LOG(text) #else #define LOG(text) + #define LOG_ERR(text...) fprintf(stderr, text) #endif const static uint32 kSetLeds = 0x2711; @@ -55,6 +57,301 @@ const static char *kKeyboardDevicesDirectory = "/dev/input/keyboard"; // "/dev/" is automatically prepended by StartMonitoringDevice() const static char *kKeyboardDevicesDirectoryUSB = "input/keyboard/usb"; +const uint32 at_keycode_map[] = { + 0x1, // Esc + 0x12, // 1 + 0x13, + 0x14, + 0x15, + 0x16, + 0x17, + 0x18, + 0x19, + 0x1a, + 0x1b, + 0x1c, // - + 0x1d, // = + 0x1e, // BKSP + 0x26, // TAB + 0x27, // Q + 0x28, // W + 0x29, // E + 0x2a, // R + 0x2b, // T + 0x2c, // Y + 0x2d, // U + 0x2e, // I + 0x2f, // O + 0x30, // P + 0x31, // [ + 0x32, // ] + 0x47, // ENTER + 0x5c, // Left Control + 0x3c, // A + 0x3d, // S + 0x3e, // D + 0x3f, // F + 0x40, // G + 0x41, // H + 0x42, // J + 0x43, // K + 0x44, // L + 0x45, // ; + 0x46, // ' + 0x11, // ` + 0x4b, // Left Shift + 0x33, // \ + 0x4c, // Z + 0x4d, // X + 0x4e, // C + 0x4f, // V + 0x50, // B + 0x51, // N + 0x52, // M + 0x53, // , + 0x54, // . + 0x55, // / + 0x56, // Right Shift + 0x24, // * + 0x5d, // Left Alt + 0x5e, // Space + 0x3b, // Caps + 0x02, // F1 + 0x03, // F2 + 0x04, // F3 + 0x05, // F4 + 0x06, // F5 + 0x07, // F6 + 0x08, // F7 + 0x09, // F8 + 0x0a, // F9 + 0x0b, // F10 + 0x22, // Num + 0x0f, // Scroll + 0x37, // KP 7 + 0x38, // KP 8 + 0x39, // KP 9 + 0x25, // KP - + 0x48, // KP 4 + 0x49, // KP 5 + 0x4a, // KP 6 + 0x3a, // KP + + 0x58, // KP 1 + 0x59, // KP 2 + 0x5a, // KP 3 + 0x64, // KP 0 + 0x65, // KP . + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x0c, // F11 + 0x0d, // F12 + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x5b, // KP Enter + 0x60, // Right Control + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x23, // KP / + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x5f, // Right Alt + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x20, // Home + 0x57, // Up Arrow + 0x21, // Page Up + 0x00, // UNMAPPED + 0x61, // Left Arrow + 0x00, // UNMAPPED + 0x63, // Right Arrow + 0x00, // UNMAPPED + 0x35, // End + 0x62, // Down Arrow + 0x36, // Page Down + 0x1f, // Insert + 0x34, // Delete + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + 0x00, // UNMAPPED + +}; + + FILE *KeyboardInputDevice::sLogFile = NULL; struct keyboard_device { @@ -84,11 +381,13 @@ KeyboardInputDevice::KeyboardInputDevice() #endif StartMonitoringDevice(kKeyboardDevicesDirectoryUSB); + LOG("%s\n", __PRETTY_FUNCTION__); } KeyboardInputDevice::~KeyboardInputDevice() { + LOG("%s\n", __PRETTY_FUNCTION__); StopMonitoringDevice(kKeyboardDevicesDirectoryUSB); #if DEBUG @@ -100,7 +399,21 @@ KeyboardInputDevice::~KeyboardInputDevice() status_t KeyboardInputDevice::InitFromSettings(void *cookie, uint32 opcode) { - // retrieve current values + LOG("%s\n", __PRETTY_FUNCTION__); + + keyboard_device *device = (keyboard_device *)cookie; + + if (get_key_repeat_rate(&device->settings.key_repeat_rate) != B_OK) + LOG_ERR("error when get_key_repeat_rate\n"); + else + if (ioctl(device->fd, kSetKeyRepeatRate, &device->settings.key_repeat_rate)!=B_OK) + LOG_ERR("error when kSetKeyRepeatRate, fd:%li\n", device->fd); + + if (get_key_repeat_delay(&device->settings.key_repeat_delay) != B_OK) + LOG_ERR("error when get_key_repeat_delay\n"); + else + if (ioctl(device->fd, kSetKeyRepeatDelay, &device->settings.key_repeat_delay)!=B_OK) + LOG_ERR("error when kSetKeyRepeatDelay, fd:%li\n", device->fd); return B_OK; } @@ -109,6 +422,7 @@ KeyboardInputDevice::InitFromSettings(void *cookie, uint32 opcode) status_t KeyboardInputDevice::InitCheck() { + LOG("%s\n", __PRETTY_FUNCTION__); RecursiveScan(kKeyboardDevicesDirectory); return B_OK; @@ -118,6 +432,7 @@ KeyboardInputDevice::InitCheck() status_t KeyboardInputDevice::Start(const char *name, void *cookie) { + LOG("%s\n", __PRETTY_FUNCTION__); keyboard_device *device = (keyboard_device *)cookie; char threadName[B_OS_NAME_LENGTH]; @@ -169,6 +484,7 @@ KeyboardInputDevice::Control(const char *name, void *cookie, status_t KeyboardInputDevice::HandleMonitor(BMessage *message) { + LOG("%s\n", __PRETTY_FUNCTION__); int32 opcode = 0; status_t status; if ((status = message->FindInt32("opcode", &opcode)) < B_OK) @@ -210,16 +526,16 @@ KeyboardInputDevice::HandleMonitor(BMessage *message) status_t KeyboardInputDevice::AddDevice(const char *path) { + LOG("%s\n", __PRETTY_FUNCTION__); keyboard_device *device = new keyboard_device(); if (!device) return B_NO_MEMORY; - + if ((device->fd = open(path, O_RDWR)) < B_OK) { delete device; return B_ERROR; } - device->fd = -1; device->device_watcher = -1; device->active = false; strcpy(device->path, path); @@ -243,6 +559,7 @@ KeyboardInputDevice::AddDevice(const char *path) status_t KeyboardInputDevice::RemoveDevice(const char *path) { + LOG("%s\n", __PRETTY_FUNCTION__); int32 i = 0; keyboard_device *device = NULL; while ((device = (keyboard_device *)fDevices.ItemAt(i)) != NULL) { @@ -267,9 +584,26 @@ KeyboardInputDevice::DeviceWatcher(void *arg) uint8 buffer[12]; while (dev->active) { - if (ioctl(dev->fd, kGetNextKey, &buffer) < B_OK) - continue; - LOG("kGetNextKey : %lx%lx%lx\n", (uint32*)buffer, (uint32*)buffer+1, (uint32*)buffer+2); + LOG("%s\n", __PRETTY_FUNCTION__); + + if (ioctl(dev->fd, kGetNextKey, &buffer) == B_OK) { + at_kbd_io *at_kbd = (at_kbd_io *)buffer; + uint32 keycode = 0; + if (at_kbd->scancode>0) + keycode = at_keycode_map[at_kbd->scancode-1]; + + LOG("kGetNextKey : %Ld, %02x, %02x, %02lx\n", at_kbd->timestamp, at_kbd->scancode, at_kbd->is_keydown, keycode); + + BMessage *msg = new BMessage; + msg->what = (at_kbd->is_keydown) ? B_KEY_DOWN : B_KEY_UP; + msg->AddInt64("when", at_kbd->timestamp); + + if (dev->owner->EnqueueMessage(msg)!=B_OK) + delete msg; + } else { + LOG("kGetNextKey error 2\n"); + snooze(100000); + } // be:key_repeat // be:old_modifiers diff --git a/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.h b/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.h index f05ebf1058..d117f40080 100644 --- a/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.h +++ b/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.h @@ -31,11 +31,8 @@ #include #include #include +#include "kb_mouse_driver.h" -typedef struct { - bigtime_t key_repeat_delay; - int32 key_repeat_rate; -} kb_settings; class KeyboardInputDevice : public BInputServerDevice { public: