panlili2024
2024-11-11 145de2dcd3124f236e7d06bcdee17c7be08048b1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.hdl.sdk.ttl.HDLAppliances.HDLLight.Parser;
 
import com.hdl.sdk.ttl.HDLAppliances.Config.HDLApConfig;
import com.hdl.sdk.ttl.HDLAppliances.HDLLight.ColourLightCtrlBackInfo;
import com.hdl.sdk.ttl.HDLDeviceManger.Bean.AppliancesInfo;
 
/**
 * Created by panlili on 2023/8/22.
 */
 
public class LightCtrlParser {
    public static final int fail = 0;
 
    public static byte[] getColourLightAddByte(AppliancesInfo appliancesInfo, int brightness, int color) {
        try {
            byte[] addBytes = new byte[10];
            addBytes[0] = (byte) appliancesInfo.getChannelNum();
            addBytes[1] = (byte) brightness;
            addBytes[2] = (byte) 254;
            addBytes[3] = (byte) 0;
            addBytes[4] = (byte) 0;
 
            if (appliancesInfo.getDeviceType() == HDLApConfig.TYPE_LIGHT_RGB || appliancesInfo.getDeviceType() == HDLApConfig.TYPE_LIGHT_DMX) {
                addBytes[5] = ColourLightCtrlBackInfo.CONTROL_TYPE_RGB;
                addBytes[6] = (byte) getColorR(color);
                addBytes[7] = (byte) getColorG(color);
                addBytes[8] = (byte) getColorB(color);
                addBytes[9] = (byte) 0;
 
            } else if (appliancesInfo.getDeviceType() == HDLApConfig.TYPE_LIGHT_CCT || appliancesInfo.getDeviceType() == HDLApConfig.TYPE_LIGHT_DALI) {
                addBytes[5] = ColourLightCtrlBackInfo.CONTROL_TYPE_CCT;
                addBytes[6] = (byte) (color / 256);
                addBytes[7] = (byte) (color % 256);
                addBytes[8] = (byte) 0;
                addBytes[9] = (byte) 0;
            }
 
            return addBytes;
        } catch (Exception e) {
            e.printStackTrace();
            return new byte[]{fail};
        }
 
    }
 
    public static int getColorR(int color) {
        int red = (color & 0xff0000) >> 16;
        return red;
    }
 
    public static int getColorG(int color) {
        int green = (color & 0x00ff00) >> 8;
        return green;
    }
 
    public static int getColorB(int color) {
        int blue = (color & 0x0000ff);
        return blue;
    }
 
}