外观
dataman 数据订阅
约 683 字大约 2 分钟
2026-07-15
dataman 把表盘数据源绑定到一个 LVGL 对象。数据变化时,宿主把对象和值传给回调。
subscribe
dataman.subscribe(key, object, callback) -> token| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
key | string | 是 | 数据源名称 |
object | LVGL userdata | 是 | 与订阅绑定的对象 |
callback | function | 是 | function(object, value) |
local token = dataman.subscribe("timeHour", label, function(obj, value)
local hour = value // 256
obj:set { text = string.format("%02d", hour) }
end)大多数数值采用 Q24.8 定点格式,即真实值乘以 256。使用整数除法 value // 256 解码。无效值通常为该运行环境的整数最大值;使用数据前应按数据源定义判断。
pause 与 resume
dataman.pause(token)
dataman.resume(token)pause 暂停派发但保留订阅;resume 恢复。页面隐藏时暂停,显示时恢复。
时间与日期数据源
| 数据源 | 含义 |
|---|---|
timeHourLow / timeHourHigh | 小时低位/高位 |
timeMinuteLow / timeMinuteHigh | 分钟低位/高位 |
timeSecondLow / timeSecondHigh | 秒低位/高位 |
timeCentiSecond | 厘秒 |
timeCentiSecondLow / timeCentiSecondHigh | 厘秒低位/高位 |
dateYear | 年 |
dateYearDigit1..4 | 年的各位数字 |
dateMonth / dateMonthLow / dateMonthHigh | 月及拆分位 |
dateDay / dateDayLow / dateDayHigh | 日及拆分位 |
dateWeek | 星期 |
dateLunarYear / dateLunarMonth / dateLunarDay | 农历年月日 |
dateWeekStringShortCN / dateWeekStringFullCN | 中文星期文本 |
dateWeekStringFullPascalEN / FullUpperEN / FullLowerEN | 英文完整星期文本 |
dateWeekStringShortPascalEN / ShortUpperEN / ShortLowerEN | 英文短星期文本 |
dateMonthStringShortCN | 中文月份文本 |
dateMonthStringFullPascalEN / FullUpperEN / FullLowerEN | 英文完整月份文本 |
dateMonthStringShortPascalEN / ShortUpperEN / ShortLowerEN | 英文短月份文本 |
miscIsPM | 是否下午 |
miscIs24H | 是否 24 小时制 |
miscTimeSection | 时间段 |
miscdateYestarday / miscdateTomorrow | 昨日/明日标识;拼写以接口为准 |
dualtimeHour / dualtimeMinute / dualtimeSecond | 第二时区时间 |
dualtimeHour12H / dualtimeHour24H | 第二时区小时格式 |
dualtimeCity | 第二时区城市 |
部分环境还提供 timeHour、timeMinute、timeSecond 组合值。
健康数据源
| 分类 | 数据源 |
|---|---|
| 步数 | healthStepCount、healthStepCountDigit1..5、healthStepProgress、healthStepKiloMeter、healthStepTarget |
| 心率 | healthHeartRate、healthHeartRateZone、healthHeartRateMin、healthHeartRateMax |
| 热量 | healthCalorie、healthCalorieValue、healthCalorieProgress、healthCalorieTarget |
| 站立 | healthStandCount、healthStandProgress、healthStandTarget |
| 血氧/压力 | healthOxygenSpO2、healthPressureIndex |
| 血压 | healthBloodDiastolicPressureMmhg、healthBloodSystolicPressureMmhg、healthBloodDiastolicPressureKpa、healthBloodSystolicPressureKpa、healthBloodPressureUnit |
| 睡眠 | healthSleepDuration、healthSleepDurationMinute、healthSleepScore、healthSleepQuality、healthSleepTargetProgress |
| 运动 | healthExerciseDuration、healthExerciseProgress、healthExerciseTarget、healthEnergyConsumed |
| 其他 | healthMiscRecoveryTime、healthMiscRunPowerIndex、healthMiscTodayVitalityValue、healthMiscSevenDaysVitalityValue |
| 血糖 | healthBloodSugarValue、healthBloodSugarUpdateTsString |
天气数据源
| 分类 | 数据源 |
|---|---|
| 日出日落 | weatherCurrentSunRise、weatherCurrentSunSet、weatherCurrentSunRiseHour、weatherCurrentSunRiseMinute、weatherCurrentSunSetHour、weatherCurrentSunSetMinute |
| 温度 | weatherTemperatureUnit、weatherCurrentTemperature、weatherCurrentTemperatureFahrenheit、weatherCurrentTemperatureFeel |
| 当前天气 | weatherCurrentHumidity、weatherCurrentWeather、weatherCurrentWindDirection、weatherCurrentWindAngle、weatherCurrentWindSpeed、weatherCurrentWindLevel |
| 环境 | weatherCurrentAirQualityIndex、weatherCurrentAirQualityLevel、weatherCurrentChanceOfRain、weatherCurrentPressure、weatherCurrentVisibility、weatherCurrentUVIndex、weatherCurrentDressIndex |
| 今日 | weatherTodayTemperatureMax、weatherTodayTemperatureMin、weatherTodayTemperatureMaxFahrenheit、weatherTodayTemperatureMinFahrenheit |
| 明日 | weatherTomorrowTemperatureMax、weatherTomorrowTemperatureMin、weatherTomorrowTemperatureMaxFahrenheit、weatherTomorrowTemperatureMinFahrenheit |
系统与闹钟数据源
systemStatusBattery、systemStatusCharge、systemStatusDisturb、systemStatusBluetooth、systemStatusWifi、systemStatusScreenLock、systemSensorFusionAltitude、appAlarmHour、appAlarmMinute。
完整示例
local tokens = {}
local function bind(key, obj, render)
tokens[#tokens + 1] = dataman.subscribe(key, obj, function(target, raw)
render(target, raw // 256)
end)
end
bind("systemStatusBattery", batteryLabel, function(obj, value)
obj:set { text = string.format("%d%%", value) }
end)
function pageOnPause()
for _, token in ipairs(tokens) do dataman.pause(token) end
end
function pageOnResume()
for _, token in ipairs(tokens) do dataman.resume(token) end
end机型可用性
| Xiaomi Smart Band 10 Pro | Xiaomi Watch S4 41mm |
|---|---|
| ✅ | ✅ |