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
@@ -14,7 +14,9 @@ window.device = device;
14
14
  // GET DEVICES
15
15
 
16
16
  /** @type {HTMLTemplateElement} */
17
- const availableDeviceTemplate = document.getElementById("availableDeviceTemplate");
17
+ const availableDeviceTemplate = document.getElementById(
18
+ "availableDeviceTemplate"
19
+ );
18
20
  const availableDevicesContainer = document.getElementById("availableDevices");
19
21
  /** @param {BS.Device[]} availableDevices */
20
22
  function onAvailableDevices(availableDevices) {
@@ -26,19 +28,24 @@ function onAvailableDevices(availableDevices) {
26
28
  const availableDeviceContainer = availableDeviceTemplate.content
27
29
  .cloneNode(true)
28
30
  .querySelector(".availableDevice");
29
- availableDeviceContainer.querySelector(".name").innerText = availableDevice.name;
30
- availableDeviceContainer.querySelector(".type").innerText = availableDevice.type;
31
+ availableDeviceContainer.querySelector(".name").innerText =
32
+ availableDevice.name;
33
+ availableDeviceContainer.querySelector(".type").innerText =
34
+ availableDevice.type;
31
35
 
32
36
  /** @type {HTMLButtonElement} */
33
- const toggleConnectionButton = availableDeviceContainer.querySelector(".toggleConnection");
37
+ const toggleConnectionButton =
38
+ availableDeviceContainer.querySelector(".toggleConnection");
34
39
  toggleConnectionButton.addEventListener("click", () => {
35
40
  device.connectionManager = availableDevice.connectionManager;
36
41
  device.reconnect();
37
42
  });
38
43
  device.addEventListener("connectionStatus", () => {
39
- toggleConnectionButton.disabled = device.connectionStatus != "notConnected";
44
+ toggleConnectionButton.disabled =
45
+ device.connectionStatus != "notConnected";
40
46
  });
41
- toggleConnectionButton.disabled = device.connectionStatus != "notConnected";
47
+ toggleConnectionButton.disabled =
48
+ device.connectionStatus != "notConnected";
42
49
 
43
50
  availableDevicesContainer.appendChild(availableDeviceContainer);
44
51
  });
@@ -87,7 +94,9 @@ device.addEventListener("connectionStatus", () => {
87
94
  case "connected":
88
95
  case "notConnected":
89
96
  toggleConnectionButton.disabled = false;
90
- toggleConnectionButton.innerText = device.isConnected ? "disconnect" : "connect";
97
+ toggleConnectionButton.innerText = device.isConnected
98
+ ? "disconnect"
99
+ : "connect";
91
100
  break;
92
101
  case "connecting":
93
102
  case "disconnecting":
@@ -98,7 +107,9 @@ device.addEventListener("connectionStatus", () => {
98
107
  });
99
108
 
100
109
  /** @type {HTMLInputElement} */
101
- const reconnectOnDisconnectionCheckbox = document.getElementById("reconnectOnDisconnection");
110
+ const reconnectOnDisconnectionCheckbox = document.getElementById(
111
+ "reconnectOnDisconnection"
112
+ );
102
113
  reconnectOnDisconnectionCheckbox.addEventListener("input", () => {
103
114
  device.reconnectOnDisconnection = reconnectOnDisconnectionCheckbox.checked;
104
115
  });
@@ -108,13 +119,23 @@ reconnectOnDisconnectionCheckbox.addEventListener("input", () => {
108
119
  /** @type {HTMLPreElement} */
109
120
  const deviceInformationPre = document.getElementById("deviceInformationPre");
110
121
  device.addEventListener("deviceInformation", () => {
111
- deviceInformationPre.textContent = JSON.stringify(device.deviceInformation, null, 2);
122
+ deviceInformationPre.textContent = JSON.stringify(
123
+ device.deviceInformation,
124
+ null,
125
+ 2
126
+ );
112
127
  });
113
128
 
114
129
  /** @type {HTMLPreElement} */
115
- const sensorConfigurationPre = document.getElementById("sensorConfigurationPre");
130
+ const sensorConfigurationPre = document.getElementById(
131
+ "sensorConfigurationPre"
132
+ );
116
133
  device.addEventListener("getSensorConfiguration", () => {
117
- sensorConfigurationPre.textContent = JSON.stringify(device.sensorConfiguration, null, 2);
134
+ sensorConfigurationPre.textContent = JSON.stringify(
135
+ device.sensorConfiguration,
136
+ null,
137
+ 2
138
+ );
118
139
  });
119
140
 
120
141
  /** @type {HTMLSpanElement} */
@@ -148,7 +169,12 @@ function setUrlParam(key, value) {
148
169
  searchParams.delete(key);
149
170
  }
150
171
  let newUrl =
151
- window.location.protocol + "//" + window.location.host + window.location.pathname + "?" + searchParams.toString();
172
+ window.location.protocol +
173
+ "//" +
174
+ window.location.host +
175
+ window.location.pathname +
176
+ "?" +
177
+ searchParams.toString();
152
178
  window.history.pushState({ path: newUrl }, "", newUrl);
153
179
  }
154
180
  }
@@ -267,8 +293,17 @@ const sensorTypeTemplate = document.getElementById("sensorTypeTemplate");
267
293
  /** @type {Object.<string, HTMLElement>} */
268
294
  const sensorTypeContainers = {};
269
295
 
270
- BS.TfliteSensorTypes.forEach((sensorType) => {
271
- const sensorTypeContainer = sensorTypeTemplate.content.cloneNode(true).querySelector(".sensorType");
296
+ const TfliteSensorTypes = BS.TfliteSensorTypes.slice();
297
+ const includeAcceleration = true;
298
+ if (includeAcceleration) {
299
+ // for testing with Frame
300
+ TfliteSensorTypes.push("acceleration");
301
+ }
302
+
303
+ TfliteSensorTypes.forEach((sensorType) => {
304
+ const sensorTypeContainer = sensorTypeTemplate.content
305
+ .cloneNode(true)
306
+ .querySelector(".sensorType");
272
307
  sensorTypeContainer.querySelector(".name").innerText = sensorType;
273
308
 
274
309
  /** @type {HTMLInputElement} */
@@ -287,7 +322,7 @@ BS.TfliteSensorTypes.forEach((sensorType) => {
287
322
  });
288
323
 
289
324
  function onSensorTypesInput() {
290
- const sensorTypes = BS.TfliteSensorTypes.filter((sensorType) => {
325
+ const sensorTypes = TfliteSensorTypes.filter((sensorType) => {
291
326
  /** @type {HTMLInputElement} */
292
327
  const input = sensorTypeContainers[sensorType].querySelector(".enabled");
293
328
  return input.checked;
@@ -403,16 +438,24 @@ toggleSamplingButton.addEventListener("click", () => {
403
438
 
404
439
  function updateToggleSamplingButton() {
405
440
  const enabled =
406
- device.isConnected && isRemoteManagementConnected() && sensorTypes.length > 0 && label.length > 0 && !isSampling;
441
+ device.isConnected &&
442
+ isRemoteManagementConnected() &&
443
+ sensorTypes.length > 0 &&
444
+ label.length > 0 &&
445
+ !isSampling;
407
446
  toggleSamplingButton.disabled = !enabled;
408
- toggleSamplingButton.innerText = isSampling ? "sampling..." : "start sampling";
447
+ toggleSamplingButton.innerText = isSampling
448
+ ? "sampling..."
449
+ : "start sampling";
409
450
  }
410
451
 
411
- ["isSampling", "remoteManagementConnection", "sensortypes", "label"].forEach((eventType) => {
412
- window.addEventListener(eventType, () => {
413
- updateToggleSamplingButton();
414
- });
415
- });
452
+ ["isSampling", "remoteManagementConnection", "sensortypes", "label"].forEach(
453
+ (eventType) => {
454
+ window.addEventListener(eventType, () => {
455
+ updateToggleSamplingButton();
456
+ });
457
+ }
458
+ );
416
459
  device.addEventListener("isConnected", () => {
417
460
  updateToggleSamplingButton();
418
461
  });
@@ -451,7 +494,9 @@ async function getProjects() {
451
494
  x.open("GET", `${studioEndpoint}/v1/api/projects`);
452
495
  x.onload = () => {
453
496
  if (x.status !== 200) {
454
- reject("No projects found: " + x.status + " - " + JSON.stringify(x.response));
497
+ reject(
498
+ "No projects found: " + x.status + " - " + JSON.stringify(x.response)
499
+ );
455
500
  } else {
456
501
  if (!x.response.success) {
457
502
  reject(x.response.error);
@@ -459,7 +504,9 @@ async function getProjects() {
459
504
  const projects = x.response.projects;
460
505
  console.log("projects", projects);
461
506
  resolve(projects);
462
- window.dispatchEvent(new CustomEvent("edgeImpulseProjects", { detail: { projects } }));
507
+ window.dispatchEvent(
508
+ new CustomEvent("edgeImpulseProjects", { detail: { projects } })
509
+ );
463
510
  }
464
511
  }
465
512
  };
@@ -476,7 +523,9 @@ async function getProject() {
476
523
  x.open("GET", `${studioEndpoint}/v1/api/${projectId}/public-info`);
477
524
  x.onload = () => {
478
525
  if (x.status !== 200) {
479
- reject("No projects found: " + x.status + " - " + JSON.stringify(x.response));
526
+ reject(
527
+ "No projects found: " + x.status + " - " + JSON.stringify(x.response)
528
+ );
480
529
  } else {
481
530
  if (!x.response.success) {
482
531
  reject(x.response.error);
@@ -484,7 +533,9 @@ async function getProject() {
484
533
  const project = x.response;
485
534
  console.log("project", project);
486
535
  resolve(project);
487
- window.dispatchEvent(new CustomEvent("edgeImpulseProject", { detail: { project } }));
536
+ window.dispatchEvent(
537
+ new CustomEvent("edgeImpulseProject", { detail: { project } })
538
+ );
488
539
  }
489
540
  }
490
541
  };
@@ -503,7 +554,12 @@ async function getHmacKey() {
503
554
  x.open("GET", `${studioEndpoint}/v1/api/${projectId}/devkeys`);
504
555
  x.onload = () => {
505
556
  if (x.status !== 200) {
506
- reject("No development keys found: " + x.status + " - " + JSON.stringify(x.response));
557
+ reject(
558
+ "No development keys found: " +
559
+ x.status +
560
+ " - " +
561
+ JSON.stringify(x.response)
562
+ );
507
563
  } else {
508
564
  if (!x.response.success) {
509
565
  reject(x.response.error);
@@ -609,10 +665,18 @@ async function connectToRemoteManagement() {
609
665
  console.log("samplingDetails", samplingDetails);
610
666
 
611
667
  /** @type {BS.ContinuousSensorType[]} */
612
- const sensorTypes = samplingDetails.sensor.split(sensorCombinationSeparator);
668
+ const sensorTypes = samplingDetails.sensor.split(
669
+ sensorCombinationSeparator
670
+ );
613
671
  console.log("sensorTypes", sensorTypes);
614
672
 
615
- const invalidSensors = sensorTypes.filter((sensorType) => !device.allowedTfliteSensorTypes.includes(sensorType));
673
+ const allowedTfliteSensorTypes = device.allowedTfliteSensorTypes;
674
+ if (includeAcceleration) {
675
+ allowedTfliteSensorTypes.push("acceleration");
676
+ }
677
+ const invalidSensors = sensorTypes.filter(
678
+ (sensorType) => !allowedTfliteSensorTypes.includes(sensorType)
679
+ );
616
680
  if (invalidSensors.length > 0) {
617
681
  console.error("invalid sensorTypes", invalidSensors);
618
682
  return;
@@ -693,8 +757,11 @@ function generateSubarrays(array) {
693
757
  const getDeviceId = () => `${device.name}.${device.type}.${device.id}`;
694
758
 
695
759
  function remoteManagementHelloMessage() {
696
- const sensors = device.allowedTfliteSensorTypes;
697
- const sensorCombinations = generateSubarrays(sensors);
760
+ const allowedTfliteSensorTypes = device.allowedTfliteSensorTypes.slice();
761
+ if (includeAcceleration) {
762
+ allowedTfliteSensorTypes.push("acceleration");
763
+ }
764
+ const sensorCombinations = generateSubarrays(allowedTfliteSensorTypes);
698
765
  console.log("sensorCombinations", sensorCombinations);
699
766
  return {
700
767
  hello: {
@@ -707,7 +774,7 @@ function remoteManagementHelloMessage() {
707
774
  return {
708
775
  name: sensorCombination,
709
776
  maxSampleLengthS: 1 * 60,
710
- frequencies: [50.0, 25.0, 12.5], // 20ms, 40ms, 80ms
777
+ frequencies: [100.0, 50.0, 25.0, 12.5], // 10ms, 20ms, 40ms, 80ms
711
778
  };
712
779
  }),
713
780
  supportsSnapshotStreaming: false,
@@ -716,11 +783,16 @@ function remoteManagementHelloMessage() {
716
783
  }
717
784
 
718
785
  function isRemoteManagementConnected() {
719
- return remoteManagementWebSocket?.readyState == WebSocket.OPEN && remoteManagementWebSocket?._isConnected;
786
+ return (
787
+ remoteManagementWebSocket?.readyState == WebSocket.OPEN &&
788
+ remoteManagementWebSocket?._isConnected
789
+ );
720
790
  }
721
791
 
722
792
  /** @type {HTMLButtonElement} */
723
- const toggleRemoteManagementConnectionButton = document.getElementById("toggleRemoteManagementConnection");
793
+ const toggleRemoteManagementConnectionButton = document.getElementById(
794
+ "toggleRemoteManagementConnection"
795
+ );
724
796
  toggleRemoteManagementConnectionButton.addEventListener("click", () => {
725
797
  if (isRemoteManagementConnected()) {
726
798
  remoteManagementWebSocket.dontReconnect = true;
@@ -756,13 +828,20 @@ let reconnectRemoteManagementOnDisconnection = false;
756
828
  const reconnectRemoteManagementOnDisconnectionInput = document.getElementById(
757
829
  "reconnectRemoteManagementOnDisconnection"
758
830
  );
759
- reconnectRemoteManagementOnDisconnectionInput.addEventListener("input", (event) => {
760
- setReconnectRemoteManagementOnDisconnection(event.target.checked);
761
- });
762
- reconnectRemoteManagementOnDisconnectionInput.checked = reconnectRemoteManagementOnDisconnection;
831
+ reconnectRemoteManagementOnDisconnectionInput.addEventListener(
832
+ "input",
833
+ (event) => {
834
+ setReconnectRemoteManagementOnDisconnection(event.target.checked);
835
+ }
836
+ );
837
+ reconnectRemoteManagementOnDisconnectionInput.checked =
838
+ reconnectRemoteManagementOnDisconnection;
763
839
  /** @param {boolean} newReconnectRemoteManagementOnDisconnection */
764
- function setReconnectRemoteManagementOnDisconnection(newReconnectRemoteManagementOnDisconnection) {
765
- reconnectRemoteManagementOnDisconnection = newReconnectRemoteManagementOnDisconnection;
840
+ function setReconnectRemoteManagementOnDisconnection(
841
+ newReconnectRemoteManagementOnDisconnection
842
+ ) {
843
+ reconnectRemoteManagementOnDisconnection =
844
+ newReconnectRemoteManagementOnDisconnection;
766
845
  console.log({ reconnectRemoteManagementOnDisconnection });
767
846
  dispatchEvent(new Event("reconnectRemoteManagementOnDisconnection"));
768
847
  }
@@ -771,6 +850,7 @@ function setReconnectRemoteManagementOnDisconnection(newReconnectRemoteManagemen
771
850
 
772
851
  const scalars = {
773
852
  pressure: 1 / (2 ** 16 - 1),
853
+ acceleration: 1 / 4,
774
854
  linearAcceleration: 1 / 4,
775
855
  gyroscope: 1 / 720,
776
856
  magnetometer: 1 / 2500,
@@ -840,11 +920,15 @@ async function uploadData(sensorTypes, deviceData) {
840
920
  let names = [];
841
921
  let units;
842
922
  switch (sensorType) {
923
+ case "acceleration":
843
924
  case "linearAcceleration":
844
925
  case "gyroscope":
845
926
  case "magnetometer":
846
- names = ["x", "y", "z"].map((component) => `${sensorType}.${component}`);
927
+ names = ["x", "y", "z"].map(
928
+ (component) => `${sensorType}.${component}`
929
+ );
847
930
  switch (sensorType) {
931
+ case "acceleration":
848
932
  case "linearAcceleration":
849
933
  units = "g/s";
850
934
  break;
@@ -883,6 +967,7 @@ async function uploadData(sensorTypes, deviceData) {
883
967
  const sensorSamples = deviceData[sensorType];
884
968
 
885
969
  switch (sensorType) {
970
+ case "acceleration":
886
971
  case "linearAcceleration":
887
972
  case "gyroscope":
888
973
  case "magnetometer":
@@ -891,8 +976,15 @@ async function uploadData(sensorTypes, deviceData) {
891
976
  });
892
977
  break;
893
978
  case "pressure":
894
- for (let pressureIndex = 0; pressureIndex < device.numberOfPressureSensors; pressureIndex++) {
895
- value.push(sensorSamples[sampleIndex].sensors[pressureIndex].rawValue * scalar);
979
+ for (
980
+ let pressureIndex = 0;
981
+ pressureIndex < device.numberOfPressureSensors;
982
+ pressureIndex++
983
+ ) {
984
+ value.push(
985
+ sensorSamples[sampleIndex].sensors[pressureIndex].rawValue *
986
+ scalar
987
+ );
896
988
  }
897
989
  break;
898
990
  default:
@@ -928,7 +1020,11 @@ async function uploadData(sensorTypes, deviceData) {
928
1020
  console.log("signature", data.signature);
929
1021
 
930
1022
  const formData = new FormData();
931
- formData.append("message", new Blob([JSON.stringify(data)], { type: "application/json" }), "message.json");
1023
+ formData.append(
1024
+ "message",
1025
+ new Blob([JSON.stringify(data)], { type: "application/json" }),
1026
+ "message.json"
1027
+ );
932
1028
 
933
1029
  return new Promise((resolve, reject) => {
934
1030
  let xml = new XMLHttpRequest();
@@ -936,7 +1032,12 @@ async function uploadData(sensorTypes, deviceData) {
936
1032
  if (xml.status === 200) {
937
1033
  resolve(xml.responseText);
938
1034
  } else {
939
- reject("Failed to upload (status code " + xml.status + "): " + xml.responseText);
1035
+ reject(
1036
+ "Failed to upload (status code " +
1037
+ xml.status +
1038
+ "): " +
1039
+ xml.responseText
1040
+ );
940
1041
  }
941
1042
  };
942
1043
  xml.onerror = () => reject(undefined);
@@ -980,10 +1081,16 @@ async function createSignature(hmacKey, data) {
980
1081
  ["sign", "verify"] // what this key can do
981
1082
  );
982
1083
  // Create signature for encoded input data
983
- const signature = await crypto.subtle.sign("HMAC", key, textEncoder.encode(JSON.stringify(data)));
1084
+ const signature = await crypto.subtle.sign(
1085
+ "HMAC",
1086
+ key,
1087
+ textEncoder.encode(JSON.stringify(data))
1088
+ );
984
1089
  // Convert back to Hex
985
1090
  const b = new Uint8Array(signature);
986
- return Array.prototype.map.call(b, (x) => ("00" + x.toString(16)).slice(-2)).join("");
1091
+ return Array.prototype.map
1092
+ .call(b, (x) => ("00" + x.toString(16)).slice(-2))
1093
+ .join("");
987
1094
  }
988
1095
 
989
1096
  // EDGE IMPULSE CONFIG
@@ -1012,7 +1119,9 @@ function loadConfigFromLocalStorage() {
1012
1119
  loadConfigFromLocalStorage();
1013
1120
 
1014
1121
  function saveConfigToLocalStorage() {
1015
- const isConfigDifferent = !loadedConfig || Object.entries(loadedConfig).some(([key, value]) => config[key] != value);
1122
+ const isConfigDifferent =
1123
+ !loadedConfig ||
1124
+ Object.entries(loadedConfig).some(([key, value]) => config[key] != value);
1016
1125
  if (!isConfigDifferent) {
1017
1126
  return;
1018
1127
  }
@@ -0,0 +1,11 @@
1
+ # Running your impulse using WebAssembly in the browser
2
+
3
+ For more information see the documentation at https://docs.edgeimpulse.com/docs/through-webassembly-browser
4
+
5
+ To start, open a terminal or command prompt and run:
6
+
7
+ ```
8
+ $ python3 server.py
9
+ ```
10
+
11
+ Then open http://localhost:8082 in a browser to see the application.