incyclist-devices 3.0.21 → 3.0.22

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.
@@ -5,10 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const adapter_js_1 = __importDefault(require("../base/adapter.js"));
7
7
  const index_js_1 = require("../../types/index.js");
8
+ const speed_js_1 = __importDefault(require("../../modes/speed.js"));
8
9
  class AntSpdAdapter extends adapter_js_1.default {
9
10
  static INCYCLIST_PROFILE_NAME = 'Speed + Cadence Sensor';
10
11
  static ANT_PROFILE_NAME = 'SC';
11
12
  static CAPABILITIES = [index_js_1.IncyclistCapability.Speed, index_js_1.IncyclistCapability.Cadence];
13
+ static controllers = {
14
+ modes: [speed_js_1.default],
15
+ default: speed_js_1.default
16
+ };
12
17
  mapToAdapterData(deviceData) {
13
18
  if (deviceData.CalculatedSpeed !== undefined) {
14
19
  this.data.speed = deviceData.CalculatedSpeed * 3.6;
@@ -22,9 +27,45 @@ class AntSpdAdapter extends adapter_js_1.default {
22
27
  this.data.timestamp = Date.now();
23
28
  }
24
29
  }
30
+ mapData(deviceData) {
31
+ const data = {
32
+ isPedalling: false,
33
+ power: 0,
34
+ pedalRpm: 0,
35
+ speed: 0
36
+ };
37
+ data.pedalRpm = (deviceData.CalculatedCadence !== undefined ? deviceData.CalculatedCadence : data.pedalRpm);
38
+ data.speed = (deviceData.CalculatedSpeed !== undefined ? deviceData.CalculatedSpeed * 3.6 : data.speed);
39
+ data.time = (deviceData.SpeedEventTime !== undefined ? deviceData.SpeedEventTime : data.time);
40
+ data.isPedalling = (data.pedalRpm ?? 0) > 0 || data.speed > 0;
41
+ return data;
42
+ }
43
+ transformData(bikeData) {
44
+ if (bikeData === undefined)
45
+ return {};
46
+ let data = {
47
+ speed: bikeData.speed,
48
+ power: bikeData.power,
49
+ cadence: bikeData.pedalRpm,
50
+ timestamp: Date.now()
51
+ };
52
+ if (bikeData.time)
53
+ data.deviceTime = bikeData.time;
54
+ this.data = data;
55
+ return data;
56
+ }
25
57
  hasData() {
26
58
  return ((this.deviceData.CalculatedSpeed !== undefined && this.deviceData.CalculatedSpeed !== null) ||
27
59
  (this.deviceData.CalculatedCadence !== undefined && this.deviceData.CalculatedCadence !== null));
28
60
  }
61
+ setCyclingMode(mode, settings, sendInitCommands) {
62
+ super.setCyclingMode(mode, settings, sendInitCommands);
63
+ try {
64
+ const sensor = this.sensor;
65
+ const wc = this.getCyclingMode().getSetting('wc');
66
+ sensor.setWheelCircumference(wc / 1000);
67
+ }
68
+ catch { }
69
+ }
29
70
  }
30
71
  exports.default = AntSpdAdapter;
@@ -5,10 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const adapter_js_1 = __importDefault(require("../base/adapter.js"));
7
7
  const index_js_1 = require("../../types/index.js");
8
+ const speed_js_1 = __importDefault(require("../../modes/speed.js"));
8
9
  class AntSpdAdapter extends adapter_js_1.default {
9
10
  static INCYCLIST_PROFILE_NAME = 'Speed Sensor';
10
11
  static ANT_PROFILE_NAME = 'SPD';
11
12
  static CAPABILITIES = [index_js_1.IncyclistCapability.Speed];
13
+ static controllers = {
14
+ modes: [speed_js_1.default],
15
+ default: speed_js_1.default
16
+ };
12
17
  mapToAdapterData(deviceData) {
13
18
  if (deviceData.CalculatedSpeed !== undefined) {
14
19
  this.data.speed = deviceData.CalculatedSpeed * 3.6;
@@ -18,8 +23,42 @@ class AntSpdAdapter extends adapter_js_1.default {
18
23
  this.data.deviceDistanceCounter = deviceData.CalculatedDistance;
19
24
  }
20
25
  }
26
+ mapData(deviceData) {
27
+ const data = {
28
+ isPedalling: false,
29
+ power: 0,
30
+ pedalRpm: 0,
31
+ speed: 0
32
+ };
33
+ data.speed = (deviceData.CalculatedSpeed !== undefined ? deviceData.CalculatedSpeed * 3.6 : data.speed);
34
+ data.time = (deviceData.SpeedEventTime !== undefined ? deviceData.SpeedEventTime : data.time);
35
+ data.isPedalling = data.speed > 0;
36
+ return data;
37
+ }
38
+ transformData(bikeData) {
39
+ if (bikeData === undefined)
40
+ return {};
41
+ let data = {
42
+ speed: bikeData.speed,
43
+ power: bikeData.power,
44
+ timestamp: Date.now()
45
+ };
46
+ if (bikeData.time)
47
+ data.deviceTime = bikeData.time;
48
+ this.data = data;
49
+ return data;
50
+ }
21
51
  hasData() {
22
52
  return this.deviceData.CalculatedSpeed !== undefined && this.deviceData.CalculatedSpeed !== null;
23
53
  }
54
+ setCyclingMode(mode, settings, sendInitCommands) {
55
+ super.setCyclingMode(mode, settings, sendInitCommands);
56
+ try {
57
+ const sensor = this.sensor;
58
+ const wc = this.getCyclingMode().getSetting('wc');
59
+ sensor.setWheelCircumference(wc / 1000);
60
+ }
61
+ catch { }
62
+ }
24
63
  }
25
64
  exports.default = AntSpdAdapter;
@@ -58,7 +58,7 @@ class BleCSCAdapter extends adapter_js_1.default {
58
58
  }
59
59
  transformData(bikeData) {
60
60
  if (bikeData === undefined)
61
- return;
61
+ return {};
62
62
  let data = {
63
63
  speed: bikeData.speed,
64
64
  power: bikeData.power,
@@ -49,6 +49,8 @@ function getCharachteristicsInfo(c) {
49
49
  return `${serviceStr}${uuid}${nameStr} ${properties}`;
50
50
  }
51
51
  const parseUUID = (str) => {
52
+ if (!str)
53
+ return str;
52
54
  const uuid = str.toUpperCase();
53
55
  if (str.startsWith('0x')) {
54
56
  const hex = uuid.slice(2);
@@ -105,6 +107,8 @@ const beautifyUUID = (str, withX = false) => {
105
107
  };
106
108
  exports.beautifyUUID = beautifyUUID;
107
109
  const fullUUID = (str) => {
110
+ if (!str)
111
+ return str;
108
112
  const uuid = (0, exports.parseUUID)(str);
109
113
  const parts = [
110
114
  uuid.substring(0, 8),
@@ -3,11 +3,11 @@ 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 base_1 = require("./base");
7
- const types_1 = require("./types");
6
+ const base_js_1 = require("./base.js");
7
+ const types_js_1 = require("./types.js");
8
8
  const calculations_js_1 = __importDefault(require("../utils/calculations.js"));
9
9
  const consts_js_1 = require("../base/consts.js");
10
- class SpeedCyclingMode extends base_1.CyclingModeBase {
10
+ class SpeedCyclingMode extends base_js_1.CyclingModeBase {
11
11
  data;
12
12
  prevUpdateTS = 0;
13
13
  prevRequest;
@@ -15,8 +15,8 @@ class SpeedCyclingMode extends base_1.CyclingModeBase {
15
15
  name: "SpeedSensor",
16
16
  description: "Calculates power based on speed and slope.",
17
17
  properties: [
18
- { key: 'bikeType', name: 'Bike Type', description: '', type: types_1.CyclingModeProperyType.SingleSelect, options: ['Race', 'Mountain', 'Triathlon'], default: 'Race' },
19
- { key: 'wc', name: 'Wheel Circumference', description: 'Circumference in mm', type: types_1.CyclingModeProperyType.Integer, default: Math.ceil(consts_js_1.DEFAULT_WHEEL_CIRCUMFERENCE * 1000) },
18
+ { key: 'bikeType', name: 'Bike Type', description: '', type: types_js_1.CyclingModeProperyType.SingleSelect, options: ['Race', 'Mountain', 'Triathlon'], default: 'Race' },
19
+ { key: 'wc', name: 'Wheel Circumference', description: 'Circumference in mm', type: types_js_1.CyclingModeProperyType.Integer, default: Math.ceil(consts_js_1.DEFAULT_WHEEL_CIRCUMFERENCE * 1000) },
20
20
  ]
21
21
  };
22
22
  constructor(adapter, props) {
@@ -1,9 +1,14 @@
1
1
  import AntAdapter from "../base/adapter.js";
2
2
  import { IncyclistCapability } from "../../types/index.js";
3
+ import SpeedCyclingMode from "../../modes/speed.js";
3
4
  export default class AntSpdAdapter extends AntAdapter {
4
5
  static INCYCLIST_PROFILE_NAME = 'Speed + Cadence Sensor';
5
6
  static ANT_PROFILE_NAME = 'SC';
6
7
  static CAPABILITIES = [IncyclistCapability.Speed, IncyclistCapability.Cadence];
8
+ static controllers = {
9
+ modes: [SpeedCyclingMode],
10
+ default: SpeedCyclingMode
11
+ };
7
12
  mapToAdapterData(deviceData) {
8
13
  if (deviceData.CalculatedSpeed !== undefined) {
9
14
  this.data.speed = deviceData.CalculatedSpeed * 3.6;
@@ -17,8 +22,44 @@ export default class AntSpdAdapter extends AntAdapter {
17
22
  this.data.timestamp = Date.now();
18
23
  }
19
24
  }
25
+ mapData(deviceData) {
26
+ const data = {
27
+ isPedalling: false,
28
+ power: 0,
29
+ pedalRpm: 0,
30
+ speed: 0
31
+ };
32
+ data.pedalRpm = (deviceData.CalculatedCadence !== undefined ? deviceData.CalculatedCadence : data.pedalRpm);
33
+ data.speed = (deviceData.CalculatedSpeed !== undefined ? deviceData.CalculatedSpeed * 3.6 : data.speed);
34
+ data.time = (deviceData.SpeedEventTime !== undefined ? deviceData.SpeedEventTime : data.time);
35
+ data.isPedalling = (data.pedalRpm ?? 0) > 0 || data.speed > 0;
36
+ return data;
37
+ }
38
+ transformData(bikeData) {
39
+ if (bikeData === undefined)
40
+ return {};
41
+ let data = {
42
+ speed: bikeData.speed,
43
+ power: bikeData.power,
44
+ cadence: bikeData.pedalRpm,
45
+ timestamp: Date.now()
46
+ };
47
+ if (bikeData.time)
48
+ data.deviceTime = bikeData.time;
49
+ this.data = data;
50
+ return data;
51
+ }
20
52
  hasData() {
21
53
  return ((this.deviceData.CalculatedSpeed !== undefined && this.deviceData.CalculatedSpeed !== null) ||
22
54
  (this.deviceData.CalculatedCadence !== undefined && this.deviceData.CalculatedCadence !== null));
23
55
  }
56
+ setCyclingMode(mode, settings, sendInitCommands) {
57
+ super.setCyclingMode(mode, settings, sendInitCommands);
58
+ try {
59
+ const sensor = this.sensor;
60
+ const wc = this.getCyclingMode().getSetting('wc');
61
+ sensor.setWheelCircumference(wc / 1000);
62
+ }
63
+ catch { }
64
+ }
24
65
  }
@@ -1,9 +1,14 @@
1
1
  import AntAdapter from "../base/adapter.js";
2
2
  import { IncyclistCapability } from "../../types/index.js";
3
+ import SpeedCyclingMode from "../../modes/speed.js";
3
4
  export default class AntSpdAdapter extends AntAdapter {
4
5
  static INCYCLIST_PROFILE_NAME = 'Speed Sensor';
5
6
  static ANT_PROFILE_NAME = 'SPD';
6
7
  static CAPABILITIES = [IncyclistCapability.Speed];
8
+ static controllers = {
9
+ modes: [SpeedCyclingMode],
10
+ default: SpeedCyclingMode
11
+ };
7
12
  mapToAdapterData(deviceData) {
8
13
  if (deviceData.CalculatedSpeed !== undefined) {
9
14
  this.data.speed = deviceData.CalculatedSpeed * 3.6;
@@ -13,7 +18,41 @@ export default class AntSpdAdapter extends AntAdapter {
13
18
  this.data.deviceDistanceCounter = deviceData.CalculatedDistance;
14
19
  }
15
20
  }
21
+ mapData(deviceData) {
22
+ const data = {
23
+ isPedalling: false,
24
+ power: 0,
25
+ pedalRpm: 0,
26
+ speed: 0
27
+ };
28
+ data.speed = (deviceData.CalculatedSpeed !== undefined ? deviceData.CalculatedSpeed * 3.6 : data.speed);
29
+ data.time = (deviceData.SpeedEventTime !== undefined ? deviceData.SpeedEventTime : data.time);
30
+ data.isPedalling = data.speed > 0;
31
+ return data;
32
+ }
33
+ transformData(bikeData) {
34
+ if (bikeData === undefined)
35
+ return {};
36
+ let data = {
37
+ speed: bikeData.speed,
38
+ power: bikeData.power,
39
+ timestamp: Date.now()
40
+ };
41
+ if (bikeData.time)
42
+ data.deviceTime = bikeData.time;
43
+ this.data = data;
44
+ return data;
45
+ }
16
46
  hasData() {
17
47
  return this.deviceData.CalculatedSpeed !== undefined && this.deviceData.CalculatedSpeed !== null;
18
48
  }
49
+ setCyclingMode(mode, settings, sendInitCommands) {
50
+ super.setCyclingMode(mode, settings, sendInitCommands);
51
+ try {
52
+ const sensor = this.sensor;
53
+ const wc = this.getCyclingMode().getSetting('wc');
54
+ sensor.setWheelCircumference(wc / 1000);
55
+ }
56
+ catch { }
57
+ }
19
58
  }
@@ -52,7 +52,7 @@ export class BleCSCAdapter extends BleAdapter {
52
52
  }
53
53
  transformData(bikeData) {
54
54
  if (bikeData === undefined)
55
- return;
55
+ return {};
56
56
  let data = {
57
57
  speed: bikeData.speed,
58
58
  power: bikeData.power,
@@ -41,6 +41,8 @@ export function getCharachteristicsInfo(c) {
41
41
  return `${serviceStr}${uuid}${nameStr} ${properties}`;
42
42
  }
43
43
  export const parseUUID = (str) => {
44
+ if (!str)
45
+ return str;
44
46
  const uuid = str.toUpperCase();
45
47
  if (str.startsWith('0x')) {
46
48
  const hex = uuid.slice(2);
@@ -95,6 +97,8 @@ export const beautifyUUID = (str, withX = false) => {
95
97
  return parts.join('-');
96
98
  };
97
99
  export const fullUUID = (str) => {
100
+ if (!str)
101
+ return str;
98
102
  const uuid = parseUUID(str);
99
103
  const parts = [
100
104
  uuid.substring(0, 8),
@@ -1,5 +1,5 @@
1
- import { CyclingModeBase } from "./base";
2
- import { CyclingModeProperyType } from "./types";
1
+ import { CyclingModeBase } from "./base.js";
2
+ import { CyclingModeProperyType } from "./types.js";
3
3
  import calc from '../utils/calculations.js';
4
4
  import { DEFAULT_BIKE_WEIGHT, DEFAULT_USER_WEIGHT, DEFAULT_WHEEL_CIRCUMFERENCE } from "../base/consts.js";
5
5
  export default class SpeedCyclingMode extends CyclingModeBase {
@@ -1,11 +1,16 @@
1
1
  import { SpeedCadenceSensorState, Profile } from "incyclist-ant-plus";
2
2
  import AntAdapter from "../base/adapter.js";
3
3
  import { LegacyProfile } from "../types.js";
4
- import { IncyclistCapability } from "../../types/index.js";
4
+ import { ControllerConfig, IncyclistAdapterData, IncyclistBikeData, IncyclistCapability } from "../../types/index.js";
5
+ import ICyclingMode from "../../modes/types.js";
5
6
  export default class AntSpdAdapter extends AntAdapter<SpeedCadenceSensorState> {
6
7
  protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
7
8
  protected static ANT_PROFILE_NAME: Profile;
8
9
  protected static CAPABILITIES: IncyclistCapability[];
10
+ protected static controllers: ControllerConfig;
9
11
  mapToAdapterData(deviceData: SpeedCadenceSensorState): void;
12
+ mapData(deviceData: SpeedCadenceSensorState): IncyclistBikeData;
13
+ transformData(bikeData: IncyclistBikeData): IncyclistAdapterData;
10
14
  hasData(): boolean;
15
+ setCyclingMode(mode: string | ICyclingMode, settings?: any, sendInitCommands?: boolean): void;
11
16
  }
@@ -1,11 +1,16 @@
1
1
  import { SpeedSensorState, Profile } from "incyclist-ant-plus";
2
2
  import AntAdapter from "../base/adapter.js";
3
3
  import { LegacyProfile } from "../types.js";
4
- import { IncyclistCapability } from "../../types/index.js";
4
+ import { ControllerConfig, IncyclistAdapterData, IncyclistBikeData, IncyclistCapability } from "../../types/index.js";
5
+ import ICyclingMode from "../../modes/types.js";
5
6
  export default class AntSpdAdapter extends AntAdapter<SpeedSensorState> {
6
7
  protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
7
8
  protected static ANT_PROFILE_NAME: Profile;
8
9
  protected static CAPABILITIES: IncyclistCapability[];
10
+ protected static controllers: ControllerConfig;
9
11
  mapToAdapterData(deviceData: SpeedSensorState): void;
12
+ mapData(deviceData: SpeedSensorState): IncyclistBikeData;
13
+ transformData(bikeData: IncyclistBikeData): IncyclistAdapterData;
10
14
  hasData(): boolean;
15
+ setCyclingMode(mode: string | ICyclingMode, settings?: any, sendInitCommands?: boolean): void;
11
16
  }
@@ -1,6 +1,6 @@
1
- import { IAdapter, IncyclistBikeData } from "../types";
2
- import { CyclingModeBase } from "./base";
3
- import ICyclingMode, { CyclingModeProperyType, Settings, UpdateRequest } from "./types";
1
+ import { IAdapter, IncyclistBikeData } from "../types/index.js";
2
+ import { CyclingModeBase } from "./base.js";
3
+ import ICyclingMode, { CyclingModeProperyType, Settings, UpdateRequest } from "./types.js";
4
4
  export default class SpeedCyclingMode extends CyclingModeBase implements ICyclingMode {
5
5
  data: IncyclistBikeData;
6
6
  prevUpdateTS: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "3.0.21",
3
+ "version": "3.0.22",
4
4
  "scripts": {
5
5
  "lint": "eslint . --ext .ts",
6
6
  "build": "npm run build:esm && npm run build:cjs",
@@ -1,113 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.useSerialPortProvider = void 0;
37
- const _Stream = __importStar(require("@serialport/stream"));
38
- const { SerialPortStream } = _Stream;
39
- const DEFAULT_BAUD_RATE = 9600;
40
- class SerialPortProvider {
41
- static _instance;
42
- interfaces;
43
- implemenations;
44
- static getInstance() {
45
- if (!SerialPortProvider._instance)
46
- SerialPortProvider._instance = new SerialPortProvider();
47
- return SerialPortProvider._instance;
48
- }
49
- constructor() {
50
- this.interfaces = [];
51
- this.implemenations = [];
52
- }
53
- setBinding(ifaceName, binding) {
54
- const existing = this.interfaces.find(ib => ib.name === ifaceName);
55
- if (existing)
56
- existing.binding = binding;
57
- else
58
- this.interfaces.push({ name: ifaceName, binding });
59
- }
60
- getBinding(ifaceName) {
61
- const existing = this.interfaces.find(ib => ib.name === ifaceName);
62
- if (existing)
63
- return existing.binding;
64
- }
65
- getSerialPort(ifaceName, props) {
66
- const binding = this.getBinding(ifaceName);
67
- if (binding) {
68
- props.binding = binding;
69
- if (props.autoOpen === undefined)
70
- props.autoOpen = false;
71
- if (!props.baudRate)
72
- props.baudRate = DEFAULT_BAUD_RATE;
73
- return new SerialPortStream(props);
74
- }
75
- const legacy = this.getLegacyInfo(ifaceName);
76
- if (legacy && legacy.Serialport) {
77
- const portName = props.path;
78
- if (props.autoOpen === undefined)
79
- props.autoOpen = false;
80
- const settings = Object.assign({}, props);
81
- delete settings.path;
82
- return new legacy.Serialport(portName, settings);
83
- }
84
- }
85
- async list(ifaceName) {
86
- const Binding = this.getBinding(ifaceName);
87
- if (Binding)
88
- return await Binding.list();
89
- const legacy = this.getLegacyInfo(ifaceName);
90
- if (legacy && legacy.Serialport && legacy.Serialport.list) {
91
- return await legacy.Serialport.list();
92
- }
93
- return [];
94
- }
95
- setLegacyClass(ifaceName, Serialport) {
96
- const existing = this.getLegacyInfo(ifaceName);
97
- if (existing)
98
- existing.Serialport = Serialport;
99
- else
100
- this.implemenations.push({ name: ifaceName, Serialport });
101
- }
102
- getLegacyInfo(ifaceName) {
103
- return this.implemenations.find(ib => ib.name === ifaceName);
104
- }
105
- getLegacyClass(ifaceName) {
106
- const existing = this.implemenations.find(ib => ib.name === ifaceName);
107
- if (existing)
108
- return existing.Serialport;
109
- }
110
- }
111
- exports.default = SerialPortProvider;
112
- const useSerialPortProvider = () => SerialPortProvider.getInstance();
113
- exports.useSerialPortProvider = useSerialPortProvider;
@@ -1,14 +0,0 @@
1
- export class BindingsFactory {
2
- static instance;
3
- binding;
4
- static getInstance() {
5
- this.instance = this.instance ?? new BindingsFactory();
6
- return this.instance;
7
- }
8
- getBinding() {
9
- return this.binding;
10
- }
11
- setBinding(binding) {
12
- this.binding = binding;
13
- }
14
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,33 +0,0 @@
1
- import PowerBasedCyclingModeBase from './power-base.js';
2
- export default class PowerMeterCyclingMode extends PowerBasedCyclingModeBase {
3
- static config = {
4
- name: 'PowerMeter',
5
- description: 'Power and cadence are taken from device. Speed is calculated from power and current slope\nThis mode will not respect maximum power and/or workout limits',
6
- properties: []
7
- };
8
- constructor(adapter, props) {
9
- super(adapter, props);
10
- this.initLogger('PowerMeterMode');
11
- this.data.slope = 0;
12
- }
13
- getBikeInitRequest() {
14
- return {};
15
- }
16
- sendBikeUpdate(request = {}) {
17
- this.logEvent({ message: "processing update request", request });
18
- const prevData = this.data;
19
- const prevSlope = prevData.slope;
20
- if (request.slope && request.slope !== prevSlope) {
21
- this.data.slope = request.slope;
22
- this.updateData(this.data, false);
23
- }
24
- return {};
25
- }
26
- copyBikeData(data, bikeData) {
27
- const newData = super.copyBikeData(data, bikeData);
28
- if (bikeData.power > 0) {
29
- newData.isPedalling = true;
30
- }
31
- return newData;
32
- }
33
- }
@@ -1,73 +0,0 @@
1
- const DEFAULT_BAUD_RATE = 9600;
2
- export default class SerialPortProvider {
3
- static _instance;
4
- interfaces;
5
- implemenations;
6
- static getInstance() {
7
- if (!SerialPortProvider._instance)
8
- SerialPortProvider._instance = new SerialPortProvider();
9
- return SerialPortProvider._instance;
10
- }
11
- constructor() {
12
- this.interfaces = [];
13
- this.implemenations = [];
14
- }
15
- setBinding(ifaceName, binding) {
16
- const existing = this.interfaces.find(ib => ib.name === ifaceName);
17
- if (existing)
18
- existing.binding = binding;
19
- else
20
- this.interfaces.push({ name: ifaceName, binding });
21
- }
22
- getBinding(ifaceName) {
23
- const existing = this.interfaces.find(ib => ib.name === ifaceName);
24
- if (existing)
25
- return existing.binding;
26
- }
27
- getSerialPort(ifaceName, props) {
28
- const binding = this.getBinding(ifaceName);
29
- if (binding) {
30
- props.binding = binding;
31
- if (props.autoOpen === undefined)
32
- props.autoOpen = false;
33
- if (!props.baudRate)
34
- props.baudRate = DEFAULT_BAUD_RATE;
35
- return new SerialPortStream(props);
36
- }
37
- const legacy = this.getLegacyInfo(ifaceName);
38
- if (legacy && legacy.Serialport) {
39
- const portName = props.path;
40
- if (props.autoOpen === undefined)
41
- props.autoOpen = false;
42
- const settings = Object.assign({}, props);
43
- delete settings.path;
44
- return new legacy.Serialport(portName, settings);
45
- }
46
- }
47
- async list(ifaceName) {
48
- const Binding = this.getBinding(ifaceName);
49
- if (Binding)
50
- return await Binding.list();
51
- const legacy = this.getLegacyInfo(ifaceName);
52
- if (legacy && legacy.Serialport && legacy.Serialport.list) {
53
- return await legacy.Serialport.list();
54
- }
55
- return [];
56
- }
57
- setLegacyClass(ifaceName, Serialport) {
58
- const existing = this.getLegacyInfo(ifaceName);
59
- if (existing)
60
- existing.Serialport = Serialport;
61
- else
62
- this.implemenations.push({ name: ifaceName, Serialport });
63
- }
64
- getLegacyInfo(ifaceName) {
65
- return this.implemenations.find(ib => ib.name === ifaceName);
66
- }
67
- getLegacyClass(ifaceName) {
68
- const existing = this.implemenations.find(ib => ib.name === ifaceName);
69
- if (existing)
70
- return existing.Serialport;
71
- }
72
- }
73
- export const useSerialPortProvider = () => SerialPortProvider.getInstance();
@@ -1,8 +0,0 @@
1
- import { IDeviceBinding } from "../types";
2
- export declare class BindingsFactory {
3
- protected static instance: BindingsFactory;
4
- protected binding: IDeviceBinding | undefined;
5
- protected static getInstance(): BindingsFactory;
6
- getBinding(): IDeviceBinding | undefined;
7
- setBinding(binding: IDeviceBinding): void;
8
- }
@@ -1,45 +0,0 @@
1
- export type KeyFormat = 'pem' | 'der';
2
- export type KeyType = 'rsa' | 'rsa-pss' | 'dsa' | 'ec' | 'ed25519' | 'ed448' | 'x25519' | 'x448';
3
- export interface KeyEncodingOptions {
4
- type: 'pkcs1' | 'pkcs8' | 'spki' | 'sec1';
5
- format: KeyFormat;
6
- }
7
- export interface GenerateKeyPairOptions {
8
- modulusLength?: number;
9
- publicExponent?: number;
10
- namedCurve?: string;
11
- publicKeyEncoding: KeyEncodingOptions;
12
- privateKeyEncoding: KeyEncodingOptions;
13
- }
14
- export interface KeyPair {
15
- publicKey: string | Buffer<ArrayBufferLike>;
16
- privateKey: string | Buffer<ArrayBufferLike>;
17
- }
18
- export interface IHash {
19
- update(data: string | Buffer<ArrayBufferLike>): IHash;
20
- digest(encoding: 'hex' | 'base64'): string;
21
- digest(): Buffer<ArrayBufferLike>;
22
- }
23
- export interface IHmac {
24
- update(data: string | Buffer<ArrayBufferLike>): IHmac;
25
- digest(encoding: 'hex' | 'base64'): string;
26
- digest(): Buffer<ArrayBufferLike>;
27
- }
28
- export interface ICipher {
29
- update(data: Buffer<ArrayBufferLike>): Buffer<ArrayBufferLike>;
30
- final(): Buffer<ArrayBufferLike>;
31
- setAutoPadding(autoPadding?: boolean): ICipher;
32
- }
33
- export interface IDecipher {
34
- update(data: Buffer<ArrayBufferLike>): Buffer<ArrayBufferLike>;
35
- final(): Buffer<ArrayBufferLike>;
36
- setAutoPadding(autoPadding?: boolean): IDecipher;
37
- }
38
- export interface ICryptoBinding {
39
- randomBytes(size: number): Buffer<ArrayBufferLike>;
40
- createHash(algorithm: string): IHash;
41
- createHmac(algorithm: string, key: string | Buffer<ArrayBufferLike>): IHmac;
42
- createCipheriv(algorithm: string, key: Buffer<ArrayBufferLike>, iv: Buffer<ArrayBufferLike>): ICipher;
43
- createDecipheriv(algorithm: string, key: Buffer<ArrayBufferLike>, iv: Buffer<ArrayBufferLike>): IDecipher;
44
- generateKeyPairSync(type: KeyType, options: GenerateKeyPairOptions): KeyPair;
45
- }
@@ -1,15 +0,0 @@
1
- import ICyclingMode, { Settings, UpdateRequest } from './types.js';
2
- import { IncyclistBikeData } from "../types/index.js";
3
- import PowerBasedCyclingModeBase from './power-base.js';
4
- import { IncyclistDeviceAdapter } from '../base/adpater.js';
5
- export default class PowerMeterCyclingMode extends PowerBasedCyclingModeBase implements ICyclingMode {
6
- protected static config: {
7
- name: string;
8
- description: string;
9
- properties: any[];
10
- };
11
- constructor(adapter: IncyclistDeviceAdapter, props?: Settings);
12
- getBikeInitRequest(): UpdateRequest;
13
- sendBikeUpdate(request?: UpdateRequest): UpdateRequest;
14
- copyBikeData(data: IncyclistBikeData, bikeData: IncyclistBikeData): IncyclistBikeData;
15
- }
@@ -1,16 +0,0 @@
1
- import { InterfaceBinding, InterfaceImplementation } from '../types.js';
2
- export default class SerialPortProvider {
3
- static _instance: SerialPortProvider;
4
- interfaces: InterfaceBinding[];
5
- implemenations: InterfaceImplementation[];
6
- static getInstance(): SerialPortProvider;
7
- constructor();
8
- setBinding(ifaceName: string, binding: any): void;
9
- getBinding(ifaceName: string): any;
10
- getSerialPort(ifaceName: string, props: any): any;
11
- list(ifaceName: string): Promise<any>;
12
- setLegacyClass(ifaceName: string, Serialport: any): void;
13
- getLegacyInfo(ifaceName: string): InterfaceImplementation;
14
- getLegacyClass(ifaceName: string): any;
15
- }
16
- export declare const useSerialPortProvider: () => SerialPortProvider;