Bleak support
This commit is contained in:
parent
ec4b800ad6
commit
1ebc0978cf
22 changed files with 1655 additions and 1621 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import asyncio
|
||||
from random import randint
|
||||
from time import sleep
|
||||
|
||||
from nxbt import Nxbt, PRO_CONTROLLER
|
||||
from nxbt import AsyncNxbtClient, PRO_CONTROLLER
|
||||
|
||||
|
||||
MACRO = """
|
||||
|
|
@ -69,39 +69,39 @@ def random_colour():
|
|||
]
|
||||
|
||||
|
||||
def demo():
|
||||
async def demo():
|
||||
"""Loops over all available Bluetooth adapters
|
||||
and creates controllers on each. The last available adapter
|
||||
is used to run a macro.
|
||||
"""
|
||||
|
||||
nx = Nxbt(debug=False)
|
||||
adapters = nx.get_available_adapters()
|
||||
if len(adapters) < 1:
|
||||
raise OSError("Unable to detect any Bluetooth adapters.")
|
||||
async with AsyncNxbtClient(debug=False) as nx:
|
||||
adapters = await nx.get_available_adapters()
|
||||
if len(adapters) < 1:
|
||||
raise OSError("Unable to detect any Bluetooth adapters.")
|
||||
|
||||
controller_idxs = []
|
||||
for i in range(0, len(adapters)):
|
||||
index = nx.create_controller(
|
||||
PRO_CONTROLLER,
|
||||
adapters[i],
|
||||
colour_body=random_colour(),
|
||||
colour_buttons=random_colour())
|
||||
controller_idxs.append(index)
|
||||
controller_idxs = []
|
||||
for adapter in adapters:
|
||||
index = await nx.create_controller(
|
||||
PRO_CONTROLLER,
|
||||
adapter,
|
||||
colour_body=random_colour(),
|
||||
colour_buttons=random_colour())
|
||||
controller_idxs.append(index)
|
||||
|
||||
# Run a macro on the last controller
|
||||
for i in range(100):
|
||||
print(f"Running Demo: Iteration {i}")
|
||||
macro_id = nx.macro(controller_idxs[-1], MACRO, block=False)
|
||||
while macro_id not in nx.state[controller_idxs[-1]]["finished_macros"]:
|
||||
state = nx.state[controller_idxs[-1]]
|
||||
if state['state'] == 'crashed':
|
||||
print("An error occurred while running the demo:")
|
||||
print(state['errors'])
|
||||
exit(1)
|
||||
sleep(1.0)
|
||||
# Run a macro on the last controller
|
||||
for i in range(100):
|
||||
print(f"Running Demo: Iteration {i}")
|
||||
macro_id = await nx.macro(controller_idxs[-1], MACRO, block=False)
|
||||
while macro_id not in nx.state[controller_idxs[-1]]["finished_macros"]:
|
||||
state = nx.state[controller_idxs[-1]]
|
||||
if state['state'] == 'crashed':
|
||||
print("An error occurred while running the demo:")
|
||||
print(state['errors'])
|
||||
exit(1)
|
||||
await asyncio.sleep(1.0)
|
||||
|
||||
print("Finished!")
|
||||
print("Finished!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo()
|
||||
asyncio.run(demo())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue