tirecheck-device-sdk 0.1.95 → 0.1.96

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/dist/index.cjs CHANGED
@@ -520,28 +520,21 @@ const deviceMeta = {
520
520
  },
521
521
  reconnect: true
522
522
  // Do we need it here?
523
+ },
524
+ pressureStick: {
525
+ nameRegex: /Pressure Stick.*/,
526
+ communication: {
527
+ serviceId: "4880c12c-fdcb-4077-8920-a450d7f9b907",
528
+ characteristicId: "fec26ec4-6d71-4442-9f81-55bc21d658d6"
529
+ },
530
+ getDeviceInfoFromAdvertising: (device) => {
531
+ const bleDevice = {
532
+ ...device,
533
+ type: "pressureStick"
534
+ };
535
+ return bleDevice;
536
+ }
523
537
  }
524
- // pressureStick: {
525
- // nameRegex: /Pressure Stick.*/,
526
- // characteristic: {
527
- // serviceId: '4880c12c-fdcb-4077-8920-a450d7f9b907',
528
- // characteristicId: 'fec26ec4-6d71-4442-9f81-55bc21d658d6',
529
- // },
530
- // getDeviceInfoFromAdvertising: () => {},
531
- // capabilities: [
532
- // {
533
- // id: 'pressure',
534
- // // processFn: processPressure,
535
- // regex: /P([0-9.]+)mBar/,
536
- // },
537
- // // only pressure is needed for initial implementation, uncomment tpms functionality when needed
538
- // // {
539
- // // id: 'tpms',
540
- // // processFn: processTpms,
541
- // // regex: /^\*TPMS/,
542
- // // },
543
- // ],
544
- // },
545
538
  };
546
539
 
547
540
  const checkUnreachableDevicesTimeouts = {};
@@ -2752,11 +2745,13 @@ const simulatorSvc = {
2752
2745
  registerEvent(eventName, callback) {
2753
2746
  callbacks[eventName] = callback;
2754
2747
  },
2755
- triggerEvent(eventName, deviceId) {
2756
- const simulatedDevice = store.simulatedDevices[deviceId];
2757
- if (!simulatedDevice) throw new Error(`Device not found`);
2758
- const payload = simulatedDevice.simulatorData?.events?.[eventName];
2759
- if (!payload) throw new Error(`Event not found`);
2748
+ triggerEvent(eventName, deviceId, payload) {
2749
+ if (payload === void 0) {
2750
+ const simulatedDevice = store.simulatedDevices[deviceId];
2751
+ if (!simulatedDevice) throw new Error(`Device not found`);
2752
+ payload = simulatedDevice.simulatorData?.events?.[eventName];
2753
+ if (!payload) throw new Error(`Event not found`);
2754
+ }
2760
2755
  const callback = callbacks[eventName];
2761
2756
  if (!callback) {
2762
2757
  console.warn(`Event ${eventName} not registered`);
@@ -2795,10 +2790,7 @@ async function getBattery(deviceId) {
2795
2790
  }
2796
2791
 
2797
2792
  let sensorReadings = [];
2798
- let treadDepthCallback;
2799
- let buttonCallback;
2800
- let tpmsCallback;
2801
- const capabilities = [
2793
+ const capabilities$1 = [
2802
2794
  {
2803
2795
  id: "td",
2804
2796
  processFn: processTreadDepth,
@@ -2835,7 +2827,7 @@ const flexiGaugeTpmsService = {
2835
2827
  processMessage(deviceId, message) {
2836
2828
  const numberArray = Array.from(new Uint8Array(message));
2837
2829
  const stringFromBytes = String.fromCharCode.apply(null, numberArray).replace("\r\n", "");
2838
- for (const capability of capabilities) {
2830
+ for (const capability of capabilities$1) {
2839
2831
  if (capability.regex.test(stringFromBytes)) {
2840
2832
  return capability.processFn(deviceId, stringFromBytes);
2841
2833
  }
@@ -2845,12 +2837,12 @@ const flexiGaugeTpmsService = {
2845
2837
  function processTreadDepth(deviceId, value) {
2846
2838
  const treadDepth = value.match(/\d+/)?.[0];
2847
2839
  const convertedValue = Number(treadDepth) / 1e3;
2848
- treadDepthCallback(deviceId, convertedValue);
2840
+ simulatorSvc.triggerEvent("fg:treadDepth", deviceId, convertedValue);
2849
2841
  }
2850
2842
  function processButtonPress(deviceId, value) {
2851
2843
  const buttonName = value.match(/\*(.)/);
2852
2844
  if (!buttonName || !buttonName[1]) throw new Error("Unrecognized button");
2853
- buttonCallback(deviceId, buttonName[1]);
2845
+ simulatorSvc.triggerEvent("fg:button", deviceId, buttonName[1]);
2854
2846
  }
2855
2847
  function processTpms(deviceId, value) {
2856
2848
  const groupedValue = value.split(" ");
@@ -2870,12 +2862,13 @@ function processTpms(deviceId, value) {
2870
2862
  }
2871
2863
  if (type === "ENDSCANNING") {
2872
2864
  if (!sensorReadings.length) {
2873
- tpmsCallback(deviceId, void 0);
2865
+ simulatorSvc.triggerEvent("fg:tpms", deviceId, null);
2866
+ return;
2874
2867
  }
2875
2868
  const strongestReading = sensorReadings.reduce((accumulator, currentReading) => {
2876
2869
  return Number(currentReading.Rssi) > Number(accumulator.Rssi) ? currentReading : accumulator;
2877
2870
  }, sensorReadings[0]);
2878
- tpmsCallback(deviceId, strongestReading);
2871
+ simulatorSvc.triggerEvent("fg:tpms", deviceId, strongestReading);
2879
2872
  }
2880
2873
  }
2881
2874
 
@@ -2904,6 +2897,55 @@ const flexiGaugeTpms = {
2904
2897
  startTpmsScan: flexiGaugeTpmsService.startTpmsScan
2905
2898
  };
2906
2899
 
2900
+ const capabilities = [
2901
+ {
2902
+ id: "pressure",
2903
+ processFn: processPressure,
2904
+ regex: /P([0-9.]+)mBar/
2905
+ }
2906
+ ];
2907
+ const pressureStickService = {
2908
+ onPressure(callback) {
2909
+ simulatorSvc.registerEvent("ps:pressure", callback);
2910
+ },
2911
+ processMessage(deviceId, message) {
2912
+ const numberArray = Array.from(new Uint8Array(message));
2913
+ const stringFromBytes = String.fromCharCode.apply(null, numberArray).replace("\r\n", "");
2914
+ for (const capability of capabilities) {
2915
+ if (capability.regex.test(stringFromBytes)) {
2916
+ return capability.processFn(deviceId, stringFromBytes);
2917
+ }
2918
+ }
2919
+ }
2920
+ };
2921
+ function processPressure(deviceId, msg) {
2922
+ const match = /P([0-9.]+)mBar/i.exec(msg);
2923
+ if (!match) throw new Error("Incorrect pressure message");
2924
+ const pressure = Number(match[1]) / 1e3;
2925
+ simulatorSvc.triggerEvent("ps:pressure", deviceId, pressure);
2926
+ }
2927
+
2928
+ const pressureStick = {
2929
+ async connect(deviceId) {
2930
+ const psMeta = deviceMeta.pressureStick;
2931
+ await bluetooth.connect(deviceId, this.disconnect);
2932
+ await ble.startNotification(
2933
+ deviceId,
2934
+ psMeta.communication.serviceId,
2935
+ psMeta.communication.characteristicId,
2936
+ (notification) => pressureStickService.processMessage(deviceId, notification),
2937
+ (error) => console.warn("ble.startNotification error", error)
2938
+ );
2939
+ store.setState(deviceId, "paired");
2940
+ },
2941
+ async disconnect(deviceId, reason) {
2942
+ store.setState(deviceId, "disconnecting");
2943
+ await bluetooth.disconnect(deviceId);
2944
+ store.setState(deviceId, void 0, reason ?? "manualDisconnection");
2945
+ },
2946
+ onPressure: pressureStickService.onPressure
2947
+ };
2948
+
2907
2949
  const bridgeSimulator = {
2908
2950
  isRebootRequired(deviceId) {
2909
2951
  return store.bridgeRebootRequired[deviceId];
@@ -3277,6 +3319,8 @@ function createTirecheckDeviceSdk(platform, bleImplementation) {
3277
3319
  bridgeOta,
3278
3320
  /** Methods for working with Tirecheck TPMS FlexiGauge */
3279
3321
  flexiGaugeTpms,
3322
+ /** Methods for working with Tirecheck Pressure Stick */
3323
+ pressureStick,
3280
3324
  /** Allows simulating devices without actually using bluetooth */
3281
3325
  simulator
3282
3326
  };
package/dist/index.d.cts CHANGED
@@ -83,6 +83,14 @@ declare const _default$1: {
83
83
  getDeviceInfoFromAdvertising: (device: PeripheralData) => BleFlexiGaugeTpms;
84
84
  reconnect: boolean;
85
85
  };
86
+ pressureStick: {
87
+ nameRegex: RegExp;
88
+ communication: {
89
+ serviceId: string;
90
+ characteristicId: string;
91
+ };
92
+ getDeviceInfoFromAdvertising: (device: PeripheralData) => BlePressureStick;
93
+ };
86
94
  };
87
95
 
88
96
  declare const _default: {
@@ -734,7 +742,7 @@ type BridgeCommandStructurized<T extends BridgeCommandStructureProperties> = {
734
742
  };
735
743
  type BleDeviceType = keyof typeof _default$1;
736
744
  /** distinguish by type, e.g. `if (device.type === 'bridge')`, to access furhter fields */
737
- type BleDevice = BleBridge | BleBridgeOta | BleFlexiGaugeTpms;
745
+ type BleDevice = BleBridge | BleBridgeOta | BleFlexiGaugeTpms | BlePressureStick;
738
746
  type BleDeviceSimulated = BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
739
747
  type BleDeviceStatus = 'connected' | 'connecting' | 'disconnecting' | undefined;
740
748
  interface BleDeviceBase {
@@ -764,6 +772,9 @@ interface BleBridgeOta extends BleDeviceBase {
764
772
  };
765
773
  type: 'bridgeOta';
766
774
  }
775
+ interface BlePressureStick extends BleDeviceBase {
776
+ type: 'pressureStick';
777
+ }
767
778
  interface BleBridgeSimulated extends BleBridge {
768
779
  isDisabled?: boolean;
769
780
  simulatorData: {
@@ -814,6 +825,7 @@ interface EventHandlers {
814
825
  'fg:treadDepth'?: (deviceId: string, value: number) => void;
815
826
  'fg:button'?: (deviceId: string, value: string) => void;
816
827
  'fg:tpms'?: (deviceId: string, value: FgSensorReading | undefined) => void;
828
+ 'ps:pressure'?: (deviceId: string, value: number) => void;
817
829
  }
818
830
  type EventName = keyof EventHandlers;
819
831
 
@@ -864,14 +876,20 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
864
876
  getBattery: (deviceId: string) => Promise<number>;
865
877
  startTpmsScan: (deviceId: string) => void;
866
878
  };
879
+ /** Methods for working with Tirecheck Pressure Stick */
880
+ pressureStick: {
881
+ connect(deviceId: string): Promise<void>;
882
+ disconnect(deviceId: string, reason?: StateReason): Promise<void>;
883
+ onPressure: (callback: (deviceId: string, value: number) => void) => void;
884
+ };
867
885
  /** Allows simulating devices without actually using bluetooth */
868
886
  simulator: {
869
887
  putSimulatedDevices(devices: Record<string, DeepPartial<BleDeviceSimulated>>): Record<string, BleDeviceSimulated>;
870
888
  putSimulatedDevice(device: DeepPartial<BleDeviceSimulated>): BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
871
889
  deleteSimulatedDevice(deviceId: string): void;
872
890
  getSimulatedDevices(): Record<string, BleDeviceSimulated>;
873
- triggerEvent: (eventName: EventName, deviceId: string) => void;
891
+ triggerEvent: (eventName: EventName, deviceId: string, payload?: any) => void;
874
892
  };
875
893
  };
876
894
 
877
- export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type Wrapper, createTirecheckDeviceSdk };
895
+ export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type Wrapper, createTirecheckDeviceSdk };
package/dist/index.d.mts CHANGED
@@ -83,6 +83,14 @@ declare const _default$1: {
83
83
  getDeviceInfoFromAdvertising: (device: PeripheralData) => BleFlexiGaugeTpms;
84
84
  reconnect: boolean;
85
85
  };
86
+ pressureStick: {
87
+ nameRegex: RegExp;
88
+ communication: {
89
+ serviceId: string;
90
+ characteristicId: string;
91
+ };
92
+ getDeviceInfoFromAdvertising: (device: PeripheralData) => BlePressureStick;
93
+ };
86
94
  };
87
95
 
88
96
  declare const _default: {
@@ -734,7 +742,7 @@ type BridgeCommandStructurized<T extends BridgeCommandStructureProperties> = {
734
742
  };
735
743
  type BleDeviceType = keyof typeof _default$1;
736
744
  /** distinguish by type, e.g. `if (device.type === 'bridge')`, to access furhter fields */
737
- type BleDevice = BleBridge | BleBridgeOta | BleFlexiGaugeTpms;
745
+ type BleDevice = BleBridge | BleBridgeOta | BleFlexiGaugeTpms | BlePressureStick;
738
746
  type BleDeviceSimulated = BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
739
747
  type BleDeviceStatus = 'connected' | 'connecting' | 'disconnecting' | undefined;
740
748
  interface BleDeviceBase {
@@ -764,6 +772,9 @@ interface BleBridgeOta extends BleDeviceBase {
764
772
  };
765
773
  type: 'bridgeOta';
766
774
  }
775
+ interface BlePressureStick extends BleDeviceBase {
776
+ type: 'pressureStick';
777
+ }
767
778
  interface BleBridgeSimulated extends BleBridge {
768
779
  isDisabled?: boolean;
769
780
  simulatorData: {
@@ -814,6 +825,7 @@ interface EventHandlers {
814
825
  'fg:treadDepth'?: (deviceId: string, value: number) => void;
815
826
  'fg:button'?: (deviceId: string, value: string) => void;
816
827
  'fg:tpms'?: (deviceId: string, value: FgSensorReading | undefined) => void;
828
+ 'ps:pressure'?: (deviceId: string, value: number) => void;
817
829
  }
818
830
  type EventName = keyof EventHandlers;
819
831
 
@@ -864,14 +876,20 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
864
876
  getBattery: (deviceId: string) => Promise<number>;
865
877
  startTpmsScan: (deviceId: string) => void;
866
878
  };
879
+ /** Methods for working with Tirecheck Pressure Stick */
880
+ pressureStick: {
881
+ connect(deviceId: string): Promise<void>;
882
+ disconnect(deviceId: string, reason?: StateReason): Promise<void>;
883
+ onPressure: (callback: (deviceId: string, value: number) => void) => void;
884
+ };
867
885
  /** Allows simulating devices without actually using bluetooth */
868
886
  simulator: {
869
887
  putSimulatedDevices(devices: Record<string, DeepPartial<BleDeviceSimulated>>): Record<string, BleDeviceSimulated>;
870
888
  putSimulatedDevice(device: DeepPartial<BleDeviceSimulated>): BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
871
889
  deleteSimulatedDevice(deviceId: string): void;
872
890
  getSimulatedDevices(): Record<string, BleDeviceSimulated>;
873
- triggerEvent: (eventName: EventName, deviceId: string) => void;
891
+ triggerEvent: (eventName: EventName, deviceId: string, payload?: any) => void;
874
892
  };
875
893
  };
876
894
 
877
- export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type Wrapper, createTirecheckDeviceSdk };
895
+ export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type Wrapper, createTirecheckDeviceSdk };
package/dist/index.d.ts CHANGED
@@ -83,6 +83,14 @@ declare const _default$1: {
83
83
  getDeviceInfoFromAdvertising: (device: PeripheralData) => BleFlexiGaugeTpms;
84
84
  reconnect: boolean;
85
85
  };
86
+ pressureStick: {
87
+ nameRegex: RegExp;
88
+ communication: {
89
+ serviceId: string;
90
+ characteristicId: string;
91
+ };
92
+ getDeviceInfoFromAdvertising: (device: PeripheralData) => BlePressureStick;
93
+ };
86
94
  };
87
95
 
88
96
  declare const _default: {
@@ -734,7 +742,7 @@ type BridgeCommandStructurized<T extends BridgeCommandStructureProperties> = {
734
742
  };
735
743
  type BleDeviceType = keyof typeof _default$1;
736
744
  /** distinguish by type, e.g. `if (device.type === 'bridge')`, to access furhter fields */
737
- type BleDevice = BleBridge | BleBridgeOta | BleFlexiGaugeTpms;
745
+ type BleDevice = BleBridge | BleBridgeOta | BleFlexiGaugeTpms | BlePressureStick;
738
746
  type BleDeviceSimulated = BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
739
747
  type BleDeviceStatus = 'connected' | 'connecting' | 'disconnecting' | undefined;
740
748
  interface BleDeviceBase {
@@ -764,6 +772,9 @@ interface BleBridgeOta extends BleDeviceBase {
764
772
  };
765
773
  type: 'bridgeOta';
766
774
  }
775
+ interface BlePressureStick extends BleDeviceBase {
776
+ type: 'pressureStick';
777
+ }
767
778
  interface BleBridgeSimulated extends BleBridge {
768
779
  isDisabled?: boolean;
769
780
  simulatorData: {
@@ -814,6 +825,7 @@ interface EventHandlers {
814
825
  'fg:treadDepth'?: (deviceId: string, value: number) => void;
815
826
  'fg:button'?: (deviceId: string, value: string) => void;
816
827
  'fg:tpms'?: (deviceId: string, value: FgSensorReading | undefined) => void;
828
+ 'ps:pressure'?: (deviceId: string, value: number) => void;
817
829
  }
818
830
  type EventName = keyof EventHandlers;
819
831
 
@@ -864,14 +876,20 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
864
876
  getBattery: (deviceId: string) => Promise<number>;
865
877
  startTpmsScan: (deviceId: string) => void;
866
878
  };
879
+ /** Methods for working with Tirecheck Pressure Stick */
880
+ pressureStick: {
881
+ connect(deviceId: string): Promise<void>;
882
+ disconnect(deviceId: string, reason?: StateReason): Promise<void>;
883
+ onPressure: (callback: (deviceId: string, value: number) => void) => void;
884
+ };
867
885
  /** Allows simulating devices without actually using bluetooth */
868
886
  simulator: {
869
887
  putSimulatedDevices(devices: Record<string, DeepPartial<BleDeviceSimulated>>): Record<string, BleDeviceSimulated>;
870
888
  putSimulatedDevice(device: DeepPartial<BleDeviceSimulated>): BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
871
889
  deleteSimulatedDevice(deviceId: string): void;
872
890
  getSimulatedDevices(): Record<string, BleDeviceSimulated>;
873
- triggerEvent: (eventName: EventName, deviceId: string) => void;
891
+ triggerEvent: (eventName: EventName, deviceId: string, payload?: any) => void;
874
892
  };
875
893
  };
876
894
 
877
- export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type Wrapper, createTirecheckDeviceSdk };
895
+ export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type Wrapper, createTirecheckDeviceSdk };
package/dist/index.mjs CHANGED
@@ -513,28 +513,21 @@ const deviceMeta = {
513
513
  },
514
514
  reconnect: true
515
515
  // Do we need it here?
516
+ },
517
+ pressureStick: {
518
+ nameRegex: /Pressure Stick.*/,
519
+ communication: {
520
+ serviceId: "4880c12c-fdcb-4077-8920-a450d7f9b907",
521
+ characteristicId: "fec26ec4-6d71-4442-9f81-55bc21d658d6"
522
+ },
523
+ getDeviceInfoFromAdvertising: (device) => {
524
+ const bleDevice = {
525
+ ...device,
526
+ type: "pressureStick"
527
+ };
528
+ return bleDevice;
529
+ }
516
530
  }
517
- // pressureStick: {
518
- // nameRegex: /Pressure Stick.*/,
519
- // characteristic: {
520
- // serviceId: '4880c12c-fdcb-4077-8920-a450d7f9b907',
521
- // characteristicId: 'fec26ec4-6d71-4442-9f81-55bc21d658d6',
522
- // },
523
- // getDeviceInfoFromAdvertising: () => {},
524
- // capabilities: [
525
- // {
526
- // id: 'pressure',
527
- // // processFn: processPressure,
528
- // regex: /P([0-9.]+)mBar/,
529
- // },
530
- // // only pressure is needed for initial implementation, uncomment tpms functionality when needed
531
- // // {
532
- // // id: 'tpms',
533
- // // processFn: processTpms,
534
- // // regex: /^\*TPMS/,
535
- // // },
536
- // ],
537
- // },
538
531
  };
539
532
 
540
533
  const checkUnreachableDevicesTimeouts = {};
@@ -2745,11 +2738,13 @@ const simulatorSvc = {
2745
2738
  registerEvent(eventName, callback) {
2746
2739
  callbacks[eventName] = callback;
2747
2740
  },
2748
- triggerEvent(eventName, deviceId) {
2749
- const simulatedDevice = store.simulatedDevices[deviceId];
2750
- if (!simulatedDevice) throw new Error(`Device not found`);
2751
- const payload = simulatedDevice.simulatorData?.events?.[eventName];
2752
- if (!payload) throw new Error(`Event not found`);
2741
+ triggerEvent(eventName, deviceId, payload) {
2742
+ if (payload === void 0) {
2743
+ const simulatedDevice = store.simulatedDevices[deviceId];
2744
+ if (!simulatedDevice) throw new Error(`Device not found`);
2745
+ payload = simulatedDevice.simulatorData?.events?.[eventName];
2746
+ if (!payload) throw new Error(`Event not found`);
2747
+ }
2753
2748
  const callback = callbacks[eventName];
2754
2749
  if (!callback) {
2755
2750
  console.warn(`Event ${eventName} not registered`);
@@ -2788,10 +2783,7 @@ async function getBattery(deviceId) {
2788
2783
  }
2789
2784
 
2790
2785
  let sensorReadings = [];
2791
- let treadDepthCallback;
2792
- let buttonCallback;
2793
- let tpmsCallback;
2794
- const capabilities = [
2786
+ const capabilities$1 = [
2795
2787
  {
2796
2788
  id: "td",
2797
2789
  processFn: processTreadDepth,
@@ -2828,7 +2820,7 @@ const flexiGaugeTpmsService = {
2828
2820
  processMessage(deviceId, message) {
2829
2821
  const numberArray = Array.from(new Uint8Array(message));
2830
2822
  const stringFromBytes = String.fromCharCode.apply(null, numberArray).replace("\r\n", "");
2831
- for (const capability of capabilities) {
2823
+ for (const capability of capabilities$1) {
2832
2824
  if (capability.regex.test(stringFromBytes)) {
2833
2825
  return capability.processFn(deviceId, stringFromBytes);
2834
2826
  }
@@ -2838,12 +2830,12 @@ const flexiGaugeTpmsService = {
2838
2830
  function processTreadDepth(deviceId, value) {
2839
2831
  const treadDepth = value.match(/\d+/)?.[0];
2840
2832
  const convertedValue = Number(treadDepth) / 1e3;
2841
- treadDepthCallback(deviceId, convertedValue);
2833
+ simulatorSvc.triggerEvent("fg:treadDepth", deviceId, convertedValue);
2842
2834
  }
2843
2835
  function processButtonPress(deviceId, value) {
2844
2836
  const buttonName = value.match(/\*(.)/);
2845
2837
  if (!buttonName || !buttonName[1]) throw new Error("Unrecognized button");
2846
- buttonCallback(deviceId, buttonName[1]);
2838
+ simulatorSvc.triggerEvent("fg:button", deviceId, buttonName[1]);
2847
2839
  }
2848
2840
  function processTpms(deviceId, value) {
2849
2841
  const groupedValue = value.split(" ");
@@ -2863,12 +2855,13 @@ function processTpms(deviceId, value) {
2863
2855
  }
2864
2856
  if (type === "ENDSCANNING") {
2865
2857
  if (!sensorReadings.length) {
2866
- tpmsCallback(deviceId, void 0);
2858
+ simulatorSvc.triggerEvent("fg:tpms", deviceId, null);
2859
+ return;
2867
2860
  }
2868
2861
  const strongestReading = sensorReadings.reduce((accumulator, currentReading) => {
2869
2862
  return Number(currentReading.Rssi) > Number(accumulator.Rssi) ? currentReading : accumulator;
2870
2863
  }, sensorReadings[0]);
2871
- tpmsCallback(deviceId, strongestReading);
2864
+ simulatorSvc.triggerEvent("fg:tpms", deviceId, strongestReading);
2872
2865
  }
2873
2866
  }
2874
2867
 
@@ -2897,6 +2890,55 @@ const flexiGaugeTpms = {
2897
2890
  startTpmsScan: flexiGaugeTpmsService.startTpmsScan
2898
2891
  };
2899
2892
 
2893
+ const capabilities = [
2894
+ {
2895
+ id: "pressure",
2896
+ processFn: processPressure,
2897
+ regex: /P([0-9.]+)mBar/
2898
+ }
2899
+ ];
2900
+ const pressureStickService = {
2901
+ onPressure(callback) {
2902
+ simulatorSvc.registerEvent("ps:pressure", callback);
2903
+ },
2904
+ processMessage(deviceId, message) {
2905
+ const numberArray = Array.from(new Uint8Array(message));
2906
+ const stringFromBytes = String.fromCharCode.apply(null, numberArray).replace("\r\n", "");
2907
+ for (const capability of capabilities) {
2908
+ if (capability.regex.test(stringFromBytes)) {
2909
+ return capability.processFn(deviceId, stringFromBytes);
2910
+ }
2911
+ }
2912
+ }
2913
+ };
2914
+ function processPressure(deviceId, msg) {
2915
+ const match = /P([0-9.]+)mBar/i.exec(msg);
2916
+ if (!match) throw new Error("Incorrect pressure message");
2917
+ const pressure = Number(match[1]) / 1e3;
2918
+ simulatorSvc.triggerEvent("ps:pressure", deviceId, pressure);
2919
+ }
2920
+
2921
+ const pressureStick = {
2922
+ async connect(deviceId) {
2923
+ const psMeta = deviceMeta.pressureStick;
2924
+ await bluetooth.connect(deviceId, this.disconnect);
2925
+ await ble.startNotification(
2926
+ deviceId,
2927
+ psMeta.communication.serviceId,
2928
+ psMeta.communication.characteristicId,
2929
+ (notification) => pressureStickService.processMessage(deviceId, notification),
2930
+ (error) => console.warn("ble.startNotification error", error)
2931
+ );
2932
+ store.setState(deviceId, "paired");
2933
+ },
2934
+ async disconnect(deviceId, reason) {
2935
+ store.setState(deviceId, "disconnecting");
2936
+ await bluetooth.disconnect(deviceId);
2937
+ store.setState(deviceId, void 0, reason ?? "manualDisconnection");
2938
+ },
2939
+ onPressure: pressureStickService.onPressure
2940
+ };
2941
+
2900
2942
  const bridgeSimulator = {
2901
2943
  isRebootRequired(deviceId) {
2902
2944
  return store.bridgeRebootRequired[deviceId];
@@ -3270,6 +3312,8 @@ function createTirecheckDeviceSdk(platform, bleImplementation) {
3270
3312
  bridgeOta,
3271
3313
  /** Methods for working with Tirecheck TPMS FlexiGauge */
3272
3314
  flexiGaugeTpms,
3315
+ /** Methods for working with Tirecheck Pressure Stick */
3316
+ pressureStick,
3273
3317
  /** Allows simulating devices without actually using bluetooth */
3274
3318
  simulator
3275
3319
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tirecheck-device-sdk",
3
- "version": "0.1.95",
3
+ "version": "0.1.96",
4
4
  "description": "SDK for working with various devices produced by Tirecheck via Bluetooth (CAN Bridge, Routers, Sensors, FlexiGauge, PressureStick, etc)",
5
5
  "author": "Leonid Buneev <leonid.buneev@tirecheck.com>",
6
6
  "license": "ISC",