From 600f089e43de0fa886b4604dc7fb52a14004536d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Thu, 2 Sep 2004 22:27:29 +0000 Subject: [PATCH] added a base keyboard addon added a grist to addons git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8808 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/input_server/devices/Jamfile | 1 + .../input_server/devices/keyboard/Jamfile | 7 + .../devices/keyboard/KeyboardInputDevice.cpp | 155 ++++++++++++++++++ .../devices/keyboard/KeyboardInputDevice.h | 68 ++++++++ .../input_server/devices/mouse/Jamfile | 2 +- 5 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 src/add-ons/input_server/devices/keyboard/Jamfile create mode 100644 src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp create mode 100644 src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.h diff --git a/src/add-ons/input_server/devices/Jamfile b/src/add-ons/input_server/devices/Jamfile index f70468c331..2efb6e9980 100644 --- a/src/add-ons/input_server/devices/Jamfile +++ b/src/add-ons/input_server/devices/Jamfile @@ -1,4 +1,5 @@ SubDir OBOS_TOP src add-ons input_server devices ; +SubInclude OBOS_TOP src add-ons input_server devices keyboard ; SubInclude OBOS_TOP src add-ons input_server devices mouse ; diff --git a/src/add-ons/input_server/devices/keyboard/Jamfile b/src/add-ons/input_server/devices/keyboard/Jamfile new file mode 100644 index 0000000000..ba25b27d49 --- /dev/null +++ b/src/add-ons/input_server/devices/keyboard/Jamfile @@ -0,0 +1,7 @@ +SubDir OBOS_TOP src add-ons input_server devices keyboard ; + +Addon keyboard : input_server/devices : + KeyboardInputDevice.cpp + : false + : be input_server ; + diff --git a/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp b/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp new file mode 100644 index 0000000000..df2cd23aad --- /dev/null +++ b/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp @@ -0,0 +1,155 @@ +/*****************************************************************************/ +// Mouse input server device addon +// Written by Stefano Ceccherini +// +// KeyboardInputDevice.cpp +// +// Copyright (c) 2004 Haiku Project +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +/*****************************************************************************/ +#include "KeyboardInputDevice.h" + +#include +#include + +const static uint32 kSetLeds = 0x2711; +const static uint32 kSetRepeatingKey = 0x2712; +const static uint32 kSetNonRepeatingKey = 0x2713; +const static uint32 kSetKeyRepeatRate = 0x2714; +const static uint32 kSetKeyRepeatDelay = 0x2716; +const static uint32 kGetNextKey = 0x270f; + + +extern "C" +BInputServerDevice * +instantiate_input_device() +{ + return new KeyboardInputDevice(); +} + + +KeyboardInputDevice::KeyboardInputDevice() + : fThread(-1), + fQuit(false) +{ + fFd = open("dev/input/keyboard/ps2/0", O_RDWR); + if (fFd >= 0) + fThread = spawn_thread(DeviceWatcher, "keyboard watcher thread", + B_NORMAL_PRIORITY, this); + + fLogFile = fopen("/boot/home/device_log.log", "w"); +} + + +KeyboardInputDevice::~KeyboardInputDevice() +{ + if (fThread >= 0) { + status_t dummy; + wait_for_thread(fThread, &dummy); + } + + if (fFd >= 0) + close(fFd); + + fclose(fLogFile); +} + + +status_t +KeyboardInputDevice::InitFromSettings(uint32 opcode) +{ + // retrieve current values + + return B_OK; +} + + +status_t +KeyboardInputDevice::InitCheck() +{ + InitFromSettings(); + + input_device_ref keyboard1 = { "Keyboard 1", B_KEYBOARD_DEVICE, (void *)this }; + + input_device_ref *devices[2] = { &keyboard1, NULL }; + + if (fFd >= 0 && fThread >= 0) { + RegisterDevices(devices); + return BInputServerDevice::InitCheck(); + } + return B_ERROR; +} + + +status_t +KeyboardInputDevice::Start(const char *name, void *cookie) +{ + fputs("Start(", fLogFile); + fputs(name, fLogFile); + fputs(")\n", fLogFile); + resume_thread(fThread); + + return B_OK; +} + + +status_t +KeyboardInputDevice::Stop(const char *device, void *cookie) +{ + fputs("Stop()\n", fLogFile); + + suspend_thread(fThread); + + return B_OK; +} + + +status_t +KeyboardInputDevice::Control(const char *name, void *cookie, + uint32 command, BMessage *message) +{ + fputs("Control()\n", fLogFile); + + if (command == B_NODE_MONITOR) + HandleMonitor(message); + else if (command >= B_KEY_MAP_CHANGED + && command <= B_KEY_REPEAT_RATE_CHANGED) { + InitFromSettings(command); + } + return B_OK; +} + + +status_t +KeyboardInputDevice::HandleMonitor(BMessage *message) +{ + return B_OK; +} + + +int32 +KeyboardInputDevice::DeviceWatcher(void *arg) +{ + KeyboardInputDevice *dev = (KeyboardInputDevice *)arg; + + return 0; +} + + diff --git a/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.h b/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.h new file mode 100644 index 0000000000..c1484fcabf --- /dev/null +++ b/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.h @@ -0,0 +1,68 @@ +/*****************************************************************************/ +// Keyboard input server device addon +// Written by Stefano Ceccherini, Jérôme Duval +// +// KeyboardInputDevice.h +// +// Copyright (c) 2004 Haiku Project +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +/*****************************************************************************/ +#ifndef __KEYBOARDINPUTDEVICE_H +#define __KEYBOARDINPUTDEVICE_H + +#include +#include +#include + +typedef struct { + bigtime_t key_repeat_delay; + int32 key_repeat_rate; +} kb_settings; + +class KeyboardInputDevice : public BInputServerDevice { +public: + KeyboardInputDevice(); + ~KeyboardInputDevice(); + + virtual status_t InitCheck(); + + virtual status_t Start(const char *name, void *cookie); + virtual status_t Stop(const char *name, void *cookie); + + virtual status_t Control(const char *name, void *cookie, + uint32 command, BMessage *message); +private: + status_t HandleMonitor(BMessage *message); + status_t InitFromSettings(uint32 opcode = 0); + + thread_id fThread; + int fFd; + bool fQuit; + FILE *fLogFile; + + static int32 DeviceWatcher(void *arg); + + kb_settings fSettings; +}; + +extern "C" BInputServerDevice *instantiate_input_device(); + +#endif + diff --git a/src/add-ons/input_server/devices/mouse/Jamfile b/src/add-ons/input_server/devices/mouse/Jamfile index 23cdf46511..f2d95b9f56 100644 --- a/src/add-ons/input_server/devices/mouse/Jamfile +++ b/src/add-ons/input_server/devices/mouse/Jamfile @@ -1,6 +1,6 @@ SubDir OBOS_TOP src add-ons input_server devices mouse ; -Addon mouse : input_server/devices : +Addon mouse : input_server/devices : MouseInputDevice.cpp : false : be input_server ;