@robotical/webapp-types 1.0.6 → 1.0.8

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.
@@ -51,7 +51,7 @@ 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 { RaftConnEvent, RaftPublishEvent } from "@robdobsn/raftjs";
54
+ import { deviceAttrGetLatestFormatted, RaftConnEvent, RaftPublishEvent } from "@robdobsn/raftjs";
55
55
  import { RaftInfoEvents } from "../../../types/events/raft-info";
56
56
  import PublishedDataAnalyser from "./PublishedDataAnalyser";
57
57
  var Cog = /** @class */ (function (_super) {
@@ -91,8 +91,23 @@ var Cog = /** @class */ (function (_super) {
91
91
  * Gets the battery strength of the RAFT
92
92
  */
93
93
  Cog.prototype.getBatteryStrength = function () {
94
- var _a;
95
- return ((_a = this.raftStateInfo) === null || _a === void 0 ? void 0 : _a.Power.battV) ? Math.round(this.raftStateInfo.Power.battV * 100) : 0;
94
+ var _a, _b, _c, _d;
95
+ /* 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)
98
+ return 0.1;
99
+ var usb = deviceAttrGetLatestFormatted(usbAttr);
100
+ if (usb === 'yes')
101
+ return 0; // 0 indicates USB is connected
102
+ /* 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);
107
+ if (!isNaN(+battV)) {
108
+ return Math.round(+battV * 100);
109
+ }
110
+ return 0;
96
111
  };
97
112
  /**
98
113
  * This methods handles RAFT events coming from the RICConnector of the wrapper
@@ -121,7 +136,7 @@ var Cog = /** @class */ (function (_super) {
121
136
  return __generator(this, function (_a) {
122
137
  switch (eventEnum) {
123
138
  case RaftConnEvent.CONN_DISCONNECTED:
124
- this.publishedDataAnalyser.unsubscribeFromPublishedData();
139
+ // this.publishedDataAnalyser.unsubscribeFromPublishedData();
125
140
  break;
126
141
  default:
127
142
  break;
@@ -1,28 +1,60 @@
1
+ /// <reference types="node" />
1
2
  import { CogStateInfo } from "@robotical/roboticaljs";
2
3
  import RAFT from "../RAFT";
4
+ import PublishedDataGetter from "./PublishedDataGetter";
5
+ import EventEmitter from "events";
3
6
  interface CogState {
4
- tilt: boolean | "forward" | "backward" | "left" | "right";
5
- movementType: boolean | "shake" | "move";
6
- rotation: boolean | "clockwise" | "counter-clockwise";
7
- buttonClick: boolean;
8
- objectSense: boolean | "left" | "right";
9
- lightSense: boolean | "left" | "right";
10
- irMessage: boolean | "left" | "right";
7
+ tilt: "none" | "forward" | "backward" | "left" | "right";
8
+ movementType: "none" | "shake" | "move";
9
+ rotation: "none" | "clockwise" | "counterClockwise";
10
+ buttonClick: "none" | "click" | "release";
11
+ objectSense: "none" | "left" | "right";
12
+ lightSense: "none" | "high" | "mid" | "low";
11
13
  }
12
- declare class PublishedDataAnalyser {
14
+ declare class PublishedDataAnalyser extends EventEmitter {
13
15
  private cog;
14
16
  cogState: CogState;
15
17
  private pubSub;
18
+ eventsMap: {
19
+ tilt: {
20
+ [key in CogState["tilt"]]: string;
21
+ };
22
+ movementType: {
23
+ [key in CogState["movementType"]]: string;
24
+ };
25
+ rotation: {
26
+ [key in CogState["rotation"]]: string;
27
+ };
28
+ buttonClick: {
29
+ [key in CogState["buttonClick"]]: string;
30
+ };
31
+ objectSense: {
32
+ [key in CogState["objectSense"]]: string;
33
+ };
34
+ lightSense: {
35
+ [key in CogState["lightSense"]]: string;
36
+ };
37
+ };
38
+ TiltDetection: typeof TiltDetection;
39
+ PublishedDataGetter: typeof PublishedDataGetter;
16
40
  constructor(cog: RAFT);
17
41
  subscribeToPublishedData(): void;
18
42
  unsubscribeFromPublishedData(): void;
19
43
  analyse(data: CogStateInfo): void;
20
- detectTilt(data: CogStateInfo, isMoving: boolean): void;
21
- detectMovement(data: CogStateInfo): boolean;
22
- detectRotation(data: CogStateInfo, isMoving: boolean): void;
23
- detectButtonClick(data: CogStateInfo): void;
24
- detectObjectSense(data: CogStateInfo): void;
25
- detectLightSense(data: CogStateInfo): void;
26
- detectIRMessage(data: CogStateInfo): void;
44
+ setTilt(tilt: CogState["tilt"]): void;
45
+ setMovementType(movementType: CogState["movementType"]): void;
46
+ setRotation(rotation: CogState["rotation"]): void;
47
+ setButtonClick(buttonClick: CogState["buttonClick"]): void;
48
+ setObjectSense(objectSense: CogState["objectSense"]): void;
49
+ setLightSense(lightSense: CogState["lightSense"]): void;
50
+ }
51
+ declare class TiltDetection {
52
+ distance(a: number, b: number): number;
53
+ static rotateAccelData(x: number, y: number, z: number, degrees: number): {
54
+ x: number;
55
+ y: number;
56
+ z: number;
57
+ };
58
+ detectTilt(ax: number, ay: number, az: number, isMoving: boolean | undefined, analyser: PublishedDataAnalyser, cogVersion: string): void;
27
59
  }
28
60
  export default PublishedDataAnalyser;
@@ -1,20 +1,76 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
1
16
  import { raftPubSubscriptionHelper } from "../raft-subscription-helpers";
2
17
  import { isVersionGreater_errorCatching } from "../../../utils/helpers/compare-version";
3
- var PublishedDataAnalyser = /** @class */ (function () {
18
+ import PublishedDataGetter from "./PublishedDataGetter";
19
+ import EventEmitter from "events";
20
+ var PublishedDataAnalyser = /** @class */ (function (_super) {
21
+ __extends(PublishedDataAnalyser, _super);
4
22
  function PublishedDataAnalyser(cog) {
5
- this.cog = cog;
6
- this.cog = cog;
7
- this.cogState = {
8
- tilt: false,
9
- movementType: false,
10
- rotation: false,
11
- buttonClick: false,
12
- objectSense: false,
13
- lightSense: false,
14
- irMessage: false
23
+ var _this = _super.call(this) || this;
24
+ _this.cog = cog;
25
+ _this.eventsMap = {
26
+ tilt: {
27
+ forward: "tiltForward",
28
+ backward: "tiltBackward",
29
+ left: "tiltLeft",
30
+ right: "tiltRight",
31
+ none: "noTilt"
32
+ },
33
+ movementType: {
34
+ shake: "shake",
35
+ move: "move",
36
+ none: "noMovement"
37
+ },
38
+ rotation: {
39
+ clockwise: "rotationClockwise",
40
+ counterClockwise: "rotationCounterClockwise",
41
+ none: "noRotation"
42
+ },
43
+ buttonClick: {
44
+ click: "buttonClick",
45
+ release: "buttonRelease",
46
+ none: "noButtonClick"
47
+ },
48
+ objectSense: {
49
+ left: "objectSenseLeft",
50
+ right: "objectSenseRight",
51
+ none: "noObjectSense"
52
+ },
53
+ lightSense: {
54
+ high: "highLightSense",
55
+ mid: "midLightSense",
56
+ low: "lowLightSense",
57
+ none: "noLightSense"
58
+ },
59
+ };
60
+ _this.TiltDetection = TiltDetection;
61
+ _this.PublishedDataGetter = PublishedDataGetter;
62
+ _this.cog = cog;
63
+ _this.cogState = {
64
+ tilt: "none",
65
+ movementType: "none",
66
+ rotation: "none",
67
+ buttonClick: "none",
68
+ objectSense: "none",
69
+ lightSense: "none",
15
70
  };
16
- this.pubSub = null;
17
- this.subscribeToPublishedData();
71
+ _this.pubSub = null;
72
+ _this.subscribeToPublishedData();
73
+ return _this;
18
74
  }
19
75
  PublishedDataAnalyser.prototype.subscribeToPublishedData = function () {
20
76
  var _this = this;
@@ -28,40 +84,47 @@ var PublishedDataAnalyser = /** @class */ (function () {
28
84
  (_a = this.pubSub) === null || _a === void 0 ? void 0 : _a.unsubscribe();
29
85
  };
30
86
  PublishedDataAnalyser.prototype.analyse = function (data) {
31
- var isMoving = this.detectMovement(data);
32
- this.detectTilt(data, isMoving);
33
- this.detectRotation(data, isMoving);
34
- this.detectButtonClick(data);
35
- this.detectObjectSense(data);
36
- this.detectLightSense(data);
37
- this.detectIRMessage(data);
87
+ //@ts-ignore
88
+ var accelData = PublishedDataGetter.getAccelerometerData(data.deviceManager);
89
+ //@ts-ignore
90
+ var gyroData = PublishedDataGetter.getGyroscopeData(data.deviceManager);
91
+ //@ts-ignore
92
+ var lightData = PublishedDataGetter.getLightData(data.deviceManager);
93
+ var isMoving;
94
+ if (accelData)
95
+ isMoving = shakeDetector.detectShake(accelData.ax, accelData.ay, accelData.az, Date.now(), this);
96
+ accelData && tiltDetection.detectTilt(accelData.ax, accelData.ay, accelData.az, isMoving, this, this.cog.getRaftVersion());
97
+ gyroData && rotationDetection.detectRotation(gyroData.gz, isMoving, this);
98
+ lightData && buttonClickDetection.detectButtonClick(lightData.ir2, this, this.cog.getRaftVersion());
99
+ lightData && objectSenseDetection.detectObjectSense([lightData.ir0, lightData.ir1], this);
100
+ lightData && lightSenseDetection.detectLightSense(lightData.amb0, this);
38
101
  };
39
- PublishedDataAnalyser.prototype.detectTilt = function (data, isMoving) {
40
- tiltDetection.detectTilt(data, isMoving, this.cogState, this.cog.getRaftVersion());
102
+ PublishedDataAnalyser.prototype.setTilt = function (tilt) {
103
+ this.cogState.tilt = tilt;
104
+ this.emit(this.eventsMap.tilt[tilt]);
41
105
  };
42
- PublishedDataAnalyser.prototype.detectMovement = function (data) {
43
- return shakeDetector.detectShake(data.LSM6DS.ax, data.LSM6DS.ay, data.LSM6DS.az, Date.now(), this.cogState);
106
+ PublishedDataAnalyser.prototype.setMovementType = function (movementType) {
107
+ this.cogState.movementType = movementType;
108
+ this.emit(this.eventsMap.movementType[movementType]);
44
109
  };
45
- PublishedDataAnalyser.prototype.detectRotation = function (data, isMoving) {
46
- rotationDetection.detectRotation(data, isMoving, this.cogState);
110
+ PublishedDataAnalyser.prototype.setRotation = function (rotation) {
111
+ this.cogState.rotation = rotation;
112
+ this.emit(this.eventsMap.rotation[rotation]);
47
113
  };
48
- PublishedDataAnalyser.prototype.detectButtonClick = function (data) {
49
- buttonClickDetection.detectButtonClick(data.Light.irVals[2], this.cogState, this.cog.getRaftVersion());
114
+ PublishedDataAnalyser.prototype.setButtonClick = function (buttonClick) {
115
+ this.cogState.buttonClick = buttonClick;
116
+ this.emit(this.eventsMap.buttonClick[buttonClick]);
50
117
  };
51
- PublishedDataAnalyser.prototype.detectObjectSense = function (data) {
52
- var objectSenseValueArray = data.Light.irVals;
53
- objectSenseDetection.detectObjectSense(objectSenseValueArray, this.cogState);
118
+ PublishedDataAnalyser.prototype.setObjectSense = function (objectSense) {
119
+ this.cogState.objectSense = objectSense;
120
+ this.emit(this.eventsMap.objectSense[objectSense]);
54
121
  };
55
- PublishedDataAnalyser.prototype.detectLightSense = function (data) {
56
- var lightSenseValue = data.Light.ambientVals[0];
57
- lightSenseDetection.detectLightSense(lightSenseValue, this.cogState);
58
- };
59
- PublishedDataAnalyser.prototype.detectIRMessage = function (data) {
60
- var irMessageData = data;
61
- // irMessageDetection.detectIRMessage(data, this.cogState);
122
+ PublishedDataAnalyser.prototype.setLightSense = function (lightSense) {
123
+ this.cogState.lightSense = lightSense;
124
+ this.emit(this.eventsMap.lightSense[lightSense]);
62
125
  };
63
126
  return PublishedDataAnalyser;
64
- }());
127
+ }(EventEmitter));
65
128
  var TiltDetection = /** @class */ (function () {
66
129
  function TiltDetection() {
67
130
  }
@@ -83,7 +146,7 @@ var TiltDetection = /** @class */ (function () {
83
146
  rotatedZ = rotatedZ; // z remains unchanged as the rotation is around the z-axis
84
147
  return { x: rotatedX, y: rotatedY, z: rotatedZ };
85
148
  };
86
- TiltDetection.prototype.detectTilt = function (data, isMoving, cogState, cogVersion) {
149
+ TiltDetection.prototype.detectTilt = function (ax, ay, az, isMoving, analyser, cogVersion) {
87
150
  if (isMoving === void 0) { isMoving = false; }
88
151
  if (isMoving)
89
152
  return;
@@ -94,7 +157,7 @@ var TiltDetection = /** @class */ (function () {
94
157
  if (isVersionGreater_errorCatching(cogVersion, correctionCutOffVersion)) {
95
158
  tiltCorrection = tiltCorrectionForNewerCog;
96
159
  }
97
- var _a = TiltDetection.rotateAccelData(data.LSM6DS.ax, data.LSM6DS.ay, data.LSM6DS.az, tiltCorrection), x = _a.x, y = _a.y, z = _a.z;
160
+ var _a = TiltDetection.rotateAccelData(ax, ay, az, tiltCorrection), x = _a.x, y = _a.y, z = _a.z;
98
161
  var pitch = Math.atan2(x, this.distance(y, z));
99
162
  var roll = Math.atan2(y, this.distance(x, z));
100
163
  var yaw = Math.atan2(z, this.distance(x, y));
@@ -106,7 +169,7 @@ var TiltDetection = /** @class */ (function () {
106
169
  var forwardBackwardThreshold = 20 * (Math.PI / 180); // threshold for forward and backward tilt
107
170
  var leftRightThreshold = 20 * (Math.PI / 180); // threshold for left and right tilt
108
171
  var upDownThreshold = 0.5; // threshold for up and down tilt
109
- var tiltDirection = false;
172
+ var tiltDirection = "none";
110
173
  if (pitch < -forwardBackwardThreshold) { // && Math.abs(yaw) < upDownThreshold) {
111
174
  tiltDirection = "forward";
112
175
  }
@@ -119,7 +182,7 @@ var TiltDetection = /** @class */ (function () {
119
182
  if (roll > leftRightThreshold) { // && Math.abs(yaw) < upDownThreshold) {
120
183
  tiltDirection = "right";
121
184
  }
122
- cogState.tilt = tiltDirection;
185
+ analyser.setTilt(tiltDirection);
123
186
  };
124
187
  return TiltDetection;
125
188
  }());
@@ -139,13 +202,10 @@ var RotationDetection = /** @class */ (function () {
139
202
  this.dataBuffer.shift();
140
203
  }
141
204
  };
142
- RotationDetection.prototype.detectRotation = function (data, isMoving, cogState) {
205
+ RotationDetection.prototype.detectRotation = function (gz, isMoving, analyser) {
143
206
  if (isMoving === void 0) { isMoving = false; }
144
- this.bufferSize = this.bufferSize;
145
- this.DELAY_FOR_ROTATION = this.DELAY_FOR_ROTATION;
146
- this.ROTATION_THRESHOLD = this.ROTATION_THRESHOLD;
147
207
  var currentTime = Date.now();
148
- this.addToBuffer(data.LSM6DS.gz);
208
+ this.addToBuffer(gz);
149
209
  if (this.dataBuffer.length < this.bufferSize) {
150
210
  return; // Wait until buffer is full
151
211
  }
@@ -158,17 +218,18 @@ var RotationDetection = /** @class */ (function () {
158
218
  if (metric > this.ROTATION_THRESHOLD || metric < -this.ROTATION_THRESHOLD) {
159
219
  this.lastRotationDetectionTime = currentTime;
160
220
  this.dataBuffer = [];
221
+ console.log("Rotation detected. Rotation: ", metric > this.ROTATION_THRESHOLD ? "clockwise" : "counter-clockwise");
161
222
  if (metric > this.ROTATION_THRESHOLD) {
162
223
  // console.log("Clockwise rotation detected:", metric);
163
- cogState.rotation = "clockwise";
224
+ analyser.setRotation("clockwise");
164
225
  }
165
226
  else if (metric < -this.ROTATION_THRESHOLD) {
166
227
  // console.log("Counter-clockwise rotation detected:", metric);
167
- cogState.rotation = "counter-clockwise";
228
+ analyser.setRotation("counterClockwise");
168
229
  }
169
230
  }
170
231
  else {
171
- cogState.rotation = false;
232
+ analyser.setRotation("none");
172
233
  }
173
234
  };
174
235
  RotationDetection.prototype.calculateMetric = function () {
@@ -201,7 +262,7 @@ var ShakeDetector = /** @class */ (function () {
201
262
  this.shakeInProgress = false;
202
263
  this.moveInProgress = false;
203
264
  }
204
- ShakeDetector.prototype.detectShake = function (xAcc, yAcc, zAcc, timestamp, cogState) {
265
+ ShakeDetector.prototype.detectShake = function (xAcc, yAcc, zAcc, timestamp, analyser) {
205
266
  this.thresholdAcceleration = this.thresholdAcceleration;
206
267
  this.thresholdAccelerationMove = this.thresholdAccelerationMove;
207
268
  this.thresholdShakeNumber = this.thresholdShakeNumber;
@@ -214,11 +275,11 @@ var ShakeDetector = /** @class */ (function () {
214
275
  this.gravityVector = [xAcc, yAcc, zAcc];
215
276
  if (this.moveInProgress) {
216
277
  // console.log("move detected");
217
- cogState.movementType = "move";
278
+ analyser.setMovementType("move");
218
279
  }
219
280
  else {
220
281
  // console.log("no move detected");
221
- cogState.movementType = false;
282
+ analyser.setMovementType("none");
222
283
  }
223
284
  this.moveInProgress = false;
224
285
  this.shakeInProgress = false;
@@ -249,7 +310,7 @@ var ShakeDetector = /** @class */ (function () {
249
310
  // console.log("Shake detected!");
250
311
  this.sensorBundles = [];
251
312
  this.shakeInProgress = false;
252
- cogState.movementType = "shake";
313
+ analyser.setMovementType("shake");
253
314
  }
254
315
  }
255
316
  // this.noMoveCallback();
@@ -260,7 +321,7 @@ var ShakeDetector = /** @class */ (function () {
260
321
  this.sensorBundles = [];
261
322
  // console.log("resetting shake detector. Move detected");
262
323
  // fire move detector
263
- cogState.movementType = "move";
324
+ analyser.setMovementType("move");
264
325
  }
265
326
  }
266
327
  }
@@ -278,7 +339,7 @@ var ShakeDetector = /** @class */ (function () {
278
339
  */
279
340
  }
280
341
  };
281
- ShakeDetector.prototype.performCheck = function (cogState) {
342
+ ShakeDetector.prototype.performCheck = function (analyser) {
282
343
  var _this = this;
283
344
  var matrix = [
284
345
  [0, 0],
@@ -301,7 +362,7 @@ var ShakeDetector = /** @class */ (function () {
301
362
  }
302
363
  this.lastTimeShakeDetected = Date.now();
303
364
  // console.log("Shake detected!", JSON.stringify(matrix));
304
- cogState.movementType = "shake";
365
+ analyser.setMovementType("shake");
305
366
  this.sensorBundles = [];
306
367
  }
307
368
  };
@@ -330,7 +391,7 @@ var ButtonClickDetection = /** @class */ (function () {
330
391
  this.lastTime = 0;
331
392
  this.buttonClicked = false;
332
393
  }
333
- ButtonClickDetection.prototype.detectButtonClick = function (buttonValue, cogState, cogVersion) {
394
+ ButtonClickDetection.prototype.detectButtonClick = function (buttonValue, analyser, cogVersion) {
334
395
  var correctionCutOffVersion = "1.2.0";
335
396
  var clickThreshold = 1600;
336
397
  if (isVersionGreater_errorCatching(cogVersion, correctionCutOffVersion)) {
@@ -347,12 +408,12 @@ var ButtonClickDetection = /** @class */ (function () {
347
408
  // console.log("Button clicked", buttonValue);
348
409
  this.buttonClicked = true;
349
410
  this.lastTime = currentTime;
350
- cogState.buttonClick = true;
411
+ analyser.setButtonClick("click");
351
412
  }
352
413
  else if (buttonValue < this.releaseThreshold && this.buttonClicked) {
353
414
  // console.log("Button released", buttonValue);
354
415
  this.buttonClicked = false;
355
- cogState.buttonClick = false;
416
+ analyser.setButtonClick("release");
356
417
  }
357
418
  // } else {
358
419
  // this.buttonClicked = false;
@@ -367,51 +428,40 @@ var ObjectSenseDetection = /** @class */ (function () {
367
428
  this.objectSensed1Threshold = 2500; // right of the arrow
368
429
  this.objectSensed2Threshold = 1500; // button
369
430
  }
370
- ObjectSenseDetection.prototype.detectObjectSense = function (objectSenseValue, cogState) {
431
+ ObjectSenseDetection.prototype.detectObjectSense = function (objectSenseValue, analyser) {
371
432
  if (objectSenseValue[0] > this.objectSensed0Threshold) {
372
- cogState.objectSense = "left";
433
+ analyser.setObjectSense("left");
373
434
  }
374
435
  else if (objectSenseValue[1] > this.objectSensed1Threshold) {
375
- cogState.objectSense = "right";
436
+ analyser.setObjectSense("right");
376
437
  }
377
438
  else {
378
- cogState.objectSense = false;
439
+ analyser.setObjectSense("none");
379
440
  }
380
441
  };
381
442
  return ObjectSenseDetection;
382
443
  }());
383
444
  var LightSenseDetection = /** @class */ (function () {
384
445
  function LightSenseDetection() {
385
- this.lightSenseThreshold = 450;
446
+ this.lowLightThreshold = 5;
447
+ this.midLightThreshold = 250;
448
+ this.highLightThreshold = 450;
386
449
  }
387
- LightSenseDetection.prototype.detectLightSense = function (lightSenseValue, cogState) {
388
- if (lightSenseValue > this.lightSenseThreshold) {
389
- cogState.lightSense = true;
390
- }
391
- else {
392
- cogState.lightSense = false;
450
+ LightSenseDetection.prototype.detectLightSense = function (lightSenseValue, analyser) {
451
+ if (lightSenseValue > this.highLightThreshold) {
452
+ analyser.setLightSense("high");
393
453
  }
394
- };
395
- return LightSenseDetection;
396
- }());
397
- var IRMessageDetection = /** @class */ (function () {
398
- function IRMessageDetection() {
399
- this.irMessage0Threshold = 0;
400
- this.irMessage1Threshold = 0;
401
- }
402
- IRMessageDetection.prototype.detectIRMessage = function (irMessageValue, cogState) {
403
- // placeholder for now
404
- if (irMessageValue[0] > this.irMessage0Threshold) {
405
- cogState.irMessage = "left";
454
+ else if (lightSenseValue > this.midLightThreshold) {
455
+ analyser.setLightSense("mid");
406
456
  }
407
- else if (irMessageValue[1] > this.irMessage1Threshold) {
408
- cogState.irMessage = "right";
457
+ else if (lightSenseValue > this.lowLightThreshold) {
458
+ analyser.setLightSense("low");
409
459
  }
410
460
  else {
411
- cogState.irMessage = false;
461
+ analyser.setLightSense("none");
412
462
  }
413
463
  };
414
- return IRMessageDetection;
464
+ return LightSenseDetection;
415
465
  }());
416
466
  var rotationDetection = new RotationDetection();
417
467
  var shakeDetector = new ShakeDetector();
@@ -419,5 +469,4 @@ var buttonClickDetection = new ButtonClickDetection();
419
469
  var tiltDetection = new TiltDetection();
420
470
  var objectSenseDetection = new ObjectSenseDetection();
421
471
  var lightSenseDetection = new LightSenseDetection();
422
- var irMessageDetection = new IRMessageDetection();
423
472
  export default PublishedDataAnalyser;
@@ -0,0 +1,23 @@
1
+ import { DeviceManager } from "@robdobsn/raftjs/dist/web/RaftDeviceManager";
2
+ export default class PublishedDataGetter {
3
+ static getPowerData(deviceManager: DeviceManager): {
4
+ battV: number;
5
+ usb: "yes" | "no";
6
+ } | undefined;
7
+ static getAccelerometerData(deviceManager: DeviceManager): {
8
+ ax: number;
9
+ ay: number;
10
+ az: number;
11
+ } | undefined;
12
+ static getGyroscopeData(deviceManager: DeviceManager): {
13
+ gx: number;
14
+ gy: number;
15
+ gz: number;
16
+ } | undefined;
17
+ static getLightData(deviceManager: DeviceManager): {
18
+ amb0: number;
19
+ ir0: number;
20
+ ir1: number;
21
+ ir2: number;
22
+ } | undefined;
23
+ }
@@ -0,0 +1,65 @@
1
+ import { deviceAttrGetLatestFormatted } from "@robdobsn/raftjs";
2
+ /* LIGHT ATTRIBUTES */
3
+ var COG_LIGHT_ATTR_KEY = 'RoboCogLightV1_0';
4
+ var AMB0_KEY = 'amb0';
5
+ var IR0_KEY = 'ir0';
6
+ var IR1_KEY = 'ir1';
7
+ var IR2_KEY = 'ir2';
8
+ /* POWER ATTRIBUTES */
9
+ var COG_POWER_ATTR_KEY = 'RoboCogPowerV1_00';
10
+ var BATTV_KEY = 'battV';
11
+ var USB_KEY = 'UST';
12
+ /* I2CA ATTRIBUTES */
13
+ var COG_I2CA_ATTR_KEY = 'I2CA_6a';
14
+ var AX_KEY = 'ax';
15
+ var AY_KEY = 'ay';
16
+ var AZ_KEY = 'az';
17
+ var GX_KEY = 'gx';
18
+ var GY_KEY = 'gy';
19
+ var GZ_KEY = 'gz';
20
+ var PublishedDataGetter = /** @class */ (function () {
21
+ function PublishedDataGetter() {
22
+ }
23
+ PublishedDataGetter.getPowerData = function (deviceManager) {
24
+ var powerAttr = deviceManager.getDeviceState(COG_POWER_ATTR_KEY);
25
+ var battV = deviceAttrGetLatestFormatted(powerAttr === null || powerAttr === void 0 ? void 0 : powerAttr.deviceAttributes[BATTV_KEY]);
26
+ var usb = deviceAttrGetLatestFormatted(powerAttr === null || powerAttr === void 0 ? void 0 : powerAttr.deviceAttributes[USB_KEY]);
27
+ return { battV: convertStringToNumber(battV), usb: usb };
28
+ };
29
+ PublishedDataGetter.getAccelerometerData = function (deviceManager) {
30
+ var i2caAttr = deviceManager.getDeviceState(COG_I2CA_ATTR_KEY);
31
+ if (!i2caAttr)
32
+ return;
33
+ var i2ca = i2caAttr.deviceAttributes;
34
+ var ax = deviceAttrGetLatestFormatted(i2ca[AX_KEY]);
35
+ var ay = deviceAttrGetLatestFormatted(i2ca[AY_KEY]);
36
+ var az = deviceAttrGetLatestFormatted(i2ca[AZ_KEY]);
37
+ return { ax: convertStringToNumber(ax), ay: convertStringToNumber(ay), az: convertStringToNumber(az) };
38
+ };
39
+ PublishedDataGetter.getGyroscopeData = function (deviceManager) {
40
+ var i2caAttr = deviceManager.getDeviceState(COG_I2CA_ATTR_KEY);
41
+ if (!i2caAttr)
42
+ return;
43
+ var i2ca = i2caAttr.deviceAttributes;
44
+ var gx = deviceAttrGetLatestFormatted(i2ca[GX_KEY]);
45
+ var gy = deviceAttrGetLatestFormatted(i2ca[GY_KEY]);
46
+ var gz = deviceAttrGetLatestFormatted(i2ca[GZ_KEY]);
47
+ return { gx: convertStringToNumber(gx), gy: convertStringToNumber(gy), gz: convertStringToNumber(gz) };
48
+ };
49
+ PublishedDataGetter.getLightData = function (deviceManager) {
50
+ var lightAttr = deviceManager.getDeviceState(COG_LIGHT_ATTR_KEY);
51
+ if (!lightAttr)
52
+ return;
53
+ var light = lightAttr.deviceAttributes;
54
+ var amb0 = deviceAttrGetLatestFormatted(light[AMB0_KEY]);
55
+ var ir0 = deviceAttrGetLatestFormatted(light[IR0_KEY]);
56
+ var ir1 = deviceAttrGetLatestFormatted(light[IR1_KEY]);
57
+ var ir2 = deviceAttrGetLatestFormatted(light[IR2_KEY]);
58
+ return { amb0: convertStringToNumber(amb0), ir0: convertStringToNumber(ir0), ir1: convertStringToNumber(ir1), ir2: convertStringToNumber(ir2) };
59
+ };
60
+ return PublishedDataGetter;
61
+ }());
62
+ export default PublishedDataGetter;
63
+ var convertStringToNumber = function (str) {
64
+ return isNaN(+str) ? 0 : +str;
65
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robotical/webapp-types",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Type definitions for the Application Manager",
5
5
  "main": "dist/application-manager.d.ts",
6
6
  "types": "dist/application-manager.d.ts",