incyclist-devices 2.2.9 → 2.3.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 (142) hide show
  1. package/lib/antv2/base/interface.js +2 -2
  2. package/lib/antv2/factories/index.d.ts +1 -0
  3. package/lib/antv2/factories/index.js +17 -0
  4. package/lib/antv2/fe/adapter.js +5 -4
  5. package/lib/antv2/index.d.ts +1 -0
  6. package/lib/antv2/index.js +12 -8
  7. package/lib/base/adpater.js +1 -1
  8. package/lib/ble/adapter-factory.d.ts +20 -24
  9. package/lib/ble/adapter-factory.js +13 -36
  10. package/lib/ble/base/adapter.d.ts +16 -5
  11. package/lib/ble/base/adapter.js +169 -52
  12. package/lib/ble/base/comms.d.ts +2 -74
  13. package/lib/ble/base/comms.js +3 -596
  14. package/lib/ble/base/interface.d.ts +96 -0
  15. package/lib/ble/base/interface.js +544 -0
  16. package/lib/ble/base/peripheral.d.ts +34 -0
  17. package/lib/ble/base/peripheral.js +286 -0
  18. package/lib/ble/base/sensor.d.ts +31 -0
  19. package/lib/ble/base/sensor.js +130 -0
  20. package/lib/ble/base/types.d.ts +7 -0
  21. package/lib/ble/base/types.js +7 -0
  22. package/lib/ble/bindings/mock.js +6 -0
  23. package/lib/ble/bindings/types.d.ts +3 -4
  24. package/lib/ble/ble-interface.d.ts +7 -4
  25. package/lib/ble/ble-interface.js +16 -2
  26. package/lib/ble/ble-peripheral.d.ts +1 -0
  27. package/lib/ble/ble-peripheral.js +7 -11
  28. package/lib/ble/consts.d.ts +0 -6
  29. package/lib/ble/consts.js +1 -7
  30. package/lib/ble/cp/adapter.d.ts +3 -3
  31. package/lib/ble/cp/adapter.js +12 -13
  32. package/lib/ble/cp/comm.d.ts +1 -1
  33. package/lib/ble/cp/comm.js +2 -2
  34. package/lib/ble/cp/index.d.ts +1 -1
  35. package/lib/ble/cp/index.js +2 -2
  36. package/lib/ble/cp/sensor.d.ts +27 -0
  37. package/lib/ble/cp/sensor.js +107 -0
  38. package/lib/ble/elite/comms.d.ts +1 -1
  39. package/lib/ble/elite/comms.js +2 -2
  40. package/lib/ble/factories/adapter-factory.d.ts +32 -0
  41. package/lib/ble/factories/adapter-factory.js +104 -0
  42. package/lib/ble/factories/index.d.ts +2 -0
  43. package/lib/ble/factories/index.js +18 -0
  44. package/lib/ble/factories/interface-factory.d.ts +7 -0
  45. package/lib/ble/factories/interface-factory.js +18 -0
  46. package/lib/ble/fm/adapter.d.ts +9 -4
  47. package/lib/ble/fm/adapter.js +104 -108
  48. package/lib/ble/fm/comms.d.ts +1 -1
  49. package/lib/ble/fm/comms.js +3 -3
  50. package/lib/ble/fm/consts.d.ts +93 -0
  51. package/lib/ble/fm/consts.js +55 -1
  52. package/lib/ble/fm/index.d.ts +1 -1
  53. package/lib/ble/fm/index.js +2 -2
  54. package/lib/ble/fm/sensor.d.ts +44 -0
  55. package/lib/ble/fm/sensor.js +384 -0
  56. package/lib/ble/hr/adapter.d.ts +3 -3
  57. package/lib/ble/hr/adapter.js +5 -8
  58. package/lib/ble/hr/comm.d.ts +1 -1
  59. package/lib/ble/hr/comm.js +2 -2
  60. package/lib/ble/hr/index.d.ts +1 -1
  61. package/lib/ble/hr/index.js +2 -2
  62. package/lib/ble/hr/sensor.d.ts +17 -0
  63. package/lib/ble/hr/sensor.js +52 -0
  64. package/lib/ble/index.d.ts +4 -3
  65. package/lib/ble/index.js +29 -13
  66. package/lib/ble/tacx/adapter.d.ts +4 -2
  67. package/lib/ble/tacx/adapter.js +26 -66
  68. package/lib/ble/tacx/comms.d.ts +1 -1
  69. package/lib/ble/tacx/comms.js +2 -2
  70. package/lib/ble/tacx/consts.d.ts +23 -0
  71. package/lib/ble/tacx/consts.js +27 -0
  72. package/lib/ble/tacx/index.d.ts +1 -1
  73. package/lib/ble/tacx/index.js +2 -2
  74. package/lib/ble/tacx/sensor.d.ts +63 -0
  75. package/lib/ble/tacx/sensor.js +596 -0
  76. package/lib/ble/types.d.ts +81 -52
  77. package/lib/ble/utils.d.ts +7 -2
  78. package/lib/ble/utils.js +84 -9
  79. package/lib/ble/wahoo/adapter.d.ts +2 -2
  80. package/lib/ble/wahoo/adapter.js +4 -72
  81. package/lib/ble/wahoo/comms.d.ts +1 -1
  82. package/lib/ble/wahoo/comms.js +2 -2
  83. package/lib/ble/wahoo/consts.d.ts +16 -0
  84. package/lib/ble/wahoo/consts.js +7 -0
  85. package/lib/ble/wahoo/index.d.ts +1 -1
  86. package/lib/ble/wahoo/index.js +2 -2
  87. package/lib/ble/wahoo/sensor.d.ts +48 -0
  88. package/lib/ble/wahoo/sensor.js +356 -0
  89. package/lib/direct-connect/base/comms.d.ts +3 -0
  90. package/lib/direct-connect/base/comms.js +7 -0
  91. package/lib/direct-connect/base/interface.d.ts +75 -0
  92. package/lib/direct-connect/base/interface.js +306 -0
  93. package/lib/direct-connect/base/peripheral.d.ts +50 -0
  94. package/lib/direct-connect/base/peripheral.js +413 -0
  95. package/lib/direct-connect/base/sensor.d.ts +3 -0
  96. package/lib/direct-connect/base/sensor.js +7 -0
  97. package/lib/direct-connect/bindings/index.d.ts +1 -0
  98. package/lib/direct-connect/bindings/index.js +17 -0
  99. package/lib/direct-connect/bindings/types.d.ts +36 -0
  100. package/lib/direct-connect/bindings/types.js +2 -0
  101. package/lib/direct-connect/consts.d.ts +17 -0
  102. package/lib/direct-connect/consts.js +20 -0
  103. package/lib/direct-connect/index.d.ts +3 -0
  104. package/lib/direct-connect/index.js +22 -0
  105. package/lib/direct-connect/messages/CharacteristicNotification.d.ts +12 -0
  106. package/lib/direct-connect/messages/CharacteristicNotification.js +23 -0
  107. package/lib/direct-connect/messages/DiscoverCharacteristics.d.ts +22 -0
  108. package/lib/direct-connect/messages/DiscoverCharacteristics.js +43 -0
  109. package/lib/direct-connect/messages/DiscoverServices.d.ts +15 -0
  110. package/lib/direct-connect/messages/DiscoverServices.js +33 -0
  111. package/lib/direct-connect/messages/EnableCharacteristicNotifications.d.ts +18 -0
  112. package/lib/direct-connect/messages/EnableCharacteristicNotifications.js +35 -0
  113. package/lib/direct-connect/messages/ReadCharacteristic.d.ts +18 -0
  114. package/lib/direct-connect/messages/ReadCharacteristic.js +34 -0
  115. package/lib/direct-connect/messages/WriteCharacteristic.d.ts +18 -0
  116. package/lib/direct-connect/messages/WriteCharacteristic.js +36 -0
  117. package/lib/direct-connect/messages/error.d.ts +5 -0
  118. package/lib/direct-connect/messages/error.js +18 -0
  119. package/lib/direct-connect/messages/factory.d.ts +6 -0
  120. package/lib/direct-connect/messages/factory.js +44 -0
  121. package/lib/direct-connect/messages/index.d.ts +9 -0
  122. package/lib/direct-connect/messages/index.js +25 -0
  123. package/lib/direct-connect/messages/message.d.ts +20 -0
  124. package/lib/direct-connect/messages/message.js +90 -0
  125. package/lib/direct-connect/types.d.ts +24 -0
  126. package/lib/direct-connect/types.js +9 -0
  127. package/lib/direct-connect/utils.d.ts +5 -0
  128. package/lib/direct-connect/utils.js +73 -0
  129. package/lib/factories/adapters.js +16 -4
  130. package/lib/factories/interfaces.d.ts +2 -1
  131. package/lib/factories/interfaces.js +10 -7
  132. package/lib/index.d.ts +5 -4
  133. package/lib/index.js +6 -2
  134. package/lib/serial/bindings/tcp.d.ts +5 -4
  135. package/lib/serial/bindings/tcp.js +16 -23
  136. package/lib/types/device.d.ts +2 -1
  137. package/lib/types/device.js +1 -0
  138. package/lib/utils/operation.d.ts +17 -0
  139. package/lib/utils/operation.js +20 -0
  140. package/lib/utils/task.d.ts +44 -0
  141. package/lib/utils/task.js +127 -0
  142. package/package.json +3 -1
@@ -16,33 +16,30 @@ const gd_eventlog_1 = require("gd-eventlog");
16
16
  const power_meter_1 = __importDefault(require("../../modes/power-meter"));
17
17
  const antble_smarttrainer_1 = __importDefault(require("../../modes/antble-smarttrainer"));
18
18
  const antble_erg_1 = __importDefault(require("../../modes/antble-erg"));
19
- const comms_1 = __importDefault(require("./comms"));
19
+ const sensor_1 = __importDefault(require("./sensor"));
20
20
  const adapter_1 = __importDefault(require("../base/adapter"));
21
21
  const consts_1 = require("./consts");
22
- const utils_1 = require("../../utils/utils");
23
22
  const types_1 = require("../../types");
23
+ const task_1 = require("../../utils/task");
24
24
  class BleFmAdapter extends adapter_1.default {
25
25
  constructor(settings, props) {
26
26
  super(settings, props);
27
27
  this.distanceInternal = 0;
28
28
  this.logger = new gd_eventlog_1.EventLogger('BLE-FM');
29
- const { id, address, name } = settings;
30
- const logger = this.logger;
31
- const ble = this.ble;
32
- this.device = new comms_1.default({ id, address, name, ble, logger });
29
+ this.device = new sensor_1.default(this.getPeripheral(), { logger: this.logger });
33
30
  this.capabilities = [
34
31
  types_1.IncyclistCapability.Power, types_1.IncyclistCapability.Speed, types_1.IncyclistCapability.Cadence,
35
32
  types_1.IncyclistCapability.Control
36
33
  ];
37
34
  }
35
+ updateSensor(peripheral) {
36
+ this.device = new sensor_1.default(peripheral, { logger: this.logger });
37
+ }
38
38
  isSame(device) {
39
39
  if (!(device instanceof BleFmAdapter))
40
40
  return false;
41
41
  return this.isEqual(device.settings);
42
42
  }
43
- getName() {
44
- return `${this.device.name}`;
45
- }
46
43
  isControllable() {
47
44
  return true;
48
45
  }
@@ -70,6 +67,7 @@ class BleFmAdapter extends adapter_1.default {
70
67
  return new power_meter_1.default(this);
71
68
  }
72
69
  mapData(deviceData) {
70
+ var _a, _b, _c;
73
71
  const data = {
74
72
  isPedalling: false,
75
73
  power: 0,
@@ -80,9 +78,9 @@ class BleFmAdapter extends adapter_1.default {
80
78
  slope: undefined,
81
79
  time: undefined
82
80
  };
83
- data.power = (deviceData.instantaneousPower !== undefined ? deviceData.instantaneousPower : data.power);
84
- data.pedalRpm = (deviceData.cadence !== undefined ? deviceData.cadence : data.pedalRpm);
85
- data.time = (deviceData.time !== undefined ? deviceData.time : data.time);
81
+ data.power = (_a = deviceData === null || deviceData === void 0 ? void 0 : deviceData.instantaneousPower) !== null && _a !== void 0 ? _a : data.power;
82
+ data.pedalRpm = (_b = deviceData === null || deviceData === void 0 ? void 0 : deviceData.cadence) !== null && _b !== void 0 ? _b : data.pedalRpm;
83
+ data.time = (_c = deviceData === null || deviceData === void 0 ? void 0 : deviceData.time) !== null && _c !== void 0 ? _c : data.time;
86
84
  data.isPedalling = data.pedalRpm > 0 || (data.pedalRpm === undefined && data.power > 0);
87
85
  data.heartrate = deviceData.heartrate || data.heartrate;
88
86
  return data;
@@ -107,107 +105,105 @@ class BleFmAdapter extends adapter_1.default {
107
105
  };
108
106
  return data;
109
107
  }
110
- start() {
111
- return __awaiter(this, arguments, void 0, function* (props = {}) {
112
- const wasPaused = this.paused;
113
- const wasStopped = this.stopped;
114
- if (wasPaused)
115
- this.resume();
116
- if (wasStopped)
117
- this.stopped = false;
118
- if (this.started && !wasPaused && !wasStopped)
119
- return true;
120
- this.logEvent(Object.assign(Object.assign({ message: 'starting device' }, this.getSettings()), { protocol: this.getProtocolName(), props, isStarted: this.started, isConnected: this.getComms().isConnected() }));
121
- const { restart = wasPaused } = props;
122
- if (!restart && this.ble.isScanning() && !this.getComms().isConnected()) {
123
- }
124
- let scanOnly = props.scanOnly;
125
- if (this.ble.isScanning() && this.getComms().isConnected()) {
126
- scanOnly = true;
127
- }
128
- else {
129
- const { timeout = 20000 } = props || {};
130
- if (!this.connectPromise)
131
- this.connectPromise = this.connect();
132
- const res = yield Promise.race([
133
- this.connectPromise.then((connected) => {
134
- return { connected, reason: connected ? null : 'could not connect' };
135
- }),
136
- (0, utils_1.sleep)(timeout).then(() => ({ connected: false, reason: 'timeout' }))
137
- ]);
138
- this.connectPromise = undefined;
139
- const connected = res.connected;
140
- if (!connected) {
141
- throw new Error(`could not start device, reason:${res.reason}`);
142
- }
108
+ checkResume() {
109
+ const wasPaused = this.paused;
110
+ const wasStopped = this.stopped;
111
+ if (wasPaused)
112
+ this.resume();
113
+ this.stopped = false;
114
+ if (this.started && !wasPaused && !wasStopped)
115
+ return [wasPaused, true];
116
+ return [wasPaused, false];
117
+ }
118
+ initControl(_startProps) {
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ this.setConstants();
121
+ yield this.establishControl();
122
+ this.setConstants();
123
+ yield this.sendInitialRequest();
124
+ });
125
+ }
126
+ setConstants() {
127
+ const mode = this.getCyclingMode();
128
+ const sensor = this.getComms();
129
+ if (mode === null || mode === void 0 ? void 0 : mode.getSetting('bikeType')) {
130
+ const bikeType = mode.getSetting('bikeType').toLowerCase();
131
+ sensor.setCrr(consts_1.cRR);
132
+ switch (bikeType) {
133
+ case 'race':
134
+ sensor.setCw(consts_1.cwABike.race);
135
+ break;
136
+ case 'triathlon':
137
+ sensor.setCw(consts_1.cwABike.triathlon);
138
+ break;
139
+ case 'mountain':
140
+ sensor.setCw(consts_1.cwABike.mountain);
141
+ break;
143
142
  }
144
- try {
145
- const comms = this.device;
146
- if (comms) {
147
- if (!scanOnly) {
148
- const mode = this.getCyclingMode();
149
- if (mode && mode.getSetting('bikeType')) {
150
- const bikeType = mode.getSetting('bikeType').toLowerCase();
151
- comms.setCrr(consts_1.cRR);
152
- switch (bikeType) {
153
- case 'race':
154
- comms.setCw(consts_1.cwABike.race);
155
- break;
156
- case 'triathlon':
157
- comms.setCw(consts_1.cwABike.triathlon);
158
- break;
159
- case 'mountain':
160
- comms.setCw(consts_1.cwABike.mountain);
161
- break;
162
- }
143
+ }
144
+ }
145
+ establishControl() {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ if (!this.isStarting())
148
+ return false;
149
+ let waitTask;
150
+ let iv;
151
+ const sensor = this.getComms();
152
+ const wait = () => {
153
+ const res = new Promise((resolve) => {
154
+ iv = setInterval(() => __awaiter(this, void 0, void 0, function* () {
155
+ if (!this.isStarting() || !(waitTask === null || waitTask === void 0 ? void 0 : waitTask.isRunning)) {
156
+ resolve(false);
157
+ clearInterval(iv);
158
+ return;
163
159
  }
164
- let hasControl = yield comms.requestControl();
165
- if (!hasControl) {
166
- let retry = 1;
167
- while (!hasControl && retry < 3) {
168
- yield (0, utils_1.sleep)(1000);
169
- hasControl = yield comms.requestControl();
170
- retry++;
171
- }
160
+ const hasControl = yield sensor.requestControl();
161
+ if (hasControl) {
162
+ clearInterval(iv);
163
+ resolve(true);
172
164
  }
173
- if (!hasControl)
174
- throw new Error('could not establish control');
175
- const startRequest = this.getCyclingMode().getBikeInitRequest();
176
- yield this.sendUpdate(startRequest, true);
177
- }
178
- if (!this.started && !wasPaused) {
179
- comms.on('data', (data) => {
180
- this.onDeviceData(data);
181
- });
182
- comms.on('disconnected', this.emit);
183
- }
184
- const before = this.capabilities.join(',');
185
- if (comms.features.heartrate && !this.hasCapability(types_1.IncyclistCapability.HeartRate)) {
186
- this.capabilities.push(types_1.IncyclistCapability.HeartRate);
187
- }
188
- if (comms.features.cadence && !this.hasCapability(types_1.IncyclistCapability.Cadence)) {
189
- this.capabilities.push(types_1.IncyclistCapability.Cadence);
190
- }
191
- if (comms.features.power && !this.hasCapability(types_1.IncyclistCapability.Power)) {
192
- this.capabilities.push(types_1.IncyclistCapability.Power);
193
- }
194
- const after = this.capabilities.join(',');
195
- if (before !== after) {
196
- this.emit('device-info', this.getSettings(), { capabilities: this.capabilities });
197
- }
198
- this.resetData();
199
- this.stopped = false;
200
- this.started = true;
201
- this.resume();
202
- return true;
203
- }
204
- }
205
- catch (err) {
206
- this.logEvent({ message: 'start result: error', error: err.message, profile: this.getProfile() });
207
- throw new Error(`could not start device, reason:${err.message}`);
208
- }
165
+ else if (!this.isStarting() || !(waitTask === null || waitTask === void 0 ? void 0 : waitTask.isRunning)) {
166
+ resolve(false);
167
+ clearInterval(iv);
168
+ }
169
+ }), 1000);
170
+ });
171
+ return res;
172
+ };
173
+ waitTask = new task_1.InteruptableTask(wait(), {
174
+ errorOnTimeout: false,
175
+ timeout: 10000
176
+ });
177
+ const hasControl = yield waitTask.run();
178
+ clearInterval(iv);
179
+ if (!hasControl && this.isStarting())
180
+ throw new Error('could not establish control');
209
181
  });
210
182
  }
183
+ sendInitialRequest() {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ const startRequest = this.getCyclingMode().getBikeInitRequest();
186
+ yield this.sendUpdate(startRequest, true);
187
+ });
188
+ }
189
+ checkCapabilities() {
190
+ var _a, _b, _c;
191
+ const before = this.capabilities.join(',');
192
+ const sensor = this.getComms();
193
+ if (((_a = sensor.features) === null || _a === void 0 ? void 0 : _a.heartrate) && !this.hasCapability(types_1.IncyclistCapability.HeartRate)) {
194
+ this.capabilities.push(types_1.IncyclistCapability.HeartRate);
195
+ }
196
+ if (((_b = sensor.features) === null || _b === void 0 ? void 0 : _b.cadence) && !this.hasCapability(types_1.IncyclistCapability.Cadence)) {
197
+ this.capabilities.push(types_1.IncyclistCapability.Cadence);
198
+ }
199
+ if (((_c = sensor.features) === null || _c === void 0 ? void 0 : _c.power) && !this.hasCapability(types_1.IncyclistCapability.Power)) {
200
+ this.capabilities.push(types_1.IncyclistCapability.Power);
201
+ }
202
+ const after = this.capabilities.join(',');
203
+ if (before !== after) {
204
+ this.emit('device-info', this.getSettings(), { capabilities: this.capabilities });
205
+ }
206
+ }
211
207
  sendUpdate(request_1) {
212
208
  return __awaiter(this, arguments, void 0, function* (request, enforced = false) {
213
209
  if (!enforced && (this.paused || !this.device))
@@ -1,6 +1,6 @@
1
1
  import { BleProtocol, BleWriteProps, IBlePeripheralConnector } from "../types";
2
2
  import { IndoorBikeData, IndoorBikeFeatures } from "./types";
3
- import { BleComms } from "../base/comms";
3
+ import { BleComms } from "../base/sensor";
4
4
  import { LegacyProfile } from "../../antv2/types";
5
5
  export default class BleFitnessMachineDevice extends BleComms {
6
6
  static protocol: BleProtocol;
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const consts_1 = require("../consts");
13
- const comms_1 = require("../base/comms");
13
+ const sensor_1 = require("../base/sensor");
14
14
  const utils_1 = require("../utils");
15
15
  const bit = (nr) => (1 << nr);
16
16
  const IndoorBikeDataFlag = {
@@ -66,7 +66,7 @@ const TargetSettingFeatureFlag = {
66
66
  SpinDownControlSupported: bit(15),
67
67
  TargetedCadenceConfigurationSupported: bit(16)
68
68
  };
69
- class BleFitnessMachineDevice extends comms_1.BleComms {
69
+ class BleFitnessMachineDevice extends sensor_1.BleComms {
70
70
  constructor(props) {
71
71
  super(props);
72
72
  this.features = undefined;
@@ -92,7 +92,7 @@ class BleFitnessMachineDevice extends comms_1.BleComms {
92
92
  subscribeWriteResponse(cuuid) {
93
93
  return __awaiter(this, void 0, void 0, function* () {
94
94
  this.logEvent({ message: 'subscribe to CP response', characteristics: cuuid });
95
- const connector = this.ble.peripheralCache.getConnector(this.peripheral);
95
+ const connector = this.getPeripheral();
96
96
  const isAlreadySubscribed = connector.isSubscribed(cuuid);
97
97
  if (!isAlreadySubscribed) {
98
98
  connector.removeAllListeners(cuuid);
@@ -4,3 +4,96 @@ export declare const cwABike: {
4
4
  mountain: number;
5
5
  };
6
6
  export declare const cRR = 0.0036;
7
+ export declare const enum OpCode {
8
+ RequestControl = 0,
9
+ Reset = 1,
10
+ SetTargetSpeed = 2,
11
+ SetTargetInclination = 3,
12
+ SetTargetResistance = 4,
13
+ SetTargetPower = 5,
14
+ SetTargetHeartRate = 6,
15
+ StartOrResume = 7,
16
+ StopOrPause = 8,
17
+ SetIndoorBikeSimulation = 17,
18
+ SetWheelCircumference = 18,
19
+ SpinDownControl = 19,
20
+ SetTargetedCadence = 20,
21
+ ResponseCode = 128
22
+ }
23
+ export declare const enum FitnessMachineStatusOpCode {
24
+ Reset = 1,
25
+ FitnessMachineStoppedOrPaused = 2,
26
+ FitnessMachineStoppedBySafetyKey = 3,
27
+ FitnessMachineStartedOrResumed = 4,
28
+ TargetSpeedChanged = 5,
29
+ TargetInclineChanged = 6,
30
+ TargetResistanceLevelChanged = 7,
31
+ TargetPowerChanged = 8,
32
+ TargetHeartRateChanged = 9,
33
+ TargetExpendedEnergyChanged = 10,
34
+ IndoorBikeSimulationParametersChanged = 18,
35
+ WheelCircumferenceChanged = 19,
36
+ SpinDownStatus = 20,
37
+ TargetedCadenceChanged = 21,
38
+ ControlPermissionLost = 255
39
+ }
40
+ export declare const enum OpCodeResut {
41
+ Success = 1,
42
+ OpCodeNotSupported = 2,
43
+ InvalidParameter = 3,
44
+ OperationFailed = 4,
45
+ ControlNotPermitted = 5
46
+ }
47
+ export declare const IndoorBikeDataFlag: {
48
+ MoreData: number;
49
+ AverageSpeedPresent: number;
50
+ InstantaneousCadence: number;
51
+ AverageCadencePresent: number;
52
+ TotalDistancePresent: number;
53
+ ResistanceLevelPresent: number;
54
+ InstantaneousPowerPresent: number;
55
+ AveragePowerPresent: number;
56
+ ExpendedEnergyPresent: number;
57
+ HeartRatePresent: number;
58
+ MetabolicEquivalentPresent: number;
59
+ ElapsedTimePresent: number;
60
+ RemainingTimePresent: number;
61
+ };
62
+ export declare const FitnessMachineFeatureFlag: {
63
+ AverageSpeedSupported: number;
64
+ CadenceSupported: number;
65
+ TotalDistanceSupported: number;
66
+ InclinationSupported: number;
67
+ ElevationGainSupported: number;
68
+ PaceSupported: number;
69
+ StepCountSupported: number;
70
+ ResistanceLevelSupported: number;
71
+ StrideCountSupported: number;
72
+ ExpendedEnergySupported: number;
73
+ HeartRateMeasurementSupported: number;
74
+ MetabolicEquivalentSupported: number;
75
+ ElapsedTimeSupported: number;
76
+ RemainingTimeSupported: number;
77
+ PowerMeasurementSupported: number;
78
+ ForceOnBeltAndPowerOutputSupported: number;
79
+ UserDataRetentionSupported: number;
80
+ };
81
+ export declare const TargetSettingFeatureFlag: {
82
+ SpeedTargetSettingSupported: number;
83
+ InclinationTargetSettingSupported: number;
84
+ ResistanceTargetSettingSupported: number;
85
+ PowerTargetSettingSupported: number;
86
+ HeartRateTargetSettingSupported: number;
87
+ TargetedExpendedEnergyConfigurationSupported: number;
88
+ TargetedStepNumberConfigurationSupported: number;
89
+ TargetedStrideNumberConfigurationSupported: number;
90
+ TargetedDistanceConfigurationSupported: number;
91
+ TargetedTrainingTimeConfigurationSupported: number;
92
+ TargetedTimeInTwoHeartRateZonesConfigurationSupported: number;
93
+ TargetedTimeInThreeHeartRateZonesConfigurationSupported: number;
94
+ TargetedTimeInFiveHeartRateZonesConfigurationSupported: number;
95
+ IndoorBikeSimulationParametersSupported: number;
96
+ WheelCircumferenceConfigurationSupported: number;
97
+ SpinDownControlSupported: number;
98
+ TargetedCadenceConfigurationSupported: number;
99
+ };
@@ -1,9 +1,63 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cRR = exports.cwABike = void 0;
3
+ exports.TargetSettingFeatureFlag = exports.FitnessMachineFeatureFlag = exports.IndoorBikeDataFlag = exports.cRR = exports.cwABike = void 0;
4
4
  exports.cwABike = {
5
5
  race: 0.35,
6
6
  triathlon: 0.29,
7
7
  mountain: 0.57
8
8
  };
9
9
  exports.cRR = 0.0036;
10
+ const bit = (nr) => (1 << nr);
11
+ exports.IndoorBikeDataFlag = {
12
+ MoreData: bit(0),
13
+ AverageSpeedPresent: bit(1),
14
+ InstantaneousCadence: bit(2),
15
+ AverageCadencePresent: bit(3),
16
+ TotalDistancePresent: bit(4),
17
+ ResistanceLevelPresent: bit(5),
18
+ InstantaneousPowerPresent: bit(6),
19
+ AveragePowerPresent: bit(7),
20
+ ExpendedEnergyPresent: bit(8),
21
+ HeartRatePresent: bit(9),
22
+ MetabolicEquivalentPresent: bit(10),
23
+ ElapsedTimePresent: bit(11),
24
+ RemainingTimePresent: bit(12)
25
+ };
26
+ exports.FitnessMachineFeatureFlag = {
27
+ AverageSpeedSupported: bit(0),
28
+ CadenceSupported: bit(1),
29
+ TotalDistanceSupported: bit(2),
30
+ InclinationSupported: bit(3),
31
+ ElevationGainSupported: bit(4),
32
+ PaceSupported: bit(5),
33
+ StepCountSupported: bit(6),
34
+ ResistanceLevelSupported: bit(7),
35
+ StrideCountSupported: bit(8),
36
+ ExpendedEnergySupported: bit(9),
37
+ HeartRateMeasurementSupported: bit(10),
38
+ MetabolicEquivalentSupported: bit(11),
39
+ ElapsedTimeSupported: bit(12),
40
+ RemainingTimeSupported: bit(13),
41
+ PowerMeasurementSupported: bit(14),
42
+ ForceOnBeltAndPowerOutputSupported: bit(15),
43
+ UserDataRetentionSupported: bit(16)
44
+ };
45
+ exports.TargetSettingFeatureFlag = {
46
+ SpeedTargetSettingSupported: bit(0),
47
+ InclinationTargetSettingSupported: bit(1),
48
+ ResistanceTargetSettingSupported: bit(2),
49
+ PowerTargetSettingSupported: bit(3),
50
+ HeartRateTargetSettingSupported: bit(4),
51
+ TargetedExpendedEnergyConfigurationSupported: bit(5),
52
+ TargetedStepNumberConfigurationSupported: bit(6),
53
+ TargetedStrideNumberConfigurationSupported: bit(7),
54
+ TargetedDistanceConfigurationSupported: bit(8),
55
+ TargetedTrainingTimeConfigurationSupported: bit(9),
56
+ TargetedTimeInTwoHeartRateZonesConfigurationSupported: bit(10),
57
+ TargetedTimeInThreeHeartRateZonesConfigurationSupported: bit(11),
58
+ TargetedTimeInFiveHeartRateZonesConfigurationSupported: bit(12),
59
+ IndoorBikeSimulationParametersSupported: bit(13),
60
+ WheelCircumferenceConfigurationSupported: bit(14),
61
+ SpinDownControlSupported: bit(15),
62
+ TargetedCadenceConfigurationSupported: bit(16)
63
+ };
@@ -1,4 +1,4 @@
1
- import BleFmComms from './comms';
1
+ import BleFmComms from './sensor';
2
2
  import BleFmAdapter from './adapter';
3
3
  import { IndoorBikeData } from './types';
4
4
  import { cRR, cwABike } from './consts';
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.cwABike = exports.cRR = exports.BleFmComms = exports.BleFmAdapter = void 0;
7
- const comms_1 = __importDefault(require("./comms"));
8
- exports.BleFmComms = comms_1.default;
7
+ const sensor_1 = __importDefault(require("./sensor"));
8
+ exports.BleFmComms = sensor_1.default;
9
9
  const adapter_1 = __importDefault(require("./adapter"));
10
10
  exports.BleFmAdapter = adapter_1.default;
11
11
  const consts_1 = require("./consts");
@@ -0,0 +1,44 @@
1
+ import { LegacyProfile } from "../../antv2/types";
2
+ import { BleProtocol, BleWriteProps } from "../types";
3
+ import { IndoorBikeData, IndoorBikeFeatures } from "./types";
4
+ import { TBleSensor } from "../base/sensor";
5
+ export default class BleFitnessMachineDevice extends TBleSensor {
6
+ static readonly profile: LegacyProfile;
7
+ static readonly protocol: BleProtocol;
8
+ static readonly services: string[];
9
+ static readonly characteristics: string[];
10
+ static readonly detectionPriority: number;
11
+ protected data: IndoorBikeData;
12
+ protected _features: IndoorBikeFeatures;
13
+ protected hasControl: boolean;
14
+ protected isCheckingControl: boolean;
15
+ protected isCPSubscribed: boolean;
16
+ protected crr: number;
17
+ protected cw: number;
18
+ protected windSpeed: number;
19
+ protected wheelSize: number;
20
+ constructor(peripheral: any, props?: any);
21
+ get features(): IndoorBikeFeatures;
22
+ reset(): void;
23
+ protected getRequiredCharacteristics(): Array<string>;
24
+ onData(characteristic: string, data: Buffer): boolean;
25
+ setCrr(crr: number): void;
26
+ getCrr(): number;
27
+ setCw(cw: number): void;
28
+ getCw(): number;
29
+ setWindSpeed(windSpeed: number): void;
30
+ getWindSpeed(): number;
31
+ requestControl(): Promise<boolean>;
32
+ setTargetPower(power: number): Promise<boolean>;
33
+ setSlope(slope: any): Promise<boolean>;
34
+ protected parseHrm(_data: Uint8Array): IndoorBikeData;
35
+ protected parseIndoorBikeData(_data: Uint8Array): IndoorBikeData;
36
+ protected parseFitnessMachineStatus(_data: Uint8Array): IndoorBikeData;
37
+ protected getFitnessMachineFeatures(): Promise<IndoorBikeFeatures | undefined>;
38
+ protected writeFtmsMessage(requestedOpCode: any, data: any, props?: BleWriteProps): Promise<number>;
39
+ setTargetInclination(inclination: number): Promise<boolean>;
40
+ setIndoorBikeSimulation(windSpeed: number, gradient: number, crr: number, cw: number): Promise<boolean>;
41
+ startRequest(): Promise<boolean>;
42
+ stopRequest(): Promise<boolean>;
43
+ PauseRequest(): Promise<boolean>;
44
+ }