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.
Files changed (202) hide show
  1. package/assets/3d/anchor.glb +0 -0
  2. package/assets/3d/coin.glb +0 -0
  3. package/assets/3d/glasses.glb +0 -0
  4. package/assets/audio/bounceMedium.wav +0 -0
  5. package/assets/audio/bounceStrong.wav +0 -0
  6. package/assets/audio/bounceWeak.wav +0 -0
  7. package/assets/audio/coin.wav +0 -0
  8. package/assets/audio/getUp.wav +0 -0
  9. package/assets/audio/grab.wav +0 -0
  10. package/assets/audio/kick.wav +0 -0
  11. package/assets/audio/platterFadeIn old.wav +0 -0
  12. package/assets/audio/platterFadeIn.wav +0 -0
  13. package/assets/audio/platterFadeOut.wav +0 -0
  14. package/assets/audio/punch.wav +0 -0
  15. package/assets/audio/punchSqueak.wav +0 -0
  16. package/assets/audio/purr.wav +0 -0
  17. package/assets/audio/purrFadeOut.wav +0 -0
  18. package/assets/audio/release.wav +0 -0
  19. package/assets/audio/splat.wav +0 -0
  20. package/assets/audio/stomp.wav +0 -0
  21. package/build/brilliantsole.cjs +3091 -741
  22. package/build/brilliantsole.cjs.map +1 -1
  23. package/build/brilliantsole.js +2759 -709
  24. package/build/brilliantsole.js.map +1 -1
  25. package/build/brilliantsole.ls.js +2602 -543
  26. package/build/brilliantsole.ls.js.map +1 -1
  27. package/build/brilliantsole.min.js +1 -1
  28. package/build/brilliantsole.min.js.map +1 -1
  29. package/build/brilliantsole.module.d.ts +295 -65
  30. package/build/brilliantsole.module.js +2749 -710
  31. package/build/brilliantsole.module.js.map +1 -1
  32. package/build/brilliantsole.module.min.d.ts +295 -65
  33. package/build/brilliantsole.module.min.js +1 -1
  34. package/build/brilliantsole.module.min.js.map +1 -1
  35. package/build/brilliantsole.node.module.d.ts +289 -62
  36. package/build/brilliantsole.node.module.js +3080 -742
  37. package/build/brilliantsole.node.module.js.map +1 -1
  38. package/build/dts/BS-output.d.ts +10 -0
  39. package/build/dts/BS.d.ts +21 -8
  40. package/build/dts/CameraManager.d.ts +72 -0
  41. package/build/dts/Device.d.ts +64 -13
  42. package/build/dts/DeviceInformationManager.d.ts +4 -4
  43. package/build/dts/DeviceManager.d.ts +2 -0
  44. package/build/dts/FileTransferManager.d.ts +18 -8
  45. package/build/dts/InformationManager.d.ts +2 -0
  46. package/build/dts/MicrophoneManager.d.ts +88 -0
  47. package/build/dts/TfliteManager.d.ts +22 -2
  48. package/build/dts/WifiManager.d.ts +61 -0
  49. package/build/dts/connection/BaseConnectionManager.d.ts +35 -3
  50. package/build/dts/connection/ClientConnectionManager.d.ts +7 -2
  51. package/build/dts/connection/bluetooth/NobleConnectionManager.d.ts +2 -1
  52. package/build/dts/connection/bluetooth/WebBluetoothConnectionManager.d.ts +1 -0
  53. package/build/dts/connection/bluetooth/bluetoothUUIDs.d.ts +2 -2
  54. package/build/dts/connection/udp/UDPConnectionManager.d.ts +28 -0
  55. package/build/dts/connection/webSocket/WebSocketConnectionManager.d.ts +25 -0
  56. package/build/dts/devicePair/DevicePair.d.ts +5 -5
  57. package/build/dts/scanner/BaseScanner.d.ts +4 -1
  58. package/build/dts/scanner/NobleScanner.d.ts +2 -1
  59. package/build/dts/sensor/MotionSensorDataManager.d.ts +5 -2
  60. package/build/dts/sensor/SensorDataManager.d.ts +5 -4
  61. package/build/dts/server/BaseClient.d.ts +5 -3
  62. package/build/dts/server/ServerUtils.d.ts +1 -1
  63. package/build/dts/server/websocket/WebSocketUtils.d.ts +1 -1
  64. package/build/dts/utils/AudioUtils.d.ts +2 -0
  65. package/build/dts/utils/Console.d.ts +2 -0
  66. package/build/dts/utils/ThrottleUtils.d.ts +2 -0
  67. package/build/dts/vibration/VibrationManager.d.ts +19 -2
  68. package/build/index.d.ts +292 -62
  69. package/build/index.node.d.ts +286 -59
  70. package/examples/3d/scene.html +19 -5
  71. package/examples/3d-generic/index.html +144 -0
  72. package/examples/3d-generic/script.js +266 -0
  73. package/examples/basic/index.html +267 -17
  74. package/examples/basic/script.js +958 -105
  75. package/examples/camera/barcode-detector.js +109 -0
  76. package/examples/camera/depth-estimation.js +71 -0
  77. package/examples/camera/face-detector.js +119 -0
  78. package/examples/camera/face-landmark.js +111 -0
  79. package/examples/camera/gesture-recognition.js +97 -0
  80. package/examples/camera/hand-landmark.js +74 -0
  81. package/examples/camera/image-segmentation.js +98 -0
  82. package/examples/camera/image-to-text.js +43 -0
  83. package/examples/camera/image-upscale.js +75 -0
  84. package/examples/camera/index.html +129 -0
  85. package/examples/camera/object-detection.js +98 -0
  86. package/examples/camera/pose-landmark.js +60 -0
  87. package/examples/camera/script.js +316 -0
  88. package/examples/camera/utils.js +165 -0
  89. package/examples/camera/yolo-tiny.js +54 -0
  90. package/examples/camera/yolo.js +119 -0
  91. package/examples/edge-impulse/script.js +157 -48
  92. package/examples/edge-impulse-test/README.md +11 -0
  93. package/examples/edge-impulse-test/edge-impulse-standalone.js +7228 -0
  94. package/examples/edge-impulse-test/edge-impulse-standalone.wasm +0 -0
  95. package/examples/edge-impulse-test/index.html +75 -0
  96. package/examples/edge-impulse-test/run-impulse.js +135 -0
  97. package/examples/edge-impulse-test/script.js +200 -0
  98. package/examples/glasses-gestures/README.md +11 -0
  99. package/examples/glasses-gestures/edge-impulse-standalone.js +7228 -0
  100. package/examples/glasses-gestures/edge-impulse-standalone.wasm +0 -0
  101. package/examples/glasses-gestures/index.html +69 -0
  102. package/examples/glasses-gestures/run-impulse.js +135 -0
  103. package/examples/glasses-gestures/script.js +226 -0
  104. package/examples/gloves/edge-impulse-standalone.js +7228 -0
  105. package/examples/gloves/edge-impulse-standalone.wasm +0 -0
  106. package/examples/gloves/index.html +4 -1
  107. package/examples/gloves/run-impulse.js +135 -0
  108. package/examples/gloves/script.js +367 -51
  109. package/examples/graph/script.js +94 -37
  110. package/examples/microphone/gender.js +54 -0
  111. package/examples/microphone/index.html +102 -0
  112. package/examples/microphone/script.js +394 -0
  113. package/examples/microphone/utils.js +45 -0
  114. package/examples/microphone/whisper-realtime.js +166 -0
  115. package/examples/microphone/whisper.js +132 -0
  116. package/examples/punch/index.html +135 -0
  117. package/examples/punch/punch.tflite +0 -0
  118. package/examples/punch/script.js +169 -0
  119. package/examples/server/index.html +98 -22
  120. package/examples/server/script.js +317 -109
  121. package/examples/ukaton-firmware-update/merged-firmware.bin +0 -0
  122. package/examples/utils/aframe/aframe-master.min.js +2 -0
  123. package/examples/utils/aframe/bs-vibration.js +150 -0
  124. package/examples/utils/aframe/force-pushable.js +80 -0
  125. package/examples/utils/aframe/grabbable-anchor.js +46 -0
  126. package/examples/utils/aframe/grabbable-listener.js +31 -0
  127. package/examples/utils/aframe/grabbable-physics-body.js +190 -0
  128. package/examples/utils/aframe/grow-shrink.js +25 -0
  129. package/examples/utils/aframe/hand-punch.js +119 -0
  130. package/examples/utils/aframe/my-obb-collider.js +293 -0
  131. package/examples/utils/aframe/occlude-hand-tracking-controls.js +47 -0
  132. package/examples/utils/aframe/occlude-mesh.js +42 -0
  133. package/examples/utils/aframe/palm-up-detector.js +47 -0
  134. package/examples/utils/aframe/shadow-material.js +20 -0
  135. package/examples/utils/aframe/soft-shadow-light.js +9 -0
  136. package/examples/webxr-2/assets/3d/soccerBall.glb +0 -0
  137. package/examples/webxr-2/assets/audio/shellBounce.wav +0 -0
  138. package/examples/webxr-2/assets/audio/shellHit.wav +0 -0
  139. package/examples/webxr-2/assets/audio/shellKick.wav +0 -0
  140. package/examples/webxr-2/assets/audio/soccerBounce.wav +0 -0
  141. package/examples/webxr-2/assets/audio/soccerKick.mp3 +0 -0
  142. package/examples/webxr-2/assets/images/shellTexture.png +0 -0
  143. package/examples/webxr-2/components/bs-ankle.js +337 -0
  144. package/examples/webxr-2/components/coin.js +84 -0
  145. package/examples/webxr-2/components/custom-wrap.js +17 -0
  146. package/examples/webxr-2/components/goomba.js +3250 -0
  147. package/examples/webxr-2/components/init-shell-material.js +215 -0
  148. package/examples/webxr-2/components/platter.js +172 -0
  149. package/examples/webxr-2/components/shell.js +374 -0
  150. package/examples/webxr-2/components/soccer-ball.js +250 -0
  151. package/examples/webxr-2/components/squashed-goomba.js +249 -0
  152. package/examples/webxr-2/edge-impulse-standalone.js +7228 -0
  153. package/examples/webxr-2/edge-impulse-standalone.wasm +0 -0
  154. package/examples/webxr-2/index.html +996 -0
  155. package/examples/webxr-2/kick.tflite +0 -0
  156. package/examples/webxr-2/kick2.tflite +0 -0
  157. package/examples/webxr-2/run-impulse.js +135 -0
  158. package/examples/webxr-2/script.js +384 -0
  159. package/examples/webxr-3/components/bs-camera.js +65 -0
  160. package/examples/webxr-3/index.html +134 -0
  161. package/examples/webxr-3/script.js +432 -0
  162. package/package.json +2 -1
  163. package/src/.prettierrc +4 -0
  164. package/src/BS.ts +79 -8
  165. package/src/CameraManager.ts +497 -0
  166. package/src/Device.ts +691 -86
  167. package/src/DeviceInformationManager.ts +19 -10
  168. package/src/DeviceManager.ts +85 -25
  169. package/src/FileTransferManager.ts +145 -20
  170. package/src/InformationManager.ts +40 -15
  171. package/src/MicrophoneManager.ts +599 -0
  172. package/src/TfliteManager.ts +171 -25
  173. package/src/WifiManager.ts +323 -0
  174. package/src/connection/BaseConnectionManager.ts +130 -30
  175. package/src/connection/ClientConnectionManager.ts +34 -10
  176. package/src/connection/bluetooth/BluetoothConnectionManager.ts +8 -2
  177. package/src/connection/bluetooth/NobleConnectionManager.ts +147 -41
  178. package/src/connection/bluetooth/WebBluetoothConnectionManager.ts +99 -34
  179. package/src/connection/bluetooth/bluetoothUUIDs.ts +40 -13
  180. package/src/connection/udp/UDPConnectionManager.ts +356 -0
  181. package/src/connection/websocket/WebSocketConnectionManager.ts +282 -0
  182. package/src/devicePair/DevicePair.ts +95 -25
  183. package/src/devicePair/DevicePairPressureSensorDataManager.ts +27 -7
  184. package/src/scanner/BaseScanner.ts +49 -11
  185. package/src/scanner/NobleScanner.ts +76 -14
  186. package/src/sensor/MotionSensorDataManager.ts +21 -6
  187. package/src/sensor/PressureSensorDataManager.ts +37 -8
  188. package/src/sensor/SensorConfigurationManager.ts +73 -22
  189. package/src/sensor/SensorDataManager.ts +109 -23
  190. package/src/server/BaseClient.ts +150 -36
  191. package/src/server/BaseServer.ts +50 -2
  192. package/src/server/ServerUtils.ts +39 -9
  193. package/src/server/udp/UDPServer.ts +73 -22
  194. package/src/server/udp/UDPUtils.ts +9 -2
  195. package/src/server/websocket/WebSocketClient.ts +27 -7
  196. package/src/server/websocket/WebSocketUtils.ts +4 -2
  197. package/src/utils/AudioUtils.ts +65 -0
  198. package/src/utils/Console.ts +62 -9
  199. package/src/utils/ParseUtils.ts +24 -5
  200. package/src/utils/ThrottleUtils.ts +62 -0
  201. package/src/utils/Timer.ts +1 -1
  202. package/src/vibration/VibrationManager.ts +166 -40
@@ -0,0 +1,134 @@
1
+ <html>
2
+ <head>
3
+ <title>WebXR Camera | BrilliantSole JavaScript SDK</title>
4
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
5
+ <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
6
+ <script src="../utils/aframe/aframe-master.min.js"></script>
7
+ <script src="../utils/aframe/occlude-hand-tracking-controls.js"></script>
8
+ <script src="./components/bs-camera.js" type="module"></script>
9
+
10
+ <script type="module" src="./script.js"></script>
11
+ </head>
12
+
13
+ <style>
14
+ a-scene {
15
+ width: 500px;
16
+ height: 400px;
17
+ margin: auto;
18
+ border-radius: 2rem;
19
+ overflow: hidden;
20
+ border: solid black;
21
+ box-sizing: border-box;
22
+ }
23
+ </style>
24
+
25
+ <body>
26
+ <nav>
27
+ <a href="../../">home</a>
28
+ </nav>
29
+
30
+ <h1>WebXR Camera | BrilliantSole JavaScript SDK</h1>
31
+
32
+ <div>
33
+ <label
34
+ >webSocket url
35
+ <input id="webSocketUrl" type="url" placeholder="localhost"
36
+ /></label>
37
+ <button id="toggleConnection">connect</button>
38
+ </div>
39
+
40
+ <div>
41
+ <label>
42
+ is scanning available?
43
+ <input id="isScanningAvailable" type="checkbox" readonly disabled />
44
+ </label>
45
+ <button id="toggleScan" disabled>scan</button>
46
+ </div>
47
+
48
+ <div>
49
+ <h2>camera</h2>
50
+
51
+ <label>
52
+ <b>is camera available?</b>
53
+ <span id="isCameraAvailable"></span>
54
+ </label>
55
+
56
+ <label><b>status:</b> <span id="cameraStatus"></span></label>
57
+ <br />
58
+
59
+ <label>auto picture: <input type="checkbox" id="autoPicture" /> </label>
60
+
61
+ <button disabled id="takePicture">take picture</button>
62
+ <progress value="0" id="cameraImageProgress"></progress>
63
+ <br />
64
+ <button disabled id="focusCamera">focus camera</button>
65
+ <br />
66
+ <button disabled id="sleepCamera">sleep camera</button>
67
+
68
+ <div style="display: flex; flex-direction: row">
69
+ <div>
70
+ <label>
71
+ <b>camera configuration: </b>
72
+ <pre id="cameraConfigurationPre"></pre>
73
+ </label>
74
+ <br />
75
+
76
+ <label>
77
+ take picture after update?
78
+ <input type="checkbox" id="takePictureAfterUpdate" />
79
+ </label>
80
+
81
+ <div id="cameraConfiguration">
82
+ <template id="cameraConfigurationTypeTemplate">
83
+ <label class="cameraConfigurationType">
84
+ <input class="value" type="range" value="" disabled />
85
+ <b class="type"></b> <span></span>
86
+ <br />
87
+ </label>
88
+ </template>
89
+ </div>
90
+ <label>
91
+ <b>white balance</b>
92
+ <input type="color" id="cameraWhiteBalance" disabled />
93
+ </label>
94
+ </div>
95
+ <div>
96
+ <img id="cameraImage" />
97
+ </div>
98
+ </div>
99
+ </div>
100
+
101
+ <a-scene
102
+ embedded
103
+ obb-collider="showColliders: false;"
104
+ xr-mode-ui="enabled: true; XRMode: ar"
105
+ device-orientation-permission-ui="enabled: false"
106
+ >
107
+ <a-assets></a-assets>
108
+
109
+ <a-camera position="0 1.6 0">
110
+ <a-image
111
+ grabbable
112
+ width="0.15"
113
+ height="0.15"
114
+ position="0 0 -0.5"
115
+ bs-camera
116
+ ></a-image>
117
+ </a-camera>
118
+
119
+ <a-entity
120
+ class="left hand"
121
+ hand-tracking-grab-controls="hand: left;"
122
+ occlude-hand-tracking-controls
123
+ ></a-entity>
124
+
125
+ <a-entity
126
+ class="right hand"
127
+ hand-tracking-grab-controls="hand: right;"
128
+ occlude-hand-tracking-controls
129
+ ></a-entity>
130
+
131
+ <a-sky hide-on-enter-ar color="black"></a-sky>
132
+ </a-scene>
133
+ </body>
134
+ </html>
@@ -0,0 +1,432 @@
1
+ import * as BS from "../../build/brilliantsole.module.js";
2
+ window.BS = BS;
3
+ console.log({ BS });
4
+ //BS.setAllConsoleLevelFlags({ log: true });
5
+
6
+ const client = new BS.WebSocketClient();
7
+ console.log({ client });
8
+
9
+ window.client = client;
10
+
11
+ // WEBSOCKET URL SEARCH PARAMS
12
+
13
+ const url = new URL(location);
14
+ function setUrlParam(key, value) {
15
+ if (history.pushState) {
16
+ let searchParams = new URLSearchParams(window.location.search);
17
+ if (value) {
18
+ searchParams.set(key, value);
19
+ } else {
20
+ searchParams.delete(key);
21
+ }
22
+ let newUrl =
23
+ window.location.protocol +
24
+ "//" +
25
+ window.location.host +
26
+ window.location.pathname +
27
+ "?" +
28
+ searchParams.toString();
29
+ window.history.pushState({ path: newUrl }, "", newUrl);
30
+ }
31
+ }
32
+ client.addEventListener("isConnected", () => {
33
+ if (client.isConnected) {
34
+ setUrlParam("webSocketUrl", client.webSocket.url);
35
+ webSocketUrlInput.value = client.webSocket.url;
36
+ webSocketUrlInput.dispatchEvent(new Event("input"));
37
+ } else {
38
+ setUrlParam("webSocketUrl");
39
+ }
40
+ });
41
+
42
+ // WEBSOCKET SERVER URL
43
+
44
+ /** @type {HTMLInputElement} */
45
+ const webSocketUrlInput = document.getElementById("webSocketUrl");
46
+ webSocketUrlInput.value = url.searchParams.get("webSocketUrl") || "";
47
+ webSocketUrlInput.dispatchEvent(new Event("input"));
48
+
49
+ // WEBSOCKET CONNECTION
50
+
51
+ /** @type {HTMLButtonElement} */
52
+ const toggleConnectionButton = document.getElementById("toggleConnection");
53
+ toggleConnectionButton.addEventListener("click", () => {
54
+ if (client.isConnected) {
55
+ client.disconnect();
56
+ } else {
57
+ /** @type {string?} */
58
+ let webSocketUrl;
59
+ if (webSocketUrlInput.value.length > 0) {
60
+ webSocketUrl = webSocketUrlInput.value;
61
+ }
62
+ client.connect(webSocketUrl);
63
+ }
64
+ });
65
+ client.addEventListener("connectionStatus", () => {
66
+ switch (client.connectionStatus) {
67
+ case "connected":
68
+ case "notConnected":
69
+ toggleConnectionButton.disabled = false;
70
+ toggleConnectionButton.innerText = client.isConnected
71
+ ? "disconnect"
72
+ : "connect";
73
+ break;
74
+ case "connecting":
75
+ case "disconnecting":
76
+ toggleConnectionButton.innerText = client.connectionStatus;
77
+ toggleConnectionButton.disabled = true;
78
+ break;
79
+ }
80
+ });
81
+
82
+ // SCANNER
83
+
84
+ /** @type {HTMLInputElement} */
85
+ const isScanningAvailableCheckbox = document.getElementById(
86
+ "isScanningAvailable"
87
+ );
88
+ client.addEventListener("isScanningAvailable", () => {
89
+ isScanningAvailableCheckbox.checked = client.isScanningAvailable;
90
+ });
91
+
92
+ /** @type {HTMLButtonElement} */
93
+ const toggleScanButton = document.getElementById("toggleScan");
94
+ toggleScanButton.addEventListener("click", () => {
95
+ client.toggleScan();
96
+ });
97
+ client.addEventListener("isScanningAvailable", () => {
98
+ toggleScanButton.disabled = !client.isScanningAvailable;
99
+ });
100
+ client.addEventListener("isScanning", () => {
101
+ toggleScanButton.innerText = client.isScanning ? "stop scanning" : "scan";
102
+ });
103
+
104
+ // DEVICES
105
+
106
+ /** @type {BS.Device?} */
107
+ let device;
108
+
109
+ client.addEventListener("discoveredDevice", (event) => {
110
+ if (device) {
111
+ return;
112
+ }
113
+ const { discoveredDevice } = event.message;
114
+ if (discoveredDevice.deviceType == "glasses") {
115
+ console.log("connecting to discoveredDevice", discoveredDevice);
116
+ device = client.connectToDevice(discoveredDevice.bluetoothId);
117
+ }
118
+ });
119
+
120
+ BS.DeviceManager.AddEventListener("deviceConnected", (event) => {
121
+ if (event.message.device.hasCamera) {
122
+ device = event.message.device;
123
+ onDevice();
124
+ }
125
+ });
126
+
127
+ const onDevice = () => {
128
+ console.log("onDevice", device);
129
+ if (client.isScanning) {
130
+ client.stopScan();
131
+ }
132
+ device.setSensorConfiguration({ camera: 5 });
133
+
134
+ // CAMERA
135
+
136
+ /** @type {HTMLSpanElement} */
137
+ const isCameraAvailableSpan = document.getElementById("isCameraAvailable");
138
+ const updateIsCameraAvailableSpan = () => {
139
+ isCameraAvailableSpan.innerText = device.hasCamera;
140
+ };
141
+ device.addEventListener("connected", () => {
142
+ updateIsCameraAvailableSpan();
143
+ });
144
+
145
+ /** @type {HTMLSpanElement} */
146
+ const cameraStatusSpan = document.getElementById("cameraStatus");
147
+ const updateCameraStatusSpan = () => {
148
+ cameraStatusSpan.innerText = device.cameraStatus;
149
+ };
150
+ device.addEventListener("cameraStatus", () => {
151
+ updateCameraStatusSpan();
152
+ });
153
+
154
+ /** @type {HTMLButtonElement} */
155
+ const takePictureButton = document.getElementById("takePicture");
156
+ takePictureButton.addEventListener("click", () => {
157
+ if (device.cameraStatus == "idle") {
158
+ device.takePicture();
159
+ } else {
160
+ device.stopCamera();
161
+ }
162
+ });
163
+ device.addEventListener("connected", () => {
164
+ updateTakePictureButton();
165
+ });
166
+ device.addEventListener("getSensorConfiguration", () => {
167
+ updateTakePictureButton();
168
+ });
169
+ const updateTakePictureButton = () => {
170
+ takePictureButton.disabled =
171
+ !device.isConnected ||
172
+ device.sensorConfiguration.camera == 0 ||
173
+ device.cameraStatus != "idle";
174
+ };
175
+ device.addEventListener("cameraStatus", () => {
176
+ updateTakePictureButton();
177
+ });
178
+ updateTakePictureButton();
179
+
180
+ /** @type {HTMLButtonElement} */
181
+ const focusCameraButton = document.getElementById("focusCamera");
182
+ focusCameraButton.addEventListener("click", () => {
183
+ if (device.cameraStatus == "idle") {
184
+ device.focusCamera();
185
+ } else {
186
+ device.stopCamera();
187
+ }
188
+ });
189
+ device.addEventListener("connected", () => {
190
+ updateFocusCameraButton();
191
+ });
192
+ device.addEventListener("getSensorConfiguration", () => {
193
+ updateFocusCameraButton();
194
+ });
195
+ const updateFocusCameraButton = () => {
196
+ focusCameraButton.disabled =
197
+ !device.isConnected ||
198
+ device.sensorConfiguration.camera == 0 ||
199
+ device.cameraStatus != "idle";
200
+ };
201
+ device.addEventListener("cameraStatus", (event) => {
202
+ updateFocusCameraButton();
203
+ if (
204
+ device.cameraStatus == "idle" &&
205
+ event.message.previousCameraStatus == "focusing"
206
+ ) {
207
+ device.takePicture();
208
+ }
209
+ });
210
+ updateFocusCameraButton();
211
+
212
+ /** @type {HTMLButtonElement} */
213
+ const sleepCameraButton = document.getElementById("sleepCamera");
214
+ sleepCameraButton.addEventListener("click", () => {
215
+ if (device.cameraStatus == "asleep") {
216
+ device.wakeCamera();
217
+ } else {
218
+ device.sleepCamera();
219
+ }
220
+ });
221
+ device.addEventListener("connected", () => {
222
+ updateSleepCameraButton();
223
+ });
224
+ device.addEventListener("getSensorConfiguration", () => {
225
+ updateSleepCameraButton();
226
+ });
227
+ const updateSleepCameraButton = () => {
228
+ let disabled = !device.isConnected || !device.hasCamera;
229
+ switch (device.cameraStatus) {
230
+ case "asleep":
231
+ sleepCameraButton.innerText = "wake camera";
232
+ break;
233
+ case "idle":
234
+ sleepCameraButton.innerText = "sleep camera";
235
+ break;
236
+ default:
237
+ disabled = true;
238
+ break;
239
+ }
240
+ sleepCameraButton.disabled = disabled;
241
+ };
242
+ device.addEventListener("cameraStatus", () => {
243
+ updateSleepCameraButton();
244
+ });
245
+ updateSleepCameraButton();
246
+
247
+ /** @type {HTMLImageElement} */
248
+ const cameraImage = document.getElementById("cameraImage");
249
+ device.addEventListener("cameraImage", (event) => {
250
+ cameraImage.src = event.message.url;
251
+ });
252
+
253
+ /** @type {HTMLProgressElement} */
254
+ const cameraImageProgress = document.getElementById("cameraImageProgress");
255
+ device.addEventListener("cameraImageProgress", (event) => {
256
+ if (event.message.type == "image") {
257
+ cameraImageProgress.value = event.message.progress;
258
+ }
259
+ });
260
+
261
+ /** @type {HTMLInputElement} */
262
+ const autoPictureCheckbox = document.getElementById("autoPicture");
263
+ let autoPicture = autoPictureCheckbox.checked;
264
+ autoPictureCheckbox.addEventListener("input", () => {
265
+ autoPicture = autoPictureCheckbox.checked;
266
+ });
267
+ device.addEventListener("cameraImage", () => {
268
+ if (autoPicture) {
269
+ device.takePicture();
270
+ }
271
+ });
272
+
273
+ /** @type {HTMLPreElement} */
274
+ const cameraConfigurationPre = document.getElementById(
275
+ "cameraConfigurationPre"
276
+ );
277
+ const updateCameraConfigurationPre = () => {
278
+ cameraConfigurationPre.textContent = JSON.stringify(
279
+ device.cameraConfiguration,
280
+ null,
281
+ 2
282
+ );
283
+ };
284
+ device.addEventListener("getCameraConfiguration", () => {
285
+ updateCameraConfigurationPre();
286
+ });
287
+
288
+ const cameraConfigurationContainer = document.getElementById(
289
+ "cameraConfiguration"
290
+ );
291
+ /** @type {HTMLTemplateElement} */
292
+ const cameraConfigurationTypeTemplate = document.getElementById(
293
+ "cameraConfigurationTypeTemplate"
294
+ );
295
+ BS.CameraConfigurationTypes.forEach((cameraConfigurationType) => {
296
+ const cameraConfigurationTypeContainer =
297
+ cameraConfigurationTypeTemplate.content
298
+ .cloneNode(true)
299
+ .querySelector(".cameraConfigurationType");
300
+
301
+ cameraConfigurationContainer.appendChild(cameraConfigurationTypeContainer);
302
+
303
+ cameraConfigurationTypeContainer.querySelector(".type").innerText =
304
+ cameraConfigurationType;
305
+
306
+ /** @type {HTMLInputElement} */
307
+ const input = cameraConfigurationTypeContainer.querySelector("input");
308
+
309
+ /** @type {HTMLSpanElement} */
310
+ const span = cameraConfigurationTypeContainer.querySelector("span");
311
+
312
+ device.addEventListener("isConnected", () => {
313
+ updateisInputDisabled();
314
+ });
315
+ device.addEventListener("cameraStatus", () => {
316
+ updateisInputDisabled();
317
+ });
318
+ const updateisInputDisabled = () => {
319
+ input.disabled =
320
+ !device.isConnected ||
321
+ !device.hasCamera ||
322
+ device.cameraStatus != "idle";
323
+ };
324
+
325
+ const updateInput = () => {
326
+ const value = device.cameraConfiguration[cameraConfigurationType];
327
+ span.innerText = value;
328
+ input.value = value;
329
+ };
330
+ const range = device.cameraConfigurationRanges[cameraConfigurationType];
331
+ input.min = range.min;
332
+ input.max = range.max;
333
+ updateInput();
334
+
335
+ device.addEventListener("connected", () => {
336
+ if (!device.hasCamera) {
337
+ return;
338
+ }
339
+
340
+ updateInput();
341
+ });
342
+
343
+ device.addEventListener("getCameraConfiguration", () => {
344
+ updateInput();
345
+ });
346
+
347
+ input.addEventListener("change", () => {
348
+ const value = Number(input.value);
349
+ // console.log(`updating ${cameraConfigurationType} to ${value}`);
350
+ device.setCameraConfiguration({
351
+ [cameraConfigurationType]: value,
352
+ });
353
+ if (takePictureAfterUpdate) {
354
+ device.addEventListener(
355
+ "getCameraConfiguration",
356
+ () => {
357
+ setTimeout(() => device.takePicture()), 100;
358
+ },
359
+ { once: true }
360
+ );
361
+ }
362
+ });
363
+ });
364
+
365
+ /** @type {HTMLInputElement} */
366
+ const takePictureAfterUpdateCheckbox = document.getElementById(
367
+ "takePictureAfterUpdate"
368
+ );
369
+ let takePictureAfterUpdate = false;
370
+ takePictureAfterUpdateCheckbox.addEventListener("input", () => {
371
+ takePictureAfterUpdate = takePictureAfterUpdateCheckbox.checked;
372
+ console.log({ takePictureAfterUpdate });
373
+ });
374
+
375
+ /** @type {HTMLInputElement} */
376
+ const cameraWhiteBalanceInput = document.getElementById("cameraWhiteBalance");
377
+ const updateWhiteBalance = BS.ThrottleUtils.throttle(
378
+ (config) => {
379
+ if (device.cameraStatus != "idle") {
380
+ return;
381
+ }
382
+
383
+ device.setCameraConfiguration(config);
384
+
385
+ if (takePictureAfterUpdate) {
386
+ device.addEventListener(
387
+ "getCameraConfiguration",
388
+ () => {
389
+ setTimeout(() => device.takePicture()), 100;
390
+ },
391
+ { once: true }
392
+ );
393
+ }
394
+ },
395
+ 200,
396
+ true
397
+ );
398
+ cameraWhiteBalanceInput.addEventListener("input", () => {
399
+ let [redGain, greenGain, blueGain] = cameraWhiteBalanceInput.value
400
+ .replace("#", "")
401
+ .match(/.{1,2}/g)
402
+ .map((value) => Number(`0x${value}`))
403
+ .map((value) => value / 255)
404
+ .map((value) => value * device.cameraConfigurationRanges.blueGain.max)
405
+ .map((value) => Math.round(value));
406
+
407
+ updateWhiteBalance({ redGain, greenGain, blueGain });
408
+ });
409
+ const updateCameraWhiteBalanceInput = () => {
410
+ if (!device.hasCamera) {
411
+ return;
412
+ }
413
+ cameraWhiteBalanceInput.disabled =
414
+ !device.isConnected || !device.hasCamera || device.cameraStatus != "idle";
415
+
416
+ const { redGain, blueGain, greenGain } = device.cameraConfiguration;
417
+
418
+ cameraWhiteBalanceInput.value = `#${[redGain, blueGain, greenGain]
419
+ .map((value) => value / device.cameraConfigurationRanges.redGain.max)
420
+ .map((value) => value * 255)
421
+ .map((value) => Math.round(value))
422
+ .map((value) => value.toString(16))
423
+ .join("")}`;
424
+ };
425
+ device.addEventListener("connected", () => {
426
+ updateCameraWhiteBalanceInput();
427
+ });
428
+ device.addEventListener("getCameraConfiguration", () => {
429
+ updateCameraWhiteBalanceInput();
430
+ });
431
+ updateCameraWhiteBalanceInput();
432
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brilliantsole",
3
- "version": "0.0.27",
3
+ "version": "0.0.29",
4
4
  "description": "JavaScript SDK for BrilliantSole Smart Insoles",
5
5
  "main": "./build/brilliantsole.module.js",
6
6
  "module": "./build/brilliantsole.module.js",
@@ -53,6 +53,7 @@
53
53
  "@types/web-bluetooth": "^0.0.20",
54
54
  "@types/ws": "^8.5.10",
55
55
  "axios": "^1.7.7",
56
+ "bonjour": "^3.5.0",
56
57
  "cors": "^2.8.5",
57
58
  "express": "^4.18.3",
58
59
  "ip": "^2.0.1",
@@ -0,0 +1,4 @@
1
+ {
2
+ "tabWidth": 2,
3
+ "useTabs": false
4
+ }
package/src/BS.ts CHANGED
@@ -1,4 +1,7 @@
1
- export { setAllConsoleLevelFlags, setConsoleLevelFlagsForType } from "./utils/Console.ts";
1
+ export {
2
+ setAllConsoleLevelFlags,
3
+ setConsoleLevelFlagsForType,
4
+ } from "./utils/Console.ts";
2
5
  export * as Environment from "./utils/environment.ts";
3
6
  export { Vector2, Vector3, Quaternion, Euler } from "./utils/MathUtils.ts";
4
7
 
@@ -18,11 +21,36 @@ export {
18
21
  } from "./DeviceManager.ts";
19
22
 
20
23
  export { DeviceInformation } from "./DeviceInformationManager.ts";
21
- export { DeviceType, DeviceTypes, MinNameLength, MaxNameLength, Sides, Side } from "./InformationManager.ts";
22
- export { SensorType, SensorTypes, ContinuousSensorType, ContinuousSensorTypes } from "./sensor/SensorDataManager.ts";
23
- export { MaxSensorRate, SensorRateStep, SensorConfiguration } from "./sensor/SensorConfigurationManager.ts";
24
+ export {
25
+ DeviceType,
26
+ DeviceTypes,
27
+ MinNameLength,
28
+ MaxNameLength,
29
+ Sides,
30
+ Side,
31
+ } from "./InformationManager.ts";
32
+ export {
33
+ MinWifiSSIDLength,
34
+ MaxWifiSSIDLength,
35
+ MinWifiPasswordLength,
36
+ MaxWifiPasswordLength,
37
+ } from "./WifiManager.ts";
38
+ export {
39
+ SensorType,
40
+ SensorTypes,
41
+ ContinuousSensorType,
42
+ ContinuousSensorTypes,
43
+ } from "./sensor/SensorDataManager.ts";
44
+ export {
45
+ MaxSensorRate,
46
+ SensorRateStep,
47
+ SensorConfiguration,
48
+ } from "./sensor/SensorConfigurationManager.ts";
24
49
 
25
- export { DefaultNumberOfPressureSensors, PressureData } from "./sensor/PressureSensorDataManager.ts";
50
+ export {
51
+ DefaultNumberOfPressureSensors,
52
+ PressureData,
53
+ } from "./sensor/PressureSensorDataManager.ts";
26
54
  export { CenterOfPressure } from "./utils/CenterOfPressureHelper.ts";
27
55
  export {
28
56
  VibrationConfiguration,
@@ -37,10 +65,41 @@ export {
37
65
  MaxNumberOfVibrationWaveformSegments,
38
66
  MaxVibrationWaveformEffectSequenceLoopCount,
39
67
  } from "./vibration/VibrationManager.ts";
40
- export { VibrationWaveformEffect, VibrationWaveformEffects } from "./vibration/VibrationWaveformEffects.ts";
68
+ export {
69
+ VibrationWaveformEffect,
70
+ VibrationWaveformEffects,
71
+ } from "./vibration/VibrationWaveformEffects.ts";
41
72
 
42
- export { FileType, FileTypes, FileTransferDirection, FileTransferDirections } from "./FileTransferManager.ts";
43
- export { TfliteSensorType, TfliteSensorTypes, TfliteTask, TfliteTasks } from "./TfliteManager.ts";
73
+ export {
74
+ FileType,
75
+ FileTypes,
76
+ FileTransferDirection,
77
+ FileTransferDirections,
78
+ } from "./FileTransferManager.ts";
79
+ export {
80
+ TfliteSensorType,
81
+ TfliteSensorTypes,
82
+ TfliteTask,
83
+ TfliteTasks,
84
+ TfliteFileConfiguration as TfliteFileConfiguration,
85
+ } from "./TfliteManager.ts";
86
+
87
+ export {
88
+ CameraConfiguration,
89
+ CameraCommand,
90
+ CameraCommands,
91
+ CameraConfigurationType,
92
+ CameraConfigurationTypes,
93
+ } from "./CameraManager.ts";
94
+
95
+ export {
96
+ MicrophoneConfiguration,
97
+ MicrophoneCommand,
98
+ MicrophoneCommands,
99
+ MicrophoneConfigurationType,
100
+ MicrophoneConfigurationTypes,
101
+ MicrophoneConfigurationValues,
102
+ } from "./MicrophoneManager.ts";
44
103
 
45
104
  export {
46
105
  default as DevicePair,
@@ -52,6 +111,18 @@ export {
52
111
  DevicePairTypes,
53
112
  } from "./devicePair/DevicePair.ts";
54
113
 
114
+ import { addEventListeners, removeEventListeners } from "./utils/EventUtils.ts";
115
+ export const EventUtils = {
116
+ addEventListeners,
117
+ removeEventListeners,
118
+ };
119
+
120
+ import { throttle, debounce } from "./utils/ThrottleUtils.ts";
121
+ export const ThrottleUtils = {
122
+ throttle,
123
+ debounce,
124
+ };
125
+
55
126
  export { DiscoveredDevice } from "./scanner/BaseScanner.ts";
56
127
  /** NODE_START */
57
128
  export { default as Scanner } from "./scanner/Scanner.ts";