Some more work on UIEventEmitter, UIEventCollector still needs better merge strategies, EV_REL is now probably broken

This commit is contained in:
Ingo Ruhnke 2011-07-12 19:10:20 +02:00
parent c160a0ffdc
commit 9975da3cd6
2 changed files with 144 additions and 0 deletions

View file

@ -0,0 +1,80 @@
/*
** Xbox360 USB Gamepad Userspace Driver
** Copyright (C) 2011 Ingo Ruhnke <grumbel@gmx.de>
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ui_event_collector.hpp"
#include <assert.h>
#include "log.hpp"
#include "uinput.hpp"
UIEventCollector::UIEventCollector(UInput& uinput,
uint32_t device_id,
int type,
int code) :
m_uinput(uinput),
m_device_id(device_id),
m_type(type),
m_code(code),
m_value(0),
m_emitters()
{
assert(m_code != -1);
}
UIEventEmitterPtr
UIEventCollector::create_emitter()
{
UIEventEmitterPtr emitter(new UIEventEmitter(*this));
m_emitters.push_back(emitter);
return emitter;
}
void
UIEventCollector::sync()
{
int value = 0;
for(Emitters::iterator i = m_emitters.begin(); i != m_emitters.end(); ++i)
{
switch(m_type)
{
case EV_KEY:
value = value || (*i)->get_value();
break;
case EV_REL:
value += (*i)->get_value();
break;
case EV_ABS:
value = (*i)->get_value();
break;
default:
assert(!"unknown type");
}
}
if (value != m_value)
{
m_value = value;
m_uinput.send(m_device_id, m_type, m_code, m_value);
}
}
/* EOF */

View file

@ -0,0 +1,64 @@
/*
** Xbox360 USB Gamepad Userspace Driver
** Copyright (C) 2011 Ingo Ruhnke <grumbel@gmx.de>
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef HEADER_XBOXDRV_UI_EVENT_COLLECTOR_HPP
#define HEADER_XBOXDRV_UI_EVENT_COLLECTOR_HPP
#include <boost/shared_ptr.hpp>
#include <stdint.h>
#include <vector>
#include "ui_event_emitter.hpp"
class UIEventCollector;
class UInput;
typedef boost::shared_ptr<UIEventCollector> UIEventCollectorPtr;
class UIEventCollector
{
private:
UInput& m_uinput;
uint32_t m_device_id;
int m_type;
int m_code;
int m_value;
typedef std::vector<UIEventEmitterPtr> Emitters;
Emitters m_emitters;
public:
UIEventCollector(UInput& uinput, uint32_t device_id, int type, int code);
uint32_t get_device_id() const { return m_device_id; }
int get_type() const { return m_type; }
int get_code() const { return m_code; }
UIEventEmitterPtr create_emitter();
void sync();
private:
UIEventCollector(const UIEventCollector&);
UIEventCollector& operator=(const UIEventCollector&);
};
#endif
/* EOF */