forked from mirror/joycontrol
cleanup Merge 'pulls/326281544/67', added comments
This commit is contained in:
@@ -171,13 +171,13 @@ class ButtonState:
|
||||
|
||||
def get_available_buttons(self):
|
||||
"""
|
||||
:returns set of valid buttons
|
||||
:returns: set of valid buttons
|
||||
"""
|
||||
return set(self._available_buttons)
|
||||
|
||||
def __iter__(self):
|
||||
"""
|
||||
:returns iterator over the button bytes
|
||||
:returns: iterator over the button bytes
|
||||
"""
|
||||
yield self._byte_1
|
||||
yield self._byte_2
|
||||
@@ -187,7 +187,12 @@ class ButtonState:
|
||||
self._byte_1 = self._byte_2 = self._byte_3 = 0
|
||||
|
||||
|
||||
async def button_down(controller_state, *buttons):
|
||||
async def button_press(controller_state, *buttons):
|
||||
"""
|
||||
Set given buttons in the controller state to the pressed down state and wait till send.
|
||||
:param controller_state:
|
||||
:param buttons: Buttons to press down (see ButtonState.get_available_buttons)
|
||||
"""
|
||||
if not buttons:
|
||||
raise ValueError('No Buttons were given.')
|
||||
|
||||
@@ -195,13 +200,18 @@ async def button_down(controller_state, *buttons):
|
||||
|
||||
for button in buttons:
|
||||
# push button
|
||||
button_state.set_button(button)
|
||||
button_state.set_button(button, pushed=True)
|
||||
|
||||
# send report
|
||||
# wait until report is send
|
||||
await controller_state.send()
|
||||
|
||||
|
||||
async def button_up(controller_state, *buttons):
|
||||
async def button_release(controller_state, *buttons):
|
||||
"""
|
||||
Set given buttons in the controller state to the unpressed state and wait till send.
|
||||
:param controller_state:
|
||||
:param buttons: Buttons to set to unpressed (see ButtonState.get_available_buttons)
|
||||
"""
|
||||
if not buttons:
|
||||
raise ValueError('No Buttons were given.')
|
||||
|
||||
@@ -211,14 +221,20 @@ async def button_up(controller_state, *buttons):
|
||||
# release button
|
||||
button_state.set_button(button, pushed=False)
|
||||
|
||||
# send report
|
||||
# wait until report is send
|
||||
await controller_state.send()
|
||||
|
||||
|
||||
async def button_push(controller_state, *buttons, sec=0.1):
|
||||
await button_down(controller_state, *buttons)
|
||||
"""
|
||||
Shortly push the given buttons. Wait until the controller state is send.
|
||||
:param controller_state:
|
||||
:param buttons: Buttons to push (see ButtonState.get_available_buttons)
|
||||
:param sec: Seconds to wait before releasing the button, default: 0.1
|
||||
"""
|
||||
await button_press(controller_state, *buttons)
|
||||
await asyncio.sleep(sec)
|
||||
await button_up(controller_state, *buttons)
|
||||
await button_release(controller_state, *buttons)
|
||||
|
||||
|
||||
class _StickCalibration:
|
||||
|
||||
Reference in New Issue
Block a user