Skip to content

Commit

Permalink
feat: firmware version is now checked for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinSauce committed Nov 5, 2022
1 parent d0c7ee1 commit 19c05bc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
26 changes: 20 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"@types/jest": "^28.1.6",
"@types/node": "^12.20.11",
"@types/node-fetch": "^2.6.2",
"@types/semver": "^7.3.13",
"@types/w3c-web-serial": "^1.0.2",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
Expand All @@ -101,6 +102,7 @@
"rollup-plugin-polyfill-node": "^0.10.1",
"rollup-plugin-visualizer": "^5.7.1",
"semantic-release": "^19.0.2",
"semver": "^7.3.8",
"typescript": "^4.2.4",
"wds": "^0.12.0"
},
Expand Down
11 changes: 11 additions & 0 deletions src/PirateMidiDevice.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import semver from 'semver';
import { BankSettings, Command, DeviceInfo, GlobalSettings } from './types';
import { BaseDevice } from './BaseDevice';
import { deviceDescriptors } from './data/deviceDescriptors';
Expand All @@ -7,6 +8,8 @@ import { WebSerialPort } from './serial/WebSerialPort';
import { EventEmitter } from 'events';
import { DevicePortMock } from './mock/DevicePortMock';

export const MINIMUM_FIRMWARE_VERSION = '1.1.3';

export class PirateMidiDevice extends EventEmitter {
deviceInfo?: DeviceInfo;
baseDevice: BaseDevice;
Expand All @@ -30,6 +33,14 @@ export class PirateMidiDevice extends EventEmitter {
return deviceDescriptors[this.deviceInfo.deviceModel];
}

getIsSupported(): boolean {
if (!this.deviceInfo) throw new Error('No device info available');
return semver.gte(
this.deviceInfo.firmwareVersion,
MINIMUM_FIRMWARE_VERSION
);
}

validateBankNumber(bank: number): void {
const { numberBanks } = this.getDeviceDescription();
if (typeof bank !== 'number')
Expand Down
7 changes: 6 additions & 1 deletion src/index.browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PirateMidiDevice } from './PirateMidiDevice';
import { MINIMUM_FIRMWARE_VERSION, PirateMidiDevice } from './PirateMidiDevice';
import { WebSerialPort } from './serial/WebSerialPort';
import { GetDevices } from './types';

Expand All @@ -25,5 +25,10 @@ export const getDevices: GetDevices = async () => {
// Populate deviceInfo immediately to reduce friction
await device.updateDeviceInfo();

if (!device.getIsSupported())
throw new Error(
`Minimum firmware version ${MINIMUM_FIRMWARE_VERSION} is required`
);

return [device];
};
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PirateMidiDevice } from './PirateMidiDevice';
import { MINIMUM_FIRMWARE_VERSION, PirateMidiDevice } from './PirateMidiDevice';
import { NodeSerialPort } from './serial/NodeSerialPort';
import { GetDevices } from './types';

Expand All @@ -24,6 +24,11 @@ export const getDevices: GetDevices = async () => {
// Populate deviceInfo immediately to reduce friction
await device.updateDeviceInfo();

if (!device.getIsSupported())
throw new Error(
`Minimum firmware version ${MINIMUM_FIRMWARE_VERSION} is required`
);

return device;
})
);
Expand Down

0 comments on commit 19c05bc

Please sign in to comment.