virtualabs / btlejack

Bluetooth Low Energy Swiss-army knife
MIT License
1.88k stars 195 forks source link

fix bug #8 #10

Closed wwj718 closed 6 years ago

wwj718 commented 6 years ago

Make it work with macOS

wwj718 commented 6 years ago

the mu-editor is cross-platform Maybe we can use find_microbit()

virtualabs commented 6 years ago

I had a look at PySerial comports() function for MacOS, and it seems it fills VID and PID automatically. This is all we need to find a microbit.

Also found this implementation:

# Regular expression to match the device id of the micro:bit
RE_VID_PID = re.compile("VID:PID=([0-9A-F]+):([0-9A-F]+)", re.I)

def find_microbit():
    """
    Returns the port for the first micro:bit found connected to the computer
    running this script. If no micro:bit is found, returns None.
    """
    for port, desc, opts in comports():
        match = RE_VID_PID.search(opts)
        if match:
            vid, pid = match.groups()
            vid, pid = int(vid, 16), int(pid, 16)
            if vid == MICROBIT_VID and pid == MICROBIT_PID:
                return port
    if sys.platform.startswith('win'):
        # No COM port found, so give an informative prompt.
        sys.stderr.write('Have you installed the micro:bit driver?\n')
        sys.stderr.write('For more details see: {}\n'.format(ARM))
    return None

I will try this fix until it fails for someone. Maybe a bad call.

wwj718 commented 6 years ago

@virtualabs 👍