brilliantsole 0.0.26 → 0.0.28

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