Skip to content

Commit

Permalink
fix: use muse preset 21 when Aux is not enabled
Browse files Browse the repository at this point in the history
close #4
  • Loading branch information
urish committed Dec 15, 2017
1 parent c7239d4 commit 1178841
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
20 changes: 18 additions & 2 deletions src/muse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('MuseClient', () => {
});

describe('start', async () => {
it('should send `h`, `s`, `p20` and `d` commands to the EEG headset', async () => {
it('should send `h`, `s`, `p21` and `d` commands to the EEG headset', async () => {
const client = new MuseClient();
const controlCharacteristic = museDevice.getServiceMock(0xfe8d)
.getCharacteristicMock('273e0001-4c4d-454d-96be-f03bac821358');
Expand All @@ -75,10 +75,26 @@ describe('MuseClient', () => {
expect(controlCharacteristic.writeValue)
.toHaveBeenCalledWith(new Uint8Array([2, ...charCodes('s'), 10]));
expect(controlCharacteristic.writeValue)
.toHaveBeenCalledWith(new Uint8Array([4, ...charCodes('p20'), 10]));
.toHaveBeenCalledWith(new Uint8Array([4, ...charCodes('p21'), 10]));
expect(controlCharacteristic.writeValue)
.toHaveBeenCalledWith(new Uint8Array([2, ...charCodes('d'), 10]));
});

it('choose preset number 20 instead of 21 if aux is enabled', async () => {
const client = new MuseClient();
const controlCharacteristic = museDevice.getServiceMock(0xfe8d)
.getCharacteristicMock('273e0001-4c4d-454d-96be-f03bac821358');
controlCharacteristic.writeValue = jest.fn();

client.enableAux = true;
await client.connect();
await client.start();

expect(controlCharacteristic.writeValue)
.toHaveBeenCalledWith(new Uint8Array([4, ...charCodes('p20'), 10]));
expect(controlCharacteristic.writeValue)
.not.toHaveBeenCalledWith(new Uint8Array([4, ...charCodes('p21'), 10]));
});
});

describe('eegReadings', () => {
Expand Down
5 changes: 2 additions & 3 deletions src/muse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ export class MuseClient {
}

async start() {
// Subscribe to EEG characteristics
await this.pause();
// Select preset number 20
await this.controlChar.writeValue(encodeCommand('p20'));
const preset = this.enableAux ? 'p20' : 'p21';
await this.controlChar.writeValue(encodeCommand(preset));
await this.controlChar.writeValue(encodeCommand('s'));
await this.resume();
}
Expand Down

0 comments on commit 1178841

Please sign in to comment.