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 /** 17 * @addtogroup Vibrator 18 * @{ 19 * 20 * @brief Provides unified APIs for vibrator services to access the vibrator driver. 21 * 22 * After obtaining a driver object or agent, a vibrator service starts or stops the vibrator 23 * using the functions provided by the driver object or agent. 24 * 25 * @version 1.0 26 */ 27 28 /** 29 * @file vibrator_type.h 30 * 31 * @brief Defines the vibrator data structure, including the vibration mode and effect type. 32 * 33 * @since 2.2 34 * @version 1.0 35 */ 36 37 #ifndef VIBRATOR_TYPE_H 38 #define VIBRATOR_TYPE_H 39 40 #include <stdint.h> 41 42 #ifdef __cplusplus 43 #if __cplusplus 44 extern "C" { 45 #endif 46 #endif /* __cplusplus */ 47 48 /** 49 * @brief Enumerates the return values of the vibrator module. 50 * 51 * @since 3.2 52 */ 53 enum VibratorStatus { 54 /** The operation is successful. */ 55 VIBRATOR_SUCCESS = 0, 56 /** The period setting is not supported. */ 57 VIBRATOR_NOT_PERIOD = -1, 58 /** The intensity setting is not supported. */ 59 VIBRATOR_NOT_INTENSITY = -2, 60 /** The frequency setting is not supported. */ 61 VIBRATOR_NOT_FREQUENCY = -3, 62 }; 63 64 /** 65 * @brief Enumerates the vibration modes of this vibrator. 66 * 67 * @since 2.2 68 */ 69 enum VibratorMode { 70 /**< Indicates the one-shot vibration with the given duration. */ 71 VIBRATOR_MODE_ONCE = 0, 72 /**< Indicates the periodic vibration with the preset effect. */ 73 VIBRATOR_MODE_PRESET = 1, 74 /**< Indicates invalid the effect mode. */ 75 VIBRATOR_MODE_BUTT 76 }; 77 78 /** 79 * @brief Enumerates the effect types of the composite effects. 80 * 81 * @since 3.2 82 */ 83 enum EffectType { 84 /**< Indicates the time effect type of the given time series. */ 85 EFFECT_TYPE_TIME, 86 /**< Indicates primitive vibration effect type for a given primitive vibration sequence. */ 87 EFFECT_TYPE_PRIMITIVE, 88 /**< Indicates invalid the effect type. */ 89 EFFECT_TYPE_BUTT, 90 }; 91 92 /** 93 * @brief Defines the vibration parameters. 94 * 95 * The parameters include the setting intensity and frequency capability the on and intensity and frequency range. 96 * 97 * @since 3.2 98 */ 99 struct VibratorInfo { 100 /**< setting intensity capability. 1 indicates support, 0 indicates not support. */ 101 bool isSupportIntensity; 102 /**< setting frequency capability. 1 indicates support, 0 indicates not support. */ 103 bool isSupportFrequency; 104 /**< Max intensity. */ 105 uint16_t intensityMaxValue; 106 /**< Min intensity. */ 107 uint16_t intensityMinValue; 108 /**< Max frequency(Hz). */ 109 int16_t frequencyMaxValue; 110 /**< Min frequency(Hz). */ 111 int16_t frequencyMinValue; 112 }; 113 114 /** 115 * @brief Defines the time effect parameters. 116 * 117 * The parameters include delay, time, intensity and frequency of vibration. 118 * 119 * @since 3.2 120 */ 121 struct TimeEffect { 122 int32_t delay; /** Waiting time. */ 123 int32_t time; /** Vibration time. */ 124 uint16_t intensity; /** Vibration intensity. */ 125 int16_t frequency; /** Vibration frequency(Hz). */ 126 }; 127 128 /** 129 * @brief Defines the primitive effect parameters. 130 * 131 * The parameters include delay, effect id and vibration intensity. 132 * 133 * @since 3.2 134 */ 135 struct PrimitiveEffect { 136 int32_t delay; /** Waiting time. */ 137 int32_t effectId; /** Effect id. */ 138 uint16_t intensity; /** Vibration intensity. */ 139 }; 140 141 /** 142 * @brief Defines two effects for custom composite effects. 143 * 144 * The parameters include time effect and primitive effect. 145 * 146 * @since 3.2 147 */ 148 union Effect { 149 struct TimeEffect timeEffect; /** Time effect, see {@link TimeEffect}. */ 150 struct PrimitiveEffect primitiveEffect; /** Primitive effect, see {@link PrimitiveEffect}. */ 151 }; 152 153 /** 154 * @brief Defines the composite vibration effect parameters. 155 * 156 * The parameters include type and sequences of composite effects. 157 * 158 * @since 3.2 159 */ 160 struct CompositeEffect { 161 /** Type of the composite effect, see {@link union HdfEffectType}. */ 162 int32_t type; 163 /** The sequences of composite effects, see {@link union Effect}. */ 164 union Effect effects[]; 165 }; 166 167 /** 168 * @brief Defines the vibration effect information. 169 * 170 * The information include the capability to set the effect and the vibration duration of the effect. 171 * 172 * @since 3.2 173 */ 174 struct EffectInfo { 175 /** Vibration duration of the effect, in milliseconds. */ 176 int32_t duration; 177 /**< setting effect capability. 1 indicates support, 0 indicates not support. */ 178 bool isSupportEffect; 179 }; 180 181 #ifdef __cplusplus 182 #if __cplusplus 183 } 184 #endif 185 #endif /* __cplusplus */ 186 187 #endif /* VIBRATOR_TYPE_H */ 188 /** @} */ 189