From 52ff9d5067877227f0cd5ac7d3d99b7623c5d63b Mon Sep 17 00:00:00 2001 From: shenpeixing Date: Mon, 12 May 2025 20:55:48 +0800 Subject: [PATCH] =?UTF-8?q?arkts=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shenpeixing --- frameworks/taihe/idl/ohos.vibrator.taihe | 728 +++++++++++++++++++++++ frameworks/taihe/user/main.ets | 0 2 files changed, 728 insertions(+) create mode 100644 frameworks/taihe/idl/ohos.vibrator.taihe create mode 100644 frameworks/taihe/user/main.ets diff --git a/frameworks/taihe/idl/ohos.vibrator.taihe b/frameworks/taihe/idl/ohos.vibrator.taihe new file mode 100644 index 0000000..ece1bc1 --- /dev/null +++ b/frameworks/taihe/idl/ohos.vibrator.taihe @@ -0,0 +1,728 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.vibrator", "vibrator") + +/** + * Preset vibration type vibration effect. + * + * @interface VibratePreset + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ +struct VibratePreset { + /** + * The value is "preset", which triggers motor vibration according to preset vibration effect. + * + * @type { 'preset' } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ + type: 'preset'; + + /** + * Preset type vibration. + * + * @type { String } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ + effectId: String; + + /** + * The number of vibration repetitions. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ + /** + * The number of vibration repetitions. + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 12 + */ + count: Optional; + + /** + * The intensity of vibration effect. + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 12 + */ + intensity: Optional; +} + +/** + * Vibrate continuously for a period of time at the default intensity of the system. + * + * @interface VibrateTime + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ +/** + * Vibrate continuously for a period of time at the default intensity of the system. + * + * @interface VibrateTime + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ +struct VibrateTime { + /** + * The value is "time", which triggers the motor vibration according to the specified duration. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ + /** + * The value is "time", which triggers the motor vibration according to the specified duration. + * + * @type { 'time' } + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ + type: 'time'; + + /** + * The duration of the vibration, in ms. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ + /** + * The duration of the vibration, in ms. + * + * @type { i32 } + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ + duration: i32; /** The duration of the vibration, in ms */ +} + +/** + * The attribute of vibration. + * + * @interface VibrateAttribute + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ +/** + * The attribute of vibration. + * + * @interface VibrateAttribute + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ +struct VibrateAttribute { + /** + * Vibrator id, default is 0. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ + /** + * Vibrator id, default is 0. + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ + id: Optional; + + /** + * The use of vibration. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ + /** + * The use of vibration. + * + * @type { Usage } + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ + usage: Usage; + + /** + * Indicates whether to bypass system management switches. + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @systemapi + * @since 12 + */ + systemUsage: Optional; +} + +/** + * The use of vibration. + * + * @typedef {'unknown' | 'alarm' | 'ring' | 'notification' | 'communication' | + * 'touch' | 'media' | 'physicalFeedback' | 'simulateReality'} + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ +/** + * The use of vibration. + * + * @typedef {'unknown' | 'alarm' | 'ring' | 'notification' | 'communication' | + * 'touch' | 'media' | 'physicalFeedback' | 'simulateReality'} + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ +enum Usage: String { + UNKNOWN = "unknown", + ALARM = "alarm", + RING = "ring", + NOTIFICATION = "notification", + COMMUNICATION = "communication", + TOUCH = "touch", + MEDIA = "media", + PHYSICALFEEDBACK = "physicalFeedback", + SIMULATEREALITY = "simulateReality" +} + +/** + * Preset vibration effect string. + * + * @enum { String } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 8 + */ +enum EffectId: String { + /** + * Describes the vibration effect of the vibrator when a user adjusts the timer. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 8 + */ + EFFECT_CLOCK_TIMER = 'haptic.clock.timer' +} + +/** + * Vibrator vibration stop mode. + * + * @enum { string } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 8 + */ +enum VibratorStopMode: String { + /** + * Indicates the mode of stopping a one-shot vibration effect. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 8 + */ + VIBRATOR_STOP_MODE_TIME = 'time', + + /** + * Indicates the mode of stopping a preset vibration effect. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 8 + */ + VIBRATOR_STOP_MODE_PRESET = 'preset' +} + +/** + * Trigger motor vibration with custom vibration effects. + * + * @interface VibrateFromPattern + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ +struct VibrateFromPattern { + /** + * The value is "pattern", which triggers motor vibration based on the combination pattern. + * + * @type { 'pattern' } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + type: 'pattern'; + + /** + * Customize the sequence of motor vibration events, the VibratorPattern object returned by the build() method. + * + * @type { VibratorPattern } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + pattern: VibratorPattern; +} + +/** + * Each 'events' attribute in the vibration sequence represents one vibration event + * + * @interface VibratorPattern + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ +struct VibratorPattern { + /** + * Absolute starting time of vibration + * + * @type { i32 } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + time: i32; + + /** + * Vibration event array, where each 'events' attribute represents one vibration event. + * + * @type { Array } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + events: Array; +} + +/** + * Vibration event. + * + * @interface VibratorEvent + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ +struct VibratorEvent { + /** + * Types of vibration events + * + * @type { VibratorEventType } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + eventType: VibratorEventType; + + /** + * Relative starting time of vibration + * + * @type { i32 } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + time: i32; + + /** + * The duration of vibration + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + duration: Optional; + + /** + * Intensity of vibration events + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + intensity: Optional; + + /** + * Vibration event frequency + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + frequency: Optional; + + /** + * Channel number + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + index: Optional; + + /** + * An array representing vibration adjustment curves. + * + * @type { Optional> } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + points: Optional>; +} + +/** + * Types of vibration events + * + * @enum { number } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ +enum VibratorEventType: i32 { + /** + * Steady state long vibration + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + CONTINUOUS = 0, + + /** + * Transient short vibration + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + TRANSIENT = 1, +} + +/** + * The vibration curve is valid when the vibration event type is 'continuous' + * + * @interface VibratorCurvePoint + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ +struct VibratorCurvePoint { + /** + * The offset of the starting time of the relative event. + * + * @type { i32 } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + time: i32; + + /** + * Gain in relative event vibration intensity + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + intensity: Optional; + /** + * Changes in relative event vibration frequency + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + frequency: Optional; +} + +/** + * The transient vibration parameters + * + * @interface TransientParam + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ +struct TransientParam { + /** + * Intensity of vibration + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + intensity: Optional; + + /** + * Frequency of vibration + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + frequency: Optional; + + /** + * Index of vibration + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + index: Optional; +} + +/** + * The continuous vibration parameters + * + * @interface ContinuousParam + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ +struct ContinuousParam { + /** + * Intensity of vibration + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + intensity: Optional; + + /** + * Frequency of vibration + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + frequency: Optional; + + /** + * The points of vibration + * + * @type { Optional> } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + points: Optional>; + + /** + * Index of vibration + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + index: Optional; +} + +/** + * Describes the effect of vibration. + * + * @typedef { VibrateTime | VibratePreset } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ +/** + * Describes the effect of vibration. + * + * @typedef { VibrateTime | VibratePreset | VibrateFromFile } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ +/** + * Describes the effect of vibration. + * + * @typedef { VibrateTime | VibratePreset | VibrateFromFile } + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ +/** + * Describes the effect of vibration. + * + * @typedef { VibrateTime | VibratePreset | VibrateFromFile | VibrateFromPattern } + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 18 + */ +union VibrateEffect { + VibrateTime_type: VibrateTime; + VibratePreset_type: VibratePreset; + VibrateFromFile_type: VibrateFromFile; + VibrateFromPattern_type: VibrateFromPattern; +} + +/** + * Custom vibration, vibrate the effect from a haptic file. + * + * @interface VibrateFromFile + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ +struct VibrateFromFile { + /** + * The value is "file", which triggers motor vibration according to the vibration profile. + * + * @type { 'file' } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ + type: 'file'; + + /** + * Haptic file descriptor, some formats are supported. + * + * @type { HapticFileDescriptor } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ + hapticFd: HapticFileDescriptor; +} + +/** + * Haptic file descriptor. The caller needs to ensure that the fd is valid and + * the offset and length are correct. + * + * @interface HapticFileDescriptor + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ +struct HapticFileDescriptor { + /** + * The file descriptor of haptic effect source from file system. The caller + * is responsible to close the file descriptor. + * + * @type { i32 } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ + fd: i32; + + /** + * The offset into the file where the data to be read, in bytes. By default, + * the offset is zero. + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ + offset: Optional; + + /** + * The length in bytes of the data to be read. By default, the length is the + * rest of bytes in the file from the offset. + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ + length: Optional; +} + +/** + * Stop the vibrator from vibrating. + * + * @permission ohos.permission.VIBRATE + * @param { VibratorStopMode } stopMode - Indicate the stop mode in which the motor vibrates, {@code VibratorStopMode}. + * @returns { void } Promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + *
2. Incorrect parameter types; 3. Parameter verification failed. + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ +@gen_async("stopVibration") +@gen_promise("stopVibration") +function stopVibrationByModeSync(stopMode: VibratorStopMode): void; + +/** + * Trigger vibrator vibration. + * + * @permission ohos.permission.VIBRATE + * @param { VibrateEffect } effect - Indicate vibrate effect, {@code VibrateEffect}. + * @param { VibrateAttribute } attribute - Indicate vibrate attribute, {@code VibrateAttribute}. + * @param { AsyncCallback } callback - The callback of startVibration. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + *
2. Incorrect parameter types; 3. Parameter verification failed. + * @throws { BusinessError } 801 - Capability not supported. + * @throws { BusinessError } 14600101 - Device operation failed. + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ +/** + * Trigger vibrator vibration. + * + * @permission ohos.permission.VIBRATE + * @param { VibrateEffect } effect - Indicate vibrate effect, {@code VibrateEffect} + * @param { VibrateAttribute } attribute - Indicate vibrate attribute, {@code VibrateAttribute} + * @param { void } callback - The callback of startVibration + * @throws { BusinessError } 201 - Permission denied + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + *
2. Incorrect parameter types; 3. Parameter verification failed. + * @throws { BusinessError } 801 - Capability not supported + * @throws { BusinessError } 14600101 - Device operation failed + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ +@gen_async("startVibration") +@gen_promise("startVibration") +function startVibrationSync(effect: VibrateEffect, attribute: VibrateAttribute): void; + +/** + * Whether the high-definition haptic is supported. + * + * @returns { bool } Returns whether the high-definition haptic is supported. + * @throws { BusinessError } 14600101 - Device operation failed. + * @syscap SystemCapability.Sensors.MiscDevice + * @since 12 + */ +function isHdHapticSupported(): bool; + +/** + * Stop any type of vibration. + * + * @permission ohos.permission.VIBRATE + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 14600101 - Device operation failed. + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 12 + */ +function stopVibrationSync(): void; + +/** + * Whether the preset vibration effect is supported. + * + * @param { String } effectId Indicate the specified effect of the preset, {@code EffectId}. + * @returns { bool } Promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + *
2. Incorrect parameter types; 3. Parameter verification failed. + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ +@gen_async("isSupportEffect") +@gen_promise("isSupportEffect") +function isSupportEffectSync(effectId: String): bool; + +/** + * Stop any type of vibration. + * + * @permission ohos.permission.VIBRATE + * @returns { void } Promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ +/** + * Stop any type of vibration. + * + * @permission ohos.permission.VIBRATE + * @returns { void } Promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ +@gen_async("stopVibration") +@gen_promise("stopVibration") +function stopVibrationSync(): void; \ No newline at end of file diff --git a/frameworks/taihe/user/main.ets b/frameworks/taihe/user/main.ets new file mode 100644 index 0000000..e69de29 -- Gitee