#include "includes.h"

MusicList_Struct PlayList;


void TempPrompt_Fun_Init(void)
{
	memset(&PlayList,0,sizeof(MusicList_Struct));
	PlayList.EnFlag = 0x00;
	PlayList.DevAddr = Find_AllDevice_List_Information2(Bus_port,DEV_RS485_MUSIC,0x01);
}


void AddPrompt_ToList(uint8_t event)
{
//	if(PlayList.ListNum < LIST_MAXNUM)
//	{
//		Dbg_Println(DBG_BIT_SYS_STATUS_bit,"AddPrompt_ToList:%d - %d - %d",event,PlayList.ListNum,PlayList.EnFlag);
////		printf("AddPrompt_ToList:%d\n\r",event);
//		if(PlayList.ListEnd == LIST_MAXNUM)
//		{
//			PlayList.ListEnd = 0x00;
//		}
//		
//		switch(event)
//		{
//			case 0x00:     //制冷
////				printf("制冷:%d\n\r",PlayList.ListEnd);
//				PlayList.PlayList[PlayList.ListEnd] = 0xA013;
//				PlayList.ListNum++;
//				PlayList.ListEnd++;
//				break;
//			case 0x01:     //制热
////				printf("制热:%d\n\r",PlayList.ListEnd);
//				PlayList.PlayList[PlayList.ListEnd] = 0xA113;
//				PlayList.ListNum++;
//				PlayList.ListEnd++;
//				break;
//			case 0x02:     //送风
////				printf("送风:%d\n\r",PlayList.ListEnd);
//				PlayList.PlayList[PlayList.ListEnd] = 0xA213;
//				PlayList.ListNum++;
//				PlayList.ListEnd++;
//				break;
//			case 0x03:     //低风速
////				printf("低风速:%d\n\r",PlayList.ListEnd);
//				PlayList.PlayList[PlayList.ListEnd] = 0xA313;
//				PlayList.ListNum++;
//				PlayList.ListEnd++;
//				break;
//			case 0x04:     //中风速
////				printf("中风速:%d\n\r",PlayList.ListEnd);
//				PlayList.PlayList[PlayList.ListEnd] = 0xA413;
//				PlayList.ListNum++;
//				PlayList.ListEnd++;
//				break;
//			case 0x05:     //高风速
////				printf("高风速:%d\n\r",PlayList.ListEnd);
//				PlayList.PlayList[PlayList.ListEnd] = 0xA513;
//				PlayList.ListNum++;
//				PlayList.ListEnd++;
//				break;
//			default:
//				break;
//		}
//	}

	switch(event)
	{
			case 0x00:     //制冷
//				printf("制冷:%d\n\r",PlayList.ListEnd);
				
				PlayList.PlayIdnex = 0xA0;
				PlayList.play_delay_tick = SysTick_1ms;

				break;
			case 0x01:     //制热
//				printf("制热:%d\n\r",PlayList.ListEnd);
				
				PlayList.PlayIdnex = 0xA1;
				PlayList.play_delay_tick = SysTick_1ms;
				break;
			case 0x02:     //送风
//				printf("送风:%d\n\r",PlayList.ListEnd);
				
				PlayList.PlayIdnex = 0xA2;
				PlayList.play_delay_tick = SysTick_1ms;
				break;
			case 0x03:     //低风速
//				printf("低风速:%d\n\r",PlayList.ListEnd);
				
				PlayList.PlayIdnex = 0xA3;
				PlayList.play_delay_tick = SysTick_1ms;
				
				break;
			case 0x04:     //中风速
//				printf("中风速:%d\n\r",PlayList.ListEnd);
				
				PlayList.PlayIdnex = 0xA4;
				PlayList.play_delay_tick = SysTick_1ms;
				break;
			case 0x05:     //高风速
//				printf("高风速:%d\n\r",PlayList.ListEnd);
				
				PlayList.PlayIdnex = 0xA5;
				PlayList.play_delay_tick = SysTick_1ms;
				break;
			case 0x06:		//空调开机

				PlayList.PlayIdnex = 11;
				PlayList.play_delay_tick = SysTick_1ms;
				break;
			case 0x07:		//空调关机

				PlayList.PlayIdnex = 12;
				PlayList.play_delay_tick = SysTick_1ms;
				break;
			default:
				break;
	}



}


void TempPrompt_Fun_Task(void)
{
	Device_Public_Information_G BUS_Public;   //共用
	BUS_C5MUSIC_INFO C5Music_Info;
	
	if( (PlayList.DevAddr == NULL) || (PlayList.EnFlag != 0x01) )
	{
//		Dbg_Println(DBG_BIT_SYS_STATUS_bit,"TempPrompt_Fun_Task Addr Or EnFlag 0");
		return;
	}
	
	if( SysTick_1ms - PlayList.scan_tick >= 50)
	{
		PlayList.scan_tick = SysTick_1ms;
		
		if( SysTick_1ms - PlayList.play_delay_tick >= 3000 )
		{
			//播放超时，清除播放序号
			PlayList.play_delay_tick = SysTick_1ms;
			PlayList.PlayIdnex = 0x00;
		}
		
		if( PlayList.PlayIdnex == 0x00 )	return;		//当前没有音乐播放
		
		/*校验音乐数据是否成功*/
		if(Device_Data_Check(PlayList.DevAddr) == 0)
		{
			SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),PlayList.DevAddr);	//拷贝所有共有数据
			SRAM_DMA_Read_Buff((uint8_t *)&C5Music_Info,sizeof(BUS_C5MUSIC_INFO),PlayList.DevAddr+Dev_Privately);
			
			if((PlayList.EnFlag == 0x01) && (BUS_Public.type == DEV_C5MUSIC_Type) && (BUS_Public.Protocol == 0x01))
			{
				//只有不是在播放提示音，就可以抢先播放
				if( (C5Music_Info.now_playback_status == BLV_C5MUSIC_Playing) && (C5Music_Info.now_playback_dir == BLV_C5MUSIC_Warning_Dir) )	return;
				//当前有提示音数据需要发送的话，就不可以抢先播放
				if( ((C5Music_Info.control_flag & C5MUSIC_Specify_Play_Flag) != 0x00 ) && (C5Music_Info.assign_dir == BLV_C5MUSIC_Warning_Dir) )	return;
				
				C5Music_Info.playback_fun = BLV_C5MUSIC_Forestall;		//播放模式 - 抢先播放
				C5Music_Info.assign_dir = BLV_C5MUSIC_Warning_Dir;		//播放提示音文件夹
				C5Music_Info.assign_playback_idx = PlayList.PlayIdnex;	//设置播放提示音序号
				
				C5Music_Info.control_flag |= C5MUSIC_Specify_Play_Flag;	//设置发送标志位
				
				PlayList.PlayIdnex = 0x00;
				
				BUS_Public.check = 0x00;
				BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&C5Music_Info, sizeof(BUS_C5MUSIC_INFO));
				SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),PlayList.DevAddr);/*将数据保存*/
				SRAM_DMA_Write_Buff((uint8_t *)&C5Music_Info,sizeof(BUS_C5MUSIC_INFO),PlayList.DevAddr+Dev_Privately);
			}
		}
		
	}
	
}



