// Вибрации (Ф-2.4): конец отдыха — однократная лёгкая; красная зона — // двойная с гистерезисом (повтор не раньше 60 с, сброс при выходе из // красной). Паттерны различаются (ui-ux: отдых/предупреждение). import Toybox.Attention; class Vibe { var RED_REPEAT_MS = 60000; var lastRedMs; var inRed; function initialize() { lastRedMs = null; inRed = false; } // Вызывается раз в секунду из compute; isRed — пульс в красной зоне. // Возвращает true, если двойная вибрация запущена. function onZone(isRed, timerTimeMs) { if (isRed) { if (!inRed) { inRed = true; lastRedMs = null; } if (lastRedMs == null || (timerTimeMs - lastRedMs) >= RED_REPEAT_MS) { vibrateDouble(); lastRedMs = timerTimeMs; return true; } } else { inRed = false; } return false; } function vibrateRestEnd() { safeVibrate([new Attention.VibeProfile(25, 300)]); } function vibrateDouble() { safeVibrate([ new Attention.VibeProfile(75, 200), new Attention.VibeProfile(0, 150), new Attention.VibeProfile(75, 200) ]); } // Вибрация недоступна на модели — молча пропускается (Ф-2.8) function safeVibrate(profiles) { try { Attention.vibrate(profiles); } catch (e) { } } }