1 /*
2  * Copyright (c) 2021-2023 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 #ifndef HDI_SENSOR_CHANNEL_H
17 #define HDI_SENSOR_CHANNEL_H
18 
19 #include "hdf_io_service_if.h"
20 #include "sensor_type.h"
21 
22 #define HDI_SENSOR_GRAVITY          (9.80665f)
23 #define HDI_SENSOR_ACCEL_LSB        1024
24 #define HDI_SENSOR_UNITS            1000
25 #define HDI_SENSOR_PI               (3.14f)
26 #define HDI_SENSOR_SEMICIRCLE       (180.0f)
27 #define HDI_SENSOR_FLOAT_UNITS      (1000.0f)
28 #define HDI_SENSOR_FLOAT_HUN_UNITS  (100.0f)
29 #define HDI_SENSOR_FLOAT_TEN_UNITS  (10.0f)
30 #define MAX_DUMP_DATA_SIZE 10
31 #define DATA_LENGTH 32
32 
33 enum SensorDataDimension {
34     DATA_X             = 1,
35     DATA_XY            = 2,
36     DATA_XYZ           = 3,
37     DATA_XYZA          = 4,
38     DATA_XYZABC        = 6,
39     DATA_POSTURE       = 8,
40     DATA_MAX_DATA_SIZE = DATA_POSTURE
41 };
42 
43 enum SensorStatusAccuracy {
44     SENSOR_STATUS_UNRELIABLE = 0,
45     SENSOR_STATUS_ACCURACY_LOW = 1,
46     SENSOR_STATUS_ACCURACY_MEDIUM = 2,
47     SENSOR_STATUS_ACCURACY_HIGH = 3,
48 };
49 
50 struct SensorCovertCoff {
51     int32_t sensorTypeId;
52     int32_t sensorId;
53     enum SensorDataDimension dim;
54     float coff[DATA_MAX_DATA_SIZE];
55 };
56 
57 struct SensorDumpDate {
58     int32_t sensorId;
59     int32_t version;
60     int64_t timestamp;
61     uint32_t option;
62     int32_t mode;
63     uint8_t data[DATA_LENGTH];
64     uint32_t dataLen;
65 };
66 
67 struct SensorDatePack {
68     int32_t count;
69     int32_t pos;
70     struct SensorDumpDate listDumpArr[MAX_DUMP_DATA_SIZE];
71 };
72 
73 int32_t Register(int32_t groupId, RecordDataCallback cb);
74 int32_t Unregister(int32_t groupId, RecordDataCallback cb);
75 struct HdfDevEventlistener *GetSensorListener(void);
76 void SetSensorIdBySensorType(enum SensorTypeTag type, int32_t sensorId);
77 struct SensorDatePack *GetEventData(void);
78 void ConvertSensorData(struct SensorEvents *event);
79 
80 #endif /* HDI_SENSOR_CHANNEL_H */
81