@medwand/mwsdk-javascript 0.0.0-stage → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -2
- package/dist/index.d.ts +1248 -0
- package/dist/index.js +49 -0
- package/dist/medwand-browser-sdk.js +1 -0
- package/package.json +38 -4
package/README.md
CHANGED
|
@@ -1,3 +1,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MedWand JavaScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Use the SDK to connect a MedWand device to a browser app and work with thermometer, pulse oximeter, ECG, stethoscope, and camera readings. The package includes TypeScript declarations.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @medwand/mwsdk-javascript
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Run your app in a Chromium-based browser with Web Serial support, over HTTPS or localhost. The user must grant access to the MedWand serial port. Camera and stethoscope preview can also require browser media permissions.
|
|
12
|
+
|
|
13
|
+
## Connect and take a reading
|
|
14
|
+
|
|
15
|
+
Use the license and public key provided for your application. Call this function from a button click so the browser can open its device chooser.
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { MedWandController } from "@medwand/mwsdk-javascript";
|
|
19
|
+
|
|
20
|
+
export async function startThermometer(license: string, publicKey: string) {
|
|
21
|
+
const controller = new MedWandController();
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
controller.Construct(license, publicKey);
|
|
25
|
+
if (!controller.IsLicenseValid) throw new Error("Invalid MedWand license.");
|
|
26
|
+
|
|
27
|
+
await controller.Connect();
|
|
28
|
+
if (!controller.IsConnected) throw new Error("MedWand connection failed.");
|
|
29
|
+
|
|
30
|
+
await controller.CheckFirmwareVersion();
|
|
31
|
+
controller.Configure();
|
|
32
|
+
await controller.Initialize();
|
|
33
|
+
if (!controller.IsInitialized) throw new Error("MedWand initialization failed.");
|
|
34
|
+
|
|
35
|
+
controller.on("OnReadingReceived", reading => console.log(reading));
|
|
36
|
+
if (!await controller.StartThermometer()) {
|
|
37
|
+
throw new Error("Could not start the thermometer.");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return controller;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
await controller.Dispose();
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Call `StopSensor()` to end the active reading and `Dispose()` when your app is done with the device. Calling `on()` returns an unsubscribe function. Subscribe to `OnDeviceStateChanged` and `OnDeviceError` to show connection status and device errors in your app.
|
|
49
|
+
|
|
50
|
+
## Use other sensors
|
|
51
|
+
|
|
52
|
+
| Sensor | Start or configure | Capture |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| Pulse oximeter | Call `StartPulseOximeter()`. | Read values through `OnReadingReceived`. |
|
|
55
|
+
| ECG | Pass a canvas to `Configure(canvas)` before initialization, then call `StartEcg()`. | Use `StartRecording()` and `StopRecording()`. Listen for `controller.Ecg`'s `RecordedStripReady` event and pass its bytes to `EcgBmpFromCapture()`. |
|
|
56
|
+
| Stethoscope | Call `SetStethoscopeMode(MicrophoneModes.Heart, null)` for SDK-managed preview on the default speaker. Omit the second argument if your app manages audio input itself. Use `MicrophoneModes.Off` when finished. | For SDK-managed audio, use `StartRecording()` and `StopRecording()`. Listen for `controller.Stethoscope`'s `RecordedFramesReady` event and pass its bytes to `StethoscopeWavFromCapture()`. |
|
|
57
|
+
| Camera | Pass a video or canvas element and a mode to `SetCameraMode(preview, CameraModes.Otoscope)`. Use `CameraModes.Off` when finished. | Call `StartRecording()` to capture one frame. Listen for `controller.Camera`'s `RecordedFrameReady` event and pass its bytes to `CameraBmpFromCapture()`. |
|
|
58
|
+
|
|
59
|
+
## Handle firmware updates
|
|
60
|
+
|
|
61
|
+
`Connect()` or `CheckFirmwareVersion()` can throw `MedWandFirmwareUpdateRequiredException`. Use its `CurrentVersion` and `RequiredVersion` fields to inform the user. Dispose the device controller, then call the firmware updater from a separate button click. Keep the MedWand connected until the update completes.
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { FirmwareController } from "@medwand/mwsdk-javascript";
|
|
65
|
+
|
|
66
|
+
export async function updateFirmware() {
|
|
67
|
+
const updater = new FirmwareController();
|
|
68
|
+
updater.on("FirmwareStateChanged", state => console.log(state));
|
|
69
|
+
updater.on("FirmwareProgressChanged", percent => console.log(percent));
|
|
70
|
+
updater.on("FirmwareError", error => console.error(error));
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
return await updater.StartAsync();
|
|
74
|
+
} finally {
|
|
75
|
+
await updater.DisposeAsync();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`StartAsync()` returns whether the update completed successfully. After success, reconnect and initialize a new `MedWandController` before starting a sensor.
|