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; } }