| 1 | // FGEventInput.hxx -- handle event driven input devices for the Linux O/S |
| 2 | // |
| 3 | // Written by Torsten Dreyer, started July 2009 |
| 4 | // |
| 5 | // Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de |
| 6 | // |
| 7 | // This program is free software; you can redistribute it and/or |
| 8 | // modify it under the terms of the GNU General Public License as |
| 9 | // published by the Free Software Foundation; either version 2 of the |
| 10 | // License, or (at your option) any later version. |
| 11 | // |
| 12 | // This program is distributed in the hope that it will be useful, but |
| 13 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | // General Public License for more details. |
| 16 | // |
| 17 | // You should have received a copy of the GNU General Public License |
| 18 | // along with this program; if not, write to the Free Software |
| 19 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | // |
| 21 | // $Id$ |
| 22 | |
| 23 | #ifndef __FGLINUXEVENTINPUT_HXX |
| 24 | #define __FGLINUXEVENTINPUT_HXX |
| 25 | |
| 26 | #include "FGEventInput.hxx" |
| 27 | #include <linux/input.h> |
| 28 | |
| 29 | struct FGLinuxEventData : public FGEventData { |
| 30 | FGLinuxEventData( struct input_event & event, double dt, int modifiers ) : |
| 31 | FGEventData( (double)event.value, dt, modifiers ), |
| 32 | type(event.type), |
| 33 | code(event.code) { |
| 34 | } |
| 35 | unsigned type; |
| 36 | unsigned code; |
| 37 | }; |
| 38 | |
| 39 | /* |
| 40 | * A implementation for linux event devices |
| 41 | */ |
| 42 | class FGLinuxInputDevice : public FGInputDevice |
| 43 | { |
| 44 | public: |
| 45 | FGLinuxInputDevice(); |
| 46 | FGLinuxInputDevice(std::string aName, std::string aDevname, std::string aSerial, std::string aDevpath); |
| 47 | virtual ~FGLinuxInputDevice(); |
| 48 | |
| 49 | bool Open() override; |
| 50 | void Close() override; |
| 51 | void Send( const char * eventName, double value ) override; |
| 52 | const char * TranslateEventName( FGEventData & eventData ) override; |
| 53 | |
| 54 | void SetDevname( const std::string & name ); |
| 55 | std::string GetDevFile() const { return devfile; } |
| 56 | std::string GetDevPath() const { return devpath; } |
| 57 | |
| 58 | int GetFd() { return fd; } |
| 59 | |
| 60 | double Normalize( struct input_event & event ); |
| 61 | private: |
| 62 | std::string devfile; |
| 63 | std::string devpath; |
| 64 | int fd {-1}; |
| 65 | std::map<unsigned int,input_absinfo> absinfo; |
| 66 | }; |
| 67 | |
| 68 | class FGLinuxEventInput : public FGEventInput |
| 69 | { |
| 70 | public: |
| 71 | FGLinuxEventInput(); |
| 72 | virtual ~ FGLinuxEventInput(); |
| 73 | |
| 74 | // Subsystem API. |
| 75 | void postinit() override; |
| 76 | void update(double dt) override; |
| 77 | |
| 78 | // Subsystem identification. |
| 79 | static const char* staticSubsystemClassId() { return "input-event"; } |
| 80 | |
| 81 | protected: |
| 82 | }; |
| 83 | |
| 84 | #endif |