Added led control
Co-authored-by: David Wright <david--wright@users.noreply.github.com>
This commit is contained in:
parent
7e37c86a69
commit
15315e06c2
66
droid.py
66
droid.py
|
@ -1,9 +1,11 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from bleak import BleakScanner, BleakClient
|
from bleak import BleakScanner, BleakClient
|
||||||
|
import pickle
|
||||||
class Droid():
|
class Droid():
|
||||||
def __init__(self, profile):
|
def __init__(self, profile):
|
||||||
print("Initializing")
|
print("Initializing")
|
||||||
|
self.disabledLeds = 0x00
|
||||||
self.profile = profile
|
self.profile = profile
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
timeout=0.0
|
timeout=0.0
|
||||||
|
@ -35,10 +37,42 @@ class Droid():
|
||||||
finally:
|
finally:
|
||||||
await self.droid.disconnect()
|
await self.droid.disconnect()
|
||||||
print("Disconnected")
|
print("Disconnected")
|
||||||
|
|
||||||
|
async def led_disable_sound(self, leds):
|
||||||
|
ledDisableCommand = bytearray.fromhex(f"27420f4444004a{leds}")
|
||||||
|
await self.droid.write_gatt_char(0x000d, ledDisableCommand)
|
||||||
|
self.disabledLeds = self.disabledLeds|int(leds, 16)
|
||||||
|
print(self.disabledLeds)
|
||||||
|
|
||||||
async def play_sound(self, sound_id=None, bank_id=None, cycle=False):
|
async def led_enable_sound(self, leds):
|
||||||
if bank_id and self.soundbank != bank_id:
|
ledEnableCommand = bytearray.fromhex(f"27420f4444004b{leds}")
|
||||||
self.set_soundbank(bank_id)
|
await self.droid.write_gatt_char(0x000d, ledEnableCommand)
|
||||||
|
self.disabledLeds = self.disabledLeds-(int(leds, 16)&self.disabledLeds)
|
||||||
|
print(self.disabledLeds)
|
||||||
|
|
||||||
|
|
||||||
|
async def led_flash(self, leds, duration):
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def led_off(self, leds):
|
||||||
|
ledOffCommand = bytearray.fromhex( f"27420f44440049{leds}" )
|
||||||
|
await self.droid.write_gatt_char(0x000d, ledOffCommand)
|
||||||
|
print(f"{self.disabledLeds:02x}")
|
||||||
|
print((f"{(~self.disabledLeds & 0x1F):02x}"))
|
||||||
|
await self.led_enable_sound(f"{(~self.disabledLeds & 0x1F):02x}")
|
||||||
|
|
||||||
|
|
||||||
|
async def led_on(self, leds):
|
||||||
|
ledOnCommand = bytearray.fromhex(f"27420f44440048{leds}")
|
||||||
|
await self.droid.write_gatt_char(0x000d, ledOnCommand)
|
||||||
|
|
||||||
|
def move (self ):
|
||||||
|
pass
|
||||||
|
async def play_sound(self, sound_id=None, bank_id=None, cycle=False, volume=None):
|
||||||
|
if volume:
|
||||||
|
self.set_volume(volume)
|
||||||
|
if bank_id and (not hasattr(self, "soundbank") or self.soundbank != bank_id):
|
||||||
|
await self.set_soundbank(bank_id)
|
||||||
if sound_id:
|
if sound_id:
|
||||||
soundSelection = bytearray.fromhex("27420f44440018{}".format(sound_id))
|
soundSelection = bytearray.fromhex("27420f44440018{}".format(sound_id))
|
||||||
elif cycle:
|
elif cycle:
|
||||||
|
@ -73,15 +107,25 @@ async def main():
|
||||||
await arms.connect()
|
await arms.connect()
|
||||||
sleep (3)
|
sleep (3)
|
||||||
try:
|
try:
|
||||||
await arms.run_routine("05")
|
# await arms.run_routine("05")
|
||||||
sleep (5)
|
# sleep (5)
|
||||||
await arms.set_soundbank("05")
|
# await arms.set_soundbank("05")
|
||||||
await arms.play_sound("00")
|
# await arms.play_sound("00")
|
||||||
sleep (5)
|
# sleep (5)
|
||||||
for i in range(5):
|
# for i in range(5):
|
||||||
await arms.play_sound(cycle=True)
|
# await arms.play_sound(cycle=True)
|
||||||
sleep(5)
|
# sleep(5)
|
||||||
|
# await arms.play_sound("00", "00")
|
||||||
|
# sleep(8)
|
||||||
|
await arms.led_disable_sound("01")
|
||||||
await arms.play_sound("00", "00")
|
await arms.play_sound("00", "00")
|
||||||
|
sleep(10)
|
||||||
|
await arms.led_on("1f")
|
||||||
|
sleep(10)
|
||||||
|
await arms.led_off("1f")
|
||||||
|
await arms.play_sound("00", "00")
|
||||||
|
sleep(10)
|
||||||
|
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
await arms.disconnect()
|
await arms.disconnect()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user