⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipod.c

📁 IPOD协议命令的驱动在CAR ENTERTAINMENT SYSTEM上的实现
💻 C
📖 第 1 页 / 共 3 页
字号:

}
static void mode04_menu(void)
{
    UB temp_category;
    UH temp;
    UH temp_count;

     if(ipod_bank == IPOD_BANK_LEFT)
        {
            if(ipod_layer)
                ipod_layer--;
            
            if(ipod_layer < IPOD_LAYER_MUSIC)
                {
                  mode04_init();
                   return;
                }
            mode04_db_reset();
             if(mode04_come_back() != AIR_ACK)
                    return;           
             
            temp_category = mode04_get_category();
            mode04_db_get(temp_category);
             if(mode04_come_back() == AIR_RET_NUM_CATE)
            {
                ipod_db_count = (uart_rc_buff[6]<<24)|(uart_rc_buff[7]<<16)|(uart_rc_buff[8]<<8)|uart_rc_buff[9];
            }
           else
            {
            }
           
            ipod_db_position = 0;
            
             if(ipod_db_count < NUM_IPOD_DISP)
                 temp_count = ipod_db_count;
            else
                 temp_count = NUM_IPOD_DISP;


            for(temp = 0; temp<temp_count; temp++)
            {
                mode04_db_retrieve(temp_category,  temp, 1);
                if(mode04_come_back() == AIR_RET_CATE_DB)
                    mode04_get_name(temp); 
                else
                    continue;
            }        
           for(;temp<NUM_IPOD_DISP;temp++)
            {
            ipod_db_disp_info[temp].file_name[0]='\0';
            ipod_db_disp_info[temp].file_name[1]='\0';   
            }
        }
     else
        {
            
        }
    IPOD_send_disp_msg(MS_OSD_REQ,DSP_ID_MP3_NAME, DSP_DAT_ON);         
}

static void mode04_play(void)
{
    UB temp_category;
    temp_category = mode04_get_category();
    if(ipod_bank == IPOD_BANK_LEFT)
        {
        if(temp_category == IPOD_LAYER_TRACK)
            {
                mode04_db_select(temp_category,ipod_db_position);
                if(mode04_come_back() != AIR_ACK)
                    return;
            }        
        }
    else
                  xprintf(IPOD_AIR_MODE,0x00,AIR_PLAY_CONTROL,IPOD_CON_FO,-1);    
}

static void mode04_arrow_up(void)
{
    UB temp_category;
    UB temp;
    UB temp_count;

    if(ipod_bank == IPOD_BANK_LEFT)
    {
        if(ipod_db_position)
            ipod_db_position--;
        
            ipod_db_page =ipod_db_position/NUM_IPOD_DISP;
            
             if(ipod_db_last_page>ipod_db_page)
            {
                ipod_db_last_page = ipod_db_page;
                temp_category = mode04_get_category();
                
//                temp_count = ipod_db_position/NUM_IPOD_DISP;

                for(temp = ipod_db_page*NUM_IPOD_DISP; temp<ipod_db_position; temp++)
                {
                     mode04_db_retrieve(temp_category,  temp, 1);
                     if(mode04_come_back() == AIR_RET_CATE_DB)
                        mode04_get_name(temp%NUM_IPOD_DISP); 
                     else
                         continue;
                }   
             
             }
     }
    else
        {
             if(ipod_pb_position)
                    ipod_pb_position--;

            ipod_pb_page = ipod_pb_position/NUM_IPOD_DISP;
            if(ipod_pb_last_page > ipod_pb_page)
                {
                ipod_pb_last_page = ipod_pb_page;
                
                 for(temp = ipod_pb_page*NUM_IPOD_DISP; temp<ipod_pb_position; temp++)
                {
                    mode04_pb_name(temp);
                    if(mode04_come_back() == AIR_RET_TRACK_NAME)
                        mode04_get_name(temp%NUM_IPOD_DISP); 
                    else
                         continue;

            }       
                }
        }
    IPOD_send_disp_msg(MS_OSD_REQ,DSP_ID_MP3_NAME, DSP_DAT_ON);         
}
static void mode04_arrow_down(void)
{
    UB temp_category;
    UB temp;
    UB temp_count;
    if(ipod_bank == IPOD_BANK_LEFT)
    {
        if(ipod_db_position < ipod_db_count)
            ipod_db_position++;

        ipod_db_page = ipod_db_position/NUM_IPOD_DISP;
        
        if(ipod_db_last_page<ipod_db_page)
            {
             ipod_db_last_page = ipod_db_page;
             
            temp_category = mode04_get_category();

            if((ipod_db_count-ipod_db_position)>=NUM_IPOD_DISP)
                temp_count = ipod_db_position+NUM_IPOD_DISP;
            else
                temp_count =ipod_db_count;

            
             for(temp = ipod_db_position; temp<(temp_count-1); temp++)
             {
                 mode04_db_retrieve(temp_category,  temp, 1);
                 if(mode04_come_back() == AIR_RET_CATE_DB)
                     mode04_get_name(temp-ipod_db_position); 
                else
                    continue;               
             }
           for(temp=temp-ipod_db_position;temp<NUM_IPOD_DISP;temp++)
            {
            ipod_db_disp_info[temp].file_name[0]='\0';
            ipod_db_disp_info[temp].file_name[1]='\0';   
            }             
            }
    }
    else
    {
        if(ipod_pb_position < ipod_pb_count)
            ipod_pb_position++;
        
        ipod_pb_page = ipod_pb_position/NUM_IPOD_DISP;
        
        if(ipod_pb_last_page<ipod_pb_page)
            {
             ipod_pb_last_page = ipod_pb_page;
             
            if((ipod_pb_count-ipod_pb_position)>=NUM_IPOD_DISP)
                temp_count = ipod_pb_position+NUM_IPOD_DISP;
            else
                temp_count =ipod_pb_count;

            
             for(temp = ipod_pb_position; temp<(temp_count-1); temp++)
             {
                    mode04_pb_name(temp);
                    if(mode04_come_back() == AIR_RET_TRACK_NAME)
                        mode04_get_name(temp%NUM_IPOD_DISP); 
                    else
                         continue;          
             }
           for(temp=temp-ipod_pb_position;temp<NUM_IPOD_DISP;temp++)
            {
            ipod_pb_disp_info[temp].file_name[0]='\0';
            ipod_pb_disp_info[temp].file_name[1]='\0';   
            }             
            }        
    }
    IPOD_send_disp_msg(MS_OSD_REQ,DSP_ID_MP3_NAME, DSP_DAT_ON);     
}
static void mode04_arrow_left(void)
{
    ipod_bank = IPOD_BANK_LEFT;
    IPOD_send_disp_msg(MS_OSD_REQ,DSP_ID_MP3_NAME, DSP_DAT_ON);         
}
static void mode04_arrow_right(void)
{
    UB temp;
    UB temp_count;
    ipod_bank = IPOD_BANK_RIGHT;
        mode04_pb_count();
        if(mode04_come_back() == AIR_RET_PLAY_TRACK)
            {
            ipod_pb_count = (uart_rc_buff[6]<<24)|(uart_rc_buff[7]<<16)|(uart_rc_buff[8]<<8)|uart_rc_buff[9];
            }

       if(ipod_pb_count < NUM_IPOD_DISP)
                 temp_count = ipod_pb_count;
            else
                 temp_count = NUM_IPOD_DISP;
        if(ipod_pb_count > 0)
            {
                for(temp = 0; temp<temp_count; temp++)
                {
                    mode04_pb_name(temp);
                    if(mode04_come_back() == AIR_RET_TRACK_NAME)
                        mode04_get_name(temp); 
                    else
                         continue;
            }            
        }    
    IPOD_send_disp_msg(MS_OSD_REQ,DSP_ID_MP3_NAME, DSP_DAT_ON);         
}

static void mode04_db_reset(void)
{
        xprintf(IPOD_AIR_MODE,0x00,AIR_RESET_DB,-1);
//    IPOD_send_disp_msg(MS_OSD_REQ,DSP_ID_MP3_NAME, DSP_DAT_ON);             
}
static void mode04_db_select(UB category, UH index)
{
    UB temp_buff[4] ;
    temp_buff[0] = (UB)index;
    temp_buff[1] = (UB)(index>>8);
    temp_buff[2] = (UB)(index>>16);
    temp_buff[3] = (UB)(index>>24);
    xprintf(IPOD_AIR_MODE,0X00,AIR_SELECT_DB,category,temp_buff[3],temp_buff[2],temp_buff[1],temp_buff[0],-1);
}
static void mode04_db_get(UB category)
{
    xprintf(IPOD_AIR_MODE,0X00,AIR_GET_NUM_CATE,category,-1);
}
static void mode04_db_retrieve(UB category, UH index, UH count)
{
    UB index_buff[4];
    UB count_buff[4];
    
    index_buff[0] = (UB)index;
    index_buff[1] = (UB)(index>>8);
    index_buff[2] = (UB)(index>>16);
    index_buff[3] = (UB)(index>>24);

    count_buff[0] = (UB)count;
    count_buff[1] = (UB)(count>>8);
    count_buff[2] = (UB)(count>>16);
    count_buff[3] = (UB)(count>>24);
    xprintf(IPOD_AIR_MODE,0X00,AIR_GET_CATE_DB,category,index_buff[3],index_buff[2],index_buff[1],index_buff[0],count_buff[3],count_buff[2],count_buff[1],count_buff[0],-1);
}

static UB   mode04_come_back(void)
{

        UINT event_flg;
        ER errorcode;

        errorcode = twai_flg(&event_flg, TS_CD_PB, EF_IPOD_MSG, TWF_ORW + TWF_CLR, T2000ms);

        if(errorcode == E_OK)   
        {
            return uart_rc_buff[5];
        }
        else
            return 0;

}

static UB   mode04_get_category(void)
{
    UB category;
    category = ipod_category[ipod_layer];
    ipod_last_category = category;
    return category;
}

static UB   mode04_set_category(void)
{
    UB category;
    if(ipod_layer == IPOD_LAYER_MUSIC)
        category = ipod_db_position+1;
    else
    {
           switch(ipod_layer)
           {
           case IPOD_LAYER_GENRE:
               switch(ipod_last_category)
                   {
               case IPOD_CATE_PLAYLIST:
                   category = IPOD_CATE_TRACK;
                   break;
               case IPOD_CATE_ARTIST:
                   category = IPOD_CATE_ALBUM;
                   break;
               case IPOD_CATE_AUDIOBOOK:
                   category = IPOD_CATE_TRACK;
                   break;
               case IPOD_CATE_TRACK:
                   category = IPOD_CATE_TRACK;
                   break;
               case IPOD_CATE_GENRE:
                   category = IPOD_CATE_ARTIST;
                   break;
               case IPOD_CATE_ALBUM:
                   category = IPOD_CATE_TRACK;
                   break;
               case IPOD_CATE_PODCAST:
                   category = IPOD_CATE_TRACK;
               case IPOD_CATE_COMPOSER:
                   category = IPOD_CATE_TRACK;                
                   break;
                   }
               break;
          case IPOD_LAYER_ARTIST:
                  switch(ipod_last_category)
                      {
                  case IPOD_CATE_PLAYLIST:
                      category = IPOD_CATE_PLAYLIST;
                      break;
                  case IPOD_CATE_ARTIST:
                      category = IPOD_CATE_ALBUM;
                      break;
                  case IPOD_CATE_AUDIOBOOK:
                      category = IPOD_CATE_AUDIOBOOK;
                      break;
                  case IPOD_CATE_TRACK:
                      category = IPOD_CATE_TRACK;
                      break;
                  case IPOD_CATE_GENRE:
                      category = IPOD_CATE_ARTIST;
                      break;
                  case IPOD_CATE_ALBUM:
                      category = IPOD_CATE_TRACK;
                      break;
                  case IPOD_CATE_PODCAST:
                      category = IPOD_CATE_PODCAST;
                  case IPOD_CATE_COMPOSER:
                      category = IPOD_CATE_COMPOSER;                
                      break;
                      }
                  break;
        
               break;     
         case IPOD_LAYER_ALBUM:
               category = IPOD_CATE_TRACK;            
              break;
        case IPOD_LAYER_TRACK:
              category = IPOD_CATE_TRACK;               
              break;
           }

        }
    ipod_category[ipod_layer] = category;
    ipod_last_category = category;
    return category;
}


static void mode04_get_name(UB index)
{
    UB length;
    length = uart_rc_buff[2]-7;
    if(length > 15)
        length = 15;

    if(ipod_bank == IPOD_BANK_LEFT)
        {
        memcpy(ipod_temp_buff, &(uart_rc_buff[10]),length);
        UTF_8ToUnicode((ipod_db_disp_info[index].file_name),ipod_temp_buff,length);
        }
    else
        {
        memcpy(ipod_temp_buff, &(uart_rc_buff[6]), length);
         UTF_8ToUnicode((ipod_pb_disp_info[index].file_name),ipod_temp_buff,length);       
        }
}

static void mode04_init_data(void)
{
//    ipod_db_disp_info[0].file_name[] = "root";
//    strcpy(ipod_db_disp_info[0].file_name, "root");   
/*
    strcpy(ipod_db_disp_info[0].file_name, "Playlists");   
    strcpy(ipod_db_disp_info[1].file_name, "Artists");   
    strcpy(ipod_db_disp_info[2].file_name, "Albums");   
    strcpy(ipod_db_disp_info[3].file_name, "Genres");   
    strcpy(ipod_db_disp_info[4].file_name, "Songs");  
    strcpy(ipod_db_disp_info[5].file_name, "Composers");     
    */

    memcpy(ipod_db_disp_info[0].file_name,str_playlists_en, sizeof(str_playlists_en));
    memcpy(ipod_db_disp_info[1].file_name,str_Artists_en, sizeof(str_Artists_en));
    memcpy(ipod_db_disp_info[2].file_name,str_Albums_en, sizeof(str_Albums_en));
    memcpy(ipod_db_disp_info[3].file_name,str_Genres_en, sizeof(str_Genres_en));
    memcpy(ipod_db_disp_info[4].file_name,str_Songs_en, sizeof(str_Songs_en));
    memcpy(ipod_db_disp_info[5].file_name,str_Composers_en, sizeof(str_Composers_en));
 //   memcpy(ipod_db_disp_info[5].file_name,str_playlists_en, sizeof(str_playlists_en));

    ipod_db_count = 5;

    memset(ipod_pb_disp_info,0,sizeof(ipod_pb_disp_info));
}

static void mode04_pb_count(void)
{
    xprintf(IPOD_AIR_MODE,0x00,AIR_GET_PLAY_TRACK,-1);
}
static void mode04_pb_position(void)
{
    xprintf(IPOD_AIR_MODE,0x00,AIR_GET_TRACK_INDEX,-1);
}

static void mode04_pb_play(UH index)
{
    UB index_buff[4];
    
    index_buff[0] = (UB)index;
    index_buff[1] = (UB)(index>>8);
    index_buff[2] = (UB)(index>>16);
    index_buff[3] = (UB)(index>>24);

    xprintf(IPOD_AIR_MODE,0x00,AIR_SET_PLAY_TRACK,index_buff[3],index_buff[2],index_buff[1],index_buff[0],-1);
}

static void mode04_pb_name(UH index)
{
    UB index_buff[4];
    
    index_buff[0] = (UB)index;
    index_buff[1] = (UB)(index>>8);
    index_buff[2] = (UB)(index>>16);
    index_buff[3] = (UB)(index>>24);

    xprintf(IPOD_AIR_MODE,0x00,AIR_GET_TRACK_NAME,index_buff[3],index_buff[2],index_buff[1],index_buff[0],-1);
}
static void mode04_pb_artist(UH index)
{
    UB index_buff[4];
    
    index_buff[0] = (UB)index;
    index_buff[1] = (UB)(index>>8);
    index_buff[2] = (UB)(index>>16);
    index_buff[3] = (UB)(index>>24);

    xprintf(IPOD_AIR_MODE,0x00,AIR_GET_TRACK_ARTIST,index_buff[3],index_buff[2],index_buff[1],index_buff[0],-1);
}
static void mode04_pb_album(UH index)
{
    UB index_buff[4];
    
    index_buff[0] = (UB)index;
    index_buff[1] = (UB)(index>>8);
    index_buff[2] = (UB)(index>>16);
    index_buff[3] = (UB)(index>>24);

    xprintf(IPOD_AIR_MODE,0x00,AIR_GET_TRACK_ALBUM,index_buff[3],index_buff[2],index_buff[1],index_buff[0],-1);
}


////////////////////////////////////////////////////////////////////////////////////////////

static void IPOD_send_disp_msg(UB kind,UB id,UB hyouji)
{
	VP	p_blf = 0;
	MSG_DISP_REQ_T *msg;

	while( 1 ){
		if (pget_blf( &p_blf, TS_DISPLAY ) == E_OK ){
			break;
		}
	}
	msg = (MSG_DISP_REQ_T *)p_blf;
	msg->head.msg_id   = kind;
	msg->head.d_taskid = TS_DISPLAY;
	msg->head.o_taskid = TS_CD_PB;
	msg->id     = id;
	msg->OnOff  = hyouji;
	snd_msg( TS_DISPLAY, (PT_MSG)msg );
	set_flg( TS_DISPLAY, (UINT)EF_COM_MSG );
}


static void UTF_8ToUnicode(B * pOut,B *pText,UB pLen)
{
    UB i,j; 
    char* uchar = (char *)pOut;

    for(i=0,j=0;i<pLen;)
    {
        if(((UB)pText[i])<0x80)
            {
            uchar[j] = 0x00;
            uchar[j+1] = pText[i];
            j = j+2;
            i++;
            }
        else if(((UB)(pText[i])>=0xC0)&&(((UB)pText[i])<0xe0))
            {
            i = i+2;
            j = j+2;
            }
        else
            {
            uchar[j] = ((pText[i] & 0x0F) << 4) + ((pText[i+1] >> 2) & 0x0F);
            uchar[j+1] = ((pText[i+1] & 0x03) << 6) + (pText[i+2] & 0x3F);
            i = i+3;
            j = j+2;
            }
        uchar[j]='\0';
        uchar[j+1] = '\0';
    }
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -