]> git.mxchange.org Git - flightgear.git/blob - src/Input/FGLinuxEventInput.hxx
Non platform specific:
[flightgear.git] / src / Input / FGLinuxEventInput.hxx
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 #include <hal/libhal.h>
29
30 struct FGLinuxEventData : public FGEventData {
31   FGLinuxEventData( struct input_event & event, double dt, int modifiers ) :
32     FGEventData( (double)event.value, dt, modifiers ),
33     type(event.type),
34     code(event.code) {
35   }
36   unsigned type;
37   unsigned code;
38 };
39
40 /*
41  * A implementation for linux event devices
42  */
43 class FGLinuxInputDevice : public FGInputDevice {
44 public:
45   FGLinuxInputDevice();
46   FGLinuxInputDevice( string name, string devname );
47   virtual ~FGLinuxInputDevice();
48
49   virtual void Open();
50   virtual void Close();
51   virtual void Send( const char * eventName, double value );
52   virtual const char * TranslateEventName( FGEventData & eventData );
53
54   void SetDevname( const string name );
55   string GetDevname() const { return devname; }
56
57   int GetFd() { return fd; }
58
59   double Normalize( struct input_event & event );
60 private:
61   string devname;
62   int fd;
63
64   map<unsigned int,input_absinfo> absinfo;
65 };
66
67 class FGLinuxEventInput : public FGEventInput {
68 public:
69   FGLinuxEventInput();
70   virtual ~ FGLinuxEventInput();
71   virtual void update (double dt);
72   virtual void postinit();
73
74   void AddHalDevice( const char * udi );
75 protected:
76   LibHalContext *halcontext;
77
78 };
79
80 #endif