muse-js icon indicating copy to clipboard operation
muse-js copied to clipboard

Handle bootloader connection issue

Open jdpigeon opened this issue 6 years ago • 5 comments

Just noticed that muse-js is running into a similar issue that Muse LSL did before this PR: https://github.com/alexandrebarachant/muse-lsl/pull/37

When a headband is charged from empty all the way to full, it will often go into a different preset mode ('bootloader') and require a 'reset to headset mode' command (0x03 2a 31 0a) before it's BLE characteristics are made available for connection.

Attempting to connect to the headset in this mode leads to the following error: No Characteristics matching UUID 273e000b-4c4d-454d-96be-f03bac821358 found in Service with UUID 0000fe8d-0000-1000-8000-00805f9b34fb.

I suggest that we add a getDeviceInfo check to the connect function and handle a 'bootloader' device state by sending a reset command with the sendCommand function

jdpigeon avatar Aug 13 '18 20:08 jdpigeon

Thanks! PR?

urish avatar Aug 13 '18 20:08 urish

Can confirm that client.sendCommand("*1") kicks the headband out of bootloader and into headset mode.

Will make a PR sometime this week. Do you agree with the addition of a deviceInfo check to the connect function?

jdpigeon avatar Aug 13 '18 21:08 jdpigeon

Awesome. Yes, sound good - this should be transparent for the user.

deviceInfo is using async/await, which is a new feature in JavaScript which add syntactic sugar on top of promises:

    async deviceInfo() {
        const resultListener = this.controlResponses.pipe(filter((r) => !!r.fw), take(1)).toPromise();
        await this.sendCommand('v1');
        return resultListener as Promise<MuseDeviceInfo>;
    }

This is equivalent to writing:

    deviceInfo() {
        const resultListener = this.controlResponses.pipe(filter((r) => !!r.fw), take(1)).toPromise();
        return this.sendCommand('v1').then(() => {
            return resultListener as Promise<MuseDeviceInfo>;
        });
    }

urish avatar Aug 13 '18 21:08 urish

Ah thanks man, I'll get on it.

Turned out I just forgot to execute it. deviceInfo sounds like a property to me, not a function. Maybe I should rename it to getDeviceInfo?

jdpigeon avatar Aug 13 '18 21:08 jdpigeon

Perhaps it'd make more sense, but that would also break the API. I'd rather keep it this way...

urish avatar Aug 13 '18 21:08 urish