incyclist-devices 2.0.38 → 2.1.0

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 (103) hide show
  1. package/lib/antv2/adapter-factory.d.ts +4 -2
  2. package/lib/antv2/adapter.d.ts +3 -20
  3. package/lib/antv2/adapter.js +2 -92
  4. package/lib/antv2/fe/adapter.d.ts +9 -5
  5. package/lib/antv2/fe/adapter.js +25 -14
  6. package/lib/antv2/hr/adapter.d.ts +2 -1
  7. package/lib/antv2/pwr/adapter.d.ts +9 -5
  8. package/lib/antv2/pwr/adapter.js +19 -8
  9. package/lib/antv2/types.d.ts +2 -1
  10. package/lib/base/adpater.d.ts +31 -13
  11. package/lib/base/adpater.js +84 -28
  12. package/lib/ble/adapter-factory.d.ts +10 -9
  13. package/lib/ble/base/adapter.d.ts +9 -20
  14. package/lib/ble/base/adapter.js +13 -69
  15. package/lib/ble/ble-interface.d.ts +5 -4
  16. package/lib/ble/cp/adapter.d.ts +5 -8
  17. package/lib/ble/cp/adapter.js +26 -10
  18. package/lib/ble/elite/adapter.d.ts +6 -5
  19. package/lib/ble/elite/adapter.js +26 -2
  20. package/lib/ble/fm/adapter.d.ts +10 -9
  21. package/lib/ble/fm/adapter.js +38 -11
  22. package/lib/ble/hr/adapter.d.ts +5 -3
  23. package/lib/ble/peripheral-cache.d.ts +3 -2
  24. package/lib/ble/tacx/adapter.d.ts +2 -2
  25. package/lib/ble/wahoo/adapter.d.ts +2 -2
  26. package/lib/index.d.ts +5 -5
  27. package/lib/index.js +4 -2
  28. package/lib/interfaces.d.ts +1 -1
  29. package/lib/modes/ant-fe-adv-st-mode.d.ts +12 -0
  30. package/lib/modes/ant-fe-adv-st-mode.js +83 -0
  31. package/lib/modes/antble-erg.d.ts +31 -0
  32. package/lib/modes/antble-erg.js +28 -0
  33. package/lib/modes/antble-smarttrainer.d.ts +23 -0
  34. package/lib/modes/antble-smarttrainer.js +65 -0
  35. package/lib/modes/base.d.ts +29 -0
  36. package/lib/modes/{cycling-mode.js → base.js} +23 -26
  37. package/lib/modes/daum-classic-standard.d.ts +16 -0
  38. package/lib/modes/daum-classic-standard.js +54 -0
  39. package/lib/modes/daum-erg.d.ts +49 -0
  40. package/lib/{serial/daum/ERGCyclingMode.js → modes/daum-erg.js} +45 -73
  41. package/lib/modes/daum-power.d.ts +5 -0
  42. package/lib/{serial/daum/DaumPowerMeterCyclingMode.js → modes/daum-power.js} +1 -10
  43. package/lib/modes/daum-premium-standard.d.ts +23 -0
  44. package/lib/{serial/daum/premium/modes/daum-classic.js → modes/daum-premium-standard.js} +26 -38
  45. package/lib/modes/daum-smarttrainer.d.ts +82 -0
  46. package/lib/{serial/daum/SmartTrainerCyclingMode.js → modes/daum-smarttrainer.js} +23 -26
  47. package/lib/modes/kettler-erg.d.ts +44 -0
  48. package/lib/{serial/kettler/ergo-racer/modes/erg.js → modes/kettler-erg.js} +12 -23
  49. package/lib/modes/power-base.d.ts +28 -3
  50. package/lib/modes/power-base.js +182 -5
  51. package/lib/modes/power-meter.d.ts +10 -16
  52. package/lib/modes/power-meter.js +15 -54
  53. package/lib/modes/simulator.d.ts +37 -10
  54. package/lib/modes/simulator.js +14 -46
  55. package/lib/modes/{cycling-mode.d.ts → types.d.ts} +22 -19
  56. package/lib/modes/types.js +56 -0
  57. package/lib/serial/adapter-factory.d.ts +7 -5
  58. package/lib/serial/adapter.d.ts +2 -2
  59. package/lib/serial/adapter.js +5 -2
  60. package/lib/serial/daum/DaumAdapter.d.ts +27 -24
  61. package/lib/serial/daum/DaumAdapter.js +200 -128
  62. package/lib/serial/daum/classic/adapter.d.ts +20 -21
  63. package/lib/serial/daum/classic/adapter.js +83 -157
  64. package/lib/serial/daum/classic/comms.d.ts +19 -13
  65. package/lib/serial/daum/classic/comms.js +39 -12
  66. package/lib/serial/daum/classic/mock.d.ts +4 -0
  67. package/lib/serial/daum/classic/mock.js +14 -4
  68. package/lib/serial/daum/premium/adapter.d.ts +16 -11
  69. package/lib/serial/daum/premium/adapter.js +98 -95
  70. package/lib/serial/daum/premium/comms.d.ts +4 -1
  71. package/lib/serial/daum/premium/comms.js +25 -17
  72. package/lib/serial/daum/premium/mock.d.ts +4 -0
  73. package/lib/serial/daum/premium/mock.js +15 -5
  74. package/lib/serial/daum/types.d.ts +11 -0
  75. package/lib/serial/daum/types.js +5 -0
  76. package/lib/serial/kettler/ergo-racer/adapter.d.ts +10 -8
  77. package/lib/serial/kettler/ergo-racer/adapter.js +17 -7
  78. package/lib/serial/serial-interface.js +1 -2
  79. package/lib/simulator/Simulator.d.ts +14 -17
  80. package/lib/simulator/Simulator.js +18 -47
  81. package/lib/types/adapter.d.ts +29 -8
  82. package/lib/types/adapter.js +68 -0
  83. package/lib/utils/utils.d.ts +1 -1
  84. package/package.json +3 -3
  85. package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +0 -9
  86. package/lib/antv2/modes/ant-fe-adv-st-mode.js +0 -51
  87. package/lib/antv2/modes/ant-fe-erg-mode.d.ts +0 -6
  88. package/lib/antv2/modes/ant-fe-erg-mode.js +0 -14
  89. package/lib/antv2/modes/ant-fe-st-mode.d.ts +0 -5
  90. package/lib/antv2/modes/ant-fe-st-mode.js +0 -13
  91. package/lib/modes/ble-erg-mode.d.ts +0 -18
  92. package/lib/modes/ble-erg-mode.js +0 -148
  93. package/lib/modes/ble-st-mode.d.ts +0 -15
  94. package/lib/modes/ble-st-mode.js +0 -96
  95. package/lib/serial/daum/DaumPowerMeterCyclingMode.d.ts +0 -8
  96. package/lib/serial/daum/ERGCyclingMode.d.ts +0 -26
  97. package/lib/serial/daum/SmartTrainerCyclingMode.d.ts +0 -42
  98. package/lib/serial/daum/classic/modes/daum-classic.d.ts +0 -13
  99. package/lib/serial/daum/classic/modes/daum-classic.js +0 -97
  100. package/lib/serial/daum/premium/modes/daum-classic.d.ts +0 -14
  101. package/lib/serial/kettler/ergo-racer/modes/erg.d.ts +0 -25
  102. /package/lib/serial/daum/{constants.d.ts → consts.d.ts} +0 -0
  103. /package/lib/serial/daum/{constants.js → consts.js} +0 -0
@@ -0,0 +1,12 @@
1
+ import { IncyclistDeviceAdapter } from "..";
2
+ import SmartTrainerCyclingMode from "./antble-smarttrainer";
3
+ import { UpdateRequest } from "./types";
4
+ export default class AntAdvSimCyclingMode extends SmartTrainerCyclingMode {
5
+ constructor(adapter: IncyclistDeviceAdapter, props?: any);
6
+ getName(): string;
7
+ getDescription(): string;
8
+ checkForResetOrEmpty(request: UpdateRequest): UpdateRequest | undefined;
9
+ protected checkForTempPowerAdjustments(request: UpdateRequest, newRequest?: UpdateRequest): void;
10
+ protected checkEmptyRequest(newRequest: UpdateRequest): void;
11
+ sendBikeUpdate(incoming: UpdateRequest): UpdateRequest;
12
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const antble_smarttrainer_1 = __importDefault(require("./antble-smarttrainer"));
7
+ const MAX_DEVIATION = 10;
8
+ class AntAdvSimCyclingMode extends antble_smarttrainer_1.default {
9
+ constructor(adapter, props) {
10
+ super(adapter, props);
11
+ this.initLogger('AdvmartTrainerMode');
12
+ }
13
+ getName() {
14
+ return 'Advanced Smart Trainer';
15
+ }
16
+ getDescription() {
17
+ return 'Sends Slope to device. Respects Limits (from workout or settings). Calculates speed based on power and slope. ';
18
+ }
19
+ checkForResetOrEmpty(request) {
20
+ if (!request || request.reset) {
21
+ this.prevRequest = {};
22
+ return { reset: true };
23
+ }
24
+ if (request.slope === undefined && request.targetPowerDelta === undefined && request.targetPower === undefined && request.refresh && this.prevRequest) {
25
+ return this.prevRequest;
26
+ }
27
+ }
28
+ checkForTempPowerAdjustments(request, newRequest = {}) {
29
+ if (request.targetPowerDelta && this.prevRequest && this.prevRequest.targetPower) {
30
+ newRequest.targetPower = this.prevRequest.targetPower + request.targetPowerDelta;
31
+ if (newRequest.targetPower < 10)
32
+ newRequest.targetPower = this.prevRequest.targetPower;
33
+ delete request.targetPowerDelta;
34
+ }
35
+ }
36
+ checkEmptyRequest(newRequest) {
37
+ if (Object.keys(newRequest).length === 0) {
38
+ if (this.prevRequest) {
39
+ newRequest.slope = this.prevRequest.slope;
40
+ newRequest.targetPower = this.prevRequest.targetPower;
41
+ newRequest.refresh = true;
42
+ }
43
+ }
44
+ }
45
+ sendBikeUpdate(incoming) {
46
+ var _a;
47
+ this.logger.logEvent({ message: "processing update request", request: incoming, prev: this.prevRequest, data: this.getData() });
48
+ let newRequest = {};
49
+ const request = Object.assign({}, incoming);
50
+ try {
51
+ const req = this.checkForResetOrEmpty(request);
52
+ if (req)
53
+ return req;
54
+ this.checkSlope(request, newRequest);
55
+ let data = this.getData();
56
+ if (data.power) {
57
+ const { minPower, maxPower } = request;
58
+ let targetPower = request.targetPower;
59
+ if (minPower !== undefined && maxPower !== undefined && minPower === maxPower)
60
+ targetPower = maxPower;
61
+ if (targetPower !== undefined && Math.abs(data.power - targetPower) > MAX_DEVIATION)
62
+ newRequest.targetPower = targetPower;
63
+ else if (minPower !== undefined && data.power < minPower)
64
+ newRequest.targetPower = minPower;
65
+ else if (request.maxPower !== undefined && data.power > request.maxPower)
66
+ newRequest.targetPower = maxPower;
67
+ else if ((_a = this.prevRequest) === null || _a === void 0 ? void 0 : _a.targetPower) {
68
+ newRequest.targetPower = this.prevRequest.targetPower;
69
+ }
70
+ if (newRequest.targetPower) {
71
+ this.checkForTempPowerAdjustments(request, newRequest);
72
+ }
73
+ }
74
+ this.checkEmptyRequest(newRequest);
75
+ this.prevRequest = JSON.parse(JSON.stringify(newRequest));
76
+ }
77
+ catch (err) {
78
+ this.logger.logEvent({ message: "error", fn: 'sendBikeUpdate()', error: err.message, stack: err.stack });
79
+ }
80
+ return newRequest;
81
+ }
82
+ }
83
+ exports.default = AntAdvSimCyclingMode;
@@ -0,0 +1,31 @@
1
+ import { IncyclistDeviceAdapter } from "..";
2
+ import ICyclingMode, { CyclingModeProperyType, UpdateRequest } from "./types";
3
+ import PowerBasedCyclingModeBase from "./power-base";
4
+ export default class ERGCyclingMode extends PowerBasedCyclingModeBase implements ICyclingMode {
5
+ protected static config: {
6
+ isERG: boolean;
7
+ name: string;
8
+ description: string;
9
+ properties: ({
10
+ key: string;
11
+ name: string;
12
+ description: string;
13
+ type: CyclingModeProperyType;
14
+ options: string[];
15
+ default: string;
16
+ min?: undefined;
17
+ max?: undefined;
18
+ } | {
19
+ key: string;
20
+ name: string;
21
+ description: string;
22
+ type: CyclingModeProperyType;
23
+ default: number;
24
+ min: number;
25
+ max: number;
26
+ options?: undefined;
27
+ })[];
28
+ };
29
+ constructor(adapter: IncyclistDeviceAdapter, props?: any);
30
+ getBikeInitRequest(): UpdateRequest;
31
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const types_1 = require("./types");
7
+ const power_base_1 = __importDefault(require("./power-base"));
8
+ class ERGCyclingMode extends power_base_1.default {
9
+ constructor(adapter, props) {
10
+ super(adapter, props);
11
+ this.initLogger('ERGMode');
12
+ }
13
+ getBikeInitRequest() {
14
+ const startPower = Number(this.getSetting('startPower'));
15
+ this.prevRequest = { targetPower: startPower };
16
+ return { targetPower: startPower };
17
+ }
18
+ }
19
+ ERGCyclingMode.config = {
20
+ isERG: true,
21
+ name: "ERG",
22
+ description: "Calculates speed based on power and slope. Power targets are set by workout or remain stable throughout the workout",
23
+ properties: [
24
+ { key: 'bikeType', name: 'Bike Type', description: '', type: types_1.CyclingModeProperyType.SingleSelect, options: ['Race', 'Mountain', 'Triathlon'], default: 'Race' },
25
+ { key: 'startPower', name: 'Starting Power', description: 'Initial power in Watts at start of training', type: types_1.CyclingModeProperyType.Integer, default: 50, min: 25, max: 800 },
26
+ ]
27
+ };
28
+ exports.default = ERGCyclingMode;
@@ -0,0 +1,23 @@
1
+ import ICyclingMode, { CyclingModeProperyType, UpdateRequest } from "./types";
2
+ import PowerBasedCyclingModeBase from "./power-base";
3
+ import { IncyclistDeviceAdapter } from "../types/adapter";
4
+ export default class SmartTrainerCyclingMode extends PowerBasedCyclingModeBase implements ICyclingMode {
5
+ protected static config: {
6
+ name: string;
7
+ description: string;
8
+ properties: {
9
+ key: string;
10
+ name: string;
11
+ description: string;
12
+ type: CyclingModeProperyType;
13
+ options: string[];
14
+ default: string;
15
+ }[];
16
+ };
17
+ constructor(adapter: IncyclistDeviceAdapter, props?: any);
18
+ getBikeInitRequest(): UpdateRequest;
19
+ checkForResetOrEmpty(request: UpdateRequest): UpdateRequest | undefined;
20
+ protected checkSlope(request: UpdateRequest, newRequest?: UpdateRequest): void;
21
+ protected checkEmptyRequest(newRequest: UpdateRequest): void;
22
+ sendBikeUpdate(incoming: UpdateRequest): UpdateRequest;
23
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const types_1 = require("./types");
7
+ const power_base_1 = __importDefault(require("./power-base"));
8
+ class SmartTrainerCyclingMode extends power_base_1.default {
9
+ constructor(adapter, props) {
10
+ super(adapter, props);
11
+ this.initLogger('SmartTrainerMode');
12
+ }
13
+ getBikeInitRequest() {
14
+ this.prevRequest = { slope: 0 };
15
+ return { slope: 0 };
16
+ }
17
+ checkForResetOrEmpty(request) {
18
+ if (!request || request.reset) {
19
+ this.prevRequest = {};
20
+ return { reset: true };
21
+ }
22
+ if (request.slope === undefined && request.refresh && this.prevRequest) {
23
+ return this.prevRequest;
24
+ }
25
+ }
26
+ checkSlope(request, newRequest = {}) {
27
+ if (request.slope !== undefined) {
28
+ newRequest.slope = parseFloat(request.slope.toFixed(1));
29
+ this.data.slope = newRequest.slope;
30
+ }
31
+ }
32
+ checkEmptyRequest(newRequest) {
33
+ if (Object.keys(newRequest).length === 0) {
34
+ if (this.prevRequest) {
35
+ newRequest.slope = this.prevRequest.slope;
36
+ newRequest.refresh = true;
37
+ }
38
+ }
39
+ }
40
+ sendBikeUpdate(incoming) {
41
+ this.logger.logEvent({ message: "processing update request", request: incoming, prev: this.prevRequest, data: this.getData() });
42
+ let newRequest = {};
43
+ const request = Object.assign({}, incoming);
44
+ try {
45
+ const req = this.checkForResetOrEmpty(request);
46
+ if (req)
47
+ return req;
48
+ this.checkSlope(request, newRequest);
49
+ this.checkEmptyRequest(newRequest);
50
+ this.prevRequest = JSON.parse(JSON.stringify(newRequest));
51
+ }
52
+ catch (err) {
53
+ this.logger.logEvent({ message: "error", fn: 'sendBikeUpdate()', error: err.message, stack: err.stack });
54
+ }
55
+ return newRequest;
56
+ }
57
+ }
58
+ SmartTrainerCyclingMode.config = {
59
+ name: "Smart Trainer",
60
+ description: "Calculates speed based on power and slope. Slope is set to the device",
61
+ properties: [
62
+ { key: 'bikeType', name: 'Bike Type', description: '', type: types_1.CyclingModeProperyType.SingleSelect, options: ['Race', 'Mountain', 'Triathlon'], default: 'Race' }
63
+ ]
64
+ };
65
+ exports.default = SmartTrainerCyclingMode;
@@ -0,0 +1,29 @@
1
+ import { IncyclistDeviceAdapter } from "../types/adapter";
2
+ import ICyclingMode, { CyclingMode, CyclingModeConfig, CyclingModeProperty, IncyclistBikeData, Settings, UpdateRequest } from "./types";
3
+ export declare abstract class CyclingModeBase extends CyclingMode implements ICyclingMode {
4
+ adapter: IncyclistDeviceAdapter;
5
+ settings: Settings;
6
+ properties: Settings;
7
+ localConfig: CyclingModeConfig;
8
+ protected static config: CyclingModeConfig;
9
+ protected static isERG: boolean;
10
+ static supportsERGMode(): boolean;
11
+ constructor(adapter: IncyclistDeviceAdapter, props?: any);
12
+ setAdapter(adapter: IncyclistDeviceAdapter): void;
13
+ setConfig(config: CyclingModeConfig): void;
14
+ getConfig(): CyclingModeConfig;
15
+ getName(): string;
16
+ getDescription(): string;
17
+ getProperties(): CyclingModeProperty[];
18
+ getProperty(name: string): CyclingModeProperty;
19
+ setSettings(settings?: any): void;
20
+ setSetting(name: string, value: any): void;
21
+ getSetting(name: string): any;
22
+ getSettingDefault(name: string): any;
23
+ getSettings(): Settings;
24
+ setModeProperty(name: string, value: any): void;
25
+ getModeProperty(name: string): any;
26
+ abstract getBikeInitRequest(): UpdateRequest;
27
+ abstract sendBikeUpdate(request: UpdateRequest): UpdateRequest;
28
+ abstract updateData(data: IncyclistBikeData): IncyclistBikeData;
29
+ }
@@ -1,47 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CyclingModeBase = exports.CyclingModeProperyType = void 0;
4
- var CyclingModeProperyType;
5
- (function (CyclingModeProperyType) {
6
- CyclingModeProperyType["Integer"] = "Integer";
7
- CyclingModeProperyType["Boolean"] = "Boolean";
8
- CyclingModeProperyType["Float"] = "Float";
9
- CyclingModeProperyType["String"] = "String";
10
- CyclingModeProperyType["SingleSelect"] = "SingleSelect";
11
- CyclingModeProperyType["MultiSelect"] = "MultiSelect";
12
- })(CyclingModeProperyType || (exports.CyclingModeProperyType = CyclingModeProperyType = {}));
13
- class CyclingModeBase {
3
+ exports.CyclingModeBase = void 0;
4
+ const types_1 = require("./types");
5
+ class CyclingModeBase extends types_1.CyclingMode {
6
+ static supportsERGMode() {
7
+ return this.config.isERG === true;
8
+ }
14
9
  constructor(adapter, props) {
10
+ super(adapter, props);
15
11
  this.settings = {};
16
12
  this.properties = {};
17
- if (!adapter)
18
- throw new Error('IllegalArgument: adapter is null');
19
13
  this.setAdapter(adapter);
20
14
  this.setSettings(props);
21
15
  }
22
16
  setAdapter(adapter) {
23
17
  this.adapter = adapter;
24
18
  }
25
- getBikeInitRequest() {
26
- return {};
19
+ setConfig(config) {
20
+ this.localConfig = config;
21
+ }
22
+ getConfig() {
23
+ if (this.localConfig)
24
+ return this.localConfig;
25
+ let cm = this.constructor;
26
+ return cm.config;
27
27
  }
28
28
  getName() {
29
- throw new Error("Method not implemented.");
29
+ return this.getConfig().name;
30
30
  }
31
31
  getDescription() {
32
- throw new Error("Method not implemented.");
33
- }
34
- sendBikeUpdate(request) {
35
- throw new Error("Method not implemented.");
36
- }
37
- updateData(data) {
38
- throw new Error("Method not implemented.");
32
+ return this.getConfig().description;
39
33
  }
40
34
  getProperties() {
41
- throw new Error("Method not implemented.");
35
+ return this.getConfig().properties;
42
36
  }
43
37
  getProperty(name) {
44
- throw new Error("Method not implemented.");
38
+ return this.getConfig().properties.find(p => p.name === name);
45
39
  }
46
40
  setSettings(settings) {
47
41
  if (settings) {
@@ -55,10 +49,12 @@ class CyclingModeBase {
55
49
  const res = this.settings[name];
56
50
  if (res !== undefined)
57
51
  return res;
52
+ return this.getSettingDefault(name);
53
+ }
54
+ getSettingDefault(name) {
58
55
  const prop = this.getProperties().find(p => p.key === name);
59
56
  if (prop && prop.default !== undefined)
60
57
  return prop.default;
61
- return undefined;
62
58
  }
63
59
  getSettings() {
64
60
  return this.settings;
@@ -77,3 +73,4 @@ class CyclingModeBase {
77
73
  }
78
74
  }
79
75
  exports.CyclingModeBase = CyclingModeBase;
76
+ CyclingModeBase.config = { name: '', description: '', properties: [] };
@@ -0,0 +1,16 @@
1
+ import ICyclingMode, { IncyclistBikeData, Settings, UpdateRequest } from "./types";
2
+ import { IncyclistDeviceAdapter } from "../types/adapter";
3
+ import SmartTrainerCyclingMode from "./antble-smarttrainer";
4
+ type DaumClassicEvent = {
5
+ noData?: boolean;
6
+ slopeUpdate?: boolean;
7
+ initialCall?: boolean;
8
+ };
9
+ export default class DaumClassicCyclingMode extends SmartTrainerCyclingMode implements ICyclingMode {
10
+ event: DaumClassicEvent;
11
+ constructor(adapter: IncyclistDeviceAdapter, props?: Settings);
12
+ getBikeInitRequest(): UpdateRequest;
13
+ checkForResetOrEmpty(request: UpdateRequest): UpdateRequest | undefined;
14
+ protected updateSpeedAndDistance(_power: number, _slope: any, _bikeType: any, data: IncyclistBikeData, prevData: any): number;
15
+ }
16
+ export {};
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const gd_eventlog_1 = require("gd-eventlog");
7
+ const types_1 = require("./types");
8
+ const antble_smarttrainer_1 = __importDefault(require("./antble-smarttrainer"));
9
+ const config = {
10
+ name: "Daum Classic",
11
+ description: "The device calculates speed and power based on slope. Incyclist will not modify any values recived from the device\nThis mode will not respect maximum power and/or workout limits",
12
+ properties: [
13
+ { key: 'bikeType', name: 'Bike Type', description: '', type: types_1.CyclingModeProperyType.SingleSelect, options: ['Race', 'Mountain'], default: 'Race' },
14
+ ]
15
+ };
16
+ class DaumClassicCyclingMode extends antble_smarttrainer_1.default {
17
+ constructor(adapter, props) {
18
+ super(adapter, props);
19
+ this.logger = adapter ? adapter.getLogger() : undefined;
20
+ if (!this.logger)
21
+ this.logger = new gd_eventlog_1.EventLogger('DaumClassic');
22
+ this.setConfig(config);
23
+ this.event = { noData: true, initialCall: true, slopeUpdate: false };
24
+ }
25
+ getBikeInitRequest() {
26
+ return { slope: 0 };
27
+ }
28
+ checkForResetOrEmpty(request) {
29
+ if (!request || request.reset) {
30
+ this.prevRequest = {};
31
+ return {};
32
+ }
33
+ if (Object.keys(request).length === 0 && this.prevRequest) {
34
+ return { slope: this.prevRequest.slope, refresh: true };
35
+ }
36
+ if (request.slope === undefined && request.refresh && this.prevRequest) {
37
+ return this.prevRequest;
38
+ }
39
+ }
40
+ updateSpeedAndDistance(_power, _slope, _bikeType, data, prevData) {
41
+ const distanceInternal = prevData.distanceInternal || 0;
42
+ const t = this.getTimeSinceLastUpdate();
43
+ if (data.pedalRpm === 0 || data.isPedalling === false) {
44
+ data.speed = 0;
45
+ data.power = 0;
46
+ }
47
+ else {
48
+ let v = data.speed / 3.6;
49
+ data.distanceInternal = distanceInternal + v * t;
50
+ }
51
+ return t;
52
+ }
53
+ }
54
+ exports.default = DaumClassicCyclingMode;
@@ -0,0 +1,49 @@
1
+ import ICyclingMode, { CyclingModeProperyType, IncyclistBikeData, UpdateRequest } from "./types";
2
+ import PowerBasedCyclingModeBase from "./power-base";
3
+ import { IncyclistDeviceAdapter } from "../types/adapter";
4
+ export type ERGEvent = {
5
+ rpmUpdated?: boolean;
6
+ gearUpdated?: boolean;
7
+ starting?: boolean;
8
+ tsStart?: number;
9
+ };
10
+ export default class ERGCyclingMode extends PowerBasedCyclingModeBase implements ICyclingMode {
11
+ prevRequest: UpdateRequest;
12
+ hasBikeUpdate: boolean;
13
+ chain: number[];
14
+ cassette: number[];
15
+ event: ERGEvent;
16
+ protected static config: {
17
+ isERG: boolean;
18
+ name: string;
19
+ description: string;
20
+ properties: ({
21
+ key: string;
22
+ name: string;
23
+ description: string;
24
+ type: CyclingModeProperyType;
25
+ options: string[];
26
+ default: string;
27
+ min?: undefined;
28
+ max?: undefined;
29
+ } | {
30
+ key: string;
31
+ name: string;
32
+ description: string;
33
+ type: CyclingModeProperyType;
34
+ default: number;
35
+ min: number;
36
+ max: number;
37
+ options?: undefined;
38
+ })[];
39
+ };
40
+ constructor(adapter: IncyclistDeviceAdapter, props?: any);
41
+ getBikeInitRequest(): UpdateRequest;
42
+ sendBikeUpdate(request: UpdateRequest): UpdateRequest;
43
+ copyBikeData(data: IncyclistBikeData, bikeData: IncyclistBikeData): IncyclistBikeData;
44
+ updateData(bikeData: IncyclistBikeData): IncyclistBikeData;
45
+ private checkForEvents;
46
+ private cleanupPrevEvents;
47
+ private checkIsStarting;
48
+ calculateTargetPower(request: any, updateMode?: boolean): any;
49
+ }
@@ -3,18 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const cycling_mode_1 = require("../../modes/cycling-mode");
7
- const calculations_1 = __importDefault(require("../../utils/calculations"));
8
- const power_base_1 = __importDefault(require("../../modes/power-base"));
9
- const MIN_SPEED = 10;
10
- const config = {
11
- name: "ERG",
12
- description: "Calculates speed based on power and slope. Power is either set by workout or calculated based on gear and cadence",
13
- properties: [
14
- { key: 'bikeType', name: 'Bike Type', description: '', type: cycling_mode_1.CyclingModeProperyType.SingleSelect, options: ['Race', 'Mountain', 'Triathlon'], default: 'Race' },
15
- { key: 'startPower', name: 'Starting Power', description: 'Initial power in Watts at start of training', type: cycling_mode_1.CyclingModeProperyType.Integer, default: 50, min: 25, max: 800 },
16
- ]
17
- };
6
+ const types_1 = require("./types");
7
+ const calculations_1 = __importDefault(require("../utils/calculations"));
8
+ const power_base_1 = __importDefault(require("./power-base"));
18
9
  class ERGCyclingMode extends power_base_1.default {
19
10
  constructor(adapter, props) {
20
11
  super(adapter, props);
@@ -22,18 +13,6 @@ class ERGCyclingMode extends power_base_1.default {
22
13
  this.event = {};
23
14
  this.initLogger('ERGMode');
24
15
  }
25
- getName() {
26
- return config.name;
27
- }
28
- getDescription() {
29
- return config.description;
30
- }
31
- getProperties() {
32
- return config.properties;
33
- }
34
- getProperty(name) {
35
- return config.properties.find(p => p.name === name);
36
- }
37
16
  getBikeInitRequest() {
38
17
  const startPower = this.getSetting('startPower');
39
18
  return { targetPower: startPower, init: true };
@@ -133,61 +112,46 @@ class ERGCyclingMode extends power_base_1.default {
133
112
  this.event.rpmUpdated = false;
134
113
  return newRequest;
135
114
  }
115
+ copyBikeData(data, bikeData) {
116
+ const newData = super.copyBikeData(data, bikeData);
117
+ if (!bikeData.pedalRpm || bikeData.isPedalling === false) {
118
+ newData.power = 0;
119
+ }
120
+ if (newData.gear === undefined)
121
+ newData.gear = 0;
122
+ return newData;
123
+ }
136
124
  updateData(bikeData) {
137
- const prevData = JSON.parse(JSON.stringify(this.data || {}));
138
- const prevSpeed = prevData.speed;
139
- const prevRequest = this.prevRequest || {};
140
- const data = this.data || {};
141
- const bikeType = this.getSetting('bikeType').toLowerCase();
125
+ try {
126
+ const prevData = JSON.parse(JSON.stringify(this.getData()));
127
+ this.cleanupPrevEvents();
128
+ this.checkIsStarting(prevData);
129
+ const data = super.updateData(bikeData);
130
+ this.checkForEvents(bikeData, prevData);
131
+ return data;
132
+ }
133
+ catch (err) {
134
+ this.logger.logEvent({ message: 'error', fn: 'updateData()', error: err.message, stack: err.stack });
135
+ return this.getData();
136
+ }
137
+ }
138
+ checkForEvents(bikeData, prevData) {
139
+ if (bikeData.gear !== prevData.gear) {
140
+ this.event.gearUpdated = true;
141
+ }
142
+ if (bikeData.pedalRpm && bikeData.pedalRpm !== prevData.pedalRpm) {
143
+ this.event.rpmUpdated = true;
144
+ }
145
+ }
146
+ cleanupPrevEvents() {
142
147
  delete this.event.gearUpdated;
143
148
  delete this.event.rpmUpdated;
149
+ }
150
+ checkIsStarting(prevData) {
144
151
  if (Object.keys(prevData).length === 0 || prevData.speed === undefined || prevData.speed === 0) {
145
152
  this.event.starting = true;
146
153
  this.event.tsStart = Date.now();
147
154
  }
148
- try {
149
- const rpm = bikeData.pedalRpm || 0;
150
- const gear = bikeData.gear || 0;
151
- let power = bikeData.power || 0;
152
- const slope = (prevData.slope !== undefined ? prevData.slope : prevRequest.slope || 0);
153
- const distanceInternal = prevData.distanceInternal || 0;
154
- if (!bikeData.pedalRpm || bikeData.isPedalling === false) {
155
- power = 0;
156
- }
157
- const m = this.getWeight();
158
- const t = this.getTimeSinceLastUpdate();
159
- const { speed, distance } = this.calculateSpeedAndDistance(power, slope, m, t, { bikeType });
160
- if (power === 0 && speed < MIN_SPEED) {
161
- data.speed = Math.round(prevData.speed - 1) < 0 ? 0 : Math.round(prevData.speed - 1);
162
- data.distanceInternal = distanceInternal + data.speed / 3.6 * t;
163
- }
164
- else {
165
- data.speed = speed;
166
- data.distanceInternal = distanceInternal + distance;
167
- }
168
- data.power = Math.round(power);
169
- data.slope = slope;
170
- data.pedalRpm = rpm;
171
- data.gear = gear;
172
- if (data.time !== undefined && !(this.event.starting && !bikeData.pedalRpm))
173
- data.time += t;
174
- else
175
- data.time = 0;
176
- data.heartrate = bikeData.heartrate;
177
- data.isPedalling = bikeData.isPedalling;
178
- if (gear !== prevData.gear) {
179
- this.event.gearUpdated = true;
180
- }
181
- if (rpm && rpm !== prevData.pedalRpm) {
182
- this.event.rpmUpdated = true;
183
- }
184
- }
185
- catch (err) {
186
- this.logger.logEvent({ message: 'error', fn: 'updateData()', error: err.message || err, stack: err.stack });
187
- }
188
- this.logger.logEvent({ message: "updateData result", data, bikeData, prevRequest, prevSpeed });
189
- this.data = data;
190
- return data;
191
155
  }
192
156
  calculateTargetPower(request, updateMode = true) {
193
157
  const bikeType = this.getSetting('bikeType').toLowerCase();
@@ -206,5 +170,13 @@ class ERGCyclingMode extends power_base_1.default {
206
170
  return target;
207
171
  }
208
172
  }
209
- ERGCyclingMode.isERG = true;
173
+ ERGCyclingMode.config = {
174
+ isERG: true,
175
+ name: "ERG",
176
+ description: "Calculates speed based on power and slope. Power is either set by workout or calculated based on gear and cadence",
177
+ properties: [
178
+ { key: 'bikeType', name: 'Bike Type', description: '', type: types_1.CyclingModeProperyType.SingleSelect, options: ['Race', 'Mountain', 'Triathlon'], default: 'Race' },
179
+ { key: 'startPower', name: 'Starting Power', description: 'Initial power in Watts at start of training', type: types_1.CyclingModeProperyType.Integer, default: 50, min: 25, max: 800 },
180
+ ]
181
+ };
210
182
  exports.default = ERGCyclingMode;
@@ -0,0 +1,5 @@
1
+ import ICyclingMode, { UpdateRequest } from "./types";
2
+ import PowerMeterCyclingMode from "./power-meter";
3
+ export default class DaumPowerMeterCyclingMode extends PowerMeterCyclingMode implements ICyclingMode {
4
+ getBikeInitRequest(): UpdateRequest;
5
+ }
@@ -3,19 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const power_meter_1 = __importDefault(require("../../modes/power-meter"));
6
+ const power_meter_1 = __importDefault(require("./power-meter"));
7
7
  class DaumPowerMeterCyclingMode extends power_meter_1.default {
8
- constructor() {
9
- super(...arguments);
10
- this.hasBikeUpdate = false;
11
- }
12
8
  getBikeInitRequest() {
13
9
  return { slope: 0 };
14
10
  }
15
- sendBikeUpdate(request) {
16
- super.sendBikeUpdate(request);
17
- this.prevRequest = {};
18
- return {};
19
- }
20
11
  }
21
12
  exports.default = DaumPowerMeterCyclingMode;