Add Sound Controls

This commit is contained in:
David Wright 2022-09-27 16:07:56 -06:00
parent 42c7117c7f
commit 7e37c86a69

View File

@ -20,26 +20,46 @@ class Droid():
print("Locked") print("Locked")
light_blink = bytearray.fromhex("2C000449020001ff01ff0aff00") light_blink = bytearray.fromhex("2C000449020001ff01ff0aff00")
await self.droid.write_gatt_char(0x000d, light_blink) await self.droid.write_gatt_char(0x000d, light_blink)
soundSelection = bytearray.fromhex("27420f4444001800")
await self.droid.write_gatt_char(0x000d, soundSelection)
connect_sound = bytearray.fromhex("25000c421102") connect_sound = bytearray.fromhex("25000c421102")
await self.droid.write_gatt_char(0x000d, connect_sound) await self.droid.write_gatt_char(0x000d, connect_sound)
sleep(3)
async def disconnect(self): async def disconnect(self):
print ("Disconnecting") print ("Disconnecting")
try: try:
soundBank = bytearray.fromhex("27420f4444001f08") soundBank = bytearray.fromhex("27420f4444001f09")
await self.droid.write_gatt_char(0x000d, soundBank) await self.droid.write_gatt_char(0x000d, soundBank)
soundSelection = bytearray.fromhex("27420f4444001808") soundSelection = bytearray.fromhex("27420f4444001800")
await self.droid.write_gatt_char(0x000d, soundSelection) await self.droid.write_gatt_char(0x000d, soundSelection)
sleep(3)
finally: finally:
await self.droid.disconnect() await self.droid.disconnect()
print("Disconnected") print("Disconnected")
async def play_sound(self, sound_id=None, bank_id=None, cycle=False):
if bank_id and self.soundbank != bank_id:
self.set_soundbank(bank_id)
if sound_id:
soundSelection = bytearray.fromhex("27420f44440018{}".format(sound_id))
elif cycle:
soundSelection = bytearray.fromhex("26420f4344001c")
else:
soundSelection = bytearray.fromhex("27420f44440010{}".format(self.bank_id))
await self.droid.write_gatt_char(0x000d, soundSelection)
async def run_routine(self, routineId): async def run_routine(self, routineId):
full_id = bytearray.fromhex("25000c42{}02".format(routineId)) full_id = bytearray.fromhex("25000c42{}02".format(routineId))
await self.droid.write_gatt_char(0x000d, full_id) await self.droid.write_gatt_char(0x000d, full_id)
async def set_soundbank(self, bank_id):
self.soundbank = bank_id
soundBank = bytearray.fromhex("27420f4444001f{}".format(bank_id))
await self.droid.write_gatt_char(0x000d, soundBank)
async def set_volume(self, volume):
volume_command = bytearray.fromhex("27420f4444000e{}".format(volume))
await self.droid.write_gatt_char(0x000d, volume_command)
def findDroid(candidate, data): def findDroid(candidate, data):
if candidate.name == "DROID": if candidate.name == "DROID":
return True return True
@ -55,6 +75,14 @@ async def main():
try: try:
await arms.run_routine("05") await arms.run_routine("05")
sleep (5) sleep (5)
await arms.set_soundbank("05")
await arms.play_sound("00")
sleep (5)
for i in range(5):
await arms.play_sound(cycle=True)
sleep(5)
await arms.play_sound("00", "00")
finally: finally:
await arms.disconnect() await arms.disconnect()
asyncio.run(main()) asyncio.run(main())