From 3291523d9af9e0ba25ec099514710ffaf289f14e Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Sat, 8 Oct 2022 10:36:59 +0000 Subject: [PATCH 1/2] Modify mock about sensor Signed-off-by: wuzhihuitmac Change-Id: I32a00d3a4bd972b17ec10919c3e55b6178ad32f6 --- .../extend/systemplugin/napi/ohos_sensor.js | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/runtime/main/extend/systemplugin/napi/ohos_sensor.js b/runtime/main/extend/systemplugin/napi/ohos_sensor.js index 46cac30a..4ebeea39 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_sensor.js +++ b/runtime/main/extend/systemplugin/napi/ohos_sensor.js @@ -168,7 +168,10 @@ export function mockSensor() { firmwareVersion: '[PC preview] unknown firmwareVersion', hardwareVersion: '[PC preview] unknown hardwareVersion', sensorTypeId: '[PC preview] unknown sensorTypeId', + SensorId: '[PC preview] unknown sensorId', maxRange: '[PC preview] unknown maxRange', + minSamplePeriod: '[PC preview] unknown minSamplePeriod', + maxSamplePeriod: '[PC preview] unknown maxSamplePeriod', precision: '[PC preview] unknown precision', power: '[PC preview] unknown power' } @@ -197,6 +200,29 @@ export function mockSensor() { SENSOR_TYPE_ID_WEAR_DETECTION: 280, SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED: 281 } + const SensorId = { + ACCELEROMETER: 1, + GYROSCOPE: 2, + AMBIENT_LIGHT: 5, + MAGNETIC_FIELD: 6, + BAROMETER: 8, + HALL: 10, + PROXIMITY: 12, + HUMIDITY: 13, + ORIENTATION: 256, + GRAVITY: 257, + LINEAR_ACCELERATION: 258, + ROTATION_VECTOR: 259, + AMBIENT_TEMPERATURE: 260, + MAGNETIC_FIELD_UNCALIBRATED: 261, + GYROSCOPE_UNCALIBRATED: 263, + SIGNIFICANT_MOTION: 264, + PEDOMETER_DETECTION: 265, + PEDOMETER: 266, + HEART_RATE: 278, + WEAR_DETECTION: 280, + ACCELEROMETER_UNCALIBRATED: 281 + } const sensor = { Sensor, SensorType, @@ -313,6 +339,18 @@ export function mockSensor() { }); } }, + getGeomagneticInfo: function (...args) { + console.warn('sensor.getGeomagneticInfo interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.') + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, GeomagneticResponse); + } else { + return new Promise((resolve, reject) => { + resolve(GeomagneticResponse); + }); + } + }, getAltitude: function (...args) { console.warn('sensor.getAltitude interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') @@ -325,6 +363,18 @@ export function mockSensor() { }); } }, + getDeviceAltitude: function (...args) { + console.warn('sensor.getDeviceAltitude interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.') + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }); + } + }, getGeomagneticDip: function (...args) { console.warn('sensor.getGeomagneticDip interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') @@ -337,6 +387,18 @@ export function mockSensor() { }); } }, + getInclination: function (...args) { + console.warn('sensor.getInclination interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.') + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }); + } + }, getAngleModify: function (...args) { console.warn('sensor.getAngleModifiy interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') @@ -349,6 +411,18 @@ export function mockSensor() { }); } }, + getAngleVariation: function (...args) { + console.warn('sensor.getAngleVariation interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.') + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paraNumberMock]); + } else { + return new Promise((resolve, reject) => { + resolve([paramMock.paraNumberMock]); + }); + } + }, createRotationMatrix: function (...args) { console.warn('sensor.createRotationMatrix interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') @@ -369,6 +443,27 @@ export function mockSensor() { args[len - 1].call(this, paramMock.businessErrorMock, paramMock.RotationMatrixResponse); } + }, + getRotationMatrix: function (...args) { + console.warn('sensor.getRotationMatrix interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.') + const len = args.length + if (len == 1) { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }); + } else if (len == 2) { + if (typeof args[len - 1] == 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(RotationMatrixResponse); + }); + } + } else if (len == 3) { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.RotationMatrixResponse); + } + }, transformCoordinateSystem: function (...args) { console.warn('sensor.transformCoordinateSystem interface mocked in the Previewer. How this interface works on the' @@ -382,6 +477,18 @@ export function mockSensor() { }); } }, + transformRotationMatrix: function (...args) { + console.warn('sensor.transformRotationMatrix interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.') + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paraNumberMock]); + } else { + return new Promise((resolve, reject) => { + resolve([paramMock.paraNumberMock]); + }); + } + }, createQuaternion: function (...args) { console.warn('sensor.createQuaternion interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') @@ -394,6 +501,18 @@ export function mockSensor() { }); } }, + getQuaternion: function (...args) { + console.warn('sensor.getQuaternion interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.') + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paraNumberMock]); + } else { + return new Promise((resolve, reject) => { + resolve([paramMock.paraNumberMock]); + }); + } + }, getDirection: function (...args) { console.warn('sensor.getDirection interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') @@ -406,6 +525,18 @@ export function mockSensor() { }); } }, + getOrientation: function (...args) { + console.warn('sensor.getOrientation interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.') + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paraNumberMock]); + } else { + return new Promise((resolve, reject) => { + resolve([paramMock.paraNumberMock]); + }); + } + }, getSingleSensor: function (...args) { console.warn('sensor.getSingleSensor interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') -- Gitee From f7c43625d9fc849f74cc40c01d02d73815ae4315 Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Sun, 9 Oct 2022 03:20:16 +0000 Subject: [PATCH 2/2] add variable SensorId Signed-off-by: wuzhihuitmac Change-Id: I4433ef0be75f5a0aa7ca97148c9664630383cf35 --- runtime/main/extend/systemplugin/napi/ohos_sensor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/main/extend/systemplugin/napi/ohos_sensor.js b/runtime/main/extend/systemplugin/napi/ohos_sensor.js index 4ebeea39..e364fe13 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_sensor.js +++ b/runtime/main/extend/systemplugin/napi/ohos_sensor.js @@ -226,6 +226,7 @@ export function mockSensor() { const sensor = { Sensor, SensorType, + SensorId, on: function (...args) { console.warn('sensor.on interface mocked in the Previewer. How this interface works on the' + 'Previewer may be different from that on a real device.') -- Gitee