• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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 * @file
18 * @kit SensorServiceKit
19 */
20
21import { AsyncCallback } from './@ohos.base';
22
23/**
24 * This module provides the capability to control motor vibration.
25 *
26 * @namespace vibrator
27 * @syscap SystemCapability.Sensors.MiscDevice
28 * @since 8
29 */
30/**
31 * This module provides the capability to control motor vibration.
32 *
33 * @namespace vibrator
34 * @syscap SystemCapability.Sensors.MiscDevice
35 * @atomicservice
36 * @since 11
37 */
38declare namespace vibrator {
39  /**
40   * The trigger motor vibrates for a specified length of time.
41   *
42   * @permission ohos.permission.VIBRATE
43   * @param { number } duration Indicate the duration of the motor vibration.
44   * @param { AsyncCallback<void> } callback The callback of vibrate.
45   * @syscap SystemCapability.Sensors.MiscDevice
46   * @since 8
47   * @deprecated since 9
48   * @useinstead vibrator#startVibration
49   */
50  function vibrate(duration: number, callback?: AsyncCallback<void>): void;
51
52  /**
53   * The trigger motor vibrates for a specified length of time.
54   *
55   * @permission ohos.permission.VIBRATE
56   * @param { number } duration Indicate the duration of the motor vibration.
57   * @returns { Promise<void> } Promise used to return the result.
58   * @syscap SystemCapability.Sensors.MiscDevice
59   * @since 8
60   * @deprecated since 9
61   * @useinstead vibrator#startVibration
62   */
63  function vibrate(duration: number): Promise<void>;
64
65  /**
66   * The trigger motor vibrates for the specified effect of the preset.
67   *
68   * @permission ohos.permission.VIBRATE
69   * @param { EffectId } effectId Indicate the specified effect of the preset, {@code EffectId}.
70   * @returns { Promise<void> } Promise used to return the result.
71   * @syscap SystemCapability.Sensors.MiscDevice
72   * @since 8
73   * @deprecated since 9
74   * @useinstead vibrator#startVibration
75   */
76  function vibrate(effectId: EffectId): Promise<void>;
77
78  /**
79   * The trigger motor vibrates for the specified effect of the preset.
80   *
81   * @permission ohos.permission.VIBRATE
82   * @param { EffectId } effectId Indicate the specified effect of the preset, {@code EffectId}.
83   * @param { AsyncCallback<void> } callback The callback of vibrate.
84   * @syscap SystemCapability.Sensors.MiscDevice
85   * @since 8
86   * @deprecated since 9
87   * @useinstead vibrator#startVibration
88   */
89  function vibrate(effectId: EffectId, callback?: AsyncCallback<void>): void;
90
91  /**
92   * Trigger vibrator vibration.
93   *
94   * @permission ohos.permission.VIBRATE
95   * @param { VibrateEffect } effect - Indicate vibrate effect, {@code VibrateEffect}.
96   * @param { VibrateAttribute } attribute - Indicate vibrate attribute, {@code VibrateAttribute}.
97   * @param { AsyncCallback<void> } callback - The callback of startVibration.
98   * @throws { BusinessError } 201 - Permission denied.
99   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
100   * <br> 2. Incorrect parameter types; 3. Parameter verification failed.
101   * @throws { BusinessError } 801 - Capability not supported.
102   * @throws { BusinessError } 14600101 - Device operation failed.
103   * @syscap SystemCapability.Sensors.MiscDevice
104   * @since 9
105   */
106  /**
107   * Trigger vibrator vibration.
108   *
109   * @permission ohos.permission.VIBRATE
110   * @param { VibrateEffect } effect - Indicate vibrate effect, {@code VibrateEffect}
111   * @param { VibrateAttribute } attribute - Indicate vibrate attribute, {@code VibrateAttribute}
112   * @param { AsyncCallback<void> } callback - The callback of startVibration
113   * @throws { BusinessError } 201 - Permission denied
114   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
115   * <br> 2. Incorrect parameter types; 3. Parameter verification failed.
116   * @throws { BusinessError } 801 - Capability not supported
117   * @throws { BusinessError } 14600101 - Device operation failed
118   * @syscap SystemCapability.Sensors.MiscDevice
119   * @atomicservice
120   * @since 11
121   */
122  function startVibration(effect: VibrateEffect, attribute: VibrateAttribute, callback: AsyncCallback<void>): void;
123
124  /**
125   * Trigger vibrator vibration.
126   *
127   * @permission ohos.permission.VIBRATE
128   * @param { VibrateEffect } effect - Indicate vibrate effect, {@code VibrateEffect}.
129   * @param { VibrateAttribute } attribute - Indicate vibrate attribute, {@code VibrateAttribute}.
130   * @returns { Promise<void> } Promise used to return the result.
131   * @throws { BusinessError } 201 - Permission denied.
132   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
133   * <br> 2. Incorrect parameter types; 3. Parameter verification failed.
134   * @throws { BusinessError } 801 - Capability not supported.
135   * @throws { BusinessError } 14600101 - Device operation failed.
136   * @syscap SystemCapability.Sensors.MiscDevice
137   * @since 9
138   */
139  /**
140   * Trigger vibrator vibration.
141   *
142   * @permission ohos.permission.VIBRATE
143   * @param { VibrateEffect } effect - Indicate vibrate effect, {@code VibrateEffect}.
144   * @param { VibrateAttribute } attribute - Indicate vibrate attribute, {@code VibrateAttribute}.
145   * @returns { Promise<void> } Promise used to return the result.
146   * @throws { BusinessError } 201 - Permission denied.
147   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
148   * <br> 2. Incorrect parameter types; 3. Parameter verification failed.
149   * @throws { BusinessError } 801 - Capability not supported.
150   * @throws { BusinessError } 14600101 - Device operation failed.
151   * @syscap SystemCapability.Sensors.MiscDevice
152   * @atomicservice
153   * @since 11
154   */
155  function startVibration(effect: VibrateEffect, attribute: VibrateAttribute): Promise<void>;
156
157  /**
158   * Stop the vibrator from vibrating.
159   *
160   * @permission ohos.permission.VIBRATE
161   * @param { VibratorStopMode } stopMode - Indicate the stop mode in which the motor vibrates, {@code VibratorStopMode}.
162   * @returns { Promise<void> } Promise used to return the result.
163   * @throws { BusinessError } 201 - Permission denied.
164   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
165   * <br> 2. Incorrect parameter types; 3. Parameter verification failed.
166   * @syscap SystemCapability.Sensors.MiscDevice
167   * @since 9
168   */
169  function stopVibration(stopMode: VibratorStopMode): Promise<void>;
170
171  /**
172   * Stop the vibrator from vibrating.
173   *
174   * @permission ohos.permission.VIBRATE
175   * @param { VibratorStopMode } stopMode - Indicate the stop mode in which the motor vibrates, {@code VibratorStopMode}.
176   * @param { AsyncCallback<void> } callback - The callback of stopVibration.
177   * @throws { BusinessError } 201 - Permission denied.
178   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
179   * <br> 2. Incorrect parameter types; 3. Parameter verification failed.
180   * @syscap SystemCapability.Sensors.MiscDevice
181   * @since 9
182   */
183  function stopVibration(stopMode: VibratorStopMode, callback: AsyncCallback<void>): void;
184
185  /**
186   * Stop any type of vibration.
187   *
188   * @permission ohos.permission.VIBRATE
189   * @param { AsyncCallback<void> } callback - The callback of stopVibration.
190   * @throws { BusinessError } 201 - Permission denied.
191   * @syscap SystemCapability.Sensors.MiscDevice
192   * @since 10
193   */
194  /**
195   * Stop any type of vibration.
196   *
197   * @permission ohos.permission.VIBRATE
198   * @param { AsyncCallback<void> } callback - The callback of stopVibration.
199   * @throws { BusinessError } 201 - Permission denied.
200   * @syscap SystemCapability.Sensors.MiscDevice
201   * @atomicservice
202   * @since 11
203   */
204  function stopVibration(callback: AsyncCallback<void>): void;
205
206  /**
207   * Stop any type of vibration.
208   *
209   * @permission ohos.permission.VIBRATE
210   * @returns { Promise<void> } Promise used to return the result.
211   * @throws { BusinessError } 201 - Permission denied.
212   * @syscap SystemCapability.Sensors.MiscDevice
213   * @since 10
214   */
215  /**
216   * Stop any type of vibration.
217   *
218   * @permission ohos.permission.VIBRATE
219   * @returns { Promise<void> } Promise used to return the result.
220   * @throws { BusinessError } 201 - Permission denied.
221   * @syscap SystemCapability.Sensors.MiscDevice
222   * @atomicservice
223   * @since 11
224   */
225  function stopVibration(): Promise<void>;
226
227  /**
228   * Stop any type of vibration.
229   *
230   * @permission ohos.permission.VIBRATE
231   * @throws { BusinessError } 201 - Permission denied.
232   * @throws { BusinessError } 14600101 - Device operation failed.
233   * @syscap SystemCapability.Sensors.MiscDevice
234   * @atomicservice
235   * @since 12
236   */
237  function stopVibrationSync(): void;
238
239  /**
240   * Whether the preset vibration effect is supported.
241   *
242   * @param { string } effectId Indicate the specified effect of the preset, {@code EffectId}.
243   * @param { AsyncCallback<boolean> } callback The callback of isSupportEffect.
244   * @throws { BusinessError } 201 - Permission denied.
245   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
246   * <br> 2. Incorrect parameter types; 3. Parameter verification failed.
247   * @syscap SystemCapability.Sensors.MiscDevice
248   * @since 10
249   */
250  function isSupportEffect(effectId: string, callback: AsyncCallback<boolean>): void;
251
252  /**
253   * Whether the preset vibration effect is supported.
254   *
255   * @param { string } effectId Indicate the specified effect of the preset, {@code EffectId}.
256   * @returns { Promise<boolean> } Promise used to return the result.
257   * @throws { BusinessError } 201 - Permission denied.
258   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
259   * <br> 2. Incorrect parameter types; 3. Parameter verification failed.
260   * @syscap SystemCapability.Sensors.MiscDevice
261   * @since 10
262   */
263  function isSupportEffect(effectId: string): Promise<boolean>;
264
265  /**
266   * Whether the preset vibration effect is supported.
267   *
268   * @param { string } effectId Indicate the specified effect of the preset, {@code EffectId}.
269   * @returns { boolean } Returns whether the effect is supported.
270   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
271   * <br> 2. Incorrect parameter types; 3. Parameter verification failed.
272   * @throws { BusinessError } 14600101 - Device operation failed.
273   * @syscap SystemCapability.Sensors.MiscDevice
274   * @since 12
275   */
276  function isSupportEffectSync(effectId: string): boolean;
277
278  /**
279   * Stop the motor from vibrating.
280   *
281   * @permission ohos.permission.VIBRATE
282   * @param { VibratorStopMode } stopMode Indicate the stop mode in which the motor vibrates, {@code VibratorStopMode}.
283   * @returns { Promise<void> } Promise used to return the result.
284   * @syscap SystemCapability.Sensors.MiscDevice
285   * @since 8
286   * @deprecated since 9
287   * @useinstead vibrator#stopVibration
288   */
289  function stop(stopMode: VibratorStopMode): Promise<void>;
290
291  /**
292   * Stop the motor from vibrating.
293   *
294   * @permission ohos.permission.VIBRATE
295   * @param { VibratorStopMode } stopMode Indicate the stop mode in which the motor vibrates, {@code VibratorStopMode}.
296   * @param { AsyncCallback<void> } callback The callback of stop.
297   * @syscap SystemCapability.Sensors.MiscDevice
298   * @since 8
299   * @deprecated since 9
300   * @useinstead vibrator#stopVibration
301   */
302  function stop(stopMode: VibratorStopMode, callback?: AsyncCallback<void>): void;
303
304  /**
305   * Whether the high-definition haptic is supported.
306   *
307   * @returns { boolean } Returns whether the high-definition haptic is supported.
308   * @throws { BusinessError } 14600101 - Device operation failed.
309   * @syscap SystemCapability.Sensors.MiscDevice
310   * @since 12
311   */
312  function isHdHapticSupported(): boolean;
313
314  /**
315   * Preset vibration effect string.
316   *
317   * @enum { string }
318   * @syscap SystemCapability.Sensors.MiscDevice
319   * @since 8
320   */
321  enum EffectId {
322  /**
323   * Describes the vibration effect of the vibrator when a user adjusts the timer.
324   *
325   * @syscap SystemCapability.Sensors.MiscDevice
326   * @since 8
327   */
328    EFFECT_CLOCK_TIMER = 'haptic.clock.timer'
329  }
330
331  /**
332   * Simple and universal vibration effects.
333   *
334   * @enum { string }
335   * @syscap SystemCapability.Sensors.MiscDevice
336   * @since 12
337   */
338  enum HapticFeedback {
339    /**
340     * Describes the soft vibration effect of the vibrator.
341     *
342     * @syscap SystemCapability.Sensors.MiscDevice
343     * @since 12
344     */
345    EFFECT_SOFT = 'haptic.effect.soft',
346
347    /**
348     * Describes the hard vibration effect of the vibrator.
349     *
350     * @syscap SystemCapability.Sensors.MiscDevice
351     * @since 12
352     */
353    EFFECT_HARD = 'haptic.effect.hard',
354
355    /**
356     * Describes the sharp vibration effect of the vibrator.
357     *
358     * @syscap SystemCapability.Sensors.MiscDevice
359     * @since 12
360     */
361    EFFECT_SHARP = 'haptic.effect.sharp',
362
363    /**
364     * Describes the vibration effect of the successful notice.
365     *
366     * @syscap SystemCapability.Sensors.MiscDevice
367     * @since 18
368     */
369    EFFECT_NOTICE_SUCCESS = 'haptic.notice.success',
370
371    /**
372     * Describes the vibration effect of the failed notice.
373     *
374     * @syscap SystemCapability.Sensors.MiscDevice
375     * @since 18
376     */
377    EFFECT_NOTICE_FAILURE = 'haptic.notice.fail',
378
379    /**
380     * Describes the vibration effect of the warning notice.
381     *
382     * @syscap SystemCapability.Sensors.MiscDevice
383     * @since 18
384     */
385    EFFECT_NOTICE_WARNING = 'haptic.notice.warning'
386  }
387
388  /**
389   * Vibrator vibration stop mode.
390   *
391   * @enum { string }
392   * @syscap SystemCapability.Sensors.MiscDevice
393   * @since 8
394   */
395  enum VibratorStopMode {
396  /**
397   * Indicates the mode of stopping a one-shot vibration effect.
398   *
399   * @syscap SystemCapability.Sensors.MiscDevice
400   * @since 8
401   */
402    VIBRATOR_STOP_MODE_TIME = 'time',
403
404  /**
405   * Indicates the mode of stopping a preset vibration effect.
406   *
407   * @syscap SystemCapability.Sensors.MiscDevice
408   * @since 8
409   */
410    VIBRATOR_STOP_MODE_PRESET = 'preset'
411  }
412
413  /**
414   * The use of vibration.
415   *
416   * @typedef {'unknown' | 'alarm' | 'ring' | 'notification' | 'communication' |
417   * 'touch' | 'media' | 'physicalFeedback' | 'simulateReality'}
418   * @syscap SystemCapability.Sensors.MiscDevice
419   * @since 9
420   */
421  /**
422   * The use of vibration.
423   *
424   * @typedef {'unknown' | 'alarm' | 'ring' | 'notification' | 'communication' |
425   * 'touch' | 'media' | 'physicalFeedback' | 'simulateReality'}
426   * @syscap SystemCapability.Sensors.MiscDevice
427   * @atomicservice
428   * @since 11
429   */
430  type Usage = 'unknown' | 'alarm' | 'ring' | 'notification' | 'communication' |
431  'touch' | 'media' | 'physicalFeedback' | 'simulateReality';
432
433  /**
434   * The attribute of vibration.
435   *
436   * @interface VibrateAttribute
437   * @syscap SystemCapability.Sensors.MiscDevice
438   * @since 9
439   */
440  /**
441   * The attribute of vibration.
442   *
443   * @interface VibrateAttribute
444   * @syscap SystemCapability.Sensors.MiscDevice
445   * @atomicservice
446   * @since 11
447   */
448  interface VibrateAttribute {
449  /**
450   * Vibrator id, default is 0.
451   *
452   * @syscap SystemCapability.Sensors.MiscDevice
453   * @since 9
454   */
455  /**
456   * Vibrator id, default is 0.
457   *
458   * @type { ?number }
459   * @syscap SystemCapability.Sensors.MiscDevice
460   * @atomicservice
461   * @since 11
462   */
463    id?: number;
464
465  /**
466   * The use of vibration.
467   *
468   * @syscap SystemCapability.Sensors.MiscDevice
469   * @since 9
470   */
471  /**
472   * The use of vibration.
473   *
474   * @type { Usage }
475   * @syscap SystemCapability.Sensors.MiscDevice
476   * @atomicservice
477   * @since 11
478   */
479    usage: Usage;
480
481  /**
482   * Indicates whether to bypass system management switches.
483   *
484   * @type { ?boolean }
485   * @syscap SystemCapability.Sensors.MiscDevice
486   * @systemapi
487   * @since 12
488   */
489    systemUsage?: boolean;
490  }
491
492  /**
493   * Describes the effect of vibration.
494   *
495   * @typedef { VibrateTime | VibratePreset }
496   * @syscap SystemCapability.Sensors.MiscDevice
497   * @since 9
498   */
499  /**
500   * Describes the effect of vibration.
501   *
502   * @typedef { VibrateTime | VibratePreset | VibrateFromFile }
503   * @syscap SystemCapability.Sensors.MiscDevice
504   * @since 10
505   */
506  /**
507   * Describes the effect of vibration.
508   *
509   * @typedef { VibrateTime | VibratePreset | VibrateFromFile }
510   * @syscap SystemCapability.Sensors.MiscDevice
511   * @atomicservice
512   * @since 11
513   */
514  /**
515   * Describes the effect of vibration.
516   *
517   * @typedef { VibrateTime | VibratePreset | VibrateFromFile | VibrateFromPattern }
518   * @syscap SystemCapability.Sensors.MiscDevice
519   * @atomicservice
520   * @since 18
521   */
522  type VibrateEffect = VibrateTime | VibratePreset | VibrateFromFile | VibrateFromPattern;
523
524  /**
525   * Vibrate continuously for a period of time at the default intensity of the system.
526   *
527   * @interface VibrateTime
528   * @syscap SystemCapability.Sensors.MiscDevice
529   * @since 9
530   */
531  /**
532   * Vibrate continuously for a period of time at the default intensity of the system.
533   *
534   * @interface VibrateTime
535   * @syscap SystemCapability.Sensors.MiscDevice
536   * @atomicservice
537   * @since 11
538   */
539  interface VibrateTime {
540    /**
541     * The value is "time", which triggers the motor vibration according to the specified duration.
542     *
543     * @syscap SystemCapability.Sensors.MiscDevice
544     * @since 9
545     */
546    /**
547     * The value is "time", which triggers the motor vibration according to the specified duration.
548     *
549     * @type { 'time' }
550     * @syscap SystemCapability.Sensors.MiscDevice
551     * @atomicservice
552     * @since 11
553     */
554    type: 'time';
555
556    /**
557     * The duration of the vibration, in ms.
558     *
559     * @syscap SystemCapability.Sensors.MiscDevice
560     * @since 9
561     */
562    /**
563     * The duration of the vibration, in ms.
564     *
565     * @type { number }
566     * @syscap SystemCapability.Sensors.MiscDevice
567     * @atomicservice
568     * @since 11
569     */
570    duration: number; /** The duration of the vibration, in ms */
571  }
572
573  /**
574   * Preset vibration type vibration effect.
575   *
576   * @interface VibratePreset
577   * @syscap SystemCapability.Sensors.MiscDevice
578   * @since 9
579   */
580  interface VibratePreset {
581    /**
582     * The value is "preset", which triggers motor vibration according to preset vibration effect.
583     *
584     * @type { 'preset' }
585     * @syscap SystemCapability.Sensors.MiscDevice
586     * @since 9
587     */
588    type: 'preset';
589
590    /**
591     * Preset type vibration.
592     *
593     * @type { string }
594     * @syscap SystemCapability.Sensors.MiscDevice
595     * @since 9
596     */
597    effectId: string;
598
599    /**
600     * The number of vibration repetitions.
601     *
602     * @syscap SystemCapability.Sensors.MiscDevice
603     * @since 9
604     */
605    /**
606     * The number of vibration repetitions.
607     *
608     * @type { ?number }
609     * @syscap SystemCapability.Sensors.MiscDevice
610     * @since 12
611     */
612    count?: number;
613
614    /**
615     * The intensity of vibration effect.
616     *
617     * @type { ?number }
618     * @syscap SystemCapability.Sensors.MiscDevice
619     * @since 12
620     */
621    intensity?: number;
622  }
623
624  /**
625   * Custom vibration, vibrate the effect from a haptic file.
626   *
627   * @interface VibrateFromFile
628   * @syscap SystemCapability.Sensors.MiscDevice
629   * @since 10
630   */
631  interface VibrateFromFile {
632  /**
633   * The value is "file", which triggers motor vibration according to the vibration profile.
634   *
635   * @type { 'file' }
636   * @syscap SystemCapability.Sensors.MiscDevice
637   * @since 10
638   */
639    type: 'file';
640
641  /**
642   * Haptic file descriptor, some formats are supported.
643   *
644   * @type { HapticFileDescriptor }
645   * @syscap SystemCapability.Sensors.MiscDevice
646   * @since 10
647   */
648    hapticFd: HapticFileDescriptor;
649  }
650
651  /**
652   * Haptic file descriptor. The caller needs to ensure that the fd is valid and
653   * the offset and length are correct.
654   *
655   * @interface HapticFileDescriptor
656   * @syscap SystemCapability.Sensors.MiscDevice
657   * @since 10
658   */
659  interface HapticFileDescriptor {
660    /**
661     * The file descriptor of haptic effect source from file system. The caller
662     * is responsible to close the file descriptor.
663     *
664     * @type { number }
665     * @syscap SystemCapability.Sensors.MiscDevice
666     * @since 10
667     */
668    fd: number;
669
670    /**
671     * The offset into the file where the data to be read, in bytes. By default,
672     * the offset is zero.
673     *
674     * @type { ?number }
675     * @syscap SystemCapability.Sensors.MiscDevice
676     * @since 10
677     */
678    offset?: number;
679
680    /**
681     * The length in bytes of the data to be read. By default, the length is the
682     * rest of bytes in the file from the offset.
683     *
684     * @type { ?number }
685     * @syscap SystemCapability.Sensors.MiscDevice
686     * @since 10
687     */
688    length?: number;
689  }
690
691  /**
692   * Types of vibration events
693   *
694   * @enum { number }
695   * @syscap SystemCapability.Sensors.MiscDevice
696   * @since 18
697   */
698  enum VibratorEventType {
699    /**
700     * Steady state long vibration
701     *
702     * @syscap SystemCapability.Sensors.MiscDevice
703     * @since 18
704     */
705    CONTINUOUS = 0,
706
707    /**
708     * Transient short vibration
709     *
710     * @syscap SystemCapability.Sensors.MiscDevice
711     * @since 18
712     */
713    TRANSIENT = 1,
714  }
715
716  /**
717   * The vibration curve is valid when the vibration event type is 'continuous'
718   *
719   * @interface VibratorCurvePoint
720   * @syscap SystemCapability.Sensors.MiscDevice
721   * @since 18
722   */
723  interface VibratorCurvePoint {
724    /**
725      * The offset of the starting time of the relative event.
726      *
727      * @type { number }
728      * @syscap SystemCapability.Sensors.MiscDevice
729      * @since 18
730      */
731    time: number;
732
733    /**
734      * Gain in relative event vibration intensity
735      *
736      * @type { ?number }
737      * @syscap SystemCapability.Sensors.MiscDevice
738      * @since 18
739      */
740    intensity?: number;
741    /**
742     * Changes in relative event vibration frequency
743     *
744     * @type { ?number }
745     * @syscap SystemCapability.Sensors.MiscDevice
746     * @since 18
747     */
748    frequency?: number;
749  }
750
751  /**
752   * Vibration event.
753   *
754   * @interface VibratorEvent
755   * @syscap SystemCapability.Sensors.MiscDevice
756   * @since 18
757   */
758  interface VibratorEvent {
759    /**
760     * Types of vibration events
761     *
762     * @type { VibratorEventType }
763     * @syscap SystemCapability.Sensors.MiscDevice
764     * @since 18
765     */
766    eventType: VibratorEventType;
767
768    /**
769     * Relative starting time of vibration
770     *
771     * @type { number }
772     * @syscap SystemCapability.Sensors.MiscDevice
773     * @since 18
774     */
775    time: number;
776
777    /**
778     * The duration of vibration
779     *
780     * @type { ?number }
781     * @syscap SystemCapability.Sensors.MiscDevice
782     * @since 18
783     */
784    duration?: number;
785
786    /**
787     * Intensity of vibration events
788     *
789     * @type { ?number }
790     * @syscap SystemCapability.Sensors.MiscDevice
791     * @since 18
792     */
793    intensity?: number;
794
795    /**
796     * Vibration event frequency
797     *
798     * @type { ?number }
799     * @syscap SystemCapability.Sensors.MiscDevice
800     * @since 18
801     */
802    frequency?: number;
803
804    /**
805     * Channel number
806     *
807     * @type { ?number }
808     * @syscap SystemCapability.Sensors.MiscDevice
809     * @since 18
810     */
811    index?: number;
812
813    /**
814     * An array representing vibration adjustment curves.
815     *
816     * @type { ?Array<VibratorCurvePoint> }
817     * @syscap SystemCapability.Sensors.MiscDevice
818     * @since 18
819     */
820    points?: Array<VibratorCurvePoint>;
821  }
822
823  /**
824   * Each 'events' attribute in the vibration sequence represents one vibration event
825   *
826   * @interface VibratorPattern
827   * @syscap SystemCapability.Sensors.MiscDevice
828   * @since 18
829   */
830  interface VibratorPattern {
831    /**
832     * Absolute starting time of vibration
833     *
834     * @type { number }
835     * @syscap SystemCapability.Sensors.MiscDevice
836     * @since 18
837     */
838    time: number;
839
840    /**
841     * Vibration event array, where each 'events' attribute represents one vibration event.
842     *
843     * @type { Array<VibratorEvent> }
844     * @syscap SystemCapability.Sensors.MiscDevice
845     * @since 18
846     */
847    events: Array<VibratorEvent>;
848  }
849
850  /**
851   * The continuous vibration parameters
852   *
853   * @interface ContinuousParam
854   * @syscap SystemCapability.Sensors.MiscDevice
855   * @since 18
856   */
857  interface ContinuousParam {
858    /**
859     * Intensity of vibration
860     *
861     * @type { ?number }
862     * @syscap SystemCapability.Sensors.MiscDevice
863     * @since 18
864     */
865    intensity?: number;
866
867    /**
868     * Frequency of vibration
869     *
870     * @type { ?number }
871     * @syscap SystemCapability.Sensors.MiscDevice
872     * @since 18
873     */
874    frequency?: number;
875
876    /**
877     * The points of vibration
878     *
879     * @type { ?VibratorCurvePoint[] }
880     * @syscap SystemCapability.Sensors.MiscDevice
881     * @since 18
882     */
883    points?: VibratorCurvePoint[];
884
885    /**
886     * Index of vibration
887     *
888     * @type { ?number }
889     * @syscap SystemCapability.Sensors.MiscDevice
890     * @since 18
891     */
892    index?: number;
893  }
894
895  /**
896   * The transient vibration parameters
897   *
898   * @interface TransientParam
899   * @syscap SystemCapability.Sensors.MiscDevice
900   * @since 18
901   */
902  interface TransientParam {
903    /**
904     * Intensity of vibration
905     *
906     * @type { ?number }
907     * @syscap SystemCapability.Sensors.MiscDevice
908     * @since 18
909     */
910    intensity?: number;
911
912    /**
913     * Frequency of vibration
914     *
915     * @type { ?number }
916     * @syscap SystemCapability.Sensors.MiscDevice
917     * @since 18
918     */
919    frequency?: number;
920
921    /**
922     * Index of vibration
923     *
924     * @type { ?number }
925     * @syscap SystemCapability.Sensors.MiscDevice
926     * @since 18
927     */
928    index?: number;
929  }
930
931  /**
932   * Provide methods for adding long or short vibration events and generate VibratorPattern objects.
933   *
934   * @name VibratorPatternBuilder
935   * @syscap SystemCapability.Sensors.MiscDevice
936   * @since 18
937   */
938  class VibratorPatternBuilder {
939    /**
940     * Method for adding long vibration events
941     *
942     * @param { number } time Relative starting time of the long-term vibration event.
943     * @param { number } duration The duration of the long-term vibration event
944     * @param { ContinuousParam } options Optional parameter object
945     * @returns { VibratorPatternBuilder } Return the current VibratorPatternBuilder object.
946     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
947     * <br> 2. Incorrect parameter types; 3. Parameter verification failed.
948     * @syscap SystemCapability.Sensors.MiscDevice
949     * @since 18
950     */
951    addContinuousEvent(time: number, duration: number, options?: ContinuousParam): VibratorPatternBuilder;
952
953    /**
954     * Method for adding short vibration events.
955     *
956     * @param { number } time Relative starting time of short oscillation events.
957     * @param { TransientParam } options Optional parameter object
958     * @returns { VibratorPatternBuilder } Return the current VibratorPatternBuilder object.
959     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
960     * <br> 2. Incorrect parameter types; 3. Parameter verification failed.
961     * @syscap SystemCapability.Sensors.MiscDevice
962     * @since 18
963     */
964    addTransientEvent(time: number, options?: TransientParam): VibratorPatternBuilder;
965
966    /**
967     * Method for constructing vibration sequences of combined short or long events.
968     *
969     * @returns { VibratorPattern } Return VibratorPattern object.
970     * @syscap SystemCapability.Sensors.MiscDevice
971     * @since 18
972     */
973    build(): VibratorPattern;
974  }
975
976  /**
977   * Trigger motor vibration with custom vibration effects.
978   *
979   * @interface VibrateFromPattern
980   * @syscap SystemCapability.Sensors.MiscDevice
981   * @since 18
982   */
983  interface VibrateFromPattern {
984    /**
985     * The value is "pattern", which triggers motor vibration based on the combination pattern.
986     *
987     * @type { 'pattern' }
988     * @syscap SystemCapability.Sensors.MiscDevice
989     * @since 18
990     */
991    type: 'pattern';
992
993    /**
994     * Customize the sequence of motor vibration events, the VibratorPattern object returned by the build() method.
995     *
996     * @type { VibratorPattern }
997     * @syscap SystemCapability.Sensors.MiscDevice
998     * @since 18
999     */
1000    pattern: VibratorPattern;
1001  }
1002}
1003
1004export default vibrator;
1005