From 425a5120e0ec306aaeb599828920cc3f2d29b5c2 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Mon, 14 Mar 2022 10:39:34 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- interfaces/plugin/src/sensor_js.cpp | 44 ++++++++++++++++------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 02c4c67f..e8289310 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -39,6 +39,8 @@ using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = {LOG_CORE, 0xD002708, "SensorJsAPI"}; +const int32_t REPORTING_INTERVAL = 200000000; + static std::map g_onceCallbackInfos; static std::map> g_onCallbackInfos; @@ -98,12 +100,12 @@ static int32_t UnsubscribeSensor(int32_t sensorTypeId) { HiLog::Info(LABEL, "%{public}s in", __func__); int32_t ret = DeactivateSensor(sensorTypeId, &user); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s DeactivateSensor failed", __func__); return ret; } ret = UnsubscribeSensor(sensorTypeId, &user); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s UnsubscribeSensor failed", __func__); return ret; } @@ -115,17 +117,17 @@ static int32_t SubscribeSensor(int32_t sensorTypeId, int64_t interval, RecordSen { HiLog::Info(LABEL, "%{public}s in, sensorTypeId: %{public}d", __func__, sensorTypeId); int32_t ret = SubscribeSensor(sensorTypeId, &user); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s subscribeSensor failed", __func__); return ret; } ret = SetBatch(sensorTypeId, &user, interval, 0); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s set batch failed", __func__); return ret; } ret = ActivateSensor(sensorTypeId, &user); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s activateSensor failed", __func__); return ret; } @@ -159,7 +161,7 @@ static napi_value Once(napi_env env, napi_callback_info info) if (g_onCallbackInfos.find(sensorTypeId) == g_onCallbackInfos.end()) { HiLog::Debug(LABEL, "%{public}s no subscription to change sensor data, registration is required", __func__); int32_t ret = SubscribeSensor(sensorTypeId, 200000000, DataCallbackImpl); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s subscribe Sensor failed", __func__); g_onceCallbackInfos.erase(sensorTypeId); return nullptr; @@ -171,11 +173,13 @@ static napi_value Once(napi_env env, napi_callback_info info) static bool IsSubscribed(napi_env env, int32_t sensorTypeId, napi_value callback) { + HiLog::Info(LABEL, "%{public}s in, sensorTypeId: %{public}d", __func__, sensorTypeId); if (g_onCallbackInfos.find(sensorTypeId) == g_onCallbackInfos.end()) { return false; } - std::vector callbackInfos = g_onCallbackInfos[sensorTypeId]; + std::vector callbackInfos = g_onCallbackInfos[sensorTypeId]; for (auto callbackInfo : callbackInfos) { + napi_value sensorCallback = nullptr; napi_get_reference_value(env, callbackInfo->callback[0], &sensorCallback); if (IsNapiValueSame(env, callback, sensorCallback)) { @@ -219,7 +223,7 @@ static napi_value On(napi_env env, napi_callback_info info) return nullptr; } int32_t sensorTypeId = GetCppInt32(args[0], env); - int64_t interval = 200000000; + int64_t interval = REPORTING_INTERVAL; if (argc == 3) { napi_value value = NapiGetNamedProperty(args[2], "interval", env); if (!IsMatchType(env, value, napi_number)) { @@ -230,7 +234,7 @@ static napi_value On(napi_env env, napi_callback_info info) HiLog::Debug(LABEL, "%{public}s interval is %{public}lld", __func__, interval); } int32_t ret = SubscribeSensor(sensorTypeId, interval, DataCallbackImpl); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s subscribeSensor failed", __func__); return nullptr; } @@ -299,7 +303,7 @@ static napi_value Off(napi_env env, napi_callback_info info) RemoveAllCallback(env, sensorTypeId); } int32_t ret = UnsubscribeSensor(sensorTypeId); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s UnsubscribeSensor failed", __func__); } return nullptr; @@ -396,7 +400,7 @@ static napi_value TransformCoordinateSystem(napi_env env, napi_callback_info inf std::vector outRotationVector(inRotationVectorLength); std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->transformCoordinateSystem(inRotationVector, axisX, axisY, outRotationVector); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s EmitPromiseWork failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -446,7 +450,7 @@ static napi_value GetAngleModify(napi_env env, napi_callback_info info) std::vector angleChange(ROTATION_VECTOR_LENGTH); std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->getAngleModify(curRotationVector, preRotationVector, angleChange); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -495,7 +499,7 @@ static napi_value GetDirection(napi_env env, napi_callback_info info) std::vector rotationAngle(ROTATION_VECTOR_LENGTH); std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->getDirection(rotationMatrix, rotationAngle); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -546,7 +550,7 @@ static napi_value CreateQuaternion(napi_env env, napi_callback_info info) std::vector quaternion(QUATERNION_LENGTH); std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->createQuaternion(rotationVector, quaternion); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -597,7 +601,7 @@ static napi_value GetAltitude(napi_env env, napi_callback_info info) float altitude = 0; std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->getAltitude(seaPressure, currentPressure, &altitude); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -643,7 +647,7 @@ static napi_value GetGeomagneticDip(napi_env env, napi_callback_info info) float geomagneticDip = 0; std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->getGeomagneticDip(inclinationMatrix, &geomagneticDip); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -690,7 +694,7 @@ static napi_value CreateRotationMatrix(napi_env env, napi_callback_info info) std::vector rotationVector = GetCppArrayFloat(env, args[0]); std::vector rotationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); int32_t ret = sensorAlgorithm->createRotationMatrix(rotationVector, rotationMatrix); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -725,7 +729,7 @@ static napi_value CreateRotationMatrix(napi_env env, napi_callback_info info) std::vector rotation(THREE_DIMENSIONAL_MATRIX_LENGTH); std::vector inclination(THREE_DIMENSIONAL_MATRIX_LENGTH); int32_t ret = sensorAlgorithm->createRotationAndInclination(gravity, geomagnetic, rotation, inclination); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -770,7 +774,7 @@ static napi_value GetSensorList(napi_env env, napi_callback_info info) .type = GET_SENSOR_LIST, }; int32_t ret = GetAllSensors(&sensorInfos, &count); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s get sensor list failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -819,7 +823,7 @@ static napi_value GetSingleSensor(napi_env env, napi_callback_info info) SensorInfo *sensorInfos = nullptr; int32_t count = 0; int32_t ret = GetAllSensors(&sensorInfos, &count); - if (ret < 0) { + if (ret != 0) { HiLog::Error(LABEL, "%{public}s get sensorlist failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; -- Gitee From 5ef7620f5e8a807c6ec6a2fe709b1d0d45b4c371 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Mon, 14 Mar 2022 11:05:42 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- interfaces/plugin/src/sensor_js.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index e8289310..5a93fbb3 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -179,7 +179,6 @@ static bool IsSubscribed(napi_env env, int32_t sensorTypeId, napi_value callback } std::vector callbackInfos = g_onCallbackInfos[sensorTypeId]; for (auto callbackInfo : callbackInfos) { - napi_value sensorCallback = nullptr; napi_get_reference_value(env, callbackInfo->callback[0], &sensorCallback); if (IsNapiValueSame(env, callback, sensorCallback)) { @@ -783,7 +782,6 @@ static napi_value GetSensorList(napi_env env, napi_callback_info info) asyncCallbackInfo->sensorInfos.push_back(*(sensorInfos + i)); } } - if (argc == 0) { napi_deferred deferred = nullptr; napi_value promise = nullptr; -- Gitee From 3fc033ab1a3bd53bd3ee5b66082225e2d20e5c15 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Mon, 14 Mar 2022 12:24:44 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- interfaces/plugin/src/sensor_js.cpp | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 5a93fbb3..1f0d0140 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -100,12 +100,12 @@ static int32_t UnsubscribeSensor(int32_t sensorTypeId) { HiLog::Info(LABEL, "%{public}s in", __func__); int32_t ret = DeactivateSensor(sensorTypeId, &user); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s DeactivateSensor failed", __func__); return ret; } ret = UnsubscribeSensor(sensorTypeId, &user); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s UnsubscribeSensor failed", __func__); return ret; } @@ -117,17 +117,17 @@ static int32_t SubscribeSensor(int32_t sensorTypeId, int64_t interval, RecordSen { HiLog::Info(LABEL, "%{public}s in, sensorTypeId: %{public}d", __func__, sensorTypeId); int32_t ret = SubscribeSensor(sensorTypeId, &user); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s subscribeSensor failed", __func__); return ret; } ret = SetBatch(sensorTypeId, &user, interval, 0); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s set batch failed", __func__); return ret; } ret = ActivateSensor(sensorTypeId, &user); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s activateSensor failed", __func__); return ret; } @@ -161,7 +161,7 @@ static napi_value Once(napi_env env, napi_callback_info info) if (g_onCallbackInfos.find(sensorTypeId) == g_onCallbackInfos.end()) { HiLog::Debug(LABEL, "%{public}s no subscription to change sensor data, registration is required", __func__); int32_t ret = SubscribeSensor(sensorTypeId, 200000000, DataCallbackImpl); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s subscribe Sensor failed", __func__); g_onceCallbackInfos.erase(sensorTypeId); return nullptr; @@ -233,7 +233,7 @@ static napi_value On(napi_env env, napi_callback_info info) HiLog::Debug(LABEL, "%{public}s interval is %{public}lld", __func__, interval); } int32_t ret = SubscribeSensor(sensorTypeId, interval, DataCallbackImpl); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s subscribeSensor failed", __func__); return nullptr; } @@ -302,7 +302,7 @@ static napi_value Off(napi_env env, napi_callback_info info) RemoveAllCallback(env, sensorTypeId); } int32_t ret = UnsubscribeSensor(sensorTypeId); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s UnsubscribeSensor failed", __func__); } return nullptr; @@ -399,7 +399,7 @@ static napi_value TransformCoordinateSystem(napi_env env, napi_callback_info inf std::vector outRotationVector(inRotationVectorLength); std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->transformCoordinateSystem(inRotationVector, axisX, axisY, outRotationVector); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s EmitPromiseWork failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -449,7 +449,7 @@ static napi_value GetAngleModify(napi_env env, napi_callback_info info) std::vector angleChange(ROTATION_VECTOR_LENGTH); std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->getAngleModify(curRotationVector, preRotationVector, angleChange); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -498,7 +498,7 @@ static napi_value GetDirection(napi_env env, napi_callback_info info) std::vector rotationAngle(ROTATION_VECTOR_LENGTH); std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->getDirection(rotationMatrix, rotationAngle); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -549,7 +549,7 @@ static napi_value CreateQuaternion(napi_env env, napi_callback_info info) std::vector quaternion(QUATERNION_LENGTH); std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->createQuaternion(rotationVector, quaternion); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -600,7 +600,7 @@ static napi_value GetAltitude(napi_env env, napi_callback_info info) float altitude = 0; std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->getAltitude(seaPressure, currentPressure, &altitude); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -646,7 +646,7 @@ static napi_value GetGeomagneticDip(napi_env env, napi_callback_info info) float geomagneticDip = 0; std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->getGeomagneticDip(inclinationMatrix, &geomagneticDip); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -693,7 +693,7 @@ static napi_value CreateRotationMatrix(napi_env env, napi_callback_info info) std::vector rotationVector = GetCppArrayFloat(env, args[0]); std::vector rotationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); int32_t ret = sensorAlgorithm->createRotationMatrix(rotationVector, rotationMatrix); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -728,7 +728,7 @@ static napi_value CreateRotationMatrix(napi_env env, napi_callback_info info) std::vector rotation(THREE_DIMENSIONAL_MATRIX_LENGTH); std::vector inclination(THREE_DIMENSIONAL_MATRIX_LENGTH); int32_t ret = sensorAlgorithm->createRotationAndInclination(gravity, geomagnetic, rotation, inclination); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -773,7 +773,7 @@ static napi_value GetSensorList(napi_env env, napi_callback_info info) .type = GET_SENSOR_LIST, }; int32_t ret = GetAllSensors(&sensorInfos, &count); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s get sensor list failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -821,7 +821,7 @@ static napi_value GetSingleSensor(napi_env env, napi_callback_info info) SensorInfo *sensorInfos = nullptr; int32_t count = 0; int32_t ret = GetAllSensors(&sensorInfos, &count); - if (ret != 0) { + if (ret != OHOS::Sensors::SUCCESS) { HiLog::Error(LABEL, "%{public}s get sensorlist failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; -- Gitee From 11e5c5dbc9c464d18b5fe0311a961a87812cc325 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Mon, 14 Mar 2022 16:25:45 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- interfaces/plugin/src/sensor_js.cpp | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 1f0d0140..d70df4a5 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -100,12 +100,12 @@ static int32_t UnsubscribeSensor(int32_t sensorTypeId) { HiLog::Info(LABEL, "%{public}s in", __func__); int32_t ret = DeactivateSensor(sensorTypeId, &user); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s DeactivateSensor failed", __func__); return ret; } ret = UnsubscribeSensor(sensorTypeId, &user); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s UnsubscribeSensor failed", __func__); return ret; } @@ -117,17 +117,17 @@ static int32_t SubscribeSensor(int32_t sensorTypeId, int64_t interval, RecordSen { HiLog::Info(LABEL, "%{public}s in, sensorTypeId: %{public}d", __func__, sensorTypeId); int32_t ret = SubscribeSensor(sensorTypeId, &user); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s subscribeSensor failed", __func__); return ret; } ret = SetBatch(sensorTypeId, &user, interval, 0); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s set batch failed", __func__); return ret; } ret = ActivateSensor(sensorTypeId, &user); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s activateSensor failed", __func__); return ret; } @@ -161,7 +161,7 @@ static napi_value Once(napi_env env, napi_callback_info info) if (g_onCallbackInfos.find(sensorTypeId) == g_onCallbackInfos.end()) { HiLog::Debug(LABEL, "%{public}s no subscription to change sensor data, registration is required", __func__); int32_t ret = SubscribeSensor(sensorTypeId, 200000000, DataCallbackImpl); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s subscribe Sensor failed", __func__); g_onceCallbackInfos.erase(sensorTypeId); return nullptr; @@ -233,7 +233,7 @@ static napi_value On(napi_env env, napi_callback_info info) HiLog::Debug(LABEL, "%{public}s interval is %{public}lld", __func__, interval); } int32_t ret = SubscribeSensor(sensorTypeId, interval, DataCallbackImpl); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s subscribeSensor failed", __func__); return nullptr; } @@ -302,7 +302,7 @@ static napi_value Off(napi_env env, napi_callback_info info) RemoveAllCallback(env, sensorTypeId); } int32_t ret = UnsubscribeSensor(sensorTypeId); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s UnsubscribeSensor failed", __func__); } return nullptr; @@ -399,7 +399,7 @@ static napi_value TransformCoordinateSystem(napi_env env, napi_callback_info inf std::vector outRotationVector(inRotationVectorLength); std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->transformCoordinateSystem(inRotationVector, axisX, axisY, outRotationVector); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s EmitPromiseWork failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -449,7 +449,7 @@ static napi_value GetAngleModify(napi_env env, napi_callback_info info) std::vector angleChange(ROTATION_VECTOR_LENGTH); std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->getAngleModify(curRotationVector, preRotationVector, angleChange); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -498,7 +498,7 @@ static napi_value GetDirection(napi_env env, napi_callback_info info) std::vector rotationAngle(ROTATION_VECTOR_LENGTH); std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->getDirection(rotationMatrix, rotationAngle); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -549,7 +549,7 @@ static napi_value CreateQuaternion(napi_env env, napi_callback_info info) std::vector quaternion(QUATERNION_LENGTH); std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->createQuaternion(rotationVector, quaternion); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -600,7 +600,7 @@ static napi_value GetAltitude(napi_env env, napi_callback_info info) float altitude = 0; std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->getAltitude(seaPressure, currentPressure, &altitude); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -646,7 +646,7 @@ static napi_value GetGeomagneticDip(napi_env env, napi_callback_info info) float geomagneticDip = 0; std::unique_ptr sensorAlgorithm = std::make_unique(); int32_t ret = sensorAlgorithm->getGeomagneticDip(inclinationMatrix, &geomagneticDip); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -693,7 +693,7 @@ static napi_value CreateRotationMatrix(napi_env env, napi_callback_info info) std::vector rotationVector = GetCppArrayFloat(env, args[0]); std::vector rotationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); int32_t ret = sensorAlgorithm->createRotationMatrix(rotationVector, rotationMatrix); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -728,7 +728,7 @@ static napi_value CreateRotationMatrix(napi_env env, napi_callback_info info) std::vector rotation(THREE_DIMENSIONAL_MATRIX_LENGTH); std::vector inclination(THREE_DIMENSIONAL_MATRIX_LENGTH); int32_t ret = sensorAlgorithm->createRotationAndInclination(gravity, geomagnetic, rotation, inclination); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -773,7 +773,7 @@ static napi_value GetSensorList(napi_env env, napi_callback_info info) .type = GET_SENSOR_LIST, }; int32_t ret = GetAllSensors(&sensorInfos, &count); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s get sensor list failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; @@ -821,7 +821,7 @@ static napi_value GetSingleSensor(napi_env env, napi_callback_info info) SensorInfo *sensorInfos = nullptr; int32_t count = 0; int32_t ret = GetAllSensors(&sensorInfos, &count); - if (ret != OHOS::Sensors::SUCCESS) { + if (ret != OHOS::ERR_OK) { HiLog::Error(LABEL, "%{public}s get sensorlist failed", __func__); asyncCallbackInfo->type = FAIL; asyncCallbackInfo->error.code = ret; -- Gitee From 594e55b6155406a03f00f3b325b2d2eac67fbd45 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Mon, 14 Mar 2022 16:46:17 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- interfaces/plugin/include/sensor_js.h | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/plugin/include/sensor_js.h b/interfaces/plugin/include/sensor_js.h index bb38db19..00d01db9 100755 --- a/interfaces/plugin/include/sensor_js.h +++ b/interfaces/plugin/include/sensor_js.h @@ -16,6 +16,7 @@ #define SENSOR_JS_H #include "sensor_agent.h" +#include "errors.h" static int32_t UnsubscribeSensor(int32_t sensorTypeId); static void DataCallbackImpl(SensorEvent *event); -- Gitee