#ifndef BLV_485_DEV_RGB_LIGHT_BELTFUN_H
#define BLV_485_DEV_RGB_LIGHT_BELTFUN_H

#include "BLV_485_Protocol.h"
#include "BLV_485_Dev_LEDFun.h"

#define DEV_RGB_LIGHT_BELT_Type		0x12		//用于设备列表中的设备类型

#define RGB_LIGHT_BELT_SET_LIGHT_CMD       0x0D     //设置亮度命令
#define RGB_LIGHT_BELT_READ_LIGHT_CMD      0x0E     //读取亮度命令
#define RGB_LIGHT_BELT_SET_ACT_CMD         0x44     //设置动作命令
#define RGB_LIGHT_BELT_STOP_DIMMING_CMD    0x46     //停止命令

#define RGB_LIGHT_BELT_SET_LIGHT_REPLY       0xAD     //设置亮度命令回复
#define RGB_LIGHT_BELT_READ_LIGHT_REPLY      0xAE     //读取亮度命令回复
#define RGB_LIGHT_BELT_SET_ACT_REPLY         0xE4    	//设置动作命令回复
#define RGB_LIGHT_BELT_STOP_DIMMING_REPLY    0xE6     //停止命令回复

#define RGB_LIGHT_BELT_CONTROL_MODE_SET    0x00     //设置绝对亮度
#define RGB_LIGHT_BELT_CONTROL_MODE_LOOP   0x03     //循环调光控制方式
#define RGB_LIGHT_BELT_LOOP_DIMMING_CMD    0x13     //循环调光动作命令

typedef enum{
	RGB_LIGHT_BELT_CH1,
	RGB_LIGHT_BELT_CH2,
	RGB_LIGHT_BELT_CH3,
	RGB_LIGHT_BELT_CH4,
	RGB_LIGHT_BELT_CH_MAX,
	
}RS485_RGB_LIGHT_BELT_NUM_E;

#if 0
typedef struct
{
	BLV_COMM_RECORD_G comm_record;	//通讯记录
	
	uint8_t light[RGB_LIGHT_BELT_CH_MAX];   		//当前亮度值
	uint8_t last_light[RGB_LIGHT_BELT_CH_MAX];   	//上一次亮度值
	
	uint8_t light_Control_Flag;                 	//亮度控制标志位
	uint8_t last_light_Control_Flag;            	//上次亮度控制标志位
	uint8_t set_light[RGB_LIGHT_BELT_CH_MAX];    	//设定亮度值
	uint16_t fade_time;  							//设定渐变时间
	
	uint8_t PWMLightRelease[RGB_LIGHT_BELT_CH_MAX];   //记忆调光
	uint8_t LEDCtrlFlag;        //调光亮度控制标志
	uint8_t LEDCtrlCnt;         //调光亮度控制计数
	uint8_t LEDLoopValidNum;    //调光有效回路数
	
	uint8_t LEDLightnessReadFlag;   //调光亮度读取标志
	uint8_t LEDLightnessReadCnt;   //调光亮度读取标志
	
	uint8_t DevSendBuf[RGB_LIGHT_BELT_CH_MAX]; 			//发送数组，每个字节存指示灯的状态
	uint8_t DevSendBuf_last[RGB_LIGHT_BELT_CH_MAX]; 		//发送数组，每个字节存指示灯的上一个状态
	
	uint8_t DevCtrlWayBuf[RGB_LIGHT_BELT_CH_MAX];        //调光控制方式
	uint8_t DevCtrlWayBuf_last[RGB_LIGHT_BELT_CH_MAX];   //调光方式控制上一个状态
	uint8_t DevCtrlWayContect[RGB_LIGHT_BELT_CH_MAX];    //调光方式控制内容 即步长
	uint8_t WayCtrli;            //方式控制的下标
		
	uint8_t LEDWayCtrlFlag;    //调光方式控制标志
	uint8_t LEDWayCtrlCnt;     //调光方式控制计数	

	uint8_t loop_dimming_control;					//控制调光通道
	uint8_t loop_dimming_Control_Flag;             	//循环调光控制标志位  bit7:停止动作控制标志位
	uint8_t last_loop_dimming_Control_Flag;        	//上次循环调光控制标志位 bit7:停止动作控制标志位
	uint16_t loop_fade_time;  						//设定循环调光渐变时间
	uint8_t loop_light;  							//设定循环调光亮度增量
	uint8_t loop_dimming_flg;                    	//循环调光标志位
	
	uint8_t stop_dimming_Control_Flag;             	//停止动作控制标志位
	uint8_t last_stop_dimming_Control_Flag;        	//上次停止动作控制标志位
		
	uint8_t SN;									//发送数据类型
	uint8_t DevSendCnt;     	//设备发送计数   计数达到重发次数都没有回复，判为离线
	uint8_t DevOffline;       	//设备离线标志 1，设备离线   0，设备在线
	uint8_t DevOfflineLast;   	//设备离线标志 1，设备离线   0，设备在线

	uint32_t inquire_tick;		//询问时间戳
}__attribute__ ((__packed__))RS485_RGB_LIGHT_BELT_INFO;						//灯带数据与函数


void BLV_485_Dev_RGB_Light_Belt_Init(uint8_t devaddr);
uint8_t BLV_RGB_Light_Belt_Cycle_Call(uint32_t DevAdd);
uint8_t BLV_RGB_Light_Belt_Data_Processing(uint32_t dev_addr,uint32_t data_addr,uint16_t len);
void BLV_RGB_Light_Belt_Light_Control_Datasend(Device_Public_Information_G *BUS_Public, RS485_RGB_LIGHT_BELT_INFO* Dev_Info);
void BLV_RGB_Light_Belt_Light_Inquire_Datasend(Device_Public_Information_G *BUS_Public, RS485_RGB_LIGHT_BELT_INFO *Dev_Info);
void BLV_RGB_Light_Belt_stop_dimming_Control_Datasend(uint32_t dev_addr, RS485_RGB_LIGHT_BELT_INFO *Dev_Info);
void BLV_RGB_Light_Belt_loop_dimming_Control_Datasend(uint32_t dev_addr, RS485_RGB_LIGHT_BELT_INFO *Dev_Info);

void BLV_RGB_Light_Belt_Control_Light(uint32_t dev_addr, uint8_t Control_Flag, uint8_t ch1, uint8_t ch2, uint8_t ch3, uint8_t ch4, uint16_t fadeTime);
void BLV_RGB_Light_Belt_Control_Loop_Dimming(uint32_t dev_addr, uint8_t Control_CH, uint8_t light, uint16_t fadeTime);
void BLV_RGB_Light_Belt_Control_Stop_Dimming(uint32_t dev_addr);
uint16_t Get_BLV_RGB_Light_Loop_Value(uint32_t dev_addr,uint16_t ch);
#endif
void BLW_RS485_RGB_Data_Init(Device_Public_Information_G *BUS_Public, RS485_LED_INFO *Rs485LED, uint16_t LoopNum);

#endif
