VEU.WathBody/3-app/5-watch/FenixDataField/source/Vibe.mc

56 lines
1.7 KiB
MonkeyC
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Вибрации (Ф-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) {
}
}
}