PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Joystick.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLINPUT_JOYSTICK_H__ 00024 #define __PLINPUT_JOYSTICK_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Base/Event/EventHandler.h> 00032 #include "PLInput/Input/Devices/Device.h" 00033 #include "PLInput/Input/Controls/Axis.h" 00034 #include "PLInput/Input/Controls/Button.h" 00035 #include "PLInput/Input/Controls/Effect.h" 00036 00037 00038 //[-------------------------------------------------------] 00039 //[ Namespace ] 00040 //[-------------------------------------------------------] 00041 namespace PLInput { 00042 00043 00044 //[-------------------------------------------------------] 00045 //[ Forward declarations ] 00046 //[-------------------------------------------------------] 00047 class HIDDevice; 00048 00049 00050 //[-------------------------------------------------------] 00051 //[ Classes ] 00052 //[-------------------------------------------------------] 00053 /** 00054 * @brief 00055 * Joystick input device 00056 * 00057 * @remarks 00058 * This class supports the following device backend types: 00059 * - UpdateDevice 00060 * - HIDDevice 00061 */ 00062 class Joystick : public Device { 00063 00064 00065 //[-------------------------------------------------------] 00066 //[ Class definition ] 00067 //[-------------------------------------------------------] 00068 pl_class(PLINPUT_RTTI_EXPORT, Joystick, "PLInput", PLInput::Device, "Joystick input controller") 00069 pl_class_end 00070 00071 00072 //[-------------------------------------------------------] 00073 //[ Controller definition ] 00074 //[-------------------------------------------------------] 00075 public: 00076 // Input 00077 Axis X; /**< X axis */ 00078 Axis Y; /**< Y axis */ 00079 Axis Z; /**< Z axis */ 00080 Axis RX; /**< Rotation X axis */ 00081 Axis RY; /**< Rotation Y axis */ 00082 Axis RZ; /**< Rotation Z axis */ 00083 Axis Hat; /**< Hat axis */ 00084 Button Button0; /**< Button #0 */ 00085 Button Button1; /**< Button #1 */ 00086 Button Button2; /**< Button #2 */ 00087 Button Button3; /**< Button #3 */ 00088 Button Button4; /**< Button #4 */ 00089 Button Button5; /**< Button #5 */ 00090 Button Button6; /**< Button #6 */ 00091 Button Button7; /**< Button #7 */ 00092 Button Button8; /**< Button #8 */ 00093 Button Button9; /**< Button #9 */ 00094 Button Button10; /**< Button #10 */ 00095 Button Button11; /**< Button #11 */ 00096 Button Button12; /**< Button #12 */ 00097 Button Button13; /**< Button #13 */ 00098 Button Button14; /**< Button #14 */ 00099 Button Button15; /**< Button #15 */ 00100 Button Button16; /**< Button #16 */ 00101 Button Button17; /**< Button #17 */ 00102 Button Button18; /**< Button #18 */ 00103 Button Button19; /**< Button #19 */ 00104 Button Button20; /**< Button #20 */ 00105 Button Button21; /**< Button #21 */ 00106 Button Button22; /**< Button #22 */ 00107 Button Button23; /**< Button #23 */ 00108 Button Button24; /**< Button #24 */ 00109 Button Button25; /**< Button #25 */ 00110 Button Button26; /**< Button #26 */ 00111 Button Button27; /**< Button #27 */ 00112 Button Button28; /**< Button #28 */ 00113 Button Button29; /**< Button #29 */ 00114 Button Button30; /**< Button #30 */ 00115 Button Button31; /**< Button #31 */ 00116 00117 // Effects 00118 Effect Rumble1; /**< Rumble effect (motor #1) */ 00119 Effect Rumble2; /**< Rumble effect (motor #2) */ 00120 Effect Rumble3; /**< Rumble effect (motor #3) */ 00121 Effect Rumble4; /**< Rumble effect (motor #4) */ 00122 00123 00124 //[-------------------------------------------------------] 00125 //[ Public functions ] 00126 //[-------------------------------------------------------] 00127 public: 00128 /** 00129 * @brief 00130 * Constructor 00131 * 00132 * @param[in] sName 00133 * Device name 00134 * @param[in] pImpl 00135 * System specific device implementation, can, but shouldn't be a null pointer 00136 */ 00137 PLINPUT_API Joystick(const PLCore::String &sName, DeviceImpl *pImpl); 00138 00139 /** 00140 * @brief 00141 * Destructor 00142 */ 00143 PLINPUT_API virtual ~Joystick(); 00144 00145 /** 00146 * @brief 00147 * Get threshold 00148 * 00149 * @return 00150 * Threshold 00151 */ 00152 PLINPUT_API int GetThreshold() const; 00153 00154 /** 00155 * @brief 00156 * Set threshold 00157 * 00158 * @param[in] nThreshold 00159 * Threshold 00160 */ 00161 PLINPUT_API void SetThreshold(int nThreshold = 12000); 00162 00163 00164 //[-------------------------------------------------------] 00165 //[ Public virtual Controller functions ] 00166 //[-------------------------------------------------------] 00167 public: 00168 PLINPUT_API virtual void Update() override; 00169 PLINPUT_API virtual void UpdateOutputControl(Control *pControl) override; 00170 00171 00172 //[-------------------------------------------------------] 00173 //[ Private functions ] 00174 //[-------------------------------------------------------] 00175 private: 00176 /** 00177 * @brief 00178 * Parse HID input report 00179 */ 00180 void ParseInputReport(); 00181 00182 /** 00183 * @brief 00184 * Called when the HID device has read some data 00185 */ 00186 void OnDeviceRead(); 00187 00188 00189 //[-------------------------------------------------------] 00190 //[ Private data ] 00191 //[-------------------------------------------------------] 00192 private: 00193 // Event handlers 00194 PLCore::EventHandler<> EventHandlerOnDeviceRead; 00195 00196 // HID connection 00197 HIDDevice *m_pHIDDevice; /**< HID device, can be a null pointer */ 00198 00199 // Configuration 00200 int m_nThreshold; /**< Movement threshold */ 00201 00202 00203 }; 00204 00205 00206 //[-------------------------------------------------------] 00207 //[ Namespace ] 00208 //[-------------------------------------------------------] 00209 } // PLInput 00210 00211 00212 #endif // __PLINPUT_JOYSTICK_H__
|