Created
October 9, 2024 02:16
-
-
Save arleighdickerson/2330a4ff3579120e462e8eacc6f2cfbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect } from 'react'; | |
| const bpmToMillis = (bpm: number) => (bpm === 0 ? 0 : Math.round(60000.0 / bpm)); | |
| let vibrateInterval: number; | |
| function startVibrate(duration: number) { | |
| navigator.vibrate([duration, duration]); | |
| } | |
| function stopVibrate() { | |
| if (vibrateInterval) { | |
| clearInterval(vibrateInterval); | |
| } | |
| navigator.vibrate(0); | |
| } | |
| function startPersistentVibrate(interval: number) { | |
| vibrateInterval = setInterval(() => { | |
| startVibrate(interval); | |
| }, interval * 2); | |
| } | |
| const millis = bpmToMillis(60); | |
| export default function PhoneTestPage() { | |
| useEffect(() => { | |
| startPersistentVibrate(millis); | |
| return () => { | |
| stopVibrate(); | |
| }; | |
| }, []); | |
| return ( | |
| <div> | |
| <h1>Touch Screen to Test Actuator</h1> | |
| </div> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment