Created
April 25, 2019 06:06
-
-
Save qdot/f178b926b11f940b29cdcb15e6993eca to your computer and use it in GitHub Desktop.
buttplug-py py3.7 implementation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from buttplug.client import (ButtplugClientWebsocketConnector, ButtplugClient, | |
ButtplugClientDevice) | |
import asyncio | |
# import signal | |
# import sys | |
async def cancel_me(): | |
print('cancel_me(): before sleep') | |
try: | |
await asyncio.sleep(3600) | |
except asyncio.CancelledError: | |
pass | |
# def signal_handler(sig, frame): | |
# print('You pressed Ctrl+C!') | |
# sys.exit(0) | |
async def run_vibration(dev: ButtplugClientDevice): | |
await dev.send_vibrate_cmd(0.5) | |
def device_added(emitter, dev: ButtplugClientDevice): | |
print("Device Added!") | |
print(dev.name) | |
asyncio.create_task(run_vibration(dev)) | |
async def main(): | |
# signal.signal(signal.SIGINT, signal_handler) | |
connector = ButtplugClientWebsocketConnector("ws://127.0.0.1:12345") | |
client = ButtplugClient("Test Client", connector) | |
client.device_added_handler += device_added | |
await client.connect() | |
await client.start_scanning() | |
task = asyncio.create_task(cancel_me()) | |
try: | |
await task | |
except asyncio.CancelledError: | |
pass | |
await client.stop_scanning() | |
await client.disconnect() | |
asyncio.run(main(), debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment