Tranquil App Haptic module Doc
Table of Contents

HapticManager Documentation

The HapticManager enum is a utility for managing haptic feedback on devices that support Core Haptics. It provides various methods to trigger different types of haptic feedback patterns. Below is a detailed explanation of each haptic mode and the corresponding algorithm used to create the vibration patterns.

Enum Definition

high-level structure

enum HapticManager {
    static nonisolated(unsafe) private var engine: CHHapticEngine?

    static func prepareHaptics()
    static private func restartEngine()
    static func triggerNormalHaptic()
    static func triggerMultiPattern(frequency: Double, amplitude: Double) async
    static func triggerGradualHaptic(intensity: Float = 0.6)
    static func triggerHeavyHaptic()
}

Methods

prepareHaptics()

This method initializes the haptic engine if the device supports haptics. It starts the engine and prints a message indicating the engine has started.

restartEngine()

This private method attempts to restart the haptic engine if it fails during operation.

triggerNormalHaptic()

This method triggers a single, short haptic tap. It creates a transient haptic event with moderate intensity and low sharpness.

Algorithm:

  1. Check if the haptic engine is available.
  2. Create haptic event parameters for intensity (0.4) and sharpness (0.2).
  3. Create a transient haptic event with the parameters.
  4. Create a haptic pattern with the event.
  5. Create a player for the pattern and start it.

triggerMultiPattern(frequency: Double, amplitude: Double) async

This method triggers a haptic pattern based on the provided frequency and amplitude. It differentiates between low and high frequencies to create continuous or transient patterns.

Note: This Pattern is designed for Feel Your Vibe game specifically.

Algorithm:

  1. Check if the haptic engine is available.
  2. For low frequencies (<= 2.0):
    • Create continuous haptic event parameters for intensity (amplitude * 0.7) and sharpness (0.3).
    • Create a continuous haptic event with a duration of 0.2 seconds.
  3. For high frequencies (> 2.0):
    • Create transient haptic event parameters for intensity (amplitude * 0.6) and sharpness (0.5).
    • Create a transient haptic event.
  4. Create a haptic pattern with the event.
  5. Create a player for the pattern and start it.

triggerGradualHaptic(intensity: Float = 0.6)

This method triggers a haptic pattern that gradually increases and then decreases in intensity over a duration of 2 seconds.

Algorithm:

  1. Check if the device supports haptics and if the haptic engine is available.
  2. Create a series of continuous haptic events with varying intensity to form a bell curve.
  3. Each event has a duration of 0.1 seconds and the intensity peaks in the middle.
  4. Create a haptic pattern with the events.
  5. Create a player for the pattern, start the engine, and start the player.

triggerHeavyHaptic()

This method triggers a haptic pattern that starts with strong intensity and gradually decreases.

Algorithm:

  1. Check if the haptic engine is available.
  2. Create a series of continuous haptic events with decreasing intensity.
  3. Each event has a duration of 0.2 seconds.
  4. Create a haptic pattern with the events.
  5. Create a player for the pattern and start it.
No Comments

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
Previous