1 /*
2  * Copyright (c) 2021-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 #ifndef VIBRATOR_AGENT_TYPE_H
17 #define VIBRATOR_AGENT_TYPE_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /**
24  * @brief Describes the vibration effect of the vibrator when a user adjusts the timer.
25  *
26  * @since 1
27  */
28 const char *VIBRATOR_TYPE_CLOCK_TIMER = "haptic.clock.timer";
29 
30 /**
31  * @brief Describes the vibration effect of the vibrator when authentication fails.
32  *
33  * @since 11
34  */
35 const char *VIBRATOR_TYPE_FAIL = "haptic.notice.fail";
36 
37 /**
38  * @brief Describes the vibration effect of the vibrator when charging.
39  *
40  * @since 11
41  */
42 const char *VIBRATOR_TYPE_CHARGING = "haptic.calib.charge";
43 
44 /**
45  * @brief Describes the vibration effect of the vibrator when long pressed.
46  *
47  * @since 11
48  */
49 const char *VIBRATOR_TYPE_LONG_PRESS_LIGHT = "haptic.long_press_light";
50 
51 /**
52  * @brief Describes the vibration effect of the vibrator when long pressed.
53  *
54  * @since 11
55  */
56 const char *VIBRATOR_TYPE_LONG_PRESS_MEDIUM = "haptic.long_press_medium";
57 
58 /**
59  * @brief Describes the vibration effect of the vibrator when long pressed.
60  *
61  * @since 11
62  */
63 const char *VIBRATOR_TYPE_LONG_PRESS_HEAVY = "haptic.long_press_medium";
64 
65 /**
66  * @brief Describes the vibration effect of the vibrator when slide.
67  *
68  * @since 11
69  */
70 const char *VIBRATOR_TYPE_SLIDE_LIGHT = "haptic.slide";
71 
72 /**
73  * @brief Describes the vibration effect of the vibrator when the threshold is reached.
74  *
75  * @since 11
76  */
77 const char *VIBRATOR_TYPE_THRESHOID = "haptic.common.threshold";
78 
79 /**
80  * @brief Describes the hard vibration effect of the vibrator.
81  *
82  * @since 12
83  */
84 const char *VIBRATOR_TYPE_HARD = "haptic.effect.hard";
85 
86 /**
87  * @brief Describes the soft vibration effect of the vibrator.
88  *
89  * @since 12
90  */
91 const char *VIBRATOR_TYPE_SOFT = "haptic.effect.soft";
92 
93 /**
94  * @brief Describes the sharp vibration effect of the vibrator.
95  *
96  * @since 12
97  */
98 const char *VIBRATOR_TYPE_SHARP = "haptic.effect.sharp";
99 
100 /**
101  * @brief Describes the vibration effect of the vibrator when slide.
102  *
103  * @since 12
104  */
105 const char *VIBRATOR_TYPE_SLIDE = "haptic.slide";
106 
107 /**
108  * @brief Enumerates vibration usages.
109  *
110  * @since 9
111  */
112 typedef enum VibratorUsage {
113     USAGE_UNKNOWN = 0,            /**< Vibration is used for unknown, lowest priority */
114     USAGE_ALARM = 1,              /**< Vibration is used for alarm */
115     USAGE_RING = 2,               /**< Vibration is used for ring */
116     USAGE_NOTIFICATION = 3,       /**< Vibration is used for notification */
117     USAGE_COMMUNICATION = 4,      /**< Vibration is used for communication */
118     USAGE_TOUCH = 5,              /**< Vibration is used for touch */
119     USAGE_MEDIA = 6,              /**< Vibration is used for media */
120     USAGE_PHYSICAL_FEEDBACK = 7,  /**< Vibration is used for physical feedback */
121     USAGE_SIMULATE_REALITY = 8,   /**< Vibration is used for simulate reality */
122     USAGE_MAX
123 } VibratorUsage;
124 
125 /**
126  * @brief Vibration effect description file.
127  *
128  * @since 11
129  */
130 typedef struct VibratorFileDescription {
131     int32_t fd = -1;
132     int64_t offset = -1;
133     int64_t length = -1;
134 } VibratorFileDescription;
135 
136 /**
137  * @brief The type of vibration event.
138  *
139  * @since 11
140  */
141 typedef enum VibratorEventType {
142     EVENT_TYPE_UNKNOWN = -1, /**< Unknown vibration event type */
143     EVENT_TYPE_CONTINUOUS = 0, /**< Continuous vibration event type */
144     EVENT_TYPE_TRANSIENT = 1, /**< Transient vibration event type */
145 } VibratorEventType;
146 
147 /**
148  * @brief Vibration curve adjustment point.
149  *
150  * @since 11
151  */
152 typedef struct VibratorCurvePoint {
153     int32_t time = -1;
154     int32_t intensity = -1;
155     int32_t frequency = -1;
156 } VibratorCurvePoint;
157 
158 /**
159  * @brief The vibration event.
160  *
161  * @since 11
162  */
163 typedef struct VibratorEvent {
164     VibratorEventType type = EVENT_TYPE_UNKNOWN;
165     int32_t time = -1;
166     int32_t duration = -1;
167     int32_t intensity = -1;
168     int32_t frequency = -1;
169     int32_t index = 0; // 0:both 1:left 2:right
170     int32_t pointNum = 0;
171     VibratorCurvePoint *points = nullptr;
172 } VibratorEvent;
173 
174 /**
175  * @brief Describe the vibration pattern, including the vibration event sequence.
176  *
177  * @since 11
178  */
179 typedef struct VibratorPattern {
180     int32_t time = -1;
181     int32_t eventNum = 0;
182     int32_t patternDuration = 0;
183     VibratorEvent *events = nullptr;
184 } VibratorPattern;
185 
186 /**
187  * @brief Describes the vibration package structure, including the vibration pattern sequence.
188  *
189  * @since 11
190  */
191 typedef struct VibratorPackage {
192     int32_t patternNum = 0; // pattern
193     int32_t packageDuration = 0;
194     VibratorPattern *patterns = nullptr;
195 } VibratorPackage;
196 
197 /**
198  * @brief Vibration effect adjustment parameters.
199  *
200  * @since 11
201  */
202 typedef struct VibratorParameter {
203     int32_t intensity = 100;  // from 0 to 100
204     int32_t frequency = 0;    // from -100 to 100
205     int32_t reserved = 0;
206 } VibratorParameter;
207 /** @} */
208 #ifdef __cplusplus
209 };
210 #endif
211 
212 #endif  // endif VIBRATOR_AGENT_TYPE_H