1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "cj_sensor_ffi.h"
17
18 #include "cj_sensor_impl.h"
19 #include "sensor_errors.h"
20
21 using OHOS::Sensors::CJSensorImpl;
22 using OHOS::Sensors::PARAMETER_ERROR;
23
24 extern "C" {
FfiSensorSubscribeSensor(int32_t sensorId,int64_t interval,void (* callback)(SensorEvent * event))25 int32_t FfiSensorSubscribeSensor(int32_t sensorId, int64_t interval, void (*callback)(SensorEvent *event))
26 {
27 return CJ_SENSOR_IMPL->OnSensorChange(sensorId, interval, callback);
28 }
29
FfiSensorUnSubscribeSensor(int32_t sensorId)30 int32_t FfiSensorUnSubscribeSensor(int32_t sensorId)
31 {
32 return CJ_SENSOR_IMPL->OffSensorChange(sensorId);
33 }
34
FfiSensorGetGeomagneticInfo(CLocationOptions location,int64_t timeMillis)35 CGeomagneticData FfiSensorGetGeomagneticInfo(CLocationOptions location, int64_t timeMillis)
36 {
37 return CJ_SENSOR_IMPL->GetGeomagneticInfo(location, timeMillis);
38 }
39
FfiSensorGetDeviceAltitude(float seaPressure,float currentPressure,float * altitude)40 int32_t FfiSensorGetDeviceAltitude(float seaPressure, float currentPressure, float *altitude)
41 {
42 return CJ_SENSOR_IMPL->GetAltitude(seaPressure, currentPressure, altitude);
43 }
44
FfiSensorGetInclination(CArrFloat32 inclinationMatrix,float * geomagneticDip)45 int32_t FfiSensorGetInclination(CArrFloat32 inclinationMatrix, float *geomagneticDip)
46 {
47 return CJ_SENSOR_IMPL->GetGeomagneticDip(inclinationMatrix, geomagneticDip);
48 }
49
FfiSensorGetAngleVariation(CArrFloat32 currentRotationMatrix,CArrFloat32 preRotationMatrix,CArrFloat32 * angleChange)50 int32_t FfiSensorGetAngleVariation(CArrFloat32 currentRotationMatrix, CArrFloat32 preRotationMatrix,
51 CArrFloat32 *angleChange)
52 {
53 return CJ_SENSOR_IMPL->GetAngleModify(currentRotationMatrix, preRotationMatrix, angleChange);
54 }
55
FfiSensorGetRotationMatrix(CArrFloat32 rotationVector,CArrFloat32 * rotation)56 int32_t FfiSensorGetRotationMatrix(CArrFloat32 rotationVector, CArrFloat32 *rotation)
57 {
58 if (rotation == nullptr) {
59 SEN_HILOGE("Invalid parameter, rotation is nullptr!");
60 return PARAMETER_ERROR;
61 }
62
63 return CJ_SENSOR_IMPL->GetRotationMatrix(rotationVector, *rotation);
64 }
65
FfiSensorTransformRotationMatrix(CArrFloat32 inRotationVector,CCoordinatesOptions coordinates,CArrFloat32 * rotationMatrix)66 int32_t FfiSensorTransformRotationMatrix(CArrFloat32 inRotationVector, CCoordinatesOptions coordinates,
67 CArrFloat32 *rotationMatrix)
68 {
69 if (rotationMatrix == nullptr) {
70 SEN_HILOGE("Invalid parameter, rotationMatrix is nullptr!");
71 return PARAMETER_ERROR;
72 }
73
74 return CJ_SENSOR_IMPL->TransformRotationMatrix(inRotationVector, coordinates.x, coordinates.y, *rotationMatrix);
75 }
76
FfiSensorGetQuaternion(CArrFloat32 rotationVector,CArrFloat32 * quaternion)77 int32_t FfiSensorGetQuaternion(CArrFloat32 rotationVector, CArrFloat32 *quaternion)
78 {
79 if (quaternion == nullptr) {
80 SEN_HILOGE("Invalid parameter, quaternion is nullptr!");
81 return PARAMETER_ERROR;
82 }
83
84 return CJ_SENSOR_IMPL->GetQuaternion(rotationVector, *quaternion);
85 }
86
FfiSensorGetOrientation(CArrFloat32 rotationMatrix,CArrFloat32 * rotationAngle)87 int32_t FfiSensorGetOrientation(CArrFloat32 rotationMatrix, CArrFloat32 *rotationAngle)
88 {
89 if (rotationAngle == nullptr) {
90 SEN_HILOGE("Invalid parameter, rotationAngle is nullptr!");
91 return PARAMETER_ERROR;
92 }
93
94 return CJ_SENSOR_IMPL->GetOrientation(rotationMatrix, *rotationAngle);
95 }
96
FfiSensorGetRotationMatrixByGravityAndGeomagnetic(CArrFloat32 gravity,CArrFloat32 geomagnetic,CRotationMatrixResponse * rotationMaxtrix)97 int32_t FfiSensorGetRotationMatrixByGravityAndGeomagnetic(CArrFloat32 gravity, CArrFloat32 geomagnetic,
98 CRotationMatrixResponse *rotationMaxtrix)
99 {
100 if (rotationMaxtrix == nullptr) {
101 SEN_HILOGE("Invalid parameter, rotationMaxtrix is nullptr!");
102 return PARAMETER_ERROR;
103 }
104
105 return CJ_SENSOR_IMPL->GetRotationMatrixByGraityAndGeomagnetic(gravity, geomagnetic, rotationMaxtrix->rotation,
106 rotationMaxtrix->inclination);
107 }
108
FfiSensorGetAllSensors(CSensorArray * sensors)109 int32_t FfiSensorGetAllSensors(CSensorArray *sensors)
110 {
111 if (sensors == nullptr) {
112 SEN_HILOGE("Invalid parameter, sensors is nullptr!");
113 return PARAMETER_ERROR;
114 }
115
116 return CJ_SENSOR_IMPL->GetAllSensorList(*sensors);
117 }
118 }