diff --git a/en/application-dev/device/vibrator-guidelines.md b/en/application-dev/device/vibrator-guidelines.md index f0eb8c5f896ae881550aeae85759692fd052c2ce..b8d201c22ed514ca0047b73b50e9f2184cf0587c 100644 --- a/en/application-dev/device/vibrator-guidelines.md +++ b/en/application-dev/device/vibrator-guidelines.md @@ -8,20 +8,20 @@ You can set different vibration effects as needed, for example, customizing the ## Available APIs - | Module| API| Description| -| -------- | -------- | -------- | -| ohos.vibrator | vibrate(duration: number): Promise<void> | Triggers vibration with the specified duration. This API uses a promise to return the result.| -| ohos.vibrator | vibrate(duration: number, callback?: AsyncCallback<void>): void | Triggers vibration with the specified duration. This API uses a callback to return the result.| -| ohos.vibrator | vibrate(effectId: EffectId): Promise<void> | Triggers vibration with the specified effect. This API uses a promise to return the result.| -| ohos.vibrator | vibrate(effectId: EffectId, callback?: AsyncCallback<void>): void | Triggers vibration with the specified effect. This API uses a callback to return the result.| -| ohos.vibrator | stop(stopMode: VibratorStopMode): Promise<void> | Stops vibration. This API uses a promise to return the result.| -| ohos.vibrator | stop(stopMode: VibratorStopMode, callback?: AsyncCallback<void>): void | Stops vibration. This API uses a callback to return the result.| +| Module | API | Description | +| ------------- | ---------------------------------------- | ------------------------------- | +| ohos.vibrator | vibrate(duration: number): Promise<void> | Triggers vibration with the specified duration. This API uses a promise to return the result. | +| ohos.vibrator | vibrate(duration: number, callback?: AsyncCallback<void>): void | Triggers vibration with the specified duration. This API uses a callback to return the result. | +| ohos.vibrator | vibrate(effectId: EffectId): Promise<void> | Triggers vibration with the specified effect. This API uses a promise to return the result. | +| ohos.vibrator | vibrate(effectId: EffectId, callback?: AsyncCallback<void>): void | Triggers vibration with the specified effect. This API uses a callback to return the result.| +| ohos.vibrator | stop(stopMode: VibratorStopMode): Promise<void> | Stops vibration. This API uses a promise to return the result. | +| ohos.vibrator | stop(stopMode: VibratorStopMode, callback?: AsyncCallback<void>): void | Stops vibration. This API uses a callback to return the result. | ## How to Develop 1. Declare the permissions required for controlling vibrators on the hardware device in the `config.json` file. - + ``` "reqPermissions": [ { @@ -58,7 +58,7 @@ You can set different vibration effects as needed, for example, customizing the ``` 2. Trigger the device to vibrate. - + ``` import vibrator from "@ohos.vibrator" vibrator.vibrate(1000).then((error)=>{ @@ -71,7 +71,7 @@ You can set different vibration effects as needed, for example, customizing the ``` 3. Stop the vibration. - + ``` import vibrator from "@ohos.vibrator" vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then((error)=>{ diff --git a/en/application-dev/reference/apis/js-apis-vibrator.md b/en/application-dev/reference/apis/js-apis-vibrator.md index 6ea1af902df9dd714aa0e3476c3419011a21f2d2..ac1b476b50dec7bc578cea40902cd863ce0999f9 100644 --- a/en/application-dev/reference/apis/js-apis-vibrator.md +++ b/en/application-dev/reference/apis/js-apis-vibrator.md @@ -1,12 +1,15 @@ + + # Vibrator -> **NOTE**
+> **NOTE** +> > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import -``` +```js import vibrator from '@ohos.vibrator'; ``` @@ -23,18 +26,18 @@ Triggers vibration with a specific duration. This API uses a promise to return t **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------ | ---- | ------------ | - | duration | number | Yes | Vibration duration. | +| Name | Type | Mandatory | Description | +| -------- | ------ | ---- | ------------ | +| duration | number | Yes | Vibration duration.| **Return value** - | Type | Description | - | ------------------- | ----------- | - | Promise<void> | Promise used to indicate whether the vibration is triggered successfully. | +| Type | Description | +| ------------------- | ----------- | +| Promise<void> | Promise used to indicate whether the vibration is triggered successfully.| **Example** - ``` + ```js vibrator.vibrate(1000).then(()=>{ console.log("Promise returned to indicate a successful vibration."); }, (error)=>{ @@ -54,13 +57,13 @@ Triggers vibration with a specific duration. This API uses an asynchronous callb **System capability**: SystemCapability.Sensors.MiscDevice **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | ----------------------- | - | duration | number | Yes | Vibration duration. | - | callback | AsyncCallback<void> | No | Callback used to indicate whether the vibration is triggered successfully. | +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ----------------------- | +| duration | number | Yes | Vibration duration. | +| callback | AsyncCallback<void> | No | Callback used to indicate whether the vibration is triggered successfully.| **Example** - ``` + ```js vibrator.vibrate(1000,function(error){ if(error){ console.log("error.code"+error.code+"error.message"+error.message); @@ -82,17 +85,17 @@ Triggers vibration with a specific effect. This API uses a promise to return the **System capability**: SystemCapability.Sensors.MiscDevice **Parameters** - | Name | Type | Mandatory | Description | - | -------- | --------------------- | ---- | ------------- | - | effectId | [EffectId](#effectid) | Yes | String that indicates the vibration effect. | +| Name | Type | Mandatory | Description | +| -------- | --------------------- | ---- | ------------- | +| effectId | [EffectId](#effectid) | Yes | Vibration effect. | **Return value** - | Type | Description | - | ------------------- | ----------- | - | Promise<void> | Promise used to indicate whether the vibration is triggered successfully. | +| Type | Description | +| ------------------- | ----------- | +| Promise<void> | Promise used to indicate whether the vibration is triggered successfully.| **Example** - ``` + ```js vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER).then(()=>{ console.log("Promise returned to indicate a successful vibration."); }, (error)=>{ @@ -112,13 +115,13 @@ Triggers vibration with a specific effect. This API uses an asynchronous callbac **System capability**: SystemCapability.Sensors.MiscDevice **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | ----------------------- | - | effectId | [EffectId](#effectid) | Yes | String that indicates the vibration effect. | - | callback | AsyncCallback<void> | No | Callback used to indicate whether the vibration is triggered successfully. | +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ----------------------- | +| effectId | [EffectId](#effectid) | Yes | Vibration effect. | +| callback | AsyncCallback<void> | No | Callback used to indicate whether the vibration is triggered successfully.| **Example** - ``` + ```js vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function(error){ if(error){ console.log("error.code"+error.code+"error.message"+error.message); @@ -140,17 +143,17 @@ Stops the vibration based on the specified **stopMode**. This API uses a promise **System capability**: SystemCapability.Sensors.MiscDevice **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------------------- | ---- | --------------- | - | stopMode | [VibratorStopMode](#vibratorstopmode) | Yes | Vibration mode to stop. | +| Name | Type | Mandatory | Description | +| -------- | ------------------------------------- | ---- | --------------- | +| stopMode | [VibratorStopMode](#vibratorstopmode) | Yes | Vibration mode to stop.| **Return value** - | Type | Description | - | ------------------- | ----------- | - | Promise<void> | Promise used to indicate whether the vibration is stopped successfully. | +| Type | Description | +| ------------------- | ----------- | +| Promise<void> | Promise used to indicate whether the vibration is stopped successfully.| **Example** - ``` + ```js vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(()=>{ console.log("Promise returned to indicate a successful vibration."); }, (error)=>{ @@ -170,13 +173,13 @@ Stops the vibration based on the specified **stopMode**. This API uses an asynch **System capability**: SystemCapability.Sensors.MiscDevice **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------------------- | ---- | ----------------------- | - | stopMode | [VibratorStopMode](#vibratorstopmode) | Yes | Vibration mode to stop. | - | callback | AsyncCallback<void> | No | Callback used to indicate whether the vibration is stopped successfully. | +| Name | Type | Mandatory | Description | +| -------- | ------------------------------------- | ---- | ----------------------- | +| stopMode | [VibratorStopMode](#vibratorstopmode) | Yes | Vibration mode to stop. | +| callback | AsyncCallback<void> | No | Callback used to indicate whether the vibration is stopped successfully.| **Example** - ``` + ```js vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function(error){ if(error){ console.log("error.code"+error.code+"error.message"+error.message); @@ -193,9 +196,9 @@ Describes the vibration effect. **System capability**: SystemCapability.Sensors.MiscDevice - | Name | Default Value | Description | - | ------------------ | -------------------- | --------------------------------------------------------------- | - | EFFECT_CLOCK_TIMER | "haptic.clock.timer" | Vibration effect of the vibrator when a user adjusts the timer. | +| Name | Default Value | Description | +| ------------------ | -------------------- | --------------- | +| EFFECT_CLOCK_TIMER | "haptic.clock.timer" | Vibration effect of the vibrator when a user adjusts the timer.| ## VibratorStopMode @@ -204,7 +207,7 @@ Describes the vibration mode to stop. **System capability**: SystemCapability.Sensors.MiscDevice - | Name | Default Value | Description | - | ------------------------- | -------- | ---------------------------------------- | - | VIBRATOR_STOP_MODE_TIME | "time" | The vibration to stop is in **duration** mode. This vibration is triggered with the parameter **duration** of the **number** type. | - | VIBRATOR_STOP_MODE_PRESET | "preset" | The vibration to stop is in **EffectId** mode. This vibration is triggered with the parameter **effectId** of the **EffectId** type. | +| Name | Default Value | Description | +| ------------------------- | -------- | ---------------------------------------- | +| VIBRATOR_STOP_MODE_TIME | "time" | The vibration to stop is in **duration** mode. This vibration is triggered with the parameter **duration** of the **number** type.| +| VIBRATOR_STOP_MODE_PRESET | "preset" | The vibration to stop is in **EffectId** mode. This vibration is triggered with the parameter **effectId** of the **EffectId** type.|