生物节律协议

更新时间:2021-12-16 03:31:39下载pdf

简介

rhythmFormatter是一个类方法,用于照明生物节律dp点的解析和反解析。parse方法可以将固件上报的十六进制字符串解析成页面所需要的数据结构,format方法则是将对象数据反解析成遵循生物节律通用协议的十六进制字符串。

API

parse

参数类型 是否必填 说明
String 十六进制字符串

format

参数类型 是否必填 说明
Object IRhythmData类型的对象
declare interface IRhythmData {
  version: number;
  power: boolean;
  mode: number;
  weeks: number[];
  number: number;
  rhythms: IRhythmItem[];
  key?: number;
}

declare interface IRhythmItem {
  power: boolean,
   hour: number,
   minute: number,
   hue: number,
   saturation: number,
   value: number,
   brightness: number,
   temperature: number,
}

使用示例

import { Utils, Formatter } from '@tuya/tuya-panel-lamp-sdk';
const { SupportUtils } = Utils;
const { RhythmFormatter } = Formatter;

const d = new RhythmFormatter(null,null,SupportUtils.isSupportTemp())

d.parse('0000007f0601060000000000006401061e000000006432010b1e00000000646401110000000000463201141e000000004632011500000000000000');

d.format({
  version: 0,
  power: false,
  mode: 0,
  weeks: [1, 1, 1, 1, 1, 1, 1, 0],
  number: 6,
  rhythms: [
    {
      power: true,
      hour: 6,
      minute: 0,
      hue: 0,
      saturation: 0,
      value: 0,
      brightness: 0,
      temperature: 100,
    },
    {
      power: true,
      hour: 6,
      minute: 30,
      hue: 0,
      saturation: 0,
      value: 0,
      brightness: 100,
      temperature: 50,
    },
    {
      power: true,
      hour: 11,
      minute: 30,
      hue: 0,
      saturation: 0,
      value: 0,
      brightness: 100,
      temperature: 100,
    },
    {
      power: true,
      hour: 17,
      minute: 0,
      hue: 0,
      saturation: 0,
      value: 0,
      brightness: 70,
      temperature: 50,
    },
    {
      power: true,
      hour: 20,
      minute: 30,
      hue: 0,
      saturation: 0,
      value: 0,
      brightness: 70,
      temperature: 50,
    },
    {
      power: true,
      hour: 21,
      minute: 0,
      hue: 0,
      saturation: 0,
      value: 0,
      brightness: 0,
      temperature: 0,
    },
  ],
});