brilliantsole 0.0.26 → 0.0.28
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 +16 -10
- package/assets/3d/anchor.glb +0 -0
- package/assets/3d/coin.glb +0 -0
- package/assets/3d/glasses.glb +0 -0
- package/assets/3d/rightHand.glb +0 -0
- package/assets/audio/bounceMedium.wav +0 -0
- package/assets/audio/bounceStrong.wav +0 -0
- package/assets/audio/bounceWeak.wav +0 -0
- package/assets/audio/coin.wav +0 -0
- package/assets/audio/getUp.wav +0 -0
- package/assets/audio/grab.wav +0 -0
- package/assets/audio/kick.wav +0 -0
- package/assets/audio/platterFadeIn old.wav +0 -0
- package/assets/audio/platterFadeIn.wav +0 -0
- package/assets/audio/platterFadeOut.wav +0 -0
- package/assets/audio/punch.wav +0 -0
- package/assets/audio/punchSqueak.wav +0 -0
- package/assets/audio/purr.wav +0 -0
- package/assets/audio/purrFadeOut.wav +0 -0
- package/assets/audio/release.wav +0 -0
- package/assets/audio/splat.wav +0 -0
- package/assets/audio/stomp.wav +0 -0
- package/assets/images/ukaton-pressure-0.svg +9 -0
- package/assets/images/ukaton-pressure-1.svg +9 -0
- package/assets/images/ukaton-pressure-10.svg +9 -0
- package/assets/images/ukaton-pressure-11.svg +9 -0
- package/assets/images/ukaton-pressure-12.svg +9 -0
- package/assets/images/ukaton-pressure-13.svg +9 -0
- package/assets/images/ukaton-pressure-14.svg +9 -0
- package/assets/images/ukaton-pressure-15.svg +9 -0
- package/assets/images/ukaton-pressure-2.svg +9 -0
- package/assets/images/ukaton-pressure-3.svg +9 -0
- package/assets/images/ukaton-pressure-4.svg +9 -0
- package/assets/images/ukaton-pressure-5.svg +9 -0
- package/assets/images/ukaton-pressure-6.svg +9 -0
- package/assets/images/ukaton-pressure-7.svg +9 -0
- package/assets/images/ukaton-pressure-8.svg +9 -0
- package/assets/images/ukaton-pressure-9.svg +9 -0
- package/assets/images/ukaton-right-insole.svg +798 -0
- package/build/brilliantsole.cjs +2870 -882
- package/build/brilliantsole.cjs.map +1 -1
- package/build/brilliantsole.js +2477 -782
- package/build/brilliantsole.js.map +1 -1
- package/build/brilliantsole.ls.js +2260 -592
- package/build/brilliantsole.ls.js.map +1 -1
- package/build/brilliantsole.min.js +1 -1
- package/build/brilliantsole.min.js.map +1 -1
- package/build/brilliantsole.module.d.ts +302 -116
- package/build/brilliantsole.module.js +2468 -782
- package/build/brilliantsole.module.js.map +1 -1
- package/build/brilliantsole.module.min.d.ts +302 -116
- package/build/brilliantsole.module.min.js +1 -1
- package/build/brilliantsole.module.min.js.map +1 -1
- package/build/brilliantsole.node.module.d.ts +295 -113
- package/build/brilliantsole.node.module.js +2860 -882
- package/build/brilliantsole.node.module.js.map +1 -1
- package/build/dts/BS-output.d.ts +10 -0
- package/build/dts/BS.d.ts +21 -9
- package/build/dts/CameraManager.d.ts +72 -0
- package/build/dts/Device.d.ts +53 -16
- package/build/dts/DeviceInformationManager.d.ts +4 -4
- package/build/dts/DeviceManager.d.ts +3 -0
- package/build/dts/FileTransferManager.d.ts +18 -8
- package/build/dts/InformationManager.d.ts +8 -5
- package/build/dts/TfliteManager.d.ts +22 -2
- package/build/dts/WifiManager.d.ts +61 -0
- package/build/dts/connection/BaseConnectionManager.d.ts +37 -3
- package/build/dts/connection/ClientConnectionManager.d.ts +11 -2
- package/build/dts/connection/bluetooth/BluetoothConnectionManager.d.ts +1 -0
- package/build/dts/connection/bluetooth/NobleConnectionManager.d.ts +3 -1
- package/build/dts/connection/bluetooth/WebBluetoothConnectionManager.d.ts +2 -0
- package/build/dts/connection/bluetooth/bluetoothUUIDs.d.ts +2 -2
- package/build/dts/connection/udp/UDPConnectionManager.d.ts +28 -0
- package/build/dts/connection/webSocket/WebSocketConnectionManager.d.ts +25 -0
- package/build/dts/devicePair/DevicePair.d.ts +14 -10
- package/build/dts/devicePair/DevicePairPressureSensorDataManager.d.ts +8 -4
- package/build/dts/devicePair/DevicePairSensorDataManager.d.ts +2 -2
- package/build/dts/scanner/BaseScanner.d.ts +4 -1
- package/build/dts/scanner/NobleScanner.d.ts +2 -1
- package/build/dts/sensor/MotionSensorDataManager.d.ts +5 -2
- package/build/dts/sensor/SensorDataManager.d.ts +5 -4
- package/build/dts/server/BaseClient.d.ts +6 -3
- package/build/dts/server/ServerUtils.d.ts +1 -1
- package/build/dts/server/websocket/WebSocketUtils.d.ts +1 -1
- package/build/dts/utils/CenterOfPressureHelper.d.ts +2 -2
- package/build/dts/utils/Console.d.ts +2 -0
- package/build/dts/utils/MathUtils.d.ts +2 -0
- package/build/dts/utils/ThrottleUtils.d.ts +2 -0
- package/build/dts/vibration/VibrationManager.d.ts +19 -2
- package/build/index.d.ts +299 -113
- package/build/index.node.d.ts +292 -110
- package/examples/3d/scene.html +19 -5
- package/examples/3d/script.js +90 -17
- package/examples/3d-generic/index.html +144 -0
- package/examples/3d-generic/script.js +266 -0
- package/examples/balance/script.js +2 -1
- package/examples/basic/index.html +232 -18
- package/examples/basic/script.js +746 -106
- package/examples/bottango/index.html +11 -1
- package/examples/bottango/script.js +2 -2
- package/examples/center-of-pressure/index.html +114 -114
- package/examples/center-of-pressure/script.js +1 -1
- package/examples/device-pair/index.html +58 -58
- package/examples/device-pair/script.js +12 -8
- package/examples/edge-impulse/script.js +135 -44
- package/examples/edge-impulse-test/README.md +11 -0
- package/examples/edge-impulse-test/edge-impulse-standalone.js +7228 -0
- package/examples/edge-impulse-test/edge-impulse-standalone.wasm +0 -0
- package/examples/edge-impulse-test/index.html +75 -0
- package/examples/edge-impulse-test/run-impulse.js +135 -0
- package/examples/edge-impulse-test/script.js +200 -0
- package/examples/gloves/edge-impulse-standalone.js +7228 -0
- package/examples/gloves/edge-impulse-standalone.wasm +0 -0
- package/examples/gloves/index.html +119 -0
- package/examples/gloves/run-impulse.js +135 -0
- package/examples/gloves/scene.html +124 -0
- package/examples/gloves/script.js +931 -0
- package/examples/graph/index.html +11 -1
- package/examples/graph/script.js +94 -37
- package/examples/pressure/index.html +180 -12
- package/examples/pressure/script.js +144 -7
- package/examples/punch/index.html +135 -0
- package/examples/punch/punch.tflite +0 -0
- package/examples/punch/script.js +169 -0
- package/examples/recording/index.html +191 -183
- package/examples/server/index.html +109 -23
- package/examples/server/script.js +322 -111
- package/examples/ukaton-firmware-update/index.html +20 -0
- package/examples/ukaton-firmware-update/manifest.json +11 -0
- package/examples/ukaton-firmware-update/merged-firmware.bin +0 -0
- package/examples/utils/aframe/aframe-master.min.js +2 -0
- package/examples/utils/aframe/bs-vibration.js +150 -0
- package/examples/utils/aframe/force-pushable.js +80 -0
- package/examples/utils/aframe/grabbable-anchor.js +46 -0
- package/examples/utils/aframe/grabbable-listener.js +31 -0
- package/examples/utils/aframe/grabbable-physics-body.js +190 -0
- package/examples/utils/aframe/grow-shrink.js +25 -0
- package/examples/utils/aframe/hand-punch.js +119 -0
- package/examples/utils/aframe/my-obb-collider.js +293 -0
- package/examples/utils/aframe/occlude-hand-tracking-controls.js +47 -0
- package/examples/utils/aframe/occlude-mesh.js +42 -0
- package/examples/utils/aframe/palm-up-detector.js +47 -0
- package/examples/utils/aframe/shadow-material.js +20 -0
- package/examples/utils/aframe/soft-shadow-light.js +9 -0
- package/examples/webxr/script.js +3 -3
- package/examples/webxr-2/assets/3d/soccerBall.glb +0 -0
- package/examples/webxr-2/assets/audio/shellBounce.wav +0 -0
- package/examples/webxr-2/assets/audio/shellHit.wav +0 -0
- package/examples/webxr-2/assets/audio/shellKick.wav +0 -0
- package/examples/webxr-2/assets/audio/soccerBounce.wav +0 -0
- package/examples/webxr-2/assets/audio/soccerKick.mp3 +0 -0
- package/examples/webxr-2/assets/images/shellTexture.png +0 -0
- package/examples/webxr-2/components/bs-ankle.js +337 -0
- package/examples/webxr-2/components/coin.js +84 -0
- package/examples/webxr-2/components/custom-wrap.js +17 -0
- package/examples/webxr-2/components/goomba.js +3250 -0
- package/examples/webxr-2/components/init-shell-material.js +215 -0
- package/examples/webxr-2/components/platter.js +172 -0
- package/examples/webxr-2/components/shell.js +374 -0
- package/examples/webxr-2/components/soccer-ball.js +250 -0
- package/examples/webxr-2/components/squashed-goomba.js +249 -0
- package/examples/webxr-2/edge-impulse-standalone.js +7228 -0
- package/examples/webxr-2/edge-impulse-standalone.wasm +0 -0
- package/examples/webxr-2/index.html +996 -0
- package/examples/webxr-2/kick.tflite +0 -0
- package/examples/webxr-2/kick2.tflite +0 -0
- package/examples/webxr-2/run-impulse.js +135 -0
- package/examples/webxr-2/script.js +384 -0
- package/package.json +2 -1
- package/src/.prettierrc +4 -0
- package/src/BS.ts +66 -9
- package/src/CameraManager.ts +499 -0
- package/src/Device.ts +620 -92
- package/src/DeviceInformationManager.ts +22 -11
- package/src/DeviceManager.ts +94 -25
- package/src/FileTransferManager.ts +146 -21
- package/src/FirmwareManager.ts +1 -1
- package/src/InformationManager.ts +62 -20
- package/src/TfliteManager.ts +172 -26
- package/src/WifiManager.ts +323 -0
- package/src/connection/BaseConnectionManager.ts +145 -30
- package/src/connection/ClientConnectionManager.ts +47 -11
- package/src/connection/bluetooth/BluetoothConnectionManager.ts +14 -3
- package/src/connection/bluetooth/NobleConnectionManager.ts +155 -42
- package/src/connection/bluetooth/WebBluetoothConnectionManager.ts +104 -35
- package/src/connection/bluetooth/bluetoothUUIDs.ts +40 -13
- package/src/connection/udp/UDPConnectionManager.ts +356 -0
- package/src/connection/websocket/WebSocketConnectionManager.ts +282 -0
- package/src/devicePair/DevicePair.ts +145 -49
- package/src/devicePair/DevicePairPressureSensorDataManager.ts +72 -24
- package/src/devicePair/DevicePairSensorDataManager.ts +5 -5
- package/src/scanner/BaseScanner.ts +49 -11
- package/src/scanner/NobleScanner.ts +81 -17
- package/src/sensor/BarometerSensorDataManager.ts +1 -1
- package/src/sensor/MotionSensorDataManager.ts +22 -7
- package/src/sensor/PressureSensorDataManager.ts +47 -13
- package/src/sensor/SensorConfigurationManager.ts +75 -24
- package/src/sensor/SensorDataManager.ts +107 -26
- package/src/server/BaseClient.ts +192 -37
- package/src/server/BaseServer.ts +201 -43
- package/src/server/ServerUtils.ts +39 -9
- package/src/server/udp/UDPServer.ts +74 -23
- package/src/server/udp/UDPUtils.ts +9 -2
- package/src/server/websocket/WebSocketClient.ts +30 -9
- package/src/server/websocket/WebSocketServer.ts +1 -1
- package/src/server/websocket/WebSocketUtils.ts +4 -2
- package/src/utils/CenterOfPressureHelper.ts +5 -5
- package/src/utils/Console.ts +62 -9
- package/src/utils/MathUtils.ts +31 -1
- package/src/utils/ParseUtils.ts +25 -6
- package/src/utils/ThrottleUtils.ts +62 -0
- package/src/utils/Timer.ts +1 -1
- package/src/utils/checksum.ts +1 -1
- package/src/utils/mcumgr.js +1 -1
- package/src/vibration/VibrationManager.ts +166 -40
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
import { createConsole } from "../utils/Console.ts";
|
|
2
2
|
import { isInBrowser } from "../utils/environment.ts";
|
|
3
|
-
import BaseConnectionManager, {
|
|
3
|
+
import BaseConnectionManager, {
|
|
4
|
+
ConnectionType,
|
|
5
|
+
ConnectionMessageType,
|
|
6
|
+
ClientConnectionType,
|
|
7
|
+
} from "./BaseConnectionManager.ts";
|
|
4
8
|
import { DeviceEventTypes } from "../Device.ts";
|
|
5
9
|
import { parseMessage } from "../utils/ParseUtils.ts";
|
|
6
|
-
import {
|
|
10
|
+
import { DeviceInformationTypes } from "../DeviceInformationManager.ts";
|
|
7
11
|
import { DeviceEventType } from "../Device.ts";
|
|
8
12
|
import { ClientDeviceMessage } from "../server/ServerUtils.ts";
|
|
13
|
+
import BaseClient from "../server/BaseClient.ts";
|
|
14
|
+
import { DiscoveredDevice } from "../BS.ts";
|
|
9
15
|
|
|
10
|
-
const _console = createConsole("ClientConnectionManager", { log:
|
|
16
|
+
const _console = createConsole("ClientConnectionManager", { log: false });
|
|
11
17
|
|
|
12
|
-
export type SendClientMessageCallback = (
|
|
18
|
+
export type SendClientMessageCallback = (
|
|
19
|
+
...messages: ClientDeviceMessage[]
|
|
20
|
+
) => void;
|
|
13
21
|
|
|
14
|
-
|
|
22
|
+
export type SendClientConnectMessageCallback = (
|
|
23
|
+
connectionType?: ClientConnectionType
|
|
24
|
+
) => void;
|
|
25
|
+
|
|
26
|
+
const ClientDeviceInformationMessageTypes: ConnectionMessageType[] = [
|
|
27
|
+
...DeviceInformationTypes,
|
|
28
|
+
"batteryLevel",
|
|
29
|
+
];
|
|
15
30
|
|
|
16
31
|
class ClientConnectionManager extends BaseConnectionManager {
|
|
17
32
|
static get isSupported() {
|
|
@@ -21,6 +36,16 @@ class ClientConnectionManager extends BaseConnectionManager {
|
|
|
21
36
|
return "client";
|
|
22
37
|
}
|
|
23
38
|
|
|
39
|
+
subType?: ClientConnectionType;
|
|
40
|
+
|
|
41
|
+
get canUpdateFirmware() {
|
|
42
|
+
// FIX - how to know if it has an smp characteristic?
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
client!: BaseClient;
|
|
47
|
+
discoveredDevice!: DiscoveredDevice;
|
|
48
|
+
|
|
24
49
|
#bluetoothId!: string;
|
|
25
50
|
get bluetoothId() {
|
|
26
51
|
return this.#bluetoothId!;
|
|
@@ -53,9 +78,13 @@ class ClientConnectionManager extends BaseConnectionManager {
|
|
|
53
78
|
}
|
|
54
79
|
}
|
|
55
80
|
|
|
81
|
+
get isAvailable() {
|
|
82
|
+
return this.client.isConnected;
|
|
83
|
+
}
|
|
84
|
+
|
|
56
85
|
async connect() {
|
|
57
86
|
await super.connect();
|
|
58
|
-
this.sendClientConnectMessage();
|
|
87
|
+
this.sendClientConnectMessage(this.subType);
|
|
59
88
|
}
|
|
60
89
|
async disconnect() {
|
|
61
90
|
await super.disconnect();
|
|
@@ -67,13 +96,13 @@ class ClientConnectionManager extends BaseConnectionManager {
|
|
|
67
96
|
}
|
|
68
97
|
async reconnect() {
|
|
69
98
|
await super.reconnect();
|
|
70
|
-
|
|
71
|
-
this.connect();
|
|
99
|
+
this.sendClientConnectMessage();
|
|
72
100
|
}
|
|
73
101
|
|
|
74
102
|
sendClientMessage!: SendClientMessageCallback;
|
|
75
|
-
sendClientConnectMessage!:
|
|
103
|
+
sendClientConnectMessage!: SendClientConnectMessageCallback;
|
|
76
104
|
sendClientDisconnectMessage!: Function;
|
|
105
|
+
sendRequiredDeviceInformationMessage!: Function;
|
|
77
106
|
|
|
78
107
|
async sendSmpMessage(data: ArrayBuffer) {
|
|
79
108
|
super.sendSmpMessage(data);
|
|
@@ -89,12 +118,19 @@ class ClientConnectionManager extends BaseConnectionManager {
|
|
|
89
118
|
}
|
|
90
119
|
|
|
91
120
|
#requestDeviceInformation() {
|
|
92
|
-
this.sendClientMessage(...ClientDeviceInformationMessageTypes);
|
|
121
|
+
//this.sendClientMessage(...ClientDeviceInformationMessageTypes);
|
|
122
|
+
this.sendRequiredDeviceInformationMessage();
|
|
93
123
|
}
|
|
94
124
|
|
|
95
125
|
onClientMessage(dataView: DataView) {
|
|
96
126
|
_console.log({ dataView });
|
|
97
|
-
parseMessage(
|
|
127
|
+
parseMessage(
|
|
128
|
+
dataView,
|
|
129
|
+
DeviceEventTypes,
|
|
130
|
+
this.#onClientMessageCallback.bind(this),
|
|
131
|
+
null,
|
|
132
|
+
true
|
|
133
|
+
);
|
|
98
134
|
this.onMessagesReceived!();
|
|
99
135
|
}
|
|
100
136
|
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { createConsole } from "../../utils/Console.ts";
|
|
2
2
|
import BaseConnectionManager from "../BaseConnectionManager.ts";
|
|
3
3
|
|
|
4
|
-
const _console = createConsole("BluetoothConnectionManager", { log:
|
|
4
|
+
const _console = createConsole("BluetoothConnectionManager", { log: false });
|
|
5
5
|
|
|
6
6
|
import { BluetoothCharacteristicName } from "./bluetoothUUIDs.ts";
|
|
7
7
|
|
|
8
8
|
abstract class BluetoothConnectionManager extends BaseConnectionManager {
|
|
9
|
+
get isAvailable() {
|
|
10
|
+
// no way to tell if the user has turned bluetooth on or off
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
isInRange = true;
|
|
10
15
|
|
|
11
|
-
protected onCharacteristicValueChanged(
|
|
16
|
+
protected onCharacteristicValueChanged(
|
|
17
|
+
characteristicName: BluetoothCharacteristicName,
|
|
18
|
+
dataView: DataView
|
|
19
|
+
) {
|
|
12
20
|
if (characteristicName == "rx") {
|
|
13
21
|
this.parseRxMessage(dataView);
|
|
14
22
|
} else {
|
|
@@ -16,7 +24,10 @@ abstract class BluetoothConnectionManager extends BaseConnectionManager {
|
|
|
16
24
|
}
|
|
17
25
|
}
|
|
18
26
|
|
|
19
|
-
protected async writeCharacteristic(
|
|
27
|
+
protected async writeCharacteristic(
|
|
28
|
+
characteristicName: BluetoothCharacteristicName,
|
|
29
|
+
data: ArrayBuffer
|
|
30
|
+
) {
|
|
20
31
|
_console.log("writeCharacteristic", ...arguments);
|
|
21
32
|
}
|
|
22
33
|
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { dataToArrayBuffer } from "../../utils/ArrayBufferUtils.ts";
|
|
2
2
|
import { createConsole } from "../../utils/Console.ts";
|
|
3
3
|
import { isInNode } from "../../utils/environment.ts";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
addEventListeners,
|
|
6
|
+
removeEventListeners,
|
|
7
|
+
BoundGenericEventListeners,
|
|
8
|
+
} from "../../utils/EventUtils.ts";
|
|
5
9
|
import {
|
|
6
10
|
allServiceUUIDs,
|
|
7
11
|
getServiceNameFromUUID,
|
|
@@ -11,26 +15,33 @@ import {
|
|
|
11
15
|
} from "./bluetoothUUIDs.ts";
|
|
12
16
|
import BluetoothConnectionManager from "./BluetoothConnectionManager.ts";
|
|
13
17
|
|
|
14
|
-
const _console = createConsole("NobleConnectionManager", { log:
|
|
18
|
+
const _console = createConsole("NobleConnectionManager", { log: false });
|
|
15
19
|
|
|
16
20
|
/** NODE_START */
|
|
17
21
|
import type * as noble from "@abandonware/noble";
|
|
18
22
|
/** NODE_END */
|
|
19
23
|
|
|
20
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
BluetoothCharacteristicName,
|
|
26
|
+
BluetoothServiceName,
|
|
27
|
+
} from "./bluetoothUUIDs.ts";
|
|
21
28
|
import { ConnectionType } from "../BaseConnectionManager.ts";
|
|
22
29
|
import NobleScanner from "../../scanner/NobleScanner.ts";
|
|
23
30
|
|
|
24
31
|
interface HasConnectionManager {
|
|
25
32
|
connectionManager: NobleConnectionManager | undefined;
|
|
26
33
|
}
|
|
27
|
-
export interface NoblePeripheral
|
|
34
|
+
export interface NoblePeripheral
|
|
35
|
+
extends noble.Peripheral,
|
|
36
|
+
HasConnectionManager {
|
|
28
37
|
scanner: NobleScanner;
|
|
29
38
|
}
|
|
30
39
|
interface NobleService extends noble.Service, HasConnectionManager {
|
|
31
40
|
name: BluetoothServiceName;
|
|
32
41
|
}
|
|
33
|
-
interface NobleCharacteristic
|
|
42
|
+
interface NobleCharacteristic
|
|
43
|
+
extends noble.Characteristic,
|
|
44
|
+
HasConnectionManager {
|
|
34
45
|
name: BluetoothCharacteristicName;
|
|
35
46
|
}
|
|
36
47
|
|
|
@@ -39,6 +50,10 @@ class NobleConnectionManager extends BluetoothConnectionManager {
|
|
|
39
50
|
return this.#noblePeripheral!.id;
|
|
40
51
|
}
|
|
41
52
|
|
|
53
|
+
get canUpdateFirmware() {
|
|
54
|
+
return this.#characteristics.has("smp");
|
|
55
|
+
}
|
|
56
|
+
|
|
42
57
|
static get isSupported() {
|
|
43
58
|
return isInNode;
|
|
44
59
|
}
|
|
@@ -59,16 +74,27 @@ class NobleConnectionManager extends BluetoothConnectionManager {
|
|
|
59
74
|
await this.#noblePeripheral!.disconnectAsync();
|
|
60
75
|
}
|
|
61
76
|
|
|
62
|
-
async writeCharacteristic(
|
|
77
|
+
async writeCharacteristic(
|
|
78
|
+
characteristicName: BluetoothCharacteristicName,
|
|
79
|
+
data: ArrayBuffer
|
|
80
|
+
) {
|
|
63
81
|
const characteristic = this.#characteristics.get(characteristicName)!;
|
|
64
|
-
_console.assertWithError(
|
|
82
|
+
_console.assertWithError(
|
|
83
|
+
characteristic,
|
|
84
|
+
`no characteristic found with name "${characteristicName}"`
|
|
85
|
+
);
|
|
65
86
|
// if (data instanceof DataView) {
|
|
66
87
|
// data = data.buffer;
|
|
67
88
|
// }
|
|
68
89
|
const properties = getCharacteristicProperties(characteristicName);
|
|
69
90
|
const buffer = Buffer.from(data);
|
|
70
91
|
const writeWithoutResponse = properties.writeWithoutResponse;
|
|
71
|
-
_console.log(
|
|
92
|
+
_console.log(
|
|
93
|
+
`writing to ${characteristicName} ${
|
|
94
|
+
writeWithoutResponse ? "without" : "with"
|
|
95
|
+
} response`,
|
|
96
|
+
buffer
|
|
97
|
+
);
|
|
72
98
|
await characteristic.writeAsync(buffer, writeWithoutResponse);
|
|
73
99
|
if (characteristic.properties.includes("read")) {
|
|
74
100
|
await characteristic.readAsync();
|
|
@@ -80,32 +106,39 @@ class NobleConnectionManager extends BluetoothConnectionManager {
|
|
|
80
106
|
}
|
|
81
107
|
async reconnect() {
|
|
82
108
|
await super.reconnect();
|
|
83
|
-
|
|
84
|
-
this.connect();
|
|
109
|
+
await this.#noblePeripheral!.connectAsync();
|
|
85
110
|
}
|
|
86
111
|
|
|
87
112
|
// NOBLE
|
|
88
|
-
#noblePeripheral
|
|
89
|
-
get noblePeripheral()
|
|
113
|
+
#noblePeripheral?: NoblePeripheral;
|
|
114
|
+
get noblePeripheral() {
|
|
90
115
|
return this.#noblePeripheral;
|
|
91
116
|
}
|
|
92
|
-
set noblePeripheral(newNoblePeripheral
|
|
93
|
-
|
|
117
|
+
set noblePeripheral(newNoblePeripheral) {
|
|
118
|
+
if (newNoblePeripheral) {
|
|
119
|
+
_console.assertTypeWithError(newNoblePeripheral, "object");
|
|
120
|
+
}
|
|
94
121
|
if (this.noblePeripheral == newNoblePeripheral) {
|
|
95
122
|
_console.log("attempted to assign duplicate noblePeripheral");
|
|
96
123
|
return;
|
|
97
124
|
}
|
|
98
125
|
|
|
99
|
-
_console.log("newNoblePeripheral", newNoblePeripheral
|
|
126
|
+
_console.log("newNoblePeripheral", newNoblePeripheral?.id);
|
|
100
127
|
|
|
101
128
|
if (this.#noblePeripheral) {
|
|
102
|
-
removeEventListeners(
|
|
129
|
+
removeEventListeners(
|
|
130
|
+
this.#noblePeripheral,
|
|
131
|
+
this.#unboundNoblePeripheralListeners
|
|
132
|
+
);
|
|
103
133
|
delete this.#noblePeripheral!.connectionManager;
|
|
104
134
|
}
|
|
105
135
|
|
|
106
136
|
if (newNoblePeripheral) {
|
|
107
137
|
newNoblePeripheral.connectionManager = this;
|
|
108
|
-
addEventListeners(
|
|
138
|
+
addEventListeners(
|
|
139
|
+
newNoblePeripheral,
|
|
140
|
+
this.#unboundNoblePeripheralListeners
|
|
141
|
+
);
|
|
109
142
|
}
|
|
110
143
|
|
|
111
144
|
this.#noblePeripheral = newNoblePeripheral;
|
|
@@ -123,9 +156,15 @@ class NobleConnectionManager extends BluetoothConnectionManager {
|
|
|
123
156
|
await this.connectionManager!.onNoblePeripheralConnect(this);
|
|
124
157
|
}
|
|
125
158
|
async onNoblePeripheralConnect(noblePeripheral: NoblePeripheral) {
|
|
126
|
-
_console.log(
|
|
159
|
+
_console.log(
|
|
160
|
+
"onNoblePeripheralConnect",
|
|
161
|
+
noblePeripheral.id,
|
|
162
|
+
noblePeripheral.state
|
|
163
|
+
);
|
|
127
164
|
if (noblePeripheral.state == "connected") {
|
|
128
|
-
await this.#noblePeripheral!.discoverServicesAsync(
|
|
165
|
+
await this.#noblePeripheral!.discoverServicesAsync(
|
|
166
|
+
allServiceUUIDs as string[]
|
|
167
|
+
);
|
|
129
168
|
}
|
|
130
169
|
// this gets called when it connects and disconnects, so we use the noblePeripheral's "state" property instead
|
|
131
170
|
await this.#onNoblePeripheralState();
|
|
@@ -140,7 +179,11 @@ class NobleConnectionManager extends BluetoothConnectionManager {
|
|
|
140
179
|
}
|
|
141
180
|
|
|
142
181
|
async #onNoblePeripheralState() {
|
|
143
|
-
_console.log(
|
|
182
|
+
_console.log(
|
|
183
|
+
`noblePeripheral ${this.bluetoothId} state ${
|
|
184
|
+
this.#noblePeripheral!.state
|
|
185
|
+
}`
|
|
186
|
+
);
|
|
144
187
|
|
|
145
188
|
switch (this.#noblePeripheral!.state) {
|
|
146
189
|
case "connected":
|
|
@@ -160,7 +203,9 @@ class NobleConnectionManager extends BluetoothConnectionManager {
|
|
|
160
203
|
_console.error("noblePeripheral error");
|
|
161
204
|
break;
|
|
162
205
|
default:
|
|
163
|
-
_console.log(
|
|
206
|
+
_console.log(
|
|
207
|
+
`uncaught noblePeripheral state ${this.#noblePeripheral!.state}`
|
|
208
|
+
);
|
|
164
209
|
break;
|
|
165
210
|
}
|
|
166
211
|
}
|
|
@@ -176,7 +221,10 @@ class NobleConnectionManager extends BluetoothConnectionManager {
|
|
|
176
221
|
_console.log(
|
|
177
222
|
`removing listeners from characteristic "${characteristic.name}" has ${characteristic.listeners.length} listeners`
|
|
178
223
|
);
|
|
179
|
-
removeEventListeners(
|
|
224
|
+
removeEventListeners(
|
|
225
|
+
characteristic,
|
|
226
|
+
this.#unboundNobleCharacteristicListeners
|
|
227
|
+
);
|
|
180
228
|
});
|
|
181
229
|
this.#characteristics.clear();
|
|
182
230
|
}
|
|
@@ -184,15 +232,27 @@ class NobleConnectionManager extends BluetoothConnectionManager {
|
|
|
184
232
|
async #onNoblePeripheralRssiUpdate(this: NoblePeripheral, rssi: number) {
|
|
185
233
|
await this.connectionManager!.onNoblePeripheralRssiUpdate(this, rssi);
|
|
186
234
|
}
|
|
187
|
-
async onNoblePeripheralRssiUpdate(
|
|
235
|
+
async onNoblePeripheralRssiUpdate(
|
|
236
|
+
noblePeripheral: NoblePeripheral,
|
|
237
|
+
rssi: number
|
|
238
|
+
) {
|
|
188
239
|
_console.log("onNoblePeripheralRssiUpdate", noblePeripheral.id, rssi);
|
|
189
|
-
//
|
|
240
|
+
// TODO: - can this be useful?
|
|
190
241
|
}
|
|
191
242
|
|
|
192
|
-
async #onNoblePeripheralServicesDiscover(
|
|
193
|
-
|
|
243
|
+
async #onNoblePeripheralServicesDiscover(
|
|
244
|
+
this: NoblePeripheral,
|
|
245
|
+
services: NobleService[]
|
|
246
|
+
) {
|
|
247
|
+
await this.connectionManager!.onNoblePeripheralServicesDiscover(
|
|
248
|
+
this,
|
|
249
|
+
services
|
|
250
|
+
);
|
|
194
251
|
}
|
|
195
|
-
async onNoblePeripheralServicesDiscover(
|
|
252
|
+
async onNoblePeripheralServicesDiscover(
|
|
253
|
+
noblePeripheral: NoblePeripheral,
|
|
254
|
+
services: NobleService[]
|
|
255
|
+
) {
|
|
196
256
|
_console.log(
|
|
197
257
|
"onNoblePeripheralServicesDiscover",
|
|
198
258
|
noblePeripheral.id,
|
|
@@ -202,7 +262,10 @@ class NobleConnectionManager extends BluetoothConnectionManager {
|
|
|
202
262
|
const service = services[index];
|
|
203
263
|
_console.log("service", service.uuid);
|
|
204
264
|
const serviceName = getServiceNameFromUUID(service.uuid)!;
|
|
205
|
-
_console.assertWithError(
|
|
265
|
+
_console.assertWithError(
|
|
266
|
+
serviceName,
|
|
267
|
+
`no name found for service uuid "${service.uuid}"`
|
|
268
|
+
);
|
|
206
269
|
_console.log({ serviceName });
|
|
207
270
|
this.#services.set(serviceName, service);
|
|
208
271
|
service.name = serviceName;
|
|
@@ -219,10 +282,19 @@ class NobleConnectionManager extends BluetoothConnectionManager {
|
|
|
219
282
|
characteristicsDiscover: this.#onNobleServiceCharacteristicsDiscover,
|
|
220
283
|
};
|
|
221
284
|
|
|
222
|
-
async #onNobleServiceCharacteristicsDiscover(
|
|
223
|
-
|
|
285
|
+
async #onNobleServiceCharacteristicsDiscover(
|
|
286
|
+
this: NobleService,
|
|
287
|
+
characteristics: NobleCharacteristic[]
|
|
288
|
+
) {
|
|
289
|
+
await this.connectionManager!.onNobleServiceCharacteristicsDiscover(
|
|
290
|
+
this,
|
|
291
|
+
characteristics
|
|
292
|
+
);
|
|
224
293
|
}
|
|
225
|
-
async onNobleServiceCharacteristicsDiscover(
|
|
294
|
+
async onNobleServiceCharacteristicsDiscover(
|
|
295
|
+
service: NobleService,
|
|
296
|
+
characteristics: NobleCharacteristic[]
|
|
297
|
+
) {
|
|
226
298
|
_console.log(
|
|
227
299
|
"onNobleServiceCharacteristicsDiscover",
|
|
228
300
|
service.uuid,
|
|
@@ -232,7 +304,9 @@ class NobleConnectionManager extends BluetoothConnectionManager {
|
|
|
232
304
|
for (const index in characteristics) {
|
|
233
305
|
const characteristic = characteristics[index];
|
|
234
306
|
_console.log("characteristic", characteristic.uuid);
|
|
235
|
-
const characteristicName = getCharacteristicNameFromUUID(
|
|
307
|
+
const characteristicName = getCharacteristicNameFromUUID(
|
|
308
|
+
characteristic.uuid
|
|
309
|
+
)!;
|
|
236
310
|
_console.assertWithError(
|
|
237
311
|
Boolean(characteristicName),
|
|
238
312
|
`no name found for characteristic uuid "${characteristic.uuid}"`
|
|
@@ -244,7 +318,10 @@ class NobleConnectionManager extends BluetoothConnectionManager {
|
|
|
244
318
|
_console.log(
|
|
245
319
|
`adding listeners to characteristic "${characteristic.name}" (currently has ${characteristic.listeners.length} listeners)`
|
|
246
320
|
);
|
|
247
|
-
addEventListeners(
|
|
321
|
+
addEventListeners(
|
|
322
|
+
characteristic,
|
|
323
|
+
this.#unboundNobleCharacteristicListeners
|
|
324
|
+
);
|
|
248
325
|
if (characteristic.properties.includes("read")) {
|
|
249
326
|
await characteristic.readAsync();
|
|
250
327
|
}
|
|
@@ -265,19 +342,40 @@ class NobleConnectionManager extends BluetoothConnectionManager {
|
|
|
265
342
|
notify: this.#onNobleCharacteristicNotify,
|
|
266
343
|
};
|
|
267
344
|
|
|
268
|
-
#characteristics: Map<BluetoothCharacteristicName, NobleCharacteristic> =
|
|
345
|
+
#characteristics: Map<BluetoothCharacteristicName, NobleCharacteristic> =
|
|
346
|
+
new Map();
|
|
269
347
|
|
|
270
348
|
get #hasAllCharacteristics() {
|
|
271
349
|
return allCharacteristicNames.every((characteristicName) => {
|
|
350
|
+
if (characteristicName == "smp") {
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
272
353
|
return this.#characteristics.has(characteristicName);
|
|
273
354
|
});
|
|
274
355
|
}
|
|
275
356
|
|
|
276
|
-
#onNobleCharacteristicData(
|
|
277
|
-
this
|
|
357
|
+
#onNobleCharacteristicData(
|
|
358
|
+
this: NobleCharacteristic,
|
|
359
|
+
data: Buffer,
|
|
360
|
+
isNotification: boolean
|
|
361
|
+
) {
|
|
362
|
+
this.connectionManager!.onNobleCharacteristicData(
|
|
363
|
+
this,
|
|
364
|
+
data,
|
|
365
|
+
isNotification
|
|
366
|
+
);
|
|
278
367
|
}
|
|
279
|
-
onNobleCharacteristicData(
|
|
280
|
-
|
|
368
|
+
onNobleCharacteristicData(
|
|
369
|
+
characteristic: NobleCharacteristic,
|
|
370
|
+
data: Buffer,
|
|
371
|
+
isNotification: boolean
|
|
372
|
+
) {
|
|
373
|
+
_console.log(
|
|
374
|
+
"onNobleCharacteristicData",
|
|
375
|
+
characteristic.uuid,
|
|
376
|
+
data,
|
|
377
|
+
isNotification
|
|
378
|
+
);
|
|
281
379
|
const dataView = new DataView(dataToArrayBuffer(data));
|
|
282
380
|
|
|
283
381
|
const characteristicName: BluetoothCharacteristicName = characteristic.name;
|
|
@@ -294,14 +392,29 @@ class NobleConnectionManager extends BluetoothConnectionManager {
|
|
|
294
392
|
}
|
|
295
393
|
onNobleCharacteristicWrite(characteristic: NobleCharacteristic) {
|
|
296
394
|
_console.log("onNobleCharacteristicWrite", characteristic.uuid);
|
|
297
|
-
//
|
|
395
|
+
// TODO: - can this be useful?
|
|
298
396
|
}
|
|
299
397
|
|
|
300
|
-
#onNobleCharacteristicNotify(
|
|
398
|
+
#onNobleCharacteristicNotify(
|
|
399
|
+
this: NobleCharacteristic,
|
|
400
|
+
isSubscribed: boolean
|
|
401
|
+
) {
|
|
301
402
|
this.connectionManager!.onNobleCharacteristicNotify(this, isSubscribed);
|
|
302
403
|
}
|
|
303
|
-
onNobleCharacteristicNotify(
|
|
304
|
-
|
|
404
|
+
onNobleCharacteristicNotify(
|
|
405
|
+
characteristic: NobleCharacteristic,
|
|
406
|
+
isSubscribed: boolean
|
|
407
|
+
) {
|
|
408
|
+
_console.log(
|
|
409
|
+
"onNobleCharacteristicNotify",
|
|
410
|
+
characteristic.uuid,
|
|
411
|
+
isSubscribed
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
remove() {
|
|
416
|
+
super.remove();
|
|
417
|
+
this.noblePeripheral = undefined;
|
|
305
418
|
}
|
|
306
419
|
}
|
|
307
420
|
|