1 #include "OISConfig.h" 2 #ifdef OIS_LIRC_SUPPORT 3 /* 4 The zlib/libpng License 5 6 Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 7 8 This software is provided 'as-is', without any express or implied warranty. In no event will 9 the authors be held liable for any damages arising from the use of this software. 10 11 Permission is granted to anyone to use this software for any purpose, including commercial 12 applications, and to alter it and redistribute it freely, subject to the following 13 restrictions: 14 15 1. The origin of this software must not be misrepresented; you must not claim that 16 you wrote the original software. If you use this software in a product, 17 an acknowledgment in the product documentation would be appreciated but is 18 not required. 19 20 2. Altered source versions must be plainly marked as such, and must not be 21 misrepresented as being the original software. 22 23 3. This notice may not be removed or altered from any source distribution. 24 */ 25 #include "OISLIRC.h" 26 #include "OISLIRCFactoryCreator.h" 27 #include "OISException.h" 28 29 using namespace OIS; 30 31 //-----------------------------------------------------------------------------------// 32 LIRCControl::LIRCControl(InputManager* creator, int id, bool buffered, LIRCFactoryCreator* local_creator, RemoteInfo &info) : 33 JoyStick("Generic LIRC", buffered, id, creator), 34 mLIRCCreator(local_creator), 35 mRingBuffer(OIS_LIRC_EVENT_BUFFER), 36 mInfo(info) 37 { 38 //Fill in joystick information 39 mState.mButtons.resize(mInfo.buttons); 40 } 41 42 //-----------------------------------------------------------------------------------// 43 LIRCControl::~LIRCControl() 44 { 45 } 46 47 //-----------------------------------------------------------------------------------// 48 void LIRCControl::_initialize() 49 { 50 mState.clear(); 51 } 52 53 //-----------------------------------------------------------------------------------// 54 void LIRCControl::setBuffered(bool buffered) 55 { 56 mBuffered = buffered; 57 } 58 59 //-----------------------------------------------------------------------------------// 60 void LIRCControl::capture() 61 { 62 //Anything to read? 63 int entries = mRingBuffer.GetReadAvailable(); 64 if( entries <= 0 ) 65 return; 66 67 LIRCEvent events[OIS_LIRC_EVENT_BUFFER]; 68 if( entries > OIS_LIRC_EVENT_BUFFER ) 69 entries = OIS_LIRC_EVENT_BUFFER; 70 71 mRingBuffer.Read(events, entries); 72 73 //Loop through each event 74 for( int i = 0; i < entries; ++i ) 75 { 76 if( mBuffered && mListener ) 77 { 78 //Quickly send off button events (there is no real stored state) 79 //As, even a held down button will kep generating button presses 80 mState.mButtons[events[i].button] = true; 81 if( !mListener->buttonPressed(JoyStickEvent(this, mState), events[i].button) ) 82 return; 83 84 mState.mButtons[events[i].button] = false; 85 if( !mListener->buttonReleased(JoyStickEvent(this, mState), events[i].button) ) 86 return; 87 } 88 } 89 } 90 91 //-----------------------------------------------------------------------------------// 92 void LIRCControl::queueButtonPressed(const std::string &id) 93 { 94 if( mRingBuffer.GetWriteAvailable() > 0 ) 95 { 96 LIRCEvent evt; 97 evt.button = mInfo.buttonMap[id]; 98 mRingBuffer.Write(&evt, 1); 99 } 100 } 101 102 //-----------------------------------------------------------------------------------// 103 Interface* LIRCControl::queryInterface(Interface::IType type) 104 { 105 return 0; 106 } 107 #endif 108