incyclist-services 1.3.35 → 1.3.36
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.
- package/lib/activities/base/repo/db.d.ts +1 -1
- package/lib/activities/base/repo/db.js +2 -2
- package/lib/devices/configuration/model/service/index.d.ts +2 -0
- package/lib/devices/configuration/service.js +7 -2
- package/lib/devices/ride/service.d.ts +4 -0
- package/lib/devices/ride/service.js +43 -2
- package/lib/workouts/ride/service.d.ts +2 -0
- package/lib/workouts/ride/service.js +17 -0
- package/package.json +5 -5
|
@@ -49,6 +49,6 @@ export declare class ActivitiesRepository {
|
|
|
49
49
|
protected scanForNewActivities(): Promise<Array<string> | null>;
|
|
50
50
|
protected _load(): Promise<void>;
|
|
51
51
|
protected getActivity(id: string): ActivityInfo;
|
|
52
|
-
protected logError(
|
|
52
|
+
protected logError(err: Error, fn: string, logProps?: any): void;
|
|
53
53
|
protected getRepo(): JsonRepository;
|
|
54
54
|
}
|
|
@@ -416,9 +416,9 @@ let ActivitiesRepository = (() => {
|
|
|
416
416
|
getActivity(id) {
|
|
417
417
|
return this.activities.find(ai => ai.summary.id === id);
|
|
418
418
|
}
|
|
419
|
-
logError(
|
|
419
|
+
logError(err, fn, logProps) {
|
|
420
420
|
const props = logProps !== null && logProps !== void 0 ? logProps : {};
|
|
421
|
-
this.logger.logEvent(Object.assign({ message: 'error',
|
|
421
|
+
this.logger.logEvent(Object.assign(Object.assign({ message: 'error', fn, error: err.message }, props), { stack: err.stack }));
|
|
422
422
|
}
|
|
423
423
|
getRepo() {
|
|
424
424
|
if (!this.repo)
|
|
@@ -544,7 +544,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
544
544
|
const device = devices.find(d => d.udid === udid);
|
|
545
545
|
if (!device)
|
|
546
546
|
return;
|
|
547
|
-
let mode, modes, settings;
|
|
547
|
+
let mode, modes, settings, isERG, isSIM;
|
|
548
548
|
let modeObj;
|
|
549
549
|
const adapter = incyclist_devices_1.AdapterFactory.create(device.settings);
|
|
550
550
|
if (!adapter) {
|
|
@@ -563,7 +563,12 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
563
563
|
if (!settings && modeObj) {
|
|
564
564
|
settings = modeObj.getSettings();
|
|
565
565
|
}
|
|
566
|
-
|
|
566
|
+
const options = modes.map(M => new M(adapter));
|
|
567
|
+
if (options === null || options === void 0 ? void 0 : options.length) {
|
|
568
|
+
isERG = options[0].isERG();
|
|
569
|
+
isSIM = options[0].isSIM();
|
|
570
|
+
}
|
|
571
|
+
return { udid, mode, settings, isERG, isSIM, options };
|
|
567
572
|
}
|
|
568
573
|
catch (err) {
|
|
569
574
|
this.logError(err, 'getModeSettings()');
|
|
@@ -18,6 +18,7 @@ export declare class DeviceRideService extends EventEmitter {
|
|
|
18
18
|
protected logger: EventLogger;
|
|
19
19
|
protected debug: any;
|
|
20
20
|
protected promiseSendUpdate: Promise<UpdateRequest | void>[];
|
|
21
|
+
protected originalMode: CyclingMode;
|
|
21
22
|
protected deviceDataHandler: any;
|
|
22
23
|
static getInstance(): DeviceRideService;
|
|
23
24
|
constructor();
|
|
@@ -66,7 +67,10 @@ export declare class DeviceRideService extends EventEmitter {
|
|
|
66
67
|
waitForUpdateFinish(): Promise<void>;
|
|
67
68
|
sendUpdate(request: UpdateRequest): Promise<void>;
|
|
68
69
|
getCyclingMode(udid?: string): CyclingMode;
|
|
70
|
+
isToggleEnabled(): boolean;
|
|
71
|
+
toggleCyclingMode(): Promise<void>;
|
|
69
72
|
resetCyclingMode(sendInit?: boolean): Promise<void>;
|
|
73
|
+
private getControlAdapter;
|
|
70
74
|
enforceERG(): Promise<void>;
|
|
71
75
|
onCyclingModeChanged(udid: string, mode: string, settings: any): Promise<void>;
|
|
72
76
|
onDeviceDeleted(settings: IncyclistDeviceSettings): void;
|
|
@@ -691,12 +691,15 @@ class DeviceRideService extends events_1.default {
|
|
|
691
691
|
}
|
|
692
692
|
start(props) {
|
|
693
693
|
return __awaiter(this, void 0, void 0, function* () {
|
|
694
|
+
var _a;
|
|
694
695
|
yield this.lazyInit();
|
|
695
696
|
const adapters = this.getAdapterList();
|
|
696
697
|
this.emit('start-request', adapters === null || adapters === void 0 ? void 0 : adapters.map(this.getAdapterStateInfo));
|
|
697
698
|
const goodToGo = yield this.waitForPreviousStartToFinish();
|
|
698
699
|
if (!goodToGo)
|
|
699
700
|
return;
|
|
701
|
+
const { adapter } = (_a = this.getControlAdapter()) !== null && _a !== void 0 ? _a : {};
|
|
702
|
+
this.originalMode = adapter.getCyclingMode();
|
|
700
703
|
return this.startAdapters(adapters, 'start', props);
|
|
701
704
|
});
|
|
702
705
|
}
|
|
@@ -916,11 +919,44 @@ class DeviceRideService extends events_1.default {
|
|
|
916
919
|
if (adapter)
|
|
917
920
|
return adapter.getCyclingMode();
|
|
918
921
|
}
|
|
922
|
+
isToggleEnabled() {
|
|
923
|
+
var _a;
|
|
924
|
+
const { adapter, udid } = (_a = this.getControlAdapter()) !== null && _a !== void 0 ? _a : {};
|
|
925
|
+
if (!adapter)
|
|
926
|
+
return false;
|
|
927
|
+
const settings = (0, configuration_1.useDeviceConfiguration)().getModeSettings(udid);
|
|
928
|
+
return settings === null || settings === void 0 ? void 0 : settings.isSIM;
|
|
929
|
+
}
|
|
930
|
+
toggleCyclingMode() {
|
|
931
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
932
|
+
var _a, _b;
|
|
933
|
+
if (!this.isToggleEnabled())
|
|
934
|
+
return;
|
|
935
|
+
const { adapter } = (_a = this.getControlAdapter()) !== null && _a !== void 0 ? _a : {};
|
|
936
|
+
if (!adapter)
|
|
937
|
+
return;
|
|
938
|
+
const ergRide = ((_b = this.originalMode) === null || _b === void 0 ? void 0 : _b.isERG());
|
|
939
|
+
const targetMode = ergRide ? adapter.getDefaultCyclingMode() : this.originalMode;
|
|
940
|
+
const currentMode = adapter.getCyclingMode();
|
|
941
|
+
if (!currentMode)
|
|
942
|
+
return;
|
|
943
|
+
if (!currentMode.isERG()) {
|
|
944
|
+
const power = adapter.getData().power;
|
|
945
|
+
this.enforceERG();
|
|
946
|
+
adapter.sendUpdate({ targetPower: power });
|
|
947
|
+
}
|
|
948
|
+
else {
|
|
949
|
+
const slope = adapter.getData().slope;
|
|
950
|
+
adapter.setCyclingMode(targetMode);
|
|
951
|
+
this.resetCyclingMode(false);
|
|
952
|
+
adapter.sendUpdate({ slope });
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
}
|
|
919
956
|
resetCyclingMode() {
|
|
920
957
|
return __awaiter(this, arguments, void 0, function* (sendInit = false) {
|
|
921
958
|
try {
|
|
922
|
-
const
|
|
923
|
-
const adapterInfo = adapters === null || adapters === void 0 ? void 0 : adapters.find(ai => ai.adapter.hasCapability(incyclist_devices_1.IncyclistCapability.Control));
|
|
959
|
+
const adapterInfo = this.getControlAdapter();
|
|
924
960
|
if (!(adapterInfo === null || adapterInfo === void 0 ? void 0 : adapterInfo.adapter))
|
|
925
961
|
return;
|
|
926
962
|
const { udid, adapter } = adapterInfo;
|
|
@@ -939,6 +975,11 @@ class DeviceRideService extends events_1.default {
|
|
|
939
975
|
}
|
|
940
976
|
});
|
|
941
977
|
}
|
|
978
|
+
getControlAdapter() {
|
|
979
|
+
const adapters = this.getAdapterList();
|
|
980
|
+
const adapterInfo = adapters === null || adapters === void 0 ? void 0 : adapters.find(ai => ai.adapter.hasCapability(incyclist_devices_1.IncyclistCapability.Control));
|
|
981
|
+
return adapterInfo;
|
|
982
|
+
}
|
|
942
983
|
enforceERG() {
|
|
943
984
|
return __awaiter(this, void 0, void 0, function* () {
|
|
944
985
|
try {
|
|
@@ -31,6 +31,7 @@ export declare class WorkoutRide extends IncyclistService {
|
|
|
31
31
|
backward(): void;
|
|
32
32
|
powerUp(delta: number): void;
|
|
33
33
|
powerDown(delta: number): void;
|
|
34
|
+
toggleCyclingMode(): void;
|
|
34
35
|
getDashboardDisplayProperties(): WorkoutDisplayProperties;
|
|
35
36
|
getCurrentLimits(): ActiveWorkoutLimit;
|
|
36
37
|
inUse(): boolean;
|
|
@@ -56,6 +57,7 @@ export declare class WorkoutRide extends IncyclistService {
|
|
|
56
57
|
protected resetWorkout(): void;
|
|
57
58
|
emit(eventName: string, ...args: any[]): boolean;
|
|
58
59
|
protected stopWorker(): void;
|
|
60
|
+
protected getCyclingModeText(): string;
|
|
59
61
|
}
|
|
60
62
|
export declare const useWorkoutRide: () => WorkoutRide;
|
|
61
63
|
export declare const getWorkoutRide: () => WorkoutRide;
|
|
@@ -250,6 +250,11 @@ let WorkoutRide = (() => {
|
|
|
250
250
|
this.logError(err, 'powerDown');
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
|
+
toggleCyclingMode() {
|
|
254
|
+
const deviceRide = (0, devices_1.useDeviceRide)();
|
|
255
|
+
deviceRide.toggleCyclingMode();
|
|
256
|
+
this.emit('update', this.getDashboardDisplayProperties());
|
|
257
|
+
}
|
|
253
258
|
getDashboardDisplayProperties() {
|
|
254
259
|
var _a;
|
|
255
260
|
try {
|
|
@@ -264,6 +269,7 @@ let WorkoutRide = (() => {
|
|
|
264
269
|
ftp: this.settings.ftp,
|
|
265
270
|
current: this.currentLimits,
|
|
266
271
|
start, stop,
|
|
272
|
+
mode: this.getCyclingModeText(),
|
|
267
273
|
canShowBackward,
|
|
268
274
|
canShowForward: true
|
|
269
275
|
};
|
|
@@ -495,6 +501,17 @@ let WorkoutRide = (() => {
|
|
|
495
501
|
this.updateInterval = undefined;
|
|
496
502
|
}
|
|
497
503
|
}
|
|
504
|
+
getCyclingModeText() {
|
|
505
|
+
const deviceRide = (0, devices_1.useDeviceRide)();
|
|
506
|
+
const mode = deviceRide.getCyclingMode();
|
|
507
|
+
const enabled = deviceRide.isToggleEnabled();
|
|
508
|
+
if (!mode || !enabled)
|
|
509
|
+
return;
|
|
510
|
+
if (mode.isERG())
|
|
511
|
+
return 'SIM';
|
|
512
|
+
if (mode.isSIM())
|
|
513
|
+
return 'ERG';
|
|
514
|
+
}
|
|
498
515
|
};
|
|
499
516
|
__setFunctionName(_classThis, "WorkoutRide");
|
|
500
517
|
(() => {
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "incyclist-services",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.36",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"gd-eventlog": "^0.1.26"
|
|
6
6
|
},
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"@types/jest": "^29.5.14",
|
|
9
9
|
"@types/node": "^22.9.0",
|
|
10
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
11
|
-
"@typescript-eslint/parser": "^8.
|
|
10
|
+
"@typescript-eslint/eslint-plugin": "^8.13.0",
|
|
11
|
+
"@typescript-eslint/parser": "^8.13.0",
|
|
12
12
|
"dotenv": "^16.4.5",
|
|
13
|
-
"eslint": "^9.
|
|
13
|
+
"eslint": "^9.14.0",
|
|
14
14
|
"formdata-node": "^6.0.3",
|
|
15
15
|
"jest": "^29.7.0",
|
|
16
16
|
"jsdoc": "^4.0.4",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"axios": "^1.7.7",
|
|
45
|
-
"incyclist-devices": "^2.2.
|
|
45
|
+
"incyclist-devices": "^2.2.7",
|
|
46
46
|
"promise.any": "^2.0.6",
|
|
47
47
|
"semver": "^7.6.3",
|
|
48
48
|
"tcx-builder": "^1.1.1",
|