3 * (c) 2011 Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
13 #include <l4/mag/server/valuator>
15 namespace Mag_server {
30 class Axis_info_vector
33 Axis_info_vector() : _i(0), _size(0) {}
34 explicit Axis_info_vector(unsigned size)
35 : _i(new Axis_info*[size]), _size(size)
37 for (unsigned i = 0; i < _size; ++i)
46 for (unsigned i = 0; i < _size; ++i)
54 unsigned size() const { return _size; }
55 Axis_info const *get(unsigned idx) const
62 Axis_info *get(unsigned idx)
69 Axis_info *create(unsigned idx)
77 _i[idx] = new Axis_info();
81 bool set(unsigned idx, Axis_info *info)
100 Axis_info_vector(Axis_info_vector const &);
112 Hid_report(l4_umword_t device_id, unsigned rels, unsigned abss, unsigned mscs,
113 unsigned sws, unsigned mts);
117 bool get(unsigned char type, unsigned code, int &val) const;
118 void set(unsigned char type, unsigned code, int val);
120 bool mt_get(unsigned id, unsigned code, int &val) const;
122 void mt_set(unsigned code, int val);
125 Mag_server::Valuator<int> const *get_vals(unsigned char type) const;
126 Mag_server::Valuator<int> *get_vals(unsigned char type);
127 Mag_server::Valuator<int> const *get_mt_vals(unsigned id) const;
129 bool add_key(int code, int value);
130 Key_event const *get_key_event(unsigned idx) const;
131 Key_event const *find_key_event(int code) const;
132 void remove_key_event(int code);
134 void sync(long long time) { _time = time; }
135 long long time() const { return _time; }
137 l4_umword_t device_id() const { return _device_id; }
139 Axis_info_vector const *abs_infos() const
140 { return _abs_info; }
142 Axis_info_vector *abs_infos()
143 { return _abs_info; }
145 void set_abs_info(Axis_info_vector *i)
154 Mt_val_offset = 0x2f,
161 l4_umword_t const _device_id;
164 Key_event _kev[Num_key_events];
166 Valuator<int> _vals[Num_types];
170 Axis_info_vector *_abs_info;
173 struct Axis_xfrm_noop
175 void operator () (unsigned, int &) const {}
179 template<typename SINK, typename XFRM>
180 bool post_hid_report(Hid_report const *e, SINK &sink, XFRM const &xfrm_abs)
183 bool trigger = false;
185 typename SINK::Event ne;
187 ne.payload.stream_id = e->device_id();
190 Valuator<int> const *v = e->get_vals(2);
191 for (unsigned i = 0; v && i < v->size(); ++i)
193 Value<int> val = v->get(i);
198 ne.payload.value = val.val();
200 trigger |= sink.put(ne);
206 for (unsigned i = 0; v && i < v->size(); ++i)
208 Value<int> val = v->get(i);
213 ne.payload.value = val.val();
214 xfrm_abs(i, ne.payload.value);
215 trigger |= sink.put(ne);
220 for (unsigned i = 0;; ++i)
222 Hid_report::Key_event const *ke = e->get_key_event(i);
226 ne.payload.code = ke->code;
227 ne.payload.value = ke->value;
228 trigger |= sink.put(ne);
232 for (unsigned mt = 0; mt < 10; ++mt)
234 Valuator<int> const *m = e->get_mt_vals(mt);
240 unsigned mt_offset = m->offset();
241 for (unsigned i = 0; i < m->size(); ++i)
243 Value<int> v = m->get(i + mt_offset);
247 ne.payload.code = i + mt_offset;
248 ne.payload.value = v.val();
249 xfrm_abs(i + mt_offset, ne.payload.value);
250 trigger |= sink.put(ne);
259 ne.payload.value = 0;
260 trigger |= sink.put(ne);
268 ne.payload.value = 0;
269 trigger |= sink.put(ne);