3 * (c) 2010 Technische Universität Dresden
4 * This file is part of TUD:OS and distributed under the terms of the
5 * GNU General Public License 2.
6 * Please see the COPYING-GPL-2 file for details.
10 #include <l4/mag/server/user_state>
11 #include <l4/mag/server/plugin>
13 #include <l4/re/event_enums.h>
15 namespace Mag_server {
17 template<int Max_axis>
21 unsigned long _changed;
31 Type axis_inf(unsigned char axis) const
32 { return Type((_changed >> (2*axis)) & 3); }
34 void set_axis_inf(unsigned char axis, Type t)
35 { _changed |= ((unsigned long)t) << (axis*2); }
38 Motion_merger() : _changed(0) {}
40 void reset() { _changed = 0; }
44 bool handle(User_state::Event const &e)
46 if (!(e.payload.type == L4RE_EV_REL || e.payload.type == L4RE_EV_ABS))
49 if (e.payload.code >= Max_axis)
52 unsigned char ax = e.payload.code;
54 if (axis_inf(ax) == T_none && e.payload.type == L4RE_EV_REL)
57 set_axis_inf(ax, T_rel);
60 switch (e.payload.type)
63 _v[ax] += e.payload.value;
66 _v[ax] = e.payload.value;
67 set_axis_inf(ax, T_abs);
74 bool set_event(unsigned char axis, User_state::Event *e)
76 unsigned i = axis_inf(axis);
81 e->payload.type = L4RE_EV_ABS;
83 e->payload.type = L4RE_EV_REL;
85 e->payload.code = axis;
86 e->payload.value = _v[axis];
91 template< typename I, typename T >
92 I merge(I const &s, I const &e, T *last_time)
94 for (I i = s; i != e; ++i)
106 template< typename E, typename I, typename F >
107 void process(I const &s, I const &end, F const &f)
109 for (I e = s; e != end; ++e)
112 me.payload.stream_id = e->payload.stream_id;
113 e = merge(e, end, &me.time);
115 for (unsigned i = 0; i < Max_axis; ++i)
116 if (set_event(i, &me))
134 template< /*typename E,*/ typename I, typename F >
135 void process(I const &s, I const &end, F const &f)
137 for (I e = s; e != end; ++e)
145 class Input_driver : public Plugin
151 Input_driver *_next_active;
154 explicit Input_driver(char const *name)
155 : Plugin(name), _core(0), _next_active(0)
158 char const *type() const { return "input-driver"; }
159 Input_driver *next_active() const { return _next_active; }
160 virtual void poll_events() = 0;
161 virtual int probe() = 0;
163 void start(Core_api *core)
168 _next_active = core->input_drivers();
169 core->add_input_driver(this);
173 virtual ~Input_driver() {}