Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tell the user if bluetooth is missing (+lint) #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions demo/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { channelNames, EEGReading, MuseClient } from './../../src/muse';
context.clearRect(0, 0, canvas.width, canvas.height);

for (let i = 0; i < reading.samples.length; i++) {
const sample = reading.samples[i] / 15.;
const sample = reading.samples[i] / 15;
if (sample > 0) {
context.fillRect(i * 25, height - sample, width, sample);
} else {
Expand All @@ -50,7 +50,7 @@ import { channelNames, EEGReading, MuseClient } from './../../src/muse';
document.getElementById('batteryLevel')!.innerText = reading.batteryLevel.toFixed(2) + '%';
});
client.accelerometerData.subscribe((accel) => {
const normalize = (v: number) => (v / 16384.).toFixed(2) + 'g';
const normalize = (v: number) => (v / 16384).toFixed(2) + 'g';
document.getElementById('accelerometer-x')!.innerText = normalize(accel.samples[2].x);
document.getElementById('accelerometer-y')!.innerText = normalize(accel.samples[2].y);
document.getElementById('accelerometer-z')!.innerText = normalize(accel.samples[2].z);
Expand All @@ -61,5 +61,6 @@ import { channelNames, EEGReading, MuseClient } from './../../src/muse';
});
} catch (err) {
console.error('Connection failed', err);
document.getElementById('headset-name')!.innerText = 'Connection failed ' + err;
}
};
10 changes: 9 additions & 1 deletion src/muse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export class MuseClient {
if (gatt) {
this.gatt = gatt;
} else {
if (!navigator.bluetooth) {
throw new Error('Bluetooth support required');
}
const device = await navigator.bluetooth.requestDevice({
filters: [{ services: [MUSE_SERVICE] }],
});
Expand Down Expand Up @@ -143,7 +146,12 @@ export class MuseClient {
}

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