diff --git a/SConstruct b/SConstruct index cc1709c..695cdac 100644 --- a/SConstruct +++ b/SConstruct @@ -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 # diff --git a/inputdrv.cpp b/inputdrv.cpp index ccb712a..3da1922 100644 --- a/inputdrv.cpp +++ b/inputdrv.cpp @@ -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(); diff --git a/toggle_button.cpp b/toggle_button.cpp new file mode 100644 index 0000000..fc28288 --- /dev/null +++ b/toggle_button.cpp @@ -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 */ diff --git a/toggle_button.hpp b/toggle_button.hpp new file mode 100644 index 0000000..5015e8e --- /dev/null +++ b/toggle_button.hpp @@ -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 */ diff --git a/xbox360_driver.hpp b/xbox360_driver.hpp index 44bacd1..7c2e30d 100644 --- a/xbox360_driver.hpp +++ b/xbox360_driver.hpp @@ -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;