Added autofire_button.?pp
This commit is contained in:
parent
1d01b66573
commit
e9fed16b27
5 changed files with 133 additions and 11 deletions
|
@ -9,6 +9,7 @@ env.Program("inputdrv",
|
|||
"control.cpp",
|
||||
"abs_to_rel.cpp",
|
||||
"abs_to_btn.cpp",
|
||||
"autofire_button.cpp",
|
||||
"uinput_driver.cpp",
|
||||
"toggle_button.cpp"],
|
||||
LIBS=['boost_signals', 'usb', 'pthread'])
|
||||
|
|
62
autofire_button.cpp
Normal file
62
autofire_button.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
/* $Id$
|
||||
** __ __ __ ___ __ __ __ __
|
||||
** / \ / \__| ____ __| _/_______/ |_|__| | | | ____
|
||||
** \ \/\/ / |/ \ / __ |/ ___/\ __\ | | | | _/ __ \
|
||||
** \ /| | | \/ /_/ |\___ \ | | | | |_| |_\ ___/
|
||||
** \__/\ / |__|___| /\____ /____ > |__| |__|____/____/\___ >
|
||||
** \/ \/ \/ \/ \/
|
||||
** Copyright (C) 2007 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 2
|
||||
** 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, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
** 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include "autofire_button.hpp"
|
||||
|
||||
AutofireButton::AutofireButton(int rate)
|
||||
: rate(rate),
|
||||
rate_counter(0)
|
||||
{
|
||||
btn_port_in.push_back(new BtnPortIn("AutofireButton-In",
|
||||
boost::bind(&AutofireButton::on_btn, this, _1)));
|
||||
btn_port_out.push_back(new BtnPortOut("AutofireButton-Out-0"));
|
||||
}
|
||||
|
||||
void
|
||||
AutofireButton::on_btn(BtnPortOut* port)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
AutofireButton::update(float delta)
|
||||
{
|
||||
if (btn_port_in[0]->out_port->get_state())
|
||||
{
|
||||
rate_counter += int(1000 * delta);
|
||||
if (rate_counter >= rate)
|
||||
{
|
||||
rate_counter = rate_counter % rate;
|
||||
btn_port_out[0]->set_state(!btn_port_out[0]->get_state());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rate_counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* EOF */
|
49
autofire_button.hpp
Normal file
49
autofire_button.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* $Id$
|
||||
** __ __ __ ___ __ __ __ __
|
||||
** / \ / \__| ____ __| _/_______/ |_|__| | | | ____
|
||||
** \ \/\/ / |/ \ / __ |/ ___/\ __\ | | | | _/ __ \
|
||||
** \ /| | | \/ /_/ |\___ \ | | | | |_| |_\ ___/
|
||||
** \__/\ / |__|___| /\____ /____ > |__| |__|____/____/\___ >
|
||||
** \/ \/ \/ \/ \/
|
||||
** Copyright (C) 2007 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 2
|
||||
** 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, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
** 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef HEADER_AUTOFIRE_BUTTON_HPP
|
||||
#define HEADER_AUTOFIRE_BUTTON_HPP
|
||||
|
||||
#include "control.hpp"
|
||||
|
||||
/** */
|
||||
class AutofireButton : public Control
|
||||
{
|
||||
private:
|
||||
int rate;
|
||||
int rate_counter;
|
||||
public:
|
||||
AutofireButton(int rate);
|
||||
void update(float delta);
|
||||
void on_btn(BtnPortOut* port);
|
||||
|
||||
private:
|
||||
AutofireButton (const AutofireButton&);
|
||||
AutofireButton& operator= (const AutofireButton&);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
10
control.hpp
10
control.hpp
|
@ -36,14 +36,15 @@ class BtnPortOut
|
|||
public:
|
||||
std::string label;
|
||||
|
||||
boost::signal<void(BtnPortOut*)> sig_change;
|
||||
|
||||
// true if pressed, false otherwise
|
||||
bool state;
|
||||
|
||||
BtnPortOut(const std::string& label)
|
||||
: label(label) {}
|
||||
boost::signal<void(BtnPortOut*)> sig_change;
|
||||
|
||||
BtnPortOut(const std::string& label)
|
||||
: label(label),
|
||||
state(false)
|
||||
{}
|
||||
|
||||
std::string get_label() { return label; }
|
||||
bool get_state() { return state; }
|
||||
|
@ -79,6 +80,7 @@ public:
|
|||
|
||||
AbsPortOut(const std::string& label, int min_value, int max_value)
|
||||
: label(label),
|
||||
state(0),
|
||||
min_value(min_value),
|
||||
max_value(max_value)
|
||||
{}
|
||||
|
|
22
inputdrv.cpp
22
inputdrv.cpp
|
@ -30,6 +30,7 @@
|
|||
#include "uinput_driver.hpp"
|
||||
#include "abs_to_rel.hpp"
|
||||
#include "toggle_button.hpp"
|
||||
#include "autofire_button.hpp"
|
||||
#include "control.hpp"
|
||||
#include "inputdrv.hpp"
|
||||
|
||||
|
@ -51,24 +52,28 @@ int main()
|
|||
usb_find_devices();
|
||||
|
||||
UInputDriver* uinput = new UInputDriver("UInputMouseEmulation");
|
||||
|
||||
uinput->add_rel(REL_X);
|
||||
uinput->add_rel(REL_Y);
|
||||
uinput->add_rel(REL_HWHEEL);
|
||||
uinput->add_rel(REL_WHEEL);
|
||||
|
||||
uinput->add_btn(BTN_LEFT);
|
||||
uinput->add_btn(BTN_RIGHT);
|
||||
uinput->add_btn(BTN_MIDDLE);
|
||||
uinput->add_btn(KEY_Y);
|
||||
uinput->add_btn(BTN_Y);
|
||||
|
||||
uinput->finish();
|
||||
|
||||
std::vector<Control*> controls;
|
||||
|
||||
Xbox360Driver* xbox360 = new Xbox360Driver(0);
|
||||
ToggleButton* toggle = new ToggleButton();
|
||||
AbsToRel* abs_to_rel_x = new AbsToRel();
|
||||
AbsToRel* abs_to_rel_y = new AbsToRel();
|
||||
AbsToRel* abs_to_rel_x2 = new AbsToRel();
|
||||
AbsToRel* abs_to_rel_y2 = new AbsToRel();
|
||||
Xbox360Driver* xbox360 = new Xbox360Driver(0);
|
||||
ToggleButton* toggle = new ToggleButton();
|
||||
AbsToRel* abs_to_rel_x = new AbsToRel();
|
||||
AbsToRel* abs_to_rel_y = new AbsToRel();
|
||||
AbsToRel* abs_to_rel_x2 = new AbsToRel();
|
||||
AbsToRel* abs_to_rel_y2 = new AbsToRel();
|
||||
AutofireButton* autofire = new AutofireButton(100);
|
||||
|
||||
controls.push_back(xbox360);
|
||||
controls.push_back(toggle);
|
||||
|
@ -76,6 +81,7 @@ int main()
|
|||
controls.push_back(abs_to_rel_y);
|
||||
controls.push_back(abs_to_rel_x2);
|
||||
controls.push_back(abs_to_rel_y2);
|
||||
controls.push_back(autofire);
|
||||
|
||||
// ----------------------------
|
||||
|
||||
|
@ -106,6 +112,8 @@ int main()
|
|||
->connect(uinput->get_btn_port_in(2));
|
||||
|
||||
xbox360->get_btn_port_out(Xbox360Driver::XBOX360_BTN_Y)
|
||||
->connect(autofire->get_btn_port_in(0));
|
||||
autofire->get_btn_port_out(0)
|
||||
->connect(uinput->get_btn_port_in(3));
|
||||
|
||||
// ----------------------------
|
||||
|
|
Loading…
Add table
Reference in a new issue