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

40 lines
1.4 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.

// Настройки поля (properties, правка — Garmin Connect Mobile/Express):
// restSec 30–600 (умолчание 120 = Rest.DefaultSec телефона),
// hrMaxBpm 0–250 (0 = формула Танаки от age), age 14–100 (45).
// Клампы защищают от значений вне диапазона (правка без редактора).
// getApp() может быть null вне контекста приложения (тесты) — 🛡 дефолты.
import Toybox.Application;
import Toybox.Lang;
class FieldSettings {
var restSec;
var hrMaxBpm;
var age;
function initialize() {
restSec = clamp(readProp("restSec"), 30, 600, 120);
hrMaxBpm = clamp(readProp("hrMaxBpm"), 0, 250, 0);
age = clamp(readProp("age"), 14, 100, 45);
}
// Значение properties или null (нет приложения/свойства/ошибка)
function readProp(name) {
try {
var app = Application.getApp();
if (app != null) {
return app.getProperty(name);
}
} catch (e) {
}
return null;
}
// null / не число / вне диапазона → умолчание
function clamp(v, lo, hi, def) {
if (v instanceof Lang.Number && v >= lo && v <= hi) {
return v;
}
return def;
}
}