@robotical/webapp-types 1.1.0 → 1.1.2

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 (35) hide show
  1. package/dist-types/src/application/ApplicationManager/ApplicationManager.d.ts +13 -3
  2. package/dist-types/src/application/ApplicationManager/ApplicationManager.js +62 -26
  3. package/dist-types/src/application/RAFTs/Cog/Cog.d.ts +7 -2
  4. package/dist-types/src/application/RAFTs/Cog/Cog.js +27 -12
  5. package/dist-types/src/application/RAFTs/Cog/PublishedDataAnalyser.d.ts +64 -4
  6. package/dist-types/src/application/RAFTs/Cog/PublishedDataAnalyser.js +98 -37
  7. package/dist-types/src/application/RAFTs/Marty/Marty.js +1 -1
  8. package/dist-types/src/application/RAFTs/RAFT.d.ts +5 -4
  9. package/dist-types/src/application/RAFTs/RAFT.js +4 -4
  10. package/dist-types/src/application/communicators/SelfdestructiveMessagePromise.js +1 -1
  11. package/dist-types/src/components/modals/ConnectingLoadingSpinnerModal/index.d.ts +3 -0
  12. package/dist-types/src/components/modals/ConnectingLoadingSpinnerModal/index.js +16 -0
  13. package/dist-types/src/components/modals/DisconnectConfirmation/index.d.ts +1 -6
  14. package/dist-types/src/components/modals/DisconnectConfirmation/index.js +2 -59
  15. package/dist-types/src/components/modals/VerificationModal/index.js +1 -1
  16. package/dist-types/src/components/modals/VerificationModalPhoneApp/index.js +11 -6
  17. package/dist-types/src/services/logger/Logger.d.ts +1 -0
  18. package/dist-types/src/services/logger/Logger.js +10 -4
  19. package/dist-types/src/state-observables/modal/ModalObserver.d.ts +1 -0
  20. package/dist-types/src/state-observables/modal/ModalState.d.ts +1 -1
  21. package/dist-types/src/state-observables/modal/ModalState.js +3 -2
  22. package/dist-types/src/types/communication-between-apps/wrapper-communication.d.ts +4 -1
  23. package/dist-types/src/types/communication-between-apps/wrapper-communication.js +3 -0
  24. package/dist-types/src/wrapper-app/WrapperAppManager.d.ts +1 -1
  25. package/dist-types/src/wrapper-app/WrapperAppManager.js +2 -2
  26. package/dist-types/src/wrapper-app/communicators/WebAppCommunicator.js +1 -1
  27. package/dist-types/src/wrapper-app/connectors/CogConnector/CogConnector.d.ts +5 -0
  28. package/dist-types/src/wrapper-app/connectors/CogConnector/CogConnector.js +33 -1
  29. package/dist-types/src/wrapper-app/connectors/Connector.d.ts +4 -1
  30. package/dist-types/src/wrapper-app/connectors/Connector.js +10 -11
  31. package/dist-types/src/wrapper-app/connectors/ConnectorFactory.d.ts +1 -1
  32. package/dist-types/src/wrapper-app/connectors/ConnectorFactory.js +2 -2
  33. package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.d.ts +5 -0
  34. package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.js +24 -0
  35. package/package.json +1 -1
@@ -42,7 +42,7 @@ export default class ApplicationManager {
42
42
  * This method is called from various environments (connection button, blocksjr, blocks etc.)
43
43
  * Known issue: connecting to a raft from within a platform won't add the newly connected raft to the connectedRafts hook
44
44
  */
45
- connectGeneric(afterRaftConnectedCb: (raft: RAFT) => void, uuid: string): Promise<void>;
45
+ connectGeneric(afterRaftConnectedCb: (raft: RAFT) => void, uuids?: string[]): Promise<void>;
46
46
  /**
47
47
  * Disconnect from RAFT generic
48
48
  * This method is called from various environments (connection button, blocksjr, blocks etc.)
@@ -52,7 +52,7 @@ export default class ApplicationManager {
52
52
  * Selects a RAFT in Phone's verification modal
53
53
  */
54
54
  selectRaft(ricToConnectTo: FOUND_RAFT_ON_DISCOVERY_RESPONSE['foundRIC'], method: RaftConnectionMethod): Promise<RAFT | null>;
55
- connectToRIC(method: RaftConnectionMethod, uuid: string): Promise<RAFT | null>;
55
+ connectToRIC(method: RaftConnectionMethod, uuids: string[]): Promise<RAFT | null>;
56
56
  /**
57
57
  * Disconnect from RAFT
58
58
  */
@@ -66,7 +66,12 @@ export default class ApplicationManager {
66
66
  * Start looking for rics to connect to
67
67
  * This is used from the Phone App only
68
68
  */
69
- startDiscovery(ricSelectedCb: (raft: RAFT) => void): Promise<void>;
69
+ startDiscovery(ricSelectedCb: (raft: RAFT) => void, uuids: string[]): Promise<void>;
70
+ /**
71
+ * Stοp discovery
72
+ * When the user cancels the discovery process without having first connected to a robot
73
+ */
74
+ stopDiscovery(): Promise<void>;
70
75
  /**
71
76
  * Stop verifying raft
72
77
  */
@@ -99,5 +104,10 @@ export default class ApplicationManager {
99
104
  * List the files from the device's local storage
100
105
  */
101
106
  listFilesFromDeviceLocalStorage(dirname: string): Promise<unknown>;
107
+ /**
108
+ * Injects JS code to the phone app
109
+ * This is used to call native functions from the web app
110
+ */
111
+ injectJS(jsCode: string): Promise<unknown>;
102
112
  getTheCurrentlySelectedDeviceOrFirstOfItsKind(deviceType: RaftTypeE): RAFT | undefined;
103
113
  }
@@ -35,7 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  }
36
36
  };
37
37
  import { createElement } from "react";
38
- import modalState from "../../state-observables/modal/ModalState";
38
+ import modalState, { secondaryModalState } from "../../state-observables/modal/ModalState";
39
39
  import { RaftConnectionMethod, RaftTypeE } from "../../types/raft";
40
40
  import WebAppCommunicator from "../../wrapper-app/communicators/WebAppCommunicator";
41
41
  import RAFT from "../RAFTs/RAFT";
@@ -45,12 +45,13 @@ import VerificationModal from "../../components/modals/VerificationModal";
45
45
  import { raftFoundSubscriptionHelper } from "../RAFTs/raft-subscription-helpers";
46
46
  import { AppSentMessage } from "../../types/communication-between-apps/wrapper-communication";
47
47
  import VerificationModalPhoneApp from "../../components/modals/VerificationModalPhoneApp";
48
- import { RaftChannelBLE, } from "@robotical/raftjs";
49
48
  import Logger from "../../services/logger/Logger";
50
49
  import isPhoneApp from "../../utils/phone-app-communication/is-phone-app";
51
50
  import DisconnectConfirmationModal from "../../components/modals/DisconnectConfirmation";
52
51
  import Toaster from "../../utils/Toaster";
53
52
  import { AnalyticsManager } from "../../analytics/AnalyticsManager";
53
+ import { ConnManager } from "@robotical/roboticaljs";
54
+ import ConnectingLoadingSpinnerModal from "../../components/modals/ConnectingLoadingSpinnerModal";
54
55
  var SHOW_LOGS = true;
55
56
  var TAG = "ApplicationManager";
56
57
  var ApplicationManager = /** @class */ (function () {
@@ -113,14 +114,14 @@ var ApplicationManager = /** @class */ (function () {
113
114
  ApplicationManager.prototype.connectGenericMarty = function (afterRaftConnectedCb) {
114
115
  return __awaiter(this, void 0, void 0, function () {
115
116
  return __generator(this, function (_a) {
116
- return [2 /*return*/, this.connectGeneric(afterRaftConnectedCb, RaftChannelBLE.RICServiceUUID)];
117
+ return [2 /*return*/, this.connectGeneric(afterRaftConnectedCb, [ConnManager.RICUUID])];
117
118
  });
118
119
  });
119
120
  };
120
121
  ApplicationManager.prototype.connectGenericCog = function (afterRaftConnectedCb) {
121
122
  return __awaiter(this, void 0, void 0, function () {
122
123
  return __generator(this, function (_a) {
123
- return [2 /*return*/, this.connectGeneric(afterRaftConnectedCb, RaftChannelBLE.CogServiceUUID)];
124
+ return [2 /*return*/, this.connectGeneric(afterRaftConnectedCb, [ConnManager.COGUUID])];
124
125
  });
125
126
  });
126
127
  };
@@ -129,13 +130,16 @@ var ApplicationManager = /** @class */ (function () {
129
130
  * This method is called from various environments (connection button, blocksjr, blocks etc.)
130
131
  * Known issue: connecting to a raft from within a platform won't add the newly connected raft to the connectedRafts hook
131
132
  */
132
- ApplicationManager.prototype.connectGeneric = function (afterRaftConnectedCb, uuid) {
133
+ ApplicationManager.prototype.connectGeneric = function (afterRaftConnectedCb, uuids) {
133
134
  return __awaiter(this, void 0, void 0, function () {
134
135
  var e_1, newRaft, e_2;
135
136
  var _this = this;
136
137
  return __generator(this, function (_a) {
137
138
  switch (_a.label) {
138
139
  case 0:
140
+ if (!uuids) {
141
+ uuids = [ConnManager.COGUUID, ConnManager.RICUUID];
142
+ }
139
143
  if (!isPhoneApp()) return [3 /*break*/, 5];
140
144
  _a.label = 1;
141
145
  case 1:
@@ -143,7 +147,7 @@ var ApplicationManager = /** @class */ (function () {
143
147
  return [4 /*yield*/, window.applicationManager.startDiscovery(function (newRaft) {
144
148
  _this.connectedRaftContextMethods.addConnectedRaft({ id: newRaft.id, type: newRaft.type, name: newRaft.getFriendlyName() || "", isSelected: true });
145
149
  afterRaftConnectedCb(newRaft);
146
- })];
150
+ }, uuids)];
147
151
  case 2:
148
152
  _a.sent();
149
153
  return [3 /*break*/, 4];
@@ -151,22 +155,28 @@ var ApplicationManager = /** @class */ (function () {
151
155
  e_1 = _a.sent();
152
156
  Logger.error(SHOW_LOGS, TAG, "Failed to start discovery: ".concat(e_1));
153
157
  return [3 /*break*/, 4];
154
- case 4: return [3 /*break*/, 8];
158
+ case 4: return [3 /*break*/, 10];
155
159
  case 5:
156
- _a.trys.push([5, 7, , 8]);
157
- return [4 /*yield*/, window.applicationManager.connectToRIC(RaftConnectionMethod.WEB_BLE, uuid)];
160
+ secondaryModalState.setModal(createElement(ConnectingLoadingSpinnerModal, {}), "Connecting...", false);
161
+ _a.label = 6;
158
162
  case 6:
163
+ _a.trys.push([6, 8, , 9]);
164
+ return [4 /*yield*/, window.applicationManager.connectToRIC(RaftConnectionMethod.WEB_BLE, uuids)];
165
+ case 7:
159
166
  newRaft = _a.sent();
160
167
  if (newRaft) {
161
168
  this.connectedRaftContextMethods.addConnectedRaft({ id: newRaft.id, type: newRaft.type, name: newRaft.getFriendlyName() || "", isSelected: true });
162
169
  afterRaftConnectedCb(newRaft);
163
170
  }
164
- return [3 /*break*/, 8];
165
- case 7:
171
+ return [3 /*break*/, 9];
172
+ case 8:
166
173
  e_2 = _a.sent();
167
174
  Logger.error(SHOW_LOGS, TAG, "Failed to connect to new robot: ".concat(e_2));
168
- return [3 /*break*/, 8];
169
- case 8: return [2 /*return*/];
175
+ return [3 /*break*/, 9];
176
+ case 9:
177
+ secondaryModalState.closeModal();
178
+ _a.label = 10;
179
+ case 10: return [2 /*return*/];
170
180
  }
171
181
  });
172
182
  });
@@ -182,7 +192,7 @@ var ApplicationManager = /** @class */ (function () {
182
192
  switch (_a.label) {
183
193
  case 0:
184
194
  _a.trys.push([0, 3, , 4]);
185
- return [4 /*yield*/, modalState.setModal(createElement(DisconnectConfirmationModal, { connectedRaft: window.applicationManager.connectedRafts[raft.id] }), "Are you sure you want to disconnect from your ".concat(raft.getFriendlyName(), "?"))];
195
+ return [4 /*yield*/, modalState.setModal(createElement(DisconnectConfirmationModal), "Are you sure you want to disconnect from your ".concat(raft.getFriendlyName(), "?"))];
186
196
  case 1:
187
197
  confirmDisconnect = _a.sent();
188
198
  if (!confirmDisconnect) {
@@ -213,7 +223,7 @@ var ApplicationManager = /** @class */ (function () {
213
223
  var selectResults, raftId, raftType, raft;
214
224
  return __generator(this, function (_c) {
215
225
  switch (_c.label) {
216
- case 0: return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.RAFT_SELECT, { discoveredRIC: ricToConnectTo, method: method })];
226
+ case 0: return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.RAFT_SELECT, { discoveredDevice: ricToConnectTo, method: method })];
217
227
  case 1:
218
228
  selectResults = _c.sent();
219
229
  if (!selectResults.success) return [3 /*break*/, 3];
@@ -253,13 +263,13 @@ var ApplicationManager = /** @class */ (function () {
253
263
  });
254
264
  });
255
265
  };
256
- ApplicationManager.prototype.connectToRIC = function (method, uuid) {
266
+ ApplicationManager.prototype.connectToRIC = function (method, uuids) {
257
267
  var _a, _b;
258
268
  return __awaiter(this, void 0, void 0, function () {
259
269
  var wasConnectedObj, raftId, raftType, raft;
260
270
  return __generator(this, function (_c) {
261
271
  switch (_c.label) {
262
- case 0: return [4 /*yield*/, RAFT.connect(method, uuid)];
272
+ case 0: return [4 /*yield*/, RAFT.connect(method, uuids)];
263
273
  case 1:
264
274
  wasConnectedObj = _c.sent();
265
275
  if (!wasConnectedObj.success) return [3 /*break*/, 3];
@@ -331,7 +341,7 @@ var ApplicationManager = /** @class */ (function () {
331
341
  * Start looking for rics to connect to
332
342
  * This is used from the Phone App only
333
343
  */
334
- ApplicationManager.prototype.startDiscovery = function (ricSelectedCb) {
344
+ ApplicationManager.prototype.startDiscovery = function (ricSelectedCb, uuids) {
335
345
  return __awaiter(this, void 0, void 0, function () {
336
346
  var foundRICs, wasDiscoveryStarted;
337
347
  return __generator(this, function (_a) {
@@ -340,33 +350,52 @@ var ApplicationManager = /** @class */ (function () {
340
350
  this.ricSelectedCb = ricSelectedCb;
341
351
  foundRICs = [];
342
352
  raftFoundSubscriptionHelper().subscribe(function (_a) {
343
- var discoveredRIC = _a.discoveredRIC;
353
+ var discoveredDevice = _a.discoveredDevice;
344
354
  // if the discovered RAFT is already in the list, don't add it, just update the rssi
345
- var foundRICIdx = foundRICs.findIndex(function (ric_) { return ric_._id === discoveredRIC._id; });
355
+ var foundRICIdx = foundRICs.findIndex(function (ric_) { return ric_._id === discoveredDevice._id; });
346
356
  if (foundRICIdx !== -1) {
347
- foundRICs[foundRICIdx] = discoveredRIC;
357
+ foundRICs[foundRICIdx] = discoveredDevice;
348
358
  }
349
359
  else {
350
- foundRICs.push(discoveredRIC);
360
+ foundRICs.push(discoveredDevice);
351
361
  }
352
362
  // foundRICs.sort((a, b) => b._rssi - a._rssi);
353
363
  modalState.setModal(createElement(VerificationModalPhoneApp, { foundRICs: foundRICs }), "Looking for RAFT");
354
364
  });
355
- return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.RAFT_START_DISCOVERY)];
365
+ modalState.setModal(createElement(VerificationModalPhoneApp, { foundRICs: [] }), "Looking for RAFT");
366
+ return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.RAFT_START_DISCOVERY, { uuids: uuids })];
356
367
  case 1:
357
368
  wasDiscoveryStarted = _a.sent();
358
- if (!wasDiscoveryStarted) {
359
- return [2 /*return*/, raftFoundSubscriptionHelper().unsubscribe()];
360
- }
361
369
  return [4 /*yield*/, modalState.setModal(createElement(VerificationModalPhoneApp, { foundRICs: [] }), "Looking for RAFT")];
362
370
  case 2:
363
371
  _a.sent();
372
+ if (!wasDiscoveryStarted) {
373
+ return [2 /*return*/, raftFoundSubscriptionHelper().unsubscribe()];
374
+ }
364
375
  raftFoundSubscriptionHelper().unsubscribe();
365
376
  return [2 /*return*/];
366
377
  }
367
378
  });
368
379
  });
369
380
  };
381
+ /**
382
+ * Stοp discovery
383
+ * When the user cancels the discovery process without having first connected to a robot
384
+ */
385
+ ApplicationManager.prototype.stopDiscovery = function () {
386
+ return __awaiter(this, void 0, void 0, function () {
387
+ var wasDiscoveryStopped;
388
+ return __generator(this, function (_a) {
389
+ switch (_a.label) {
390
+ case 0: return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.RAFT_STOP_DISCOVERY)];
391
+ case 1:
392
+ wasDiscoveryStopped = _a.sent();
393
+ Logger.phoneAppLog(SHOW_LOGS, TAG, "Was discovery stopped: " + wasDiscoveryStopped);
394
+ return [2 /*return*/];
395
+ }
396
+ });
397
+ });
398
+ };
370
399
  /**
371
400
  * Stop verifying raft
372
401
  */
@@ -479,6 +508,13 @@ var ApplicationManager = /** @class */ (function () {
479
508
  });
480
509
  });
481
510
  };
511
+ /**
512
+ * Injects JS code to the phone app
513
+ * This is used to call native functions from the web app
514
+ */
515
+ ApplicationManager.prototype.injectJS = function (jsCode) {
516
+ return window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.INJECT_JS, { jsCode: jsCode });
517
+ };
482
518
  /*======== END OF NATIVE COMMANDS ONLY ========*/
483
519
  //======================//
484
520
  /* UI */
@@ -1,7 +1,8 @@
1
1
  import RAFT from "../RAFT";
2
2
  import RICInterface from "../RAFTInterface";
3
3
  import { RaftTypeE } from "../../../types/raft";
4
- import { CogStateInfo, RICLedLcdColours } from "@robotical/roboticaljs";
4
+ import { RICLedLcdColours } from "@robotical/roboticaljs";
5
+ import { SimplifiedCogStateInfo } from "@robotical/roboticaljs/dist/SystemTypeCog/CogTypes";
5
6
  import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@robotical/raftjs";
6
7
  import { RaftInfoEvents } from "../../../types/events/raft-info";
7
8
  import PublishedDataAnalyser from "./PublishedDataAnalyser";
@@ -9,7 +10,7 @@ export declare class Cog extends RAFT implements RICInterface {
9
10
  id: string;
10
11
  type: RaftTypeE;
11
12
  _ledLcdColours: RICLedLcdColours;
12
- raftStateInfo: CogStateInfo | null;
13
+ raftStateInfo: SimplifiedCogStateInfo | null;
13
14
  publishedDataAnalyser: PublishedDataAnalyser;
14
15
  constructor(id: string);
15
16
  get ledLcdColours(): RICLedLcdColours;
@@ -17,6 +18,10 @@ export declare class Cog extends RAFT implements RICInterface {
17
18
  * Gets the RSSI of the RAFT
18
19
  */
19
20
  getRSSI(): number;
21
+ /**
22
+ * Helper function to calculate battery strength based on voltage
23
+ */
24
+ calculateBatteryStrength(voltage: number): number;
20
25
  /**
21
26
  * Gets the battery strength of the RAFT
22
27
  */
@@ -51,9 +51,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
51
51
  };
52
52
  import RAFT from "../RAFT";
53
53
  import { RaftTypeE } from "../../../types/raft";
54
- import { deviceAttrGetLatestFormatted, RaftConnEvent, RaftPublishEvent } from "@robotical/raftjs";
54
+ import { RaftConnEvent, RaftPublishEvent } from "@robotical/raftjs";
55
55
  import { RaftInfoEvents } from "../../../types/events/raft-info";
56
- import PublishedDataAnalyser from "./PublishedDataAnalyser";
56
+ import PublishedDataAnalyser, { setButtonThresholdsUtil } from "./PublishedDataAnalyser";
57
57
  var Cog = /** @class */ (function (_super) {
58
58
  __extends(Cog, _super);
59
59
  function Cog(id) {
@@ -87,25 +87,36 @@ var Cog = /** @class */ (function (_super) {
87
87
  var possibleValues = [126, 127];
88
88
  return possibleValues[Math.floor(Math.random() * possibleValues.length)];
89
89
  };
90
+ /**
91
+ * Helper function to calculate battery strength based on voltage
92
+ */
93
+ Cog.prototype.calculateBatteryStrength = function (voltage) {
94
+ if (voltage >= 2.7) {
95
+ return 100;
96
+ }
97
+ else if (voltage >= 2.3) {
98
+ return ((voltage - 2.3) / 0.4) * 80 + 20;
99
+ }
100
+ else if (voltage >= 2.0) {
101
+ return ((voltage - 2.0) / 0.3) * 20;
102
+ }
103
+ else {
104
+ return 0;
105
+ }
106
+ };
90
107
  /**
91
108
  * Gets the battery strength of the RAFT
92
109
  */
93
110
  Cog.prototype.getBatteryStrength = function () {
94
- var _a, _b, _c, _d;
95
111
  /* check if usb is connected */
96
- var usbAttr = (_b = (_a = this.raftStateInfo) === null || _a === void 0 ? void 0 : _a.deviceManager.getDeviceState('RoboCogPowerV1_00')) === null || _b === void 0 ? void 0 : _b.deviceAttributes['USB'];
97
- if (!usbAttr)
112
+ if (!this.raftStateInfo)
98
113
  return 0.1;
99
- var usb = deviceAttrGetLatestFormatted(usbAttr);
100
- if (usb === 'yes')
114
+ if (this.raftStateInfo.power.usb === 'yes')
101
115
  return 0; // 0 indicates USB is connected
102
116
  /* if usb is not connected, check battery voltage */
103
- var battVAttr = (_d = (_c = this.raftStateInfo) === null || _c === void 0 ? void 0 : _c.deviceManager.getDeviceState('RoboCogPowerV1_00')) === null || _d === void 0 ? void 0 : _d.deviceAttributes['battV'];
104
- if (!battVAttr)
105
- return 0.1;
106
- var battV = deviceAttrGetLatestFormatted(battVAttr);
117
+ var battV = this.raftStateInfo.power.battV;
107
118
  if (!isNaN(+battV)) {
108
- return Math.round(+battV * 100);
119
+ return Math.round(this.calculateBatteryStrength(+battV));
109
120
  }
110
121
  return 0;
111
122
  };
@@ -135,6 +146,10 @@ var Cog = /** @class */ (function (_super) {
135
146
  return __awaiter(this, void 0, void 0, function () {
136
147
  return __generator(this, function (_a) {
137
148
  switch (eventEnum) {
149
+ case RaftConnEvent.CONN_VERIFIED_CORRECT:
150
+ // set up cog thresholds
151
+ setButtonThresholdsUtil(this);
152
+ break;
138
153
  case RaftConnEvent.CONN_DISCONNECTED:
139
154
  // this.publishedDataAnalyser.unsubscribeFromPublishedData();
140
155
  break;
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
- import { CogStateInfo } from "@robotical/roboticaljs";
3
2
  import RAFT from "../RAFT";
4
- import PublishedDataGetter from "./PublishedDataGetter";
5
3
  import EventEmitter from "events";
4
+ import Cog from "./Cog";
5
+ import { SimplifiedCogStateInfo } from "@robotical/roboticaljs/dist/SystemTypeCog/CogTypes";
6
6
  interface CogState {
7
7
  tilt: "none" | "forward" | "backward" | "left" | "right";
8
8
  movementType: "none" | "shake" | "move";
@@ -15,6 +15,12 @@ declare class PublishedDataAnalyser extends EventEmitter {
15
15
  private cog;
16
16
  cogState: CogState;
17
17
  private pubSub;
18
+ rotationDetection: RotationDetection;
19
+ shakeDetector: ShakeDetector;
20
+ buttonClickDetection: ButtonClickDetection;
21
+ tiltDetection: TiltDetection;
22
+ objectSenseDetection: ObjectSenseDetection;
23
+ lightSenseDetection: LightSenseDetection;
18
24
  eventsMap: {
19
25
  tilt: {
20
26
  [key in CogState["tilt"]]: string;
@@ -36,11 +42,10 @@ declare class PublishedDataAnalyser extends EventEmitter {
36
42
  };
37
43
  };
38
44
  TiltDetection: typeof TiltDetection;
39
- PublishedDataGetter: typeof PublishedDataGetter;
40
45
  constructor(cog: RAFT);
41
46
  subscribeToPublishedData(): void;
42
47
  unsubscribeFromPublishedData(): void;
43
- analyse(data: CogStateInfo): void;
48
+ analyse(data: SimplifiedCogStateInfo): void;
44
49
  setTilt(tilt: CogState["tilt"]): void;
45
50
  setMovementType(movementType: CogState["movementType"]): void;
46
51
  setRotation(rotation: CogState["rotation"]): void;
@@ -57,4 +62,59 @@ declare class TiltDetection {
57
62
  };
58
63
  detectTilt(ax: number, ay: number, az: number, isMoving: boolean | undefined, analyser: PublishedDataAnalyser, cogVersion: string): void;
59
64
  }
65
+ declare class RotationDetection {
66
+ private dataBuffer;
67
+ private bufferSize;
68
+ private DELAY_FOR_ROTATION;
69
+ private ROTATION_THRESHOLD;
70
+ private rotationDetected;
71
+ private lastRotationDetectionTime;
72
+ private rotationTimer;
73
+ constructor();
74
+ addToBuffer(data: number): void;
75
+ detectRotation(gz: number, isMoving: boolean | undefined, analyser: PublishedDataAnalyser): void;
76
+ calculateMetric(): number;
77
+ }
78
+ declare class ShakeDetector {
79
+ private thresholdAccelerationMove;
80
+ private thresholdAcceleration;
81
+ private thresholdShakeNumber;
82
+ private interval;
83
+ private maxShakeDuration;
84
+ private coolOffPeriod;
85
+ private lastTime;
86
+ private lastTimeShakeDetected;
87
+ private sensorBundles;
88
+ private gravityVector;
89
+ private lastVector;
90
+ private shakeInProgress;
91
+ private moveInProgress;
92
+ constructor();
93
+ detectShake(xAcc: number, yAcc: number, zAcc: number, timestamp: number, analyser: PublishedDataAnalyser): boolean;
94
+ performCheck(analyser: PublishedDataAnalyser): void;
95
+ updateAxis(index: number, acceleration: number, matrix: number[][], adjustment?: number): void;
96
+ }
97
+ export declare class ButtonClickDetection {
98
+ clickThreshold: number;
99
+ releaseThreshold: number;
100
+ lastTime: number;
101
+ buttonClicked: boolean;
102
+ constructor();
103
+ detectButtonClick(buttonValue: number, analyser: PublishedDataAnalyser, cogVersion: string): void;
104
+ }
105
+ declare class ObjectSenseDetection {
106
+ private objectSensed0Threshold;
107
+ private objectSensed1Threshold;
108
+ private objectSensed2Threshold;
109
+ constructor();
110
+ detectObjectSense(objectSenseValue: number[], analyser: PublishedDataAnalyser): void;
111
+ }
112
+ declare class LightSenseDetection {
113
+ private lowLightThreshold;
114
+ private midLightThreshold;
115
+ private highLightThreshold;
116
+ constructor();
117
+ detectLightSense(lightSenseValue: number, analyser: PublishedDataAnalyser): void;
118
+ }
119
+ export declare const setButtonThresholdsUtil: (connectedCog: Cog) => Promise<void>;
60
120
  export default PublishedDataAnalyser;