XJoypad is a Python2/3 iterator and wrapper API ofevdev, for reading and parsing joypad and game-controller input events.
Bash Variables
_module_name='xjoypad'_module_https_url="https://github.com/python-utilities/${_module_name}.git"_module_relative_path="lib/modules/${_module_name}"Bash Submodule Commands
cd"<your-git-project-path>"git checkout mastermkdir -vp"lib/modules"git submodule add\ -b master --name"${_module_name}"\"${_module_https_url}""${_module_relative_path}"Suggested additions for yourReadMe.md file so everyone has a good time with submodules
Install Python dependenciespip3 install --user evdevClone with the following to avoid incomplete downloadsgit clone --recurse-submodules <url-for-your-project>Update/upgrade submodules viagit submodule update --init --merge --recursive
As animport
#!/usr/bin/env python3fromlib.modules.xjoypadimportXJoypadif__name__=='__main__':importtimexjoypad=XJoypad()forevent_datainxjoypad:ifevent_data:print("{name} --> {value} --> {normalized_value}".format(**event_data))time.sleep(0.001)As a baseclass
#!/usr/bin/env python3importtimefromlib.modules.xjoypadimportXJoypadclassXJoypad_Buffer(XJoypad):"""Extends `XJoypad` class with buffer and timeout features"""def__init__(self,device_index=0,amend_settings=None,**kwargs):""" Use `amend_settings` to modify select `self['sleeps']` settings """self['sleeps']= {'min':0.001,'max':0.01,'acceleration':0.001,'timeout':120,'current':0.001, }super(XJoypad_Buffer,self).__init__(device_index=device_index,amend_settings=amend_settings,**kwargs)defnext(self):""" Throws `GeneratorExit` if timeout is set and reached, otherwise returns `event_data` when available """while1:_event_data=super(XJoypad_Buffer,self).next()if_event_data:self['sleeps']['slept_start']=Noneself['sleeps']['current']=self['sleeps']['min']return_event_dataifnotself['sleeps'].get('slept_start'):self['sleeps']['slept_start']=time.time()ifself['sleeps']['current']<self['sleeps']['max']:self['sleeps']['current']+=self['sleeps']['acceleration']ifself['sleeps'].get('timeout')andself['sleeps'].get('slept_last'):ifself['sleeps']['slept_last']-self['sleeps']['slept_start']>self['sleeps']['timeout']:self.throw(GeneratorExit)self['sleeps']['slept_last']=time.time()time.sleep(self['sleeps']['current'])if__name__=='__main__':xjoypad=XJoypad_Buffer()forevent_datainxjoypad:print("Event name -> {name} -- {value} -- {normalized_value}".format(**event_data))time.sleep(0.001)git add .gitmodulesgit add lib/modules/xjoypad## Add any changed files toogit commit -F-<<'EOF':heavy_plus_sign: Adds `python-utilities/xjoypad#1` submodule# ... anything else noteworthyEOFgit push origin master
🎉 Excellent 🎉 your repository is now ready to begin unitizing code from this project!
Pull Requests are welcome for fixing bugs and/or adding features.
Legal bits of Open Source software
XJoypad ReadMe documenting how things like this could be utilizedCopyright (C) 2019 S0AndS0This program is free software: you can redistribute it and/or modifyit under the terms of the GNU Affero General Public License as publishedby the Free Software Foundation; version 3 of the License.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU Affero General Public License for more details.You should have received a copy of the GNU Affero General Public Licensealong with this program. If not, see <https://www.gnu.org/licenses/>.