Skip to content

Instantly share code, notes, and snippets.

@KarimJedda
Last active April 5, 2022 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KarimJedda/4e63d70b92bf0460227e679b79e8f0b2 to your computer and use it in GitHub Desktop.
Save KarimJedda/4e63d70b92bf0460227e679b79e8f0b2 to your computer and use it in GitHub Desktop.
Smooth Q3 Debug
import pygatt
# pip install pygatt
import logging
from binascii import hexlify
import time
from itertools import repeat
import re
def string_to_bytearr_repr(value):
a = re.findall('..', value)
return ['0x'+val for val in a]
logging.basicConfig()
logging.getLogger('pygatt').setLevel(logging.DEBUG)
adapter = pygatt.GATTToolBackend()
move_right_guess = [0x06, 0x10, 0x01, 0x08, 0x24, 0x0c, 0x5d]
move_right_guess_1 = [0x06, 0x10, 0x02, 0x08, 0x00, 0x31, 0xeb]
move_right_guess_2 = [0x06, 0x10, 0x03, 0x0f, 0xbd, 0xe9, 0x3a]
def turn_right(device, n=1):
for i in repeat(None, n):
device.char_write('d44bc439-abfd-45a2-b575-925416129600', bytearray(move_right_guess) )
device.char_write('d44bc439-abfd-45a2-b575-925416129600', bytearray(move_right_guess_1) )
device.char_write('d44bc439-abfd-45a2-b575-925416129600', bytearray(move_right_guess_2) )
move_left_guess = [0x06, 0x10, 0x01, 0x07, 0xd0, 0xb3, 0xf8]
move_left_guess_1 = [0x06, 0x10, 0x02, 0x08, 0x00, 0x31, 0xeb]
move_left_guess_2 = [0x06, 0x10, 0x03, 0x01, 0xf6, 0x33, 0x9a]
def turn_left(device, n=1):
for i in repeat(None, n):
device.char_write('d44bc439-abfd-45a2-b575-925416129600', bytearray(move_left_guess) )
device.char_write('d44bc439-abfd-45a2-b575-925416129600', bytearray(move_left_guess_1) )
device.char_write('d44bc439-abfd-45a2-b575-925416129600', bytearray(move_left_guess_2) )
def handle_data(handle, value):
"""
handle -- integer, characteristic read handle the data was received on
value -- bytearray, the data returned in the notification
"""
print("Received data: %s" % hexlify(value))
try:
adapter.start()
# Smooth Q3
device = adapter.connect('ac:9a:22:54:27:34')
device.subscribe("d44bc439-abfd-45a2-b575-925416129601", callback=handle_data)
device.subscribe("d44bc439-abfd-45a2-b575-925416129610", callback=handle_data)
time.sleep(1)
time.sleep(1)
turn_left(device, n=6)
time.sleep(1)
turn_right(device, n=6)
finally:
adapter.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment