From 30177a536915fee0abe201ef53a4e792d288f305 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Fri, 17 Jun 2022 17:04:52 +0800 Subject: [PATCH] ohos_sensor.js Signed-off-by: li-yaoyao777 --- .../extend/systemplugin/napi/ohos_sensor.js | 334 +++++++++--------- 1 file changed, 167 insertions(+), 167 deletions(-) diff --git a/runtime/main/extend/systemplugin/napi/ohos_sensor.js b/runtime/main/extend/systemplugin/napi/ohos_sensor.js index d7d4cbd0..993b2eec 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_sensor.js +++ b/runtime/main/extend/systemplugin/napi/ohos_sensor.js @@ -20,7 +20,7 @@ export function mockSensor() { x: '[PC preview] unknown x', y: '[PC preview] unknown y', z: '[PC preview] unknown z' - } + } const LinearAccelerometerResponse = { x: '[PC preview] unknown x', y: '[PC preview] unknown y', @@ -210,181 +210,181 @@ export function mockSensor() { } else if (args[0] == 281) { callback.call(this, paramMock.businessErrorMock, AccelerometerUncalibratedResponse); } - }, - once: function (...args) { - console.warn('sensor.once interface mocked in the Previewer. How this interface works on the' - + 'Previewer may be different from that on a real device.') + }, + once: function (...args) { + console.warn('sensor.once 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 (args[0] == 1) { + args[len - 1].call(this, paramMock.businessErrorMock, AccelerometerResponse); + } else if (args[0] == 2) { + args[len - 1].call(this, paramMock.businessErrorMock, GyroscopeResponse); + } else if (args[0] == 5) { + args[len - 1].call(this, paramMock.businessErrorMock, LightResponse); + } else if (args[0] == 6) { + args[len - 1].call(this, paramMock.businessErrorMock, MagneticFieldResponse); + } else if (args[0] == 8) { + args[len - 1].call(this, paramMock.businessErrorMock, BarometerResponse); + } else if (args[0] == 10) { + args[len - 1].call(this, paramMock.businessErrorMock, HallResponse); + } else if (args[0] == 12) { + args[len - 1].call(this, paramMock.businessErrorMock, ProximityResponse); + } else if (args[0] == 13) { + args[len - 1].call(this, paramMock.businessErrorMock, HumidityResponse); + } else if (args[0] == 256) { + args[len - 1].call(this, paramMock.businessErrorMock, OrientationResponse); + } else if (args[0] == 257) { + args[len - 1].call(this, paramMock.businessErrorMock, GravityResponse); + } else if (args[0] == 258) { + args[len - 1].call(this, paramMock.businessErrorMock, LinearAccelerometerResponse); + } else if (args[0] == 259) { + args[len - 1].call(this, paramMock.businessErrorMock, RotationVectorResponse); + } else if (args[0] == 260) { + args[len - 1].call(this, paramMock.businessErrorMock, AmbientTemperatureResponse); + } else if (args[0] == 261) { + args[len - 1].call(this, paramMock.businessErrorMock, MagneticFieldUncalibratedResponse); + } else if (args[0] == 263) { + args[len - 1].call(this, paramMock.businessErrorMock, GyroscopeUncalibratedResponse); + } else if (args[0] == 264) { + args[len - 1].call(this, paramMock.businessErrorMock, SignificantMotionResponse); + } else if (args[0] == 265) { + args[len - 1].call(this, paramMock.businessErrorMock, PedometerDetectResponse); + } else if (args[0] == 266) { + args[len - 1].call(this, paramMock.businessErrorMock, PedometerResponse); + } else if (args[0] == 278) { + args[len - 1].call(this, paramMock.businessErrorMock, HeartRateResponse); + } else if (args[0] == 280) { + args[len - 1].call(this, paramMock.businessErrorMock, WearDetectionResponse); + } else if (args[0] == 281) { + args[len - 1].call(this, paramMock.businessErrorMock, AccelerometerUncalibratedResponse); + } + }, + off: function (...args) { + console.warn('sensor.off 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 (args[0] == 1) { - args[len - 1].call(this, paramMock.businessErrorMock, AccelerometerResponse); - } else if (args[0] == 2) { - args[len - 1].call(this, paramMock.businessErrorMock, GyroscopeResponse); - } else if (args[0] == 5) { - args[len - 1].call(this, paramMock.businessErrorMock, LightResponse); - } else if (args[0] == 6) { - args[len - 1].call(this, paramMock.businessErrorMock, MagneticFieldResponse); - } else if (args[0] == 8) { - args[len - 1].call(this, paramMock.businessErrorMock, BarometerResponse); - } else if (args[0] == 10) { - args[len - 1].call(this, paramMock.businessErrorMock, HallResponse); - } else if (args[0] == 12) { - args[len - 1].call(this, paramMock.businessErrorMock, ProximityResponse); - } else if (args[0] == 13) { - args[len - 1].call(this, paramMock.businessErrorMock, HumidityResponse); - } else if (args[0] == 256) { - args[len - 1].call(this, paramMock.businessErrorMock, OrientationResponse); - } else if (args[0] == 257) { - args[len - 1].call(this, paramMock.businessErrorMock, GravityResponse); - } else if (args[0] == 258) { - args[len - 1].call(this, paramMock.businessErrorMock, LinearAccelerometerResponse); - } else if (args[0] == 259) { - args[len - 1].call(this, paramMock.businessErrorMock, RotationVectorResponse); - } else if (args[0] == 260) { - args[len - 1].call(this, paramMock.businessErrorMock, AmbientTemperatureResponse); - } else if (args[0] == 261) { - args[len - 1].call(this, paramMock.businessErrorMock, MagneticFieldUncalibratedResponse); - } else if (args[0] == 263) { - args[len - 1].call(this, paramMock.businessErrorMock, GyroscopeUncalibratedResponse); - } else if (args[0] == 264) { - args[len - 1].call(this, paramMock.businessErrorMock, SignificantMotionResponse); - } else if (args[0] == 265) { - args[len - 1].call(this, paramMock.businessErrorMock, PedometerDetectResponse); - } else if (args[0] == 266) { - args[len - 1].call(this, paramMock.businessErrorMock, PedometerResponse); - } else if (args[0] == 278) { - args[len - 1].call(this, paramMock.businessErrorMock, HeartRateResponse); - } else if (args[0] == 280) { - args[len - 1].call(this, paramMock.businessErrorMock, WearDetectionResponse); - } else if (args[0] == 281) { - args[len - 1].call(this, paramMock.businessErrorMock, AccelerometerUncalibratedResponse); - } + args[len - 1].call(this, paramMock.businessErrorMock); }, - off: function (...args) { - console.warn('sensor.off 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 - args[len - 1].call(this, paramMock.businessErrorMock); - }, - getGeomagneticField: function (...args) { - console.warn('sensor.getGeomagneticField 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.businessErrorMoc, 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.') - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMoc, 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.') - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramNumberMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramNumberMock); - }); - } - }, - getAngleModifiy: 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.') - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramArrayMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramArrayMock); - }); - } - }, - 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.') - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramArrayMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramArrayMock); - }); - } - }, - transformCoordinateSystem: function (...args) { - console.warn('sensor.transformCoordinateSystem 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.businessErrorMoc, paramMock.paramArrayMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramArrayMock); + getGeomagneticField: function (...args) { + console.warn('sensor.getGeomagneticField 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.businessErrorMoc, GeomagneticResponse); + } else { + return new Promise((resolve, reject) => { + resolve(GeomagneticResponse); }); } }, - createQuaternion: function (...args) { - console.warn('sensor.createQuaternion interface mocked in the Previewer. How this interface works on the' + 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.') + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, 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.') + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramNumberMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }); + } + }, + getAngleModifiy: 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.') - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramArrayMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramArrayMock); + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); }); } }, - 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.') - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramArrayMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramArrayMock); - }); + 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.') + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }); + } + }, + transformCoordinateSystem: function (...args) { + console.warn('sensor.transformCoordinateSystem 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.businessErrorMoc, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }); + } + }, + 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.') + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }); + } + }, + 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.') + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }); + } + }, + 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.') + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.Sensor); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.Sensor); + }); + } + }, + getSensorLists: function (...args) { + console.warn('sensor.getSensorLists 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.businessErrorMoc, paramMock.paramArrayMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }); + } } - }, - 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.') - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMoc, paramMock.Sensor); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.Sensor); - }); - } - }, - getSensorLists: function (...args) { - console.warn('sensor.getSensorLists 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.businessErrorMoc, paramMock.paramArrayMock); - } else { - return new Promise((resolve, reject) => { - resolve(paramMock.paramArrayMock); - }); - } - }, - } + }; return sensor } \ No newline at end of file