LightOperationUtils.java 1.92 KB
package com.qnbar.smc.utils;

import android.util.Log;
import com.qnbar.smc.service.TelinkLightService;

/**
 * Created by wugian on 2017/4/27
 */
public class LightOperationUtils {
    public static void setLightValue(int value) {
        int addr = 0xFFFF;//addr of all
        //change group brightness or color temperature
//            addr = 0x8003;
        byte opcode;
        byte[] params;
        opcode = (byte) 0xD2;//brightness
        params = new byte[]{(byte) value};
        if (TelinkLightService.Instance() != null && TelinkLightService.Instance().sendCommandNoResponse(opcode, addr, params, true)) {
            Log.d("LightOperationUtils", "setLightValue success");
        } else {
            Log.d("LightOperationUtils", "setLightValue:" + (TelinkLightService.Instance() != null));

        }
//        opcode = (byte) 0xE2;//temperature
//        params = new byte[]{0x05, (byte) value};
//        TelinkLightService.Instance().sendCommandNoResponse(opcode, addr, params, true);
    }

    public static void open() {
        byte opcode = (byte) 0xD0;
        int address = 0xFFFF;
        byte[] params = new byte[]{0x01, 0x00, 0x00};
        if (TelinkLightService.Instance() != null && TelinkLightService.Instance().sendCommandNoResponse(opcode, address, params)) {
            Log.d("LightOperationUtils", "open all success");
        } else {
            Log.d("LightOperationUtils", "open:" + (TelinkLightService.Instance() != null));
        }
    }

    public static void close() {
        byte opcode = (byte) 0xD0;
        int address = 0xFFFF;
        byte[] params = new byte[]{0x00, 0x00, 0x00};
        if (TelinkLightService.Instance() != null && TelinkLightService.Instance().sendCommandNoResponse(opcode, address, params)) {
            Log.d("LightOperationUtils", "close all success");
        } else {
            Log.d("LightOperationUtils", "close:" + (TelinkLightService.Instance() != null));
        }
    }
}