00001 /* 00002 * gamepad-config.h 00003 * 00004 * Copyright (C) 2010 Thomas A. Vaughan 00005 * All rights reserved. 00006 * 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the <organization> nor the 00016 * names of its contributors may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY 00020 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY 00023 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00026 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 * 00031 * Object to help with manual configuration of gamepads 00032 */ 00033 00034 #ifndef GAMEPAD_OPENGL_GAMEPAD_CONFIG_H__ 00035 #define GAMEPAD_OPENGL_GAMEPAD_CONFIG_H__ 00036 00037 // includes -------------------------------------------------------------------- 00038 #include "gamepad/manager.h" 00039 00040 00041 namespace gamepad { 00042 00043 00044 /// \ingroup gamepad_api 00045 /// \defgroup gamepad_config Gamepad Configuration 00046 /// 00047 /*@{*/ 00048 00049 00050 /// instruction set for user 00051 enum eInstruction { 00052 // instructions 00053 eInstruction_Calibrate = 0x401,///< press and move all controls 00054 00055 eInstruction_ButtonPress = 0x111,///< press the specified button 00056 00057 // Dpad instructions: typically you'll need to do this (center or move 00058 // dpad) and then press the gamepad's primay action button 00059 eInstruction_DpadCenter = 0x310,///< center dpad 00060 eInstruction_DpadLeft = 0x311,///< move dpad to left and 00061 eInstruction_DpadRight = 0x312,///< move specified dpad up 00062 eInstruction_DpadUp = 0x313,///< move specified dpad up 00063 eInstruction_DpadDown = 0x314,///< move specified dpad up 00064 00065 // Joystick instructions: typically you'll need to do this (center or 00066 // move joystick) and then press the gamepad's primary action 00067 // button. 00068 eInstruction_JoyCenter = 0x320,///< center joystick 00069 eInstruction_JoyLeft = 0x321,///< push joystick left 00070 eInstruction_JoyUp = 0x322,///< push joystick up 00071 00072 // Potentiometer instructions: you'll do this and press the gamepad's 00073 // primary action button. 00074 eInstruction_PotCenter = 0x330,///< pot is centered/zero'd 00075 eInstruction_PotExtreme = 0x331,///< now move pot to extreme 00076 00077 // these are NOT instructions! These are bit flags 00078 eInstruction_RequestControl = 0x100,///< specific to one control 00079 eInstruction_PressMainAction = 0x200,///< main action button press 00080 eInstruction_ExternalEvent = 0x400,///< requires non-gamepad event 00081 00082 // keep this last! 00083 eInstruction_Invalid = 0 00084 }; 00085 00086 00087 00088 /// specifies the current status of gamepad configuration 00089 struct config_status_t { 00090 // constructor, manipulators 00091 config_status_t(void) throw() { this->clear(); } 00092 void clear(void) throw() { 00093 currStep = -1; 00094 maxSteps = 0; 00095 instruct = eInstruction_Invalid; 00096 primary = NULL; 00097 logical = NULL; 00098 } 00099 00100 // data fields 00101 int currStep; ///< current step of config (first is 0) 00102 int maxSteps; ///< total number of configuration steps 00103 eInstruction instruct; ///< what user should do 00104 const char * primary; ///< logical name of primary button 00105 const char * logical; ///< logical input being configured 00106 }; 00107 00108 00109 00110 class Configurator { 00111 public: 00112 // virtual destructor -------------------------------------------------- 00113 virtual ~Configurator(void) throw(); 00114 00115 // gamepad::Configurator class interface methods ----------------------- 00116 00117 /// call this to reset configuration state and go back to calibration 00118 virtual void reset(void) = 0; 00119 00120 /// call this frequently (multiple times per second). Returns false 00121 /// when the configurator is done. 00122 virtual bool update(OUT config_status_t& status) = 0; 00123 00124 /// if the current instruction is eInstruction_Calibrate, you can only 00125 /// move to the next step by calling this method. This should be 00126 /// called once all controls have been moved/pressed, and all 00127 /// controls are currently released (no buttons pressed, joysticks 00128 /// pushed off center, etc.). So the Configurator knows it is now 00129 /// safe to take a snapshot of gamepad state. 00130 virtual void calibrationComplete(void) = 0; 00131 00132 /// once done, call this to get the mapping 00133 virtual smart_ptr<Map> getMapping(void) = 0; 00134 00135 // static factory methods ---------------------------------------------- 00136 00137 /// walk through and configure a mapping to the specified gamepad 00138 /// type, from the specified device. Caller also supplies a 00139 /// friendly name for the mapping. 00140 static smart_ptr<Configurator> create(IN smart_ptr<Manager>& mgr, 00141 IN smart_ptr<SourceDevice>& device, 00142 IN smart_ptr<Type>& type, 00143 IN const char * name); 00144 }; 00145 00146 00147 00148 /// handy string token given enum (can be used as key for localized string) 00149 const char * getInstructionToken(IN eInstruction instruct); 00150 00151 00152 }; // gamepad namespace 00153 00154 00155 #endif // GAMEPAD_OPENGL_GAMEPAD_CONFIG_H__ 00156