brilliantsole 0.0.27 → 0.0.29
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/assets/3d/anchor.glb +0 -0
- package/assets/3d/coin.glb +0 -0
- package/assets/3d/glasses.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/build/brilliantsole.cjs +3091 -741
- package/build/brilliantsole.cjs.map +1 -1
- package/build/brilliantsole.js +2759 -709
- package/build/brilliantsole.js.map +1 -1
- package/build/brilliantsole.ls.js +2602 -543
- 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 +295 -65
- package/build/brilliantsole.module.js +2749 -710
- package/build/brilliantsole.module.js.map +1 -1
- package/build/brilliantsole.module.min.d.ts +295 -65
- package/build/brilliantsole.module.min.js +1 -1
- package/build/brilliantsole.module.min.js.map +1 -1
- package/build/brilliantsole.node.module.d.ts +289 -62
- package/build/brilliantsole.node.module.js +3080 -742
- 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 -8
- package/build/dts/CameraManager.d.ts +72 -0
- package/build/dts/Device.d.ts +64 -13
- package/build/dts/DeviceInformationManager.d.ts +4 -4
- package/build/dts/DeviceManager.d.ts +2 -0
- package/build/dts/FileTransferManager.d.ts +18 -8
- package/build/dts/InformationManager.d.ts +2 -0
- package/build/dts/MicrophoneManager.d.ts +88 -0
- package/build/dts/TfliteManager.d.ts +22 -2
- package/build/dts/WifiManager.d.ts +61 -0
- package/build/dts/connection/BaseConnectionManager.d.ts +35 -3
- package/build/dts/connection/ClientConnectionManager.d.ts +7 -2
- package/build/dts/connection/bluetooth/NobleConnectionManager.d.ts +2 -1
- package/build/dts/connection/bluetooth/WebBluetoothConnectionManager.d.ts +1 -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 +5 -5
- 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 +5 -3
- package/build/dts/server/ServerUtils.d.ts +1 -1
- package/build/dts/server/websocket/WebSocketUtils.d.ts +1 -1
- package/build/dts/utils/AudioUtils.d.ts +2 -0
- package/build/dts/utils/Console.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 +292 -62
- package/build/index.node.d.ts +286 -59
- package/examples/3d/scene.html +19 -5
- package/examples/3d-generic/index.html +144 -0
- package/examples/3d-generic/script.js +266 -0
- package/examples/basic/index.html +267 -17
- package/examples/basic/script.js +958 -105
- package/examples/camera/barcode-detector.js +109 -0
- package/examples/camera/depth-estimation.js +71 -0
- package/examples/camera/face-detector.js +119 -0
- package/examples/camera/face-landmark.js +111 -0
- package/examples/camera/gesture-recognition.js +97 -0
- package/examples/camera/hand-landmark.js +74 -0
- package/examples/camera/image-segmentation.js +98 -0
- package/examples/camera/image-to-text.js +43 -0
- package/examples/camera/image-upscale.js +75 -0
- package/examples/camera/index.html +129 -0
- package/examples/camera/object-detection.js +98 -0
- package/examples/camera/pose-landmark.js +60 -0
- package/examples/camera/script.js +316 -0
- package/examples/camera/utils.js +165 -0
- package/examples/camera/yolo-tiny.js +54 -0
- package/examples/camera/yolo.js +119 -0
- package/examples/edge-impulse/script.js +157 -48
- 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/glasses-gestures/README.md +11 -0
- package/examples/glasses-gestures/edge-impulse-standalone.js +7228 -0
- package/examples/glasses-gestures/edge-impulse-standalone.wasm +0 -0
- package/examples/glasses-gestures/index.html +69 -0
- package/examples/glasses-gestures/run-impulse.js +135 -0
- package/examples/glasses-gestures/script.js +226 -0
- package/examples/gloves/edge-impulse-standalone.js +7228 -0
- package/examples/gloves/edge-impulse-standalone.wasm +0 -0
- package/examples/gloves/index.html +4 -1
- package/examples/gloves/run-impulse.js +135 -0
- package/examples/gloves/script.js +367 -51
- package/examples/graph/script.js +94 -37
- package/examples/microphone/gender.js +54 -0
- package/examples/microphone/index.html +102 -0
- package/examples/microphone/script.js +394 -0
- package/examples/microphone/utils.js +45 -0
- package/examples/microphone/whisper-realtime.js +166 -0
- package/examples/microphone/whisper.js +132 -0
- package/examples/punch/index.html +135 -0
- package/examples/punch/punch.tflite +0 -0
- package/examples/punch/script.js +169 -0
- package/examples/server/index.html +98 -22
- package/examples/server/script.js +317 -109
- 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-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/examples/webxr-3/components/bs-camera.js +65 -0
- package/examples/webxr-3/index.html +134 -0
- package/examples/webxr-3/script.js +432 -0
- package/package.json +2 -1
- package/src/.prettierrc +4 -0
- package/src/BS.ts +79 -8
- package/src/CameraManager.ts +497 -0
- package/src/Device.ts +691 -86
- package/src/DeviceInformationManager.ts +19 -10
- package/src/DeviceManager.ts +85 -25
- package/src/FileTransferManager.ts +145 -20
- package/src/InformationManager.ts +40 -15
- package/src/MicrophoneManager.ts +599 -0
- package/src/TfliteManager.ts +171 -25
- package/src/WifiManager.ts +323 -0
- package/src/connection/BaseConnectionManager.ts +130 -30
- package/src/connection/ClientConnectionManager.ts +34 -10
- package/src/connection/bluetooth/BluetoothConnectionManager.ts +8 -2
- package/src/connection/bluetooth/NobleConnectionManager.ts +147 -41
- package/src/connection/bluetooth/WebBluetoothConnectionManager.ts +99 -34
- 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 +95 -25
- package/src/devicePair/DevicePairPressureSensorDataManager.ts +27 -7
- package/src/scanner/BaseScanner.ts +49 -11
- package/src/scanner/NobleScanner.ts +76 -14
- package/src/sensor/MotionSensorDataManager.ts +21 -6
- package/src/sensor/PressureSensorDataManager.ts +37 -8
- package/src/sensor/SensorConfigurationManager.ts +73 -22
- package/src/sensor/SensorDataManager.ts +109 -23
- package/src/server/BaseClient.ts +150 -36
- package/src/server/BaseServer.ts +50 -2
- package/src/server/ServerUtils.ts +39 -9
- package/src/server/udp/UDPServer.ts +73 -22
- package/src/server/udp/UDPUtils.ts +9 -2
- package/src/server/websocket/WebSocketClient.ts +27 -7
- package/src/server/websocket/WebSocketUtils.ts +4 -2
- package/src/utils/AudioUtils.ts +65 -0
- package/src/utils/Console.ts +62 -9
- package/src/utils/ParseUtils.ts +24 -5
- package/src/utils/ThrottleUtils.ts +62 -0
- package/src/utils/Timer.ts +1 -1
- package/src/vibration/VibrationManager.ts +166 -40
package/src/Device.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { createConsole } from "./utils/Console.ts";
|
|
2
|
-
import EventDispatcher, {
|
|
2
|
+
import EventDispatcher, {
|
|
3
|
+
BoundEventListeners,
|
|
4
|
+
Event,
|
|
5
|
+
EventListenerMap,
|
|
6
|
+
EventMap,
|
|
7
|
+
} from "./utils/EventDispatcher.ts";
|
|
3
8
|
import BaseConnectionManager, {
|
|
4
9
|
TxMessage,
|
|
5
10
|
TxRxMessageType,
|
|
@@ -9,6 +14,9 @@ import BaseConnectionManager, {
|
|
|
9
14
|
BatteryLevelMessageTypes,
|
|
10
15
|
ConnectionEventTypes,
|
|
11
16
|
ConnectionStatusEventMessages,
|
|
17
|
+
ConnectionTypes,
|
|
18
|
+
ConnectionType,
|
|
19
|
+
ConnectOptions,
|
|
12
20
|
} from "./connection/BaseConnectionManager.ts";
|
|
13
21
|
import { isInBrowser, isInNode } from "./utils/environment.ts";
|
|
14
22
|
import WebBluetoothConnectionManager from "./connection/bluetooth/WebBluetoothConnectionManager.ts";
|
|
@@ -29,10 +37,15 @@ import SensorDataManager, {
|
|
|
29
37
|
SensorType,
|
|
30
38
|
ContinuousSensorTypes,
|
|
31
39
|
SensorDataEventDispatcher,
|
|
40
|
+
RequiredPressureMessageTypes,
|
|
32
41
|
} from "./sensor/SensorDataManager.ts";
|
|
33
42
|
import VibrationManager, {
|
|
34
43
|
SendVibrationMessageCallback,
|
|
35
44
|
VibrationConfiguration,
|
|
45
|
+
VibrationEventDispatcher,
|
|
46
|
+
VibrationEventTypes,
|
|
47
|
+
VibrationMessageType,
|
|
48
|
+
VibrationMessageTypes,
|
|
36
49
|
} from "./vibration/VibrationManager.ts";
|
|
37
50
|
import FileTransferManager, {
|
|
38
51
|
FileTransferEventTypes,
|
|
@@ -42,6 +55,8 @@ import FileTransferManager, {
|
|
|
42
55
|
FileTransferMessageTypes,
|
|
43
56
|
FileTransferMessageType,
|
|
44
57
|
FileType,
|
|
58
|
+
FileTypes,
|
|
59
|
+
RequiredFileTransferMessageTypes,
|
|
45
60
|
} from "./FileTransferManager.ts";
|
|
46
61
|
import TfliteManager, {
|
|
47
62
|
TfliteEventTypes,
|
|
@@ -51,6 +66,9 @@ import TfliteManager, {
|
|
|
51
66
|
TfliteMessageTypes,
|
|
52
67
|
TfliteMessageType,
|
|
53
68
|
TfliteSensorTypes,
|
|
69
|
+
TfliteFileConfiguration,
|
|
70
|
+
TfliteSensorType,
|
|
71
|
+
RequiredTfliteMessageTypes,
|
|
54
72
|
} from "./TfliteManager.ts";
|
|
55
73
|
import FirmwareManager, {
|
|
56
74
|
FirmwareEventDispatcher,
|
|
@@ -62,8 +80,8 @@ import FirmwareManager, {
|
|
|
62
80
|
import DeviceInformationManager, {
|
|
63
81
|
DeviceInformationEventDispatcher,
|
|
64
82
|
DeviceInformationEventTypes,
|
|
65
|
-
|
|
66
|
-
|
|
83
|
+
DeviceInformationType,
|
|
84
|
+
DeviceInformationTypes,
|
|
67
85
|
DeviceInformationEventMessages,
|
|
68
86
|
} from "./DeviceInformationManager.ts";
|
|
69
87
|
import InformationManager, {
|
|
@@ -77,8 +95,41 @@ import InformationManager, {
|
|
|
77
95
|
} from "./InformationManager.ts";
|
|
78
96
|
import { FileLike } from "./utils/ArrayBufferUtils.ts";
|
|
79
97
|
import DeviceManager from "./DeviceManager.ts";
|
|
80
|
-
|
|
81
|
-
|
|
98
|
+
import CameraManager, {
|
|
99
|
+
CameraEventDispatcher,
|
|
100
|
+
CameraEventMessages,
|
|
101
|
+
CameraEventTypes,
|
|
102
|
+
CameraMessageType,
|
|
103
|
+
CameraMessageTypes,
|
|
104
|
+
RequiredCameraMessageTypes,
|
|
105
|
+
SendCameraMessageCallback,
|
|
106
|
+
} from "./CameraManager.ts";
|
|
107
|
+
import MicrophoneManager, {
|
|
108
|
+
MicrophoneEventDispatcher,
|
|
109
|
+
MicrophoneEventMessages,
|
|
110
|
+
MicrophoneEventTypes,
|
|
111
|
+
MicrophoneMessageType,
|
|
112
|
+
MicrophoneMessageTypes,
|
|
113
|
+
RequiredMicrophoneMessageTypes,
|
|
114
|
+
SendMicrophoneMessageCallback,
|
|
115
|
+
} from "./MicrophoneManager.ts";
|
|
116
|
+
import WifiManager, {
|
|
117
|
+
RequiredWifiMessageTypes,
|
|
118
|
+
SendWifiMessageCallback,
|
|
119
|
+
WifiEventDispatcher,
|
|
120
|
+
WifiEventMessages,
|
|
121
|
+
WifiEventTypes,
|
|
122
|
+
WifiMessageType,
|
|
123
|
+
WifiMessageTypes,
|
|
124
|
+
} from "./WifiManager.ts";
|
|
125
|
+
import WebSocketConnectionManager from "./connection/websocket/WebSocketConnectionManager.ts";
|
|
126
|
+
import ClientConnectionManager from "./connection/ClientConnectionManager.ts";
|
|
127
|
+
|
|
128
|
+
/** NODE_START */
|
|
129
|
+
import UDPConnectionManager from "./connection/udp/UDPConnectionManager.ts";
|
|
130
|
+
/** NODE_END */
|
|
131
|
+
|
|
132
|
+
const _console = createConsole("Device", { log: false });
|
|
82
133
|
|
|
83
134
|
export const DeviceEventTypes = [
|
|
84
135
|
"connectionMessage",
|
|
@@ -89,8 +140,12 @@ export const DeviceEventTypes = [
|
|
|
89
140
|
...DeviceInformationEventTypes,
|
|
90
141
|
...SensorConfigurationEventTypes,
|
|
91
142
|
...SensorDataEventTypes,
|
|
143
|
+
...VibrationEventTypes,
|
|
92
144
|
...FileTransferEventTypes,
|
|
93
145
|
...TfliteEventTypes,
|
|
146
|
+
...WifiEventTypes,
|
|
147
|
+
...CameraEventTypes,
|
|
148
|
+
...MicrophoneEventTypes,
|
|
94
149
|
...FirmwareEventTypes,
|
|
95
150
|
] as const;
|
|
96
151
|
export type DeviceEventType = (typeof DeviceEventTypes)[number];
|
|
@@ -103,6 +158,9 @@ export interface DeviceEventMessages
|
|
|
103
158
|
SensorConfigurationEventMessages,
|
|
104
159
|
TfliteEventMessages,
|
|
105
160
|
FileTransferEventMessages,
|
|
161
|
+
WifiEventMessages,
|
|
162
|
+
CameraEventMessages,
|
|
163
|
+
MicrophoneEventMessages,
|
|
106
164
|
FirmwareEventMessages {
|
|
107
165
|
batteryLevel: { batteryLevel: number };
|
|
108
166
|
connectionMessage: { messageType: ConnectionMessageType; dataView: DataView };
|
|
@@ -115,11 +173,27 @@ export type SendMessageCallback<MessageType extends string> = (
|
|
|
115
173
|
|
|
116
174
|
export type SendSmpMessageCallback = (data: ArrayBuffer) => Promise<void>;
|
|
117
175
|
|
|
118
|
-
export type DeviceEventDispatcher = EventDispatcher<
|
|
176
|
+
export type DeviceEventDispatcher = EventDispatcher<
|
|
177
|
+
Device,
|
|
178
|
+
DeviceEventType,
|
|
179
|
+
DeviceEventMessages
|
|
180
|
+
>;
|
|
119
181
|
export type DeviceEvent = Event<Device, DeviceEventType, DeviceEventMessages>;
|
|
120
|
-
export type DeviceEventMap = EventMap<
|
|
121
|
-
|
|
122
|
-
|
|
182
|
+
export type DeviceEventMap = EventMap<
|
|
183
|
+
Device,
|
|
184
|
+
DeviceEventType,
|
|
185
|
+
DeviceEventMessages
|
|
186
|
+
>;
|
|
187
|
+
export type DeviceEventListenerMap = EventListenerMap<
|
|
188
|
+
Device,
|
|
189
|
+
DeviceEventType,
|
|
190
|
+
DeviceEventMessages
|
|
191
|
+
>;
|
|
192
|
+
export type BoundDeviceEventListeners = BoundEventListeners<
|
|
193
|
+
Device,
|
|
194
|
+
DeviceEventType,
|
|
195
|
+
DeviceEventMessages
|
|
196
|
+
>;
|
|
123
197
|
|
|
124
198
|
export const RequiredInformationConnectionMessages: TxRxMessageType[] = [
|
|
125
199
|
"isCharging",
|
|
@@ -132,22 +206,12 @@ export const RequiredInformationConnectionMessages: TxRxMessageType[] = [
|
|
|
132
206
|
"getCurrentTime",
|
|
133
207
|
"getSensorConfiguration",
|
|
134
208
|
"getSensorScalars",
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
"
|
|
139
|
-
|
|
140
|
-
"
|
|
141
|
-
"fileTransferStatus",
|
|
142
|
-
|
|
143
|
-
"getTfliteName",
|
|
144
|
-
"getTfliteTask",
|
|
145
|
-
"getTfliteSampleRate",
|
|
146
|
-
"getTfliteSensorTypes",
|
|
147
|
-
"tfliteIsReady",
|
|
148
|
-
"getTfliteCaptureDelay",
|
|
149
|
-
"getTfliteThreshold",
|
|
150
|
-
"getTfliteInferencingEnabled",
|
|
209
|
+
|
|
210
|
+
"getVibrationLocations",
|
|
211
|
+
|
|
212
|
+
"getFileTypes",
|
|
213
|
+
|
|
214
|
+
"isWifiAvailable",
|
|
151
215
|
];
|
|
152
216
|
|
|
153
217
|
class Device {
|
|
@@ -160,32 +224,120 @@ class Device {
|
|
|
160
224
|
}
|
|
161
225
|
|
|
162
226
|
constructor() {
|
|
163
|
-
this.#deviceInformationManager.eventDispatcher = this
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
this._informationManager.
|
|
167
|
-
|
|
168
|
-
this
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
this.#
|
|
172
|
-
|
|
173
|
-
this.#
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
this.#
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
this.#
|
|
180
|
-
|
|
181
|
-
this.#
|
|
182
|
-
|
|
227
|
+
this.#deviceInformationManager.eventDispatcher = this
|
|
228
|
+
.#eventDispatcher as DeviceInformationEventDispatcher;
|
|
229
|
+
|
|
230
|
+
this._informationManager.sendMessage = this
|
|
231
|
+
.sendTxMessages as SendInformationMessageCallback;
|
|
232
|
+
this._informationManager.eventDispatcher = this
|
|
233
|
+
.#eventDispatcher as InformationEventDispatcher;
|
|
234
|
+
|
|
235
|
+
this.#sensorConfigurationManager.sendMessage = this
|
|
236
|
+
.sendTxMessages as SendSensorConfigurationMessageCallback;
|
|
237
|
+
this.#sensorConfigurationManager.eventDispatcher = this
|
|
238
|
+
.#eventDispatcher as SensorConfigurationEventDispatcher;
|
|
239
|
+
|
|
240
|
+
this.#sensorDataManager.eventDispatcher = this
|
|
241
|
+
.#eventDispatcher as SensorDataEventDispatcher;
|
|
242
|
+
|
|
243
|
+
this.#vibrationManager.sendMessage = this
|
|
244
|
+
.sendTxMessages as SendVibrationMessageCallback;
|
|
245
|
+
this.#vibrationManager.eventDispatcher = this
|
|
246
|
+
.#eventDispatcher as VibrationEventDispatcher;
|
|
247
|
+
|
|
248
|
+
this.#tfliteManager.sendMessage = this
|
|
249
|
+
.sendTxMessages as SendTfliteMessageCallback;
|
|
250
|
+
this.#tfliteManager.eventDispatcher = this
|
|
251
|
+
.#eventDispatcher as TfliteEventDispatcher;
|
|
252
|
+
|
|
253
|
+
this.#fileTransferManager.sendMessage = this
|
|
254
|
+
.sendTxMessages as SendFileTransferMessageCallback;
|
|
255
|
+
this.#fileTransferManager.eventDispatcher = this
|
|
256
|
+
.#eventDispatcher as FileTransferEventDispatcher;
|
|
257
|
+
|
|
258
|
+
this.#wifiManager.sendMessage = this
|
|
259
|
+
.sendTxMessages as SendWifiMessageCallback;
|
|
260
|
+
this.#wifiManager.eventDispatcher = this
|
|
261
|
+
.#eventDispatcher as WifiEventDispatcher;
|
|
262
|
+
|
|
263
|
+
this.#cameraManager.sendMessage = this
|
|
264
|
+
.sendTxMessages as SendCameraMessageCallback;
|
|
265
|
+
this.#cameraManager.eventDispatcher = this
|
|
266
|
+
.#eventDispatcher as CameraEventDispatcher;
|
|
267
|
+
|
|
268
|
+
this.#microphoneManager.sendMessage = this
|
|
269
|
+
.sendTxMessages as SendMicrophoneMessageCallback;
|
|
270
|
+
this.#microphoneManager.eventDispatcher = this
|
|
271
|
+
.#eventDispatcher as MicrophoneEventDispatcher;
|
|
272
|
+
|
|
273
|
+
this.#firmwareManager.sendMessage = this
|
|
274
|
+
.sendSmpMessage as SendSmpMessageCallback;
|
|
275
|
+
this.#firmwareManager.eventDispatcher = this
|
|
276
|
+
.#eventDispatcher as FirmwareEventDispatcher;
|
|
183
277
|
|
|
184
278
|
this.addEventListener("getMtu", () => {
|
|
185
279
|
this.#firmwareManager.mtu = this.mtu;
|
|
186
280
|
this.#fileTransferManager.mtu = this.mtu;
|
|
187
281
|
this.connectionManager!.mtu = this.mtu;
|
|
188
282
|
});
|
|
283
|
+
this.addEventListener("getSensorConfiguration", () => {
|
|
284
|
+
if (this.connectionStatus != "connecting") {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (this.sensorTypes.includes("pressure")) {
|
|
288
|
+
_console.log("requesting required pressure information");
|
|
289
|
+
const messages = RequiredPressureMessageTypes.map((messageType) => ({
|
|
290
|
+
type: messageType,
|
|
291
|
+
}));
|
|
292
|
+
this.sendTxMessages(messages, false);
|
|
293
|
+
} else {
|
|
294
|
+
_console.log("don't need to request pressure infomration");
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (this.sensorTypes.includes("camera")) {
|
|
298
|
+
_console.log("requesting required camera information");
|
|
299
|
+
const messages = RequiredCameraMessageTypes.map((messageType) => ({
|
|
300
|
+
type: messageType,
|
|
301
|
+
}));
|
|
302
|
+
this.sendTxMessages(messages, false);
|
|
303
|
+
} else {
|
|
304
|
+
_console.log("don't need to request camera infomration");
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (this.sensorTypes.includes("microphone")) {
|
|
308
|
+
_console.log("requesting required microphone information");
|
|
309
|
+
const messages = RequiredMicrophoneMessageTypes.map((messageType) => ({
|
|
310
|
+
type: messageType,
|
|
311
|
+
}));
|
|
312
|
+
this.sendTxMessages(messages, false);
|
|
313
|
+
} else {
|
|
314
|
+
_console.log("don't need to request microphone infomration");
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
this.addEventListener("getFileTypes", () => {
|
|
318
|
+
if (this.connectionStatus != "connecting") {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (this.fileTypes.length > 0) {
|
|
322
|
+
this.#fileTransferManager.requestRequiredInformation();
|
|
323
|
+
}
|
|
324
|
+
if (this.fileTypes.includes("tflite")) {
|
|
325
|
+
this.#tfliteManager.requestRequiredInformation();
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
this.addEventListener("isWifiAvailable", () => {
|
|
329
|
+
if (this.connectionStatus != "connecting") {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (this.connectionType == "client" && !isInNode) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (this.isWifiAvailable) {
|
|
336
|
+
if (this.connectionType != "client") {
|
|
337
|
+
this.#wifiManager.requestRequiredInformation();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
});
|
|
189
341
|
DeviceManager.onDevice(this);
|
|
190
342
|
if (isInBrowser) {
|
|
191
343
|
window.addEventListener("beforeunload", () => {
|
|
@@ -208,7 +360,10 @@ class Device {
|
|
|
208
360
|
return new WebBluetoothConnectionManager();
|
|
209
361
|
}
|
|
210
362
|
|
|
211
|
-
#eventDispatcher: DeviceEventDispatcher = new EventDispatcher(
|
|
363
|
+
#eventDispatcher: DeviceEventDispatcher = new EventDispatcher(
|
|
364
|
+
this as Device,
|
|
365
|
+
DeviceEventTypes
|
|
366
|
+
);
|
|
212
367
|
get addEventListener() {
|
|
213
368
|
return this.#eventDispatcher.addEventListener;
|
|
214
369
|
}
|
|
@@ -241,29 +396,100 @@ class Device {
|
|
|
241
396
|
}
|
|
242
397
|
|
|
243
398
|
if (this.connectionManager) {
|
|
244
|
-
this.connectionManager.
|
|
245
|
-
this.connectionManager.onMessageReceived = undefined;
|
|
246
|
-
this.connectionManager.onMessagesReceived = undefined;
|
|
399
|
+
this.connectionManager.remove();
|
|
247
400
|
}
|
|
248
401
|
if (newConnectionManager) {
|
|
249
|
-
newConnectionManager.onStatusUpdated =
|
|
250
|
-
|
|
251
|
-
newConnectionManager.
|
|
402
|
+
newConnectionManager.onStatusUpdated =
|
|
403
|
+
this.#onConnectionStatusUpdated.bind(this);
|
|
404
|
+
newConnectionManager.onMessageReceived =
|
|
405
|
+
this.#onConnectionMessageReceived.bind(this);
|
|
406
|
+
newConnectionManager.onMessagesReceived =
|
|
407
|
+
this.#onConnectionMessagesReceived.bind(this);
|
|
252
408
|
}
|
|
253
409
|
|
|
254
410
|
this.#connectionManager = newConnectionManager;
|
|
255
411
|
_console.log("assigned new connectionManager", this.#connectionManager);
|
|
412
|
+
|
|
413
|
+
this._informationManager.connectionType = this.connectionType;
|
|
256
414
|
}
|
|
257
415
|
async #sendTxMessages(messages?: TxMessage[], sendImmediately?: boolean) {
|
|
258
416
|
await this.#connectionManager?.sendTxMessages(messages, sendImmediately);
|
|
259
417
|
}
|
|
260
418
|
private sendTxMessages = this.#sendTxMessages.bind(this);
|
|
261
419
|
|
|
262
|
-
async connect() {
|
|
420
|
+
async connect(options?: ConnectOptions) {
|
|
421
|
+
_console.log("connect options", options);
|
|
422
|
+
if (options) {
|
|
423
|
+
switch (options.type) {
|
|
424
|
+
case "webBluetooth":
|
|
425
|
+
if (this.connectionType != "webBluetooth") {
|
|
426
|
+
this.connectionManager = new WebBluetoothConnectionManager();
|
|
427
|
+
}
|
|
428
|
+
break;
|
|
429
|
+
case "webSocket":
|
|
430
|
+
{
|
|
431
|
+
let createConnectionManager = false;
|
|
432
|
+
if (this.connectionType == "webSocket") {
|
|
433
|
+
const connectionManager = this
|
|
434
|
+
.connectionManager as WebSocketConnectionManager;
|
|
435
|
+
if (
|
|
436
|
+
connectionManager.ipAddress != options.ipAddress ||
|
|
437
|
+
connectionManager.isSecure != options.isWifiSecure
|
|
438
|
+
) {
|
|
439
|
+
createConnectionManager = true;
|
|
440
|
+
}
|
|
441
|
+
} else {
|
|
442
|
+
createConnectionManager = true;
|
|
443
|
+
}
|
|
444
|
+
if (createConnectionManager) {
|
|
445
|
+
this.connectionManager = new WebSocketConnectionManager(
|
|
446
|
+
options.ipAddress,
|
|
447
|
+
options.isWifiSecure,
|
|
448
|
+
this.bluetoothId
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
break;
|
|
454
|
+
case "udp":
|
|
455
|
+
{
|
|
456
|
+
let createConnectionManager = false;
|
|
457
|
+
if (this.connectionType == "udp") {
|
|
458
|
+
const connectionManager = this
|
|
459
|
+
.connectionManager as UDPConnectionManager;
|
|
460
|
+
if (connectionManager.ipAddress != options.ipAddress) {
|
|
461
|
+
createConnectionManager = true;
|
|
462
|
+
}
|
|
463
|
+
this.reconnectOnDisconnection = true;
|
|
464
|
+
} else {
|
|
465
|
+
createConnectionManager = true;
|
|
466
|
+
}
|
|
467
|
+
if (createConnectionManager) {
|
|
468
|
+
this.connectionManager = new UDPConnectionManager(
|
|
469
|
+
options.ipAddress,
|
|
470
|
+
this.bluetoothId
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
263
477
|
if (!this.connectionManager) {
|
|
264
478
|
this.connectionManager = Device.#DefaultConnectionManager();
|
|
265
479
|
}
|
|
266
480
|
this.#clear();
|
|
481
|
+
|
|
482
|
+
if (options?.type == "client") {
|
|
483
|
+
_console.assertWithError(
|
|
484
|
+
this.connectionType == "client",
|
|
485
|
+
"expected clientConnectionManager"
|
|
486
|
+
);
|
|
487
|
+
const clientConnectionManager = this
|
|
488
|
+
.connectionManager as ClientConnectionManager;
|
|
489
|
+
clientConnectionManager.subType = options.subType;
|
|
490
|
+
return clientConnectionManager.connect();
|
|
491
|
+
}
|
|
492
|
+
_console.log("connectionManager type", this.connectionManager.type);
|
|
267
493
|
return this.connectionManager.connect();
|
|
268
494
|
}
|
|
269
495
|
#isConnected = false;
|
|
@@ -275,19 +501,54 @@ class Device {
|
|
|
275
501
|
_console.assertWithError(this.isConnected, "notConnected");
|
|
276
502
|
}
|
|
277
503
|
|
|
278
|
-
|
|
279
|
-
return
|
|
280
|
-
const hasConnectionMessage =
|
|
504
|
+
#didReceiveMessageTypes(messageTypes: ConnectionMessageType[]) {
|
|
505
|
+
return messageTypes.every((messageType) => {
|
|
506
|
+
const hasConnectionMessage =
|
|
507
|
+
this.latestConnectionMessages.has(messageType);
|
|
281
508
|
if (!hasConnectionMessage) {
|
|
282
509
|
_console.log(`didn't receive "${messageType}" message`);
|
|
283
510
|
}
|
|
284
511
|
return hasConnectionMessage;
|
|
285
512
|
});
|
|
286
513
|
}
|
|
514
|
+
get #hasRequiredInformation() {
|
|
515
|
+
let hasRequiredInformation = this.#didReceiveMessageTypes(
|
|
516
|
+
RequiredInformationConnectionMessages
|
|
517
|
+
);
|
|
518
|
+
if (hasRequiredInformation && this.sensorTypes.includes("pressure")) {
|
|
519
|
+
hasRequiredInformation = this.#didReceiveMessageTypes(
|
|
520
|
+
RequiredPressureMessageTypes
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
if (hasRequiredInformation && this.isWifiAvailable) {
|
|
524
|
+
hasRequiredInformation = this.#didReceiveMessageTypes(
|
|
525
|
+
RequiredWifiMessageTypes
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
if (hasRequiredInformation && this.fileTypes.length > 0) {
|
|
529
|
+
hasRequiredInformation = this.#didReceiveMessageTypes(
|
|
530
|
+
RequiredFileTransferMessageTypes
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
if (hasRequiredInformation && this.fileTypes.includes("tflite")) {
|
|
534
|
+
hasRequiredInformation = this.#didReceiveMessageTypes(
|
|
535
|
+
RequiredTfliteMessageTypes
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
if (hasRequiredInformation && this.hasCamera) {
|
|
539
|
+
hasRequiredInformation = this.#didReceiveMessageTypes(
|
|
540
|
+
RequiredCameraMessageTypes
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
return hasRequiredInformation;
|
|
544
|
+
}
|
|
287
545
|
#requestRequiredInformation() {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
546
|
+
_console.log("requesting required information");
|
|
547
|
+
const messages: TxMessage[] = RequiredInformationConnectionMessages.map(
|
|
548
|
+
(messageType) => ({
|
|
549
|
+
type: messageType,
|
|
550
|
+
})
|
|
551
|
+
);
|
|
291
552
|
this.#sendTxMessages(messages);
|
|
292
553
|
}
|
|
293
554
|
|
|
@@ -351,7 +612,12 @@ class Device {
|
|
|
351
612
|
if (this.isConnected) {
|
|
352
613
|
this.disconnect();
|
|
353
614
|
} else if (this.canReconnect) {
|
|
354
|
-
|
|
615
|
+
try {
|
|
616
|
+
this.reconnect();
|
|
617
|
+
} catch (error) {
|
|
618
|
+
_console.error("error trying to reconnect", error);
|
|
619
|
+
this.connect();
|
|
620
|
+
}
|
|
355
621
|
} else {
|
|
356
622
|
this.connect();
|
|
357
623
|
}
|
|
@@ -370,7 +636,10 @@ class Device {
|
|
|
370
636
|
}
|
|
371
637
|
}
|
|
372
638
|
get isConnectionBusy() {
|
|
373
|
-
return
|
|
639
|
+
return (
|
|
640
|
+
this.connectionStatus == "connecting" ||
|
|
641
|
+
this.connectionStatus == "disconnecting"
|
|
642
|
+
);
|
|
374
643
|
}
|
|
375
644
|
|
|
376
645
|
#onConnectionStatusUpdated(connectionStatus: ConnectionStatus) {
|
|
@@ -397,14 +666,18 @@ class Device {
|
|
|
397
666
|
this.#checkConnection();
|
|
398
667
|
|
|
399
668
|
if (connectionStatus == "connected" && !this.#isConnected) {
|
|
400
|
-
this
|
|
669
|
+
if (this.connectionType != "client") {
|
|
670
|
+
this.#requestRequiredInformation();
|
|
671
|
+
}
|
|
401
672
|
}
|
|
402
673
|
|
|
403
674
|
DeviceManager.OnDeviceConnectionStatusUpdated(this, connectionStatus);
|
|
404
675
|
}
|
|
405
676
|
|
|
406
677
|
#dispatchConnectionEvents(includeIsConnected: boolean = false) {
|
|
407
|
-
this.#dispatchEvent("connectionStatus", {
|
|
678
|
+
this.#dispatchEvent("connectionStatus", {
|
|
679
|
+
connectionStatus: this.connectionStatus,
|
|
680
|
+
});
|
|
408
681
|
this.#dispatchEvent(this.connectionStatus, {});
|
|
409
682
|
if (includeIsConnected) {
|
|
410
683
|
this.#dispatchEvent("isConnected", { isConnected: this.isConnected });
|
|
@@ -435,13 +708,20 @@ class Device {
|
|
|
435
708
|
this.#clearConnection();
|
|
436
709
|
this._informationManager.clear();
|
|
437
710
|
this.#deviceInformationManager.clear();
|
|
711
|
+
this.#tfliteManager.clear();
|
|
712
|
+
this.#wifiManager.clear();
|
|
713
|
+
this.#cameraManager.clear();
|
|
714
|
+
this.#microphoneManager.clear();
|
|
438
715
|
}
|
|
439
716
|
#clearConnection() {
|
|
440
717
|
this.connectionManager?.clear();
|
|
441
718
|
this.latestConnectionMessages.clear();
|
|
442
719
|
}
|
|
443
720
|
|
|
444
|
-
#onConnectionMessageReceived(
|
|
721
|
+
#onConnectionMessageReceived(
|
|
722
|
+
messageType: ConnectionMessageType,
|
|
723
|
+
dataView: DataView
|
|
724
|
+
) {
|
|
445
725
|
_console.log({ messageType, dataView });
|
|
446
726
|
switch (messageType) {
|
|
447
727
|
case "batteryLevel":
|
|
@@ -451,26 +731,100 @@ class Device {
|
|
|
451
731
|
break;
|
|
452
732
|
|
|
453
733
|
default:
|
|
454
|
-
if (
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
this.#
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
734
|
+
if (
|
|
735
|
+
FileTransferMessageTypes.includes(
|
|
736
|
+
messageType as FileTransferMessageType
|
|
737
|
+
)
|
|
738
|
+
) {
|
|
739
|
+
this.#fileTransferManager.parseMessage(
|
|
740
|
+
messageType as FileTransferMessageType,
|
|
741
|
+
dataView
|
|
742
|
+
);
|
|
743
|
+
} else if (
|
|
744
|
+
TfliteMessageTypes.includes(messageType as TfliteMessageType)
|
|
745
|
+
) {
|
|
746
|
+
this.#tfliteManager.parseMessage(
|
|
747
|
+
messageType as TfliteMessageType,
|
|
748
|
+
dataView
|
|
749
|
+
);
|
|
750
|
+
} else if (
|
|
751
|
+
SensorDataMessageTypes.includes(messageType as SensorDataMessageType)
|
|
752
|
+
) {
|
|
753
|
+
this.#sensorDataManager.parseMessage(
|
|
754
|
+
messageType as SensorDataMessageType,
|
|
755
|
+
dataView
|
|
756
|
+
);
|
|
757
|
+
} else if (
|
|
758
|
+
FirmwareMessageTypes.includes(messageType as FirmwareMessageType)
|
|
759
|
+
) {
|
|
760
|
+
this.#firmwareManager.parseMessage(
|
|
761
|
+
messageType as FirmwareMessageType,
|
|
762
|
+
dataView
|
|
763
|
+
);
|
|
764
|
+
} else if (
|
|
765
|
+
DeviceInformationTypes.includes(messageType as DeviceInformationType)
|
|
766
|
+
) {
|
|
767
|
+
this.#deviceInformationManager.parseMessage(
|
|
768
|
+
messageType as DeviceInformationType,
|
|
769
|
+
dataView
|
|
770
|
+
);
|
|
771
|
+
} else if (
|
|
772
|
+
InformationMessageTypes.includes(
|
|
773
|
+
messageType as InformationMessageType
|
|
774
|
+
)
|
|
775
|
+
) {
|
|
776
|
+
this._informationManager.parseMessage(
|
|
777
|
+
messageType as InformationMessageType,
|
|
778
|
+
dataView
|
|
779
|
+
);
|
|
780
|
+
} else if (
|
|
781
|
+
SensorConfigurationMessageTypes.includes(
|
|
782
|
+
messageType as SensorConfigurationMessageType
|
|
783
|
+
)
|
|
784
|
+
) {
|
|
785
|
+
this.#sensorConfigurationManager.parseMessage(
|
|
786
|
+
messageType as SensorConfigurationMessageType,
|
|
787
|
+
dataView
|
|
788
|
+
);
|
|
789
|
+
} else if (
|
|
790
|
+
VibrationMessageTypes.includes(messageType as VibrationMessageType)
|
|
791
|
+
) {
|
|
792
|
+
this.#vibrationManager.parseMessage(
|
|
793
|
+
messageType as VibrationMessageType,
|
|
794
|
+
dataView
|
|
795
|
+
);
|
|
796
|
+
} else if (WifiMessageTypes.includes(messageType as WifiMessageType)) {
|
|
797
|
+
this.#wifiManager.parseMessage(
|
|
798
|
+
messageType as WifiMessageType,
|
|
799
|
+
dataView
|
|
800
|
+
);
|
|
801
|
+
} else if (
|
|
802
|
+
CameraMessageTypes.includes(messageType as CameraMessageType)
|
|
803
|
+
) {
|
|
804
|
+
this.#cameraManager.parseMessage(
|
|
805
|
+
messageType as CameraMessageType,
|
|
806
|
+
dataView
|
|
807
|
+
);
|
|
808
|
+
} else if (
|
|
809
|
+
MicrophoneMessageTypes.includes(messageType as MicrophoneMessageType)
|
|
810
|
+
) {
|
|
811
|
+
this.#microphoneManager.parseMessage(
|
|
812
|
+
messageType as MicrophoneMessageType,
|
|
813
|
+
dataView
|
|
814
|
+
);
|
|
468
815
|
} else {
|
|
469
816
|
throw Error(`uncaught messageType ${messageType}`);
|
|
470
817
|
}
|
|
471
818
|
}
|
|
472
819
|
|
|
473
820
|
this.latestConnectionMessages.set(messageType, dataView);
|
|
821
|
+
if (messageType.startsWith("set")) {
|
|
822
|
+
this.latestConnectionMessages.set(
|
|
823
|
+
// @ts-expect-error
|
|
824
|
+
messageType.replace("set", "get"),
|
|
825
|
+
dataView
|
|
826
|
+
);
|
|
827
|
+
}
|
|
474
828
|
this.#dispatchEvent("connectionMessage", { messageType, dataView });
|
|
475
829
|
}
|
|
476
830
|
#onConnectionMessagesReceived() {
|
|
@@ -558,7 +912,9 @@ class Device {
|
|
|
558
912
|
return Object.keys(this.sensorConfiguration) as SensorType[];
|
|
559
913
|
}
|
|
560
914
|
get continuousSensorTypes() {
|
|
561
|
-
return ContinuousSensorTypes.filter((sensorType) =>
|
|
915
|
+
return ContinuousSensorTypes.filter((sensorType) =>
|
|
916
|
+
this.sensorTypes.includes(sensorType)
|
|
917
|
+
);
|
|
562
918
|
}
|
|
563
919
|
|
|
564
920
|
// SENSOR CONFIGURATION
|
|
@@ -569,8 +925,14 @@ class Device {
|
|
|
569
925
|
return this.#sensorConfigurationManager.configuration;
|
|
570
926
|
}
|
|
571
927
|
|
|
572
|
-
async setSensorConfiguration(
|
|
573
|
-
|
|
928
|
+
async setSensorConfiguration(
|
|
929
|
+
newSensorConfiguration: SensorConfiguration,
|
|
930
|
+
clearRest?: boolean
|
|
931
|
+
) {
|
|
932
|
+
await this.#sensorConfigurationManager.setConfiguration(
|
|
933
|
+
newSensorConfiguration,
|
|
934
|
+
clearRest
|
|
935
|
+
);
|
|
574
936
|
}
|
|
575
937
|
|
|
576
938
|
async clearSensorConfiguration() {
|
|
@@ -581,7 +943,9 @@ class Device {
|
|
|
581
943
|
static get ClearSensorConfigurationOnLeave() {
|
|
582
944
|
return this.#ClearSensorConfigurationOnLeave;
|
|
583
945
|
}
|
|
584
|
-
static set ClearSensorConfigurationOnLeave(
|
|
946
|
+
static set ClearSensorConfigurationOnLeave(
|
|
947
|
+
newClearSensorConfigurationOnLeave
|
|
948
|
+
) {
|
|
585
949
|
_console.assertTypeWithError(newClearSensorConfigurationOnLeave, "boolean");
|
|
586
950
|
this.#ClearSensorConfigurationOnLeave = newClearSensorConfigurationOnLeave;
|
|
587
951
|
}
|
|
@@ -607,19 +971,44 @@ class Device {
|
|
|
607
971
|
}
|
|
608
972
|
|
|
609
973
|
// VIBRATION
|
|
974
|
+
get vibrationLocations() {
|
|
975
|
+
return this.#vibrationManager.vibrationLocations;
|
|
976
|
+
}
|
|
977
|
+
|
|
610
978
|
#vibrationManager = new VibrationManager();
|
|
611
|
-
async triggerVibration(
|
|
612
|
-
|
|
979
|
+
async triggerVibration(
|
|
980
|
+
vibrationConfigurations: VibrationConfiguration[],
|
|
981
|
+
sendImmediately?: boolean
|
|
982
|
+
) {
|
|
983
|
+
this.#vibrationManager.triggerVibration(
|
|
984
|
+
vibrationConfigurations,
|
|
985
|
+
sendImmediately
|
|
986
|
+
);
|
|
613
987
|
}
|
|
614
988
|
|
|
615
989
|
// FILE TRANSFER
|
|
616
990
|
#fileTransferManager = new FileTransferManager();
|
|
617
991
|
|
|
992
|
+
get fileTypes() {
|
|
993
|
+
return this.#fileTransferManager.fileTypes;
|
|
994
|
+
}
|
|
618
995
|
get maxFileLength() {
|
|
619
996
|
return this.#fileTransferManager.maxLength;
|
|
620
997
|
}
|
|
998
|
+
get validFileTypes() {
|
|
999
|
+
return FileTypes.filter((fileType) => {
|
|
1000
|
+
if (fileType.includes("wifi") && !this.isWifiAvailable) {
|
|
1001
|
+
return false;
|
|
1002
|
+
}
|
|
1003
|
+
return true;
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
621
1006
|
|
|
622
1007
|
async sendFile(fileType: FileType, file: FileLike) {
|
|
1008
|
+
_console.assertWithError(
|
|
1009
|
+
this.validFileTypes.includes(fileType),
|
|
1010
|
+
`invalid fileType ${fileType}`
|
|
1011
|
+
);
|
|
623
1012
|
const promise = this.waitForEvent("fileTransferComplete");
|
|
624
1013
|
this.#fileTransferManager.send(fileType, file);
|
|
625
1014
|
await promise;
|
|
@@ -648,6 +1037,18 @@ class Device {
|
|
|
648
1037
|
return this.#tfliteManager.setName;
|
|
649
1038
|
}
|
|
650
1039
|
|
|
1040
|
+
async sendTfliteConfiguration(configuration: TfliteFileConfiguration) {
|
|
1041
|
+
configuration.type = "tflite";
|
|
1042
|
+
this.#tfliteManager.sendConfiguration(configuration, false);
|
|
1043
|
+
const didSendFile = await this.#fileTransferManager.send(
|
|
1044
|
+
configuration.type,
|
|
1045
|
+
configuration.file
|
|
1046
|
+
);
|
|
1047
|
+
if (!didSendFile) {
|
|
1048
|
+
this.#sendTxMessages();
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
|
|
651
1052
|
// TFLITE MODEL CONFIG
|
|
652
1053
|
get tfliteTask() {
|
|
653
1054
|
return this.#tfliteManager.task;
|
|
@@ -665,7 +1066,9 @@ class Device {
|
|
|
665
1066
|
return this.#tfliteManager.sensorTypes;
|
|
666
1067
|
}
|
|
667
1068
|
get allowedTfliteSensorTypes() {
|
|
668
|
-
return this.sensorTypes.filter((sensorType) =>
|
|
1069
|
+
return this.sensorTypes.filter((sensorType) =>
|
|
1070
|
+
TfliteSensorTypes.includes(sensorType as TfliteSensorType)
|
|
1071
|
+
);
|
|
669
1072
|
}
|
|
670
1073
|
get setTfliteSensorTypes() {
|
|
671
1074
|
return this.#tfliteManager.setSensorTypes;
|
|
@@ -728,8 +1131,14 @@ class Device {
|
|
|
728
1131
|
this.#assertCanUpdateFirmware();
|
|
729
1132
|
return this.#firmwareManager.uploadFirmware;
|
|
730
1133
|
}
|
|
1134
|
+
get canReset() {
|
|
1135
|
+
return this.canUpdateFirmware;
|
|
1136
|
+
}
|
|
731
1137
|
async reset() {
|
|
732
|
-
|
|
1138
|
+
_console.assertWithError(
|
|
1139
|
+
this.canReset,
|
|
1140
|
+
"reset is not enabled for this device"
|
|
1141
|
+
);
|
|
733
1142
|
await this.#firmwareManager.reset();
|
|
734
1143
|
return this.#connectionManager!.disconnect();
|
|
735
1144
|
}
|
|
@@ -776,6 +1185,202 @@ class Device {
|
|
|
776
1185
|
get isUkaton() {
|
|
777
1186
|
return this.deviceInformation.modelNumber.includes("Ukaton");
|
|
778
1187
|
}
|
|
1188
|
+
|
|
1189
|
+
// WIFI MANAGER
|
|
1190
|
+
#wifiManager = new WifiManager();
|
|
1191
|
+
get isWifiAvailable() {
|
|
1192
|
+
return this.#wifiManager.isWifiAvailable;
|
|
1193
|
+
}
|
|
1194
|
+
get wifiSSID() {
|
|
1195
|
+
return this.#wifiManager.wifiSSID;
|
|
1196
|
+
}
|
|
1197
|
+
async setWifiSSID(newWifiSSID: string) {
|
|
1198
|
+
return this.#wifiManager.setWifiSSID(newWifiSSID);
|
|
1199
|
+
}
|
|
1200
|
+
get wifiPassword() {
|
|
1201
|
+
return this.#wifiManager.wifiPassword;
|
|
1202
|
+
}
|
|
1203
|
+
async setWifiPassword(newWifiPassword: string) {
|
|
1204
|
+
return this.#wifiManager.setWifiPassword(newWifiPassword);
|
|
1205
|
+
}
|
|
1206
|
+
get isWifiConnected() {
|
|
1207
|
+
return this.#wifiManager.isWifiConnected;
|
|
1208
|
+
}
|
|
1209
|
+
get ipAddress() {
|
|
1210
|
+
return this.#wifiManager.ipAddress;
|
|
1211
|
+
}
|
|
1212
|
+
get wifiConnectionEnabled() {
|
|
1213
|
+
return this.#wifiManager.wifiConnectionEnabled;
|
|
1214
|
+
}
|
|
1215
|
+
get enableWifiConnection() {
|
|
1216
|
+
return this.#wifiManager.enableWifiConnection;
|
|
1217
|
+
}
|
|
1218
|
+
get setWifiConnectionEnabled() {
|
|
1219
|
+
return this.#wifiManager.setWifiConnectionEnabled;
|
|
1220
|
+
}
|
|
1221
|
+
get disableWifiConnection() {
|
|
1222
|
+
return this.#wifiManager.disableWifiConnection;
|
|
1223
|
+
}
|
|
1224
|
+
get toggleWifiConnection() {
|
|
1225
|
+
return this.#wifiManager.toggleWifiConnection;
|
|
1226
|
+
}
|
|
1227
|
+
get isWifiSecure() {
|
|
1228
|
+
return this.#wifiManager.isWifiSecure;
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
async reconnectViaWebSockets() {
|
|
1232
|
+
_console.assertWithError(this.isWifiConnected, "wifi is not connected");
|
|
1233
|
+
_console.assertWithError(
|
|
1234
|
+
this.connectionType != "webSocket",
|
|
1235
|
+
"already connected via webSockets"
|
|
1236
|
+
);
|
|
1237
|
+
_console.assertTypeWithError(this.ipAddress, "string");
|
|
1238
|
+
_console.log("reconnecting via websockets...");
|
|
1239
|
+
await this.disconnect();
|
|
1240
|
+
await this.connect({
|
|
1241
|
+
type: "webSocket",
|
|
1242
|
+
ipAddress: this.ipAddress!,
|
|
1243
|
+
isWifiSecure: this.isWifiSecure,
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
async reconnectViaUDP() {
|
|
1248
|
+
_console.assertWithError(isInNode, "udp is only available in node");
|
|
1249
|
+
_console.assertWithError(this.isWifiConnected, "wifi is not connected");
|
|
1250
|
+
_console.assertWithError(
|
|
1251
|
+
this.connectionType != "udp",
|
|
1252
|
+
"already connected via udp"
|
|
1253
|
+
);
|
|
1254
|
+
_console.assertTypeWithError(this.ipAddress, "string");
|
|
1255
|
+
_console.log("reconnecting via udp...");
|
|
1256
|
+
await this.disconnect();
|
|
1257
|
+
await this.connect({
|
|
1258
|
+
type: "udp",
|
|
1259
|
+
ipAddress: this.ipAddress!,
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
// CAMERA MANAGER
|
|
1264
|
+
#cameraManager = new CameraManager();
|
|
1265
|
+
get hasCamera() {
|
|
1266
|
+
return this.sensorTypes.includes("camera");
|
|
1267
|
+
}
|
|
1268
|
+
get cameraStatus() {
|
|
1269
|
+
return this.#cameraManager.cameraStatus;
|
|
1270
|
+
}
|
|
1271
|
+
#assertHasCamera() {
|
|
1272
|
+
_console.assertWithError(this.hasCamera, "camera not available");
|
|
1273
|
+
}
|
|
1274
|
+
async takePicture() {
|
|
1275
|
+
this.#assertHasCamera();
|
|
1276
|
+
await this.#cameraManager.takePicture();
|
|
1277
|
+
}
|
|
1278
|
+
async focusCamera() {
|
|
1279
|
+
this.#assertHasCamera();
|
|
1280
|
+
await this.#cameraManager.focus();
|
|
1281
|
+
}
|
|
1282
|
+
async stopCamera() {
|
|
1283
|
+
this.#assertHasCamera();
|
|
1284
|
+
await this.#cameraManager.stop();
|
|
1285
|
+
}
|
|
1286
|
+
async wakeCamera() {
|
|
1287
|
+
this.#assertHasCamera();
|
|
1288
|
+
await this.#cameraManager.wake();
|
|
1289
|
+
}
|
|
1290
|
+
async sleepCamera() {
|
|
1291
|
+
this.#assertHasCamera();
|
|
1292
|
+
await this.#cameraManager.sleep();
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
get cameraConfiguration() {
|
|
1296
|
+
return this.#cameraManager.cameraConfiguration;
|
|
1297
|
+
}
|
|
1298
|
+
get availableCameraConfigurationTypes() {
|
|
1299
|
+
return this.#cameraManager.availableCameraConfigurationTypes;
|
|
1300
|
+
}
|
|
1301
|
+
get cameraConfigurationRanges() {
|
|
1302
|
+
return this.#cameraManager.cameraConfigurationRanges;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
get setCameraConfiguration() {
|
|
1306
|
+
return this.#cameraManager.setCameraConfiguration;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
// MICROPHONE
|
|
1310
|
+
#microphoneManager = new MicrophoneManager();
|
|
1311
|
+
get hasMicrophone() {
|
|
1312
|
+
return this.sensorTypes.includes("microphone");
|
|
1313
|
+
}
|
|
1314
|
+
get microphoneStatus() {
|
|
1315
|
+
return this.#microphoneManager.microphoneStatus;
|
|
1316
|
+
}
|
|
1317
|
+
#assertHasMicrophone() {
|
|
1318
|
+
_console.assertWithError(this.hasMicrophone, "microphone not available");
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
async startMicrophone() {
|
|
1322
|
+
this.#assertHasMicrophone();
|
|
1323
|
+
await this.#microphoneManager.start();
|
|
1324
|
+
}
|
|
1325
|
+
async stopMicrophone() {
|
|
1326
|
+
this.#assertHasMicrophone();
|
|
1327
|
+
await this.#microphoneManager.stop();
|
|
1328
|
+
}
|
|
1329
|
+
async enableMicrophoneVad() {
|
|
1330
|
+
this.#assertHasMicrophone();
|
|
1331
|
+
await this.#microphoneManager.vad();
|
|
1332
|
+
}
|
|
1333
|
+
async toggleMicrophone() {
|
|
1334
|
+
this.#assertHasMicrophone();
|
|
1335
|
+
await this.#microphoneManager.toggle();
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
get microphoneConfiguration() {
|
|
1339
|
+
return this.#microphoneManager.microphoneConfiguration;
|
|
1340
|
+
}
|
|
1341
|
+
get availableMicrophoneConfigurationTypes() {
|
|
1342
|
+
return this.#microphoneManager.availableMicrophoneConfigurationTypes;
|
|
1343
|
+
}
|
|
1344
|
+
get setMicrophoneConfiguration() {
|
|
1345
|
+
return this.#microphoneManager.setMicrophoneConfiguration;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
#assertWebAudioSupport() {
|
|
1349
|
+
_console.assertWithError(AudioContext, "WebAudio is not supported");
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
get audioContext() {
|
|
1353
|
+
this.#assertWebAudioSupport();
|
|
1354
|
+
return this.#microphoneManager.audioContext;
|
|
1355
|
+
}
|
|
1356
|
+
set audioContext(newAudioContext) {
|
|
1357
|
+
this.#assertWebAudioSupport();
|
|
1358
|
+
this.#microphoneManager.audioContext = newAudioContext;
|
|
1359
|
+
}
|
|
1360
|
+
get microphoneMediaStreamDestination() {
|
|
1361
|
+
this.#assertWebAudioSupport();
|
|
1362
|
+
return this.#microphoneManager.mediaStreamDestination;
|
|
1363
|
+
}
|
|
1364
|
+
get microphoneGainNode() {
|
|
1365
|
+
this.#assertWebAudioSupport();
|
|
1366
|
+
return this.#microphoneManager.gainNode;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
get isRecordingMicrophone() {
|
|
1370
|
+
return this.#microphoneManager.isRecording;
|
|
1371
|
+
}
|
|
1372
|
+
startRecordingMicrophone() {
|
|
1373
|
+
this.#assertWebAudioSupport();
|
|
1374
|
+
this.#microphoneManager.startRecording();
|
|
1375
|
+
}
|
|
1376
|
+
stopRecordingMicrophone() {
|
|
1377
|
+
this.#assertWebAudioSupport();
|
|
1378
|
+
this.#microphoneManager.stopRecording();
|
|
1379
|
+
}
|
|
1380
|
+
toggleMicrophoneRecording() {
|
|
1381
|
+
this.#assertWebAudioSupport();
|
|
1382
|
+
this.#microphoneManager.toggleRecording();
|
|
1383
|
+
}
|
|
779
1384
|
}
|
|
780
1385
|
|
|
781
1386
|
export default Device;
|