- added toggle button class

This commit is contained in:
Ingo Ruhnke 2008-04-24 20:24:39 +02:00
parent 1c8790b5c6
commit 2efb68a5e7
5 changed files with 122 additions and 6 deletions

View file

@ -2,7 +2,11 @@
env = Environment(CPPFLAGS=["-g", "-O2", "-Wall"], LIBS=["usb"])
env.Program("xboxdrv", ["xboxdrv.cpp", "uinput.cpp"])
env.Program("inputdrv", ["inputdrv.cpp", "xbox360_driver.cpp", "control.cpp"],
env.Program("inputdrv",
["inputdrv.cpp",
"xbox360_driver.cpp",
"control.cpp",
"toggle_button.cpp"],
LIBS=['boost_signals', 'usb'])
# EOF #

View file

@ -27,6 +27,7 @@
#include <iostream>
#include <boost/bind.hpp>
#include "xbox360_driver.hpp"
#include "toggle_button.hpp"
#include "control.hpp"
#include "inputdrv.hpp"
@ -43,15 +44,18 @@ int main()
usb_find_devices();
Xbox360Driver xbox360(0);
ToggleButton toggle;
BtnPortOut* btn_a = xbox360.get_btn_port_out(0);
BtnPortOut* btn_b = xbox360.get_btn_port_out(1);
BtnPortOut* btn_a = xbox360.get_btn_port_out(Xbox360Driver::XBOX360_BTN_A);
BtnPortOut* btn_b = xbox360.get_btn_port_out(Xbox360Driver::XBOX360_BTN_B);
BtnPortIn* toggle_in = toggle.get_btn_port_in(0);
BtnPortOut* toggle_out = toggle.get_btn_port_out(0);
btn_a->connect(btn_change);
btn_b->connect(btn_change);
btn_b->connect(toggle_in);
btn_a->connect(xbox360.get_btn_port_in(0));
btn_b->connect(xbox360.get_btn_port_in(1));
toggle_out->connect(xbox360.get_btn_port_in(1));
xbox360.run();

51
toggle_button.cpp Normal file
View file

@ -0,0 +1,51 @@
/* $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 "toggle_button.hpp"
ToggleButton::ToggleButton()
: state(false)
{
btn_port_out.push_back(new BtnPortOut("ToggleButtonIn(out)"));
btn_port_in.push_back(new BtnPortIn("ToggleButton(in)",
boost::bind(&ToggleButton::on_btn, this, _1)));
}
ToggleButton::~ToggleButton()
{
}
void
ToggleButton::on_btn(BtnPortOut* out)
{
if (out->get_state())
{
state = !state;
btn_port_out[0]->set_state(state);
}
}
/* EOF */

50
toggle_button.hpp Normal file
View file

@ -0,0 +1,50 @@
/* $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_TOGGLE_BUTTON_HPP
#define HEADER_TOGGLE_BUTTON_HPP
#include "control.hpp"
/** */
class ToggleButton : public Control
{
private:
bool state;
public:
ToggleButton();
virtual ~ToggleButton();
void on_btn(BtnPortOut* out);
private:
ToggleButton (const ToggleButton&);
ToggleButton& operator= (const ToggleButton&);
};
#endif
/* EOF */

View file

@ -33,7 +33,7 @@
/** */
class Xbox360Driver : public Control
{
private:
public:
enum {
XBOX360_DPAD_UP,
XBOX360_DPAD_DOWN,
@ -54,6 +54,13 @@ private:
XBOX360_BTN_LENGTH,
};
enum {
PORT_IN_LED,
PORT_IN_RUMBLE,
PORT_IN_MAX,
};
private:
struct usb_device* dev;
struct usb_dev_handle* handle;