#include "includes.h"
#include "BLV_Nor_Dev_LVoutputFun.h"
#include "BLV_485_Dev_C12DimFun.h"
#include "BLV_Nor_Dev_HVoutFun.h"



///************2022.11.22 林开锐 增加侧面键功能函数开始************/
//#define SIDE_KEY_INIT			0x80	//侧面键初始化完成
//#define C12_SIDE_KEY			0x40	//C12侧面键
//#define C5_SIDE_KEY				0x20	//C5侧面键
//#define SIDE_KEY_FUNCTION		0x60	//按键功能
///*******************************************************************************
//* Function Name  :  Side_Key_C12 
//* Description    :  C12侧面键
//* Input          :  lvoutput_addr - 弱电输出设备存在链表地址
//					c12dimming_addr - C12调光设备存在链表地址
//					relay_addr - 强电继电器设备存在链表地址
//* Return         :  none
//*******************************************************************************/
//void Side_Key_C12(uint32_t lvoutput_addr,uint32_t c12dimming_addr,uint32_t relay_addr)
//{
//	static uint8_t press = 0;	//按键按下次数
//	uint8_t lvoutput_write_flag = 0, c12dimming_write_flag = 0, relay_write_flag = 0;	//弱电输出，C12调光，强电继电器写入SRAM标志   0：不写入   1：写入
//	Device_Public_Information_G LVOUTPUT_public_info;	//弱电输出共有属性
//	NOR_LVOUTPUT_INFO LVOUTPUT_private_info;	//弱电输出私有属性
//	Device_Public_Information_G C12DIMMING_public_info;	//C12调光共有属性
//	RS485_LED_INFO C12DIMMING_private_info;	//C12调光私有属性
//	Device_Public_Information_G RELAY_public_info;	//继电器共有属性
//	NOR_HVOUT_INFO RELAY_private_info;	//继电器私有属性
//	
//	memset(&LVOUTPUT_public_info, 0, sizeof(Device_Public_Information_G));	//初始化弱电输出公有属性
//	memset(&LVOUTPUT_private_info, 0, sizeof(NOR_LVOUTPUT_INFO));	//初始化弱电输出私有属性
//	SRAM_DMA_Read_Buff((uint8_t *)&LVOUTPUT_public_info, sizeof(Device_Public_Information_G), lvoutput_addr);	//读取弱电输出共有属性
//	SRAM_DMA_Read_Buff((uint8_t *)&LVOUTPUT_private_info, sizeof(NOR_LVOUTPUT_INFO), lvoutput_addr + Dev_Privately);	//读取弱电输出私有属性
//	
//	memset(&C12DIMMING_public_info, 0, sizeof(Device_Public_Information_G));	//初始化C12调光公有属性
//	memset(&C12DIMMING_private_info, 0, sizeof(RS485_LED_INFO));	//初始化C12调光回路属性
//	SRAM_DMA_Read_Buff((uint8_t *)&C12DIMMING_public_info, sizeof(Device_Public_Information_G), c12dimming_addr);	//读取C12调光共有属性
//	SRAM_DMA_Read_Buff((uint8_t *)&C12DIMMING_private_info, sizeof(RS485_LED_INFO), c12dimming_addr + Dev_Privately);	//读取C12调光私有属性
//	
//	memset(&RELAY_public_info, 0, sizeof(Device_Public_Information_G));	//初始化继电器公有属性
//	memset(&RELAY_private_info, 0, sizeof(NOR_HVOUT_INFO));	//初始化继电器回路属性
//	SRAM_DMA_Read_Buff((uint8_t *)&RELAY_public_info, sizeof(Device_Public_Information_G), relay_addr);	//读取继电器共有属性
//	SRAM_DMA_Read_Buff((uint8_t *)&RELAY_private_info, sizeof(NOR_HVOUT_INFO), relay_addr + Dev_Privately);	//读取继电器私有属性
//	press++;
//	if(press > 27) press = 1;	//超过27次（清除状态（27次）之后）,按键次数设为1
//	if(press > 0 && press <= 12)	//打开C12板上调光
//	{
//		if(press > 0 && press <= 6)	//前5次控弱电输出，之后就不控
//		{
//			LVOUTPUT_private_info.DevLVoutputState[0] = 0x00;
//			LVOUTPUT_private_info.DevLVoutputState[1] = 0x00;
//			LVOUTPUT_private_info.DevLVoutputState[2] = 0x00;
//			LVOUTPUT_private_info.DevLVoutputState[3] = 0x00;
//			LVOUTPUT_private_info.DevLVoutputState[4] = 0x00;
//			if(press != 6) UINT64DATACONVER(LVOUTPUT_private_info.DevLVoutputState) |= (0x01<<(press-1));	//第1~5次控制弱电输出0~4状态
//			lvoutput_write_flag = 1;	//弱电输出写入
//		}
//		memset(C12DIMMING_private_info.DevSendBuf, 0x00, 12);	//C12调光亮度赋值（亮度值0相当于关）
//		C12DIMMING_private_info.DevSendBuf[press-1] = 0x50;	//C12调光亮度赋值
//		c12dimming_write_flag = 1;	//C12调光写入
//	}
//	if(press > 12 && press <= 25)	//打开C12板上继电器
//	{
//		if(press == 13)
//		{
//			memset(C12DIMMING_private_info.DevSendBuf, 0x00, 12);	//C12调光亮度赋值（亮度值0相当于关）
//			c12dimming_write_flag = 1;	//C12调光写入
//		}
//		UINT64DATACONVER(RELAY_private_info.DevHVoutState) &= ~(0x1FFF);	//关闭继电器0~11
//		UINT64DATACONVER(RELAY_private_info.DevHVoutState) |= (0x01<<(press - 13));	//打开继电器
//		relay_write_flag = 1;	//强电继电器写入
//	}
//	if(press == 26)	//C12调光和继电器全开
//	{
//		UINT64DATACONVER(LVOUTPUT_private_info.DevLVoutputState) |= 0x1F;	//打开弱电输出0~4状态
//		memset(C12DIMMING_private_info.DevSendBuf, 0x50, 12);	//C12调光亮度赋值
//		UINT64DATACONVER(RELAY_private_info.DevHVoutState) |= 0x1FFF;	//打开继电器
//		lvoutput_write_flag = 1;	//弱电输出写入
//		c12dimming_write_flag = 1;	//C12调光写入
//		relay_write_flag = 1;	//强电继电器写入
//	}
//	if(press == 27)	//C12调光和继电器全关
//	{
//		UINT64DATACONVER(LVOUTPUT_private_info.DevLVoutputState) &= ~(0x1F);	//关闭弱电输出0~4状态
//		memset(C12DIMMING_private_info.DevSendBuf, 0x00, 12);	//C12调光亮度赋值（亮度值0相当于关）
//		UINT64DATACONVER(RELAY_private_info.DevHVoutState) &= ~(0x1FFF);	//关闭继电器0~11
//		lvoutput_write_flag = 1;	//弱电输出写入
//		c12dimming_write_flag = 1;	//C12调光写入
//		relay_write_flag = 1;	//强电继电器写入
//	}
//	if(lvoutput_write_flag == 1)	//弱电输出写入SRAM
//	{
//		LVOUTPUT_public_info.check = 0x00;	//弱电输出共有属性校验清0
//		LVOUTPUT_public_info.check = DoubleData_CheckSum((uint8_t *)&LVOUTPUT_public_info, sizeof(Device_Public_Information_G), \
//									(uint8_t *)&LVOUTPUT_private_info, sizeof(NOR_LVOUTPUT_INFO));	//计算校验
//		SRAM_DMA_Write_Buff((uint8_t *)&LVOUTPUT_public_info, sizeof(Device_Public_Information_G), lvoutput_addr);	//保存弱电输出共有属性到SRAM
//		SRAM_DMA_Write_Buff((uint8_t *)&LVOUTPUT_private_info, sizeof(NOR_LVOUTPUT_INFO), lvoutput_addr + Dev_Privately);	//保存弱电输出私有属性到SRAM
//	}
//	if(c12dimming_write_flag == 1)	//C12调光写入SRAM
//	{
//		C12DIMMING_public_info.check = 0x00;	//C12共有属性校验清0
//		C12DIMMING_public_info.check = DoubleData_CheckSum((uint8_t *)&C12DIMMING_public_info, sizeof(Device_Public_Information_G), \
//										(uint8_t *)&C12DIMMING_private_info, sizeof(RS485_LED_INFO));	//计算校验
//		SRAM_DMA_Write_Buff((uint8_t *)&C12DIMMING_public_info, sizeof(Device_Public_Information_G), c12dimming_addr);	//保存C12共有属性到SRAM
//		SRAM_DMA_Write_Buff((uint8_t *)&C12DIMMING_private_info, sizeof(RS485_LED_INFO), c12dimming_addr + Dev_Privately);	//保存C12私有属性到SRAM
//	}
//	if(relay_write_flag == 1)	//强电继电器写入SRAM
//	{
//		RELAY_public_info.check = 0x00;	//继电器共有属性校验清0
//		RELAY_public_info.check = DoubleData_CheckSum((uint8_t *)&RELAY_public_info, sizeof(Device_Public_Information_G), \
//									(uint8_t *)&RELAY_private_info, sizeof(NOR_HVOUT_INFO));	//计算校验
//		SRAM_DMA_Write_Buff((uint8_t *)&RELAY_public_info, sizeof(Device_Public_Information_G), relay_addr);	//保存继电器共有属性到SRAM
//		SRAM_DMA_Write_Buff((uint8_t *)&RELAY_private_info, sizeof(NOR_HVOUT_INFO), relay_addr + Dev_Privately);	//保存继电器私有属性到SRAM
//	}
//	Dbg_Print(DBG_BIT_LOGIC_STATUS_bit,"侧面键按下次数为：%d",press);
//}

///*******************************************************************************
//* Function Name  :  Side_Key_C5 
//* Description    :  C5侧面键
//* Input          :  lvoutput_addr - 弱电输出设备存在链表地址
//					hvout_addr - 强电继电器设备存在链表地址
//* Return         :  none
//*******************************************************************************/
//void Side_Key_C5(uint32_t lvoutput_addr,uint32_t relay_addr)
//{
//	static uint8_t press = 0;	//按键按下次数
//	uint8_t lvoutput_write_flag = 0;	//弱电输出写入SRAM标志   0：不写入   1：写入
//	Device_Public_Information_G LVOUTPUT_public_info;	//弱电输出共有属性
//	NOR_LVOUTPUT_INFO LVOUTPUT_private_info;	//弱电输出私有属性
//	Device_Public_Information_G RELAY_public_info;	//继电器共有属性
//	NOR_HVOUT_INFO RELAY_private_info;	//继电器私有属性
//	
//	memset(&LVOUTPUT_public_info, 0, sizeof(Device_Public_Information_G));	//初始化弱电输出公有属性
//	memset(&LVOUTPUT_private_info, 0, sizeof(NOR_LVOUTPUT_INFO));	//初始化弱电输出私有属性
//	SRAM_DMA_Read_Buff((uint8_t *)&LVOUTPUT_public_info, sizeof(Device_Public_Information_G), lvoutput_addr);	//读取弱电输出共有属性
//	SRAM_DMA_Read_Buff((uint8_t *)&LVOUTPUT_private_info, sizeof(NOR_LVOUTPUT_INFO), lvoutput_addr + Dev_Privately);	//读取弱电输出私有属性
//	
//	memset(&RELAY_public_info, 0, sizeof(Device_Public_Information_G));	//初始化继电器公有属性
//	memset(&RELAY_private_info, 0, sizeof(NOR_HVOUT_INFO));	//初始化继电器私有属性
//	SRAM_DMA_Read_Buff((uint8_t *)&RELAY_public_info, sizeof(Device_Public_Information_G), relay_addr);	//读取继电器共有属性
//	SRAM_DMA_Read_Buff((uint8_t *)&RELAY_private_info, sizeof(NOR_HVOUT_INFO), relay_addr + Dev_Privately);	//读取继电器私有属性
//	press++;
//	if(press > 26) press = 1;	//超过26次（清除状态（26次）之后）,按键次数设为1
//	if(press > 0 && press <= 24)	//C5板上弱电输出和继电器
//	{
//		if(press > 0 && press <= 6)	//前5次控弱电输出，之后就不控
//		{
//			UINT64DATACONVER(LVOUTPUT_private_info.DevLVoutputState) &= ~(0x1F);	//关闭弱电输出0~4状态
//			if(press != 6) UINT64DATACONVER(LVOUTPUT_private_info.DevLVoutputState) |= (0x01<<(press-1));	//第1~5次控制弱电输出0~4状态
//			lvoutput_write_flag = 1;	//弱电输出写入
//		}
//		UINT64DATACONVER(RELAY_private_info.DevHVoutState) &= ~(0xFFFFFF);	//关闭继电器0~23
//		UINT64DATACONVER(RELAY_private_info.DevHVoutState) |= (0x01<<(press-1));	//打开继电器
//	}
//	if(press == 25)	//弱电输出和继电器全开
//	{
//		UINT64DATACONVER(LVOUTPUT_private_info.DevLVoutputState) |= 0x1F;	//打开弱电输出0~4状态
//		UINT64DATACONVER(RELAY_private_info.DevHVoutState) |= 0xFFFFFF;	//打开继电器0~23
//		lvoutput_write_flag = 1;	//弱电输出写入
//	}
//	if(press == 26)	//弱电输出和继电器全关
//	{
//		UINT64DATACONVER(LVOUTPUT_private_info.DevLVoutputState) &= ~(0x1F);	//关闭弱电输出0~4状态
//		UINT64DATACONVER(RELAY_private_info.DevHVoutState) &= ~(0xFFFFFF);	//关闭继电器0~23
//		lvoutput_write_flag = 1;	//弱电输出写入
//	}
//	if(lvoutput_write_flag == 1)	//弱电输出写入SRAM
//	{
//		LVOUTPUT_public_info.check = 0x00;	//弱电输出共有属性校验清0
//		LVOUTPUT_public_info.check = DoubleData_CheckSum((uint8_t *)&LVOUTPUT_public_info, sizeof(Device_Public_Information_G), \
//									(uint8_t *)&LVOUTPUT_private_info, sizeof(NOR_LVOUTPUT_INFO));	//计算校验
//		SRAM_DMA_Write_Buff((uint8_t *)&LVOUTPUT_public_info, sizeof(Device_Public_Information_G), lvoutput_addr);	//保存弱电输出共有属性到SRAM
//		SRAM_DMA_Write_Buff((uint8_t *)&LVOUTPUT_private_info, sizeof(NOR_LVOUTPUT_INFO), lvoutput_addr + Dev_Privately);	//保存弱电输出私有属性到SRAM
//	}
//	RELAY_public_info.check = 0x00;	//继电器共有属性校验清0
//	RELAY_public_info.check = DoubleData_CheckSum((uint8_t *)&RELAY_public_info, sizeof(Device_Public_Information_G), (uint8_t *)&RELAY_private_info, \
//								sizeof(NOR_HVOUT_INFO));	//计算校验
//	SRAM_DMA_Write_Buff((uint8_t *)&RELAY_public_info, sizeof(Device_Public_Information_G), relay_addr);	//保存继电器共有属性到SRAM
//	SRAM_DMA_Write_Buff((uint8_t *)&RELAY_private_info, sizeof(NOR_HVOUT_INFO), relay_addr + Dev_Privately);	//保存继电器私有属性到SRAM
//	Dbg_Print(DBG_BIT_LOGIC_STATUS_bit,"侧面键按下次数为：%d",press);
//}

///*******************************************************************************
//* Function Name  : Side_Key_Fun 
//* Description    : 侧面键功能函数，包含C5和C12侧面键
//* Input          : none
//* Return         : none
//*******************************************************************************/
//void Side_Key_Fun(void)
//{
//	static uint8_t side_key = 0x00;	//bit7：侧面按键初始化完成标志   bit6~5：C5和C12按键功能   bit4~0：按键按下次数
//	static uint32_t lvoutput_addr = 0x00, c12dimming_addr = 0x00, relay_addr = 0x00;	//用于保存弱电输出，C12调光，强电继电器设备存在存放的SRAM地址
//	
//	if((side_key & SIDE_KEY_INIT) == 0x00)	//只判断一次
//	{
//		uint8_t data[7];	//保存设置的底板型号
//		
//		side_key |= SIDE_KEY_INIT;	//侧面键初始化完成
//		memset(data,0,7);	//初始化变量
//		Flash_Read(&data[0],7,FLASH_MCU_Control_Revision_ADDRESS);	//读底板信息
//		if(strcmp((const char *)data,"BLV-C12") == 0)	//C12底板
//		{
//			side_key |= C12_SIDE_KEY;	//C12侧面键功能
//			Dbg_Print(DBG_BIT_LOGIC_STATUS_bit,"C12底板");
//			for(uint8_t	i = 0; i < (SRAM_Read_DW(SRAM_BUS_Device_List_Addr) / SRAM_Device_List_Size); i++)	//找BUS设备存在链表
//			{
//				if((SRAM_Read_Byte(SRAM_Device_List_Start_Addr + (i * SRAM_Device_List_Size) + Dev_Type) == DEV_RS485_PWM) && \
//					(SRAM_Read_Byte(SRAM_Device_List_Start_Addr + (i * SRAM_Device_List_Size) + Dev_Protocol) == 0x05))
//				{
//					c12dimming_addr = SRAM_Device_List_Start_Addr+(i*SRAM_Device_List_Size);	//保存C12调光设备存放地址
//				}
//				if((SRAM_Read_Byte(SRAM_Device_List_Start_Addr + (i * SRAM_Device_List_Size) + Dev_Type) == Dev_Host_HVout) && \
//					(SRAM_Read_Byte(SRAM_Device_List_Start_Addr + (i * SRAM_Device_List_Size) + Dev_Protocol) == 0x01))
//				{
//					relay_addr = SRAM_Device_List_Start_Addr+(i*SRAM_Device_List_Size);	//保存强电继电器设备存放地址
//				}
//			}
//			for(uint8_t i = (SRAM_Read_DW(SRAM_ACTIVE_Device_List_Addr) / SRAM_Device_List_Size); \
//				i < (SRAM_Read_DW(SRAM_NORMAL_Device_List_Addr) / SRAM_Device_List_Size); i++)	//找普通设备存在链表
//			{
//				if((SRAM_Read_Byte(SRAM_Device_List_Start_Addr + (i * SRAM_Device_List_Size) + Dev_Type) == Dev_Host_LVoutput) && \
//					(SRAM_Read_Byte(SRAM_Device_List_Start_Addr + (i * SRAM_Device_List_Size) + Dev_Protocol) == 0x00))
//				{
//					lvoutput_addr = SRAM_Device_List_Start_Addr + (i * SRAM_Device_List_Size);	//保存强电继电器设备存放地址
//					break;	//找到就直接退出
//				}
//			}
//		}
//		if(strcmp((const char *)data,"BLV-C5") == 0)	//C5底板
//		{
//			side_key |= C5_SIDE_KEY;	//C5侧面键功能
//			Dbg_Print(DBG_BIT_LOGIC_STATUS_bit,"C5底板");
//			for(uint8_t	i = 0; i < (SRAM_Read_DW(SRAM_BUS_Device_List_Addr) / SRAM_Device_List_Size); i++)	//找BUS设备存在链表
//			{
//				if((SRAM_Read_Byte(SRAM_Device_List_Start_Addr + (i * SRAM_Device_List_Size) + Dev_Type) == Dev_Host_HVout) && \
//					(SRAM_Read_Byte(SRAM_Device_List_Start_Addr + (i * SRAM_Device_List_Size) + Dev_Protocol) == 0x01))
//				{
//					relay_addr = SRAM_Device_List_Start_Addr+(i*SRAM_Device_List_Size);	//保存强电继电器设备存放地址
//					break;
//				}
//			}
//			for(uint8_t i = (SRAM_Read_DW(SRAM_ACTIVE_Device_List_Addr) / SRAM_Device_List_Size); \
//				i < (SRAM_Read_DW(SRAM_NORMAL_Device_List_Addr) / SRAM_Device_List_Size); i++)	//找普通设备存在链表
//			{
//				if((SRAM_Read_Byte(SRAM_Device_List_Start_Addr + (i * SRAM_Device_List_Size) + Dev_Type) == Dev_Host_LVoutput) && \
//					(SRAM_Read_Byte(SRAM_Device_List_Start_Addr + (i * SRAM_Device_List_Size) + Dev_Protocol) == 0x00))
//				{
//					lvoutput_addr = SRAM_Device_List_Start_Addr + (i * SRAM_Device_List_Size);	//保存强电继电器设备存放地址
//					break;	//找到就直接退出
//				}
//			}
//		}
//	}
//	if(((side_key & SIDE_KEY_INIT) == SIDE_KEY_INIT) && ((side_key & SIDE_KEY_FUNCTION) != 0x00))	//侧面键初始化完成，已设置侧面键功能
//	{
//		switch(side_key & SIDE_KEY_FUNCTION)	//C12、C5侧面键判断
//		{
//			case C12_SIDE_KEY:	//C12侧面键
//				Side_Key_C12(lvoutput_addr, c12dimming_addr, relay_addr);	//C12侧面键
//				break;
//			case C5_SIDE_KEY:
//				Side_Key_C5(lvoutput_addr, relay_addr);	//C5侧面键
//				break;
//		}
//	}
//}
/************2022.11.22 林开锐 增加侧面键功能函数结束************/

/*对于BLV-C5-V05,BLV-C12-V04硬件版本之后才有一个测试按键
这测试按键原来是BUS485的使能引脚，BUS端口取消了485，才空出PB11该引脚
*/
#ifndef MCU_Local_Test_Button_EN

void Multipexing_IO_Init(void)
{

}

void Multipexing_IO_Task(void)
{

}

#else

/*2022-05-10 复用*/
MultIO_State_t g_mult_io;
	
/*******************************************************************************
* Function Name  : Multipexing_IO_Init
* Description    : 复用IO初始化
* Input          : 
* Return         : None
*******************************************************************************/
void Multipexing_IO_Init(void)
{
	memset(&g_mult_io,0,sizeof(MultIO_State_t));
	
	MultIO_Pin1_ModeCfg(MultIO_INPUT);
	MultIO_Pin1_H;
	
	
}

/*******************************************************************************
* Function Name  : Multipexing_IO_Output
* Description    : 设置IO输出状态
*******************************************************************************/
void Multipexing_IO_Output(uint8_t CHx,uint8_t state)
{
	switch(CHx)
	{
		case MultIO_CH1:
			if(state == MultIO_Pin_High)
			{
				MultIO_Pin1_H;
			}else if(state == MultIO_Pin_Low){
				MultIO_Pin1_L;
			}
			break;
	}
}



/*******************************************************************************
* Function Name  : Multipexing_Get_IO_State
* Description    : 获取IO输入状态
*******************************************************************************/
uint8_t Multipexing_Get_IO_State(uint8_t CHx)
{
	uint8_t rev = 0;
	switch(CHx)
	{
		case MultIO_CH1:
			if(MultIO_Pin1_Read != 0x00)	
			{
				rev = MultIO_Pin_High;
			}else {
				rev = MultIO_Pin_Low;
			}
			break;
	}
	return rev;
}

void Multipexing_IO_Scan_Task(void)
{
//	for(uint8_t i=0; i<MultIO_CHN_Max; i++)
//	{
//		switch(g_mult_io.input_state[i])
//		{
//			case INPUT_STA_S0:    
//				if( Multipexing_Get_IO_State(i) == MultIO_Input_PRESS )
//				{
//					if(g_mult_io.delayCnt[i] < MultIO_Input_DELAY_COUNT)
//					{
//						g_mult_io.delayCnt[i]++;
//					}
//					else
//					{
//						g_mult_io.input_state[i] = INPUT_STA_S1;              //消抖后
//						g_mult_io.input_time[i] = 0;
//						g_mult_io.delayCnt[i] = 0;
//					}
//				}
//				else
//				{
//					g_mult_io.delayCnt[i] = 0;
//					g_mult_io.input_state[i] = INPUT_STA_S0;
//					g_mult_io.input_val[i] = INPUT_NOT;
//				}
//				break;
//			case INPUT_STA_S1:    
//				g_mult_io.input_time[i] ++;
//				if( g_mult_io.input_time[i] < MultIO_Input_DELAY_COUNT_LONG )
//				{
//					if( Multipexing_Get_IO_State(i) == MultIO_Input_LOOSEN )                   //松开
//					{
//						g_mult_io.input_val[i] = INPUT_SHORT_PRESS;             //短按松开
//						g_mult_io.input_time[i] = 0;
//						g_mult_io.input_state[i] = INPUT_STA_S0;
//					}
//				}
//				else
//				{
//					g_mult_io.input_state[i] = INPUT_STA_S2;
//					g_mult_io.input_time[i] = 0;
//					g_mult_io.input_val[i] = INPUT_CONT_LONG_PRESS;             //长按按下
//				}   
//				break;
//								
//			case INPUT_STA_S2:    
//				if( Multipexing_Get_IO_State(i) == MultIO_Input_LOOSEN )
//				{
//					g_mult_io.input_state[i] = INPUT_STA_S0;
//					g_mult_io.input_val[i] = INPUT_LONG_PRESS_LOOSEN;           //长按松开
//				}
//				break;
//		} 
//	}
	
	/*硬件版本号：BLV-C5-V08 将复用IO作为断电检测引脚 修改输入检测机制 2025-03-24*/
	for(uint8_t i=0; i<MultIO_CHN_Max; i++)
	{
		
		if( Multipexing_Get_IO_State(i) == MultIO_Input_PRESS )
		{
			g_mult_io.delayCnt[i]++;
			g_mult_io.delayOffCnt[i] = 0x00;
			
			if(g_mult_io.delayCnt[i] >= MultIO_Input_DELAY_COUNT)
			{
				g_mult_io.delayCnt[i] = 0x00;
				g_mult_io.input_val[i] = INPUT_SHORT_PRESS;
			}
		}
		else
		{
			g_mult_io.delayCnt[i] = 0x00;
			g_mult_io.delayOffCnt[i]++;
			
			if(g_mult_io.delayOffCnt[i] >= MultIO_Input_DELAY_COUNT)
			{
				g_mult_io.delayOffCnt[i] = 0x00;
				g_mult_io.input_val[i] = INPUT_NOT;
			}
		}
		
	}
	

}


/*******************************************************************************
* Function Name  : Multipexing_IO_Task
* Description    : 复用IO任务 输入检测10ms ,然后切换到输出模式40ms
*******************************************************************************/
void Multipexing_IO_Task(void)
{
	static uint32_t Multipexing_test_tick = 0;
	switch(g_mult_io.State)
	{
		case MultIO_IDLE:			//空闲状态
			if(SysTick_1ms - g_mult_io.wait_tick >= MultIO_OutPut_Time)
			{
				g_mult_io.State = MultIO_Input_Mode;
			}
			break;
		case MultIO_Input_Mode:		//输入模式
			MultIO_Pin1_ModeCfg(MultIO_INPUT);
			Multipexing_IO_Scan_Task();
			g_mult_io.State = MultIO_Output_Mode;
			g_mult_io.wait_tick = SysTick_1ms;
			break;
		case MultIO_Output_Mode:	//输出模式
			g_mult_io.State = MultIO_IDLE;
			g_mult_io.wait_tick = SysTick_1ms;
			/*设置输出*/
			for(uint8_t i=0;i<MultIO_CHN_Max;i++)
			{
				MultIO_Pin1_ModeCfg(MultIO_OUTPUT);
				Multipexing_IO_Output(i,g_mult_io.output_state[i]);
			}
			break;
	}
	
	if(SysTick_1ms - Multipexing_test_tick >= 1000)
	{
		Multipexing_test_tick = SysTick_1ms;
		
		if(g_mult_io.output_state[0] == MultIO_Pin_High)
		{
			
			g_mult_io.output_state[0] = MultIO_Pin_Low;
		}else {
			
			g_mult_io.output_state[0] = MultIO_Pin_High;
		}
	}
	
	if(g_mult_io.input_val[0] != g_mult_io.last_input_val[0] ){
		g_mult_io.last_input_val[0] = g_mult_io.input_val[0];
		if(g_mult_io.input_val[0] == INPUT_SHORT_PRESS)
		{
			Dbg_Println(DBG_BIT_SYS_STATUS_bit,"检测到设备 电源已断电");
			

			
		}else if(g_mult_io.input_val[0] == INPUT_NOT){
			Dbg_Println(DBG_BIT_SYS_STATUS_bit,"检测到设备 电源已恢复");
			

		}
	}


}


#endif

