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

📄 photobroevent_api.c

📁 C 代码C 代码C 代码C 代码C 代码C 代码C 代码C 代码C 代码C 代码
💻 C
字号:
#pragma codeseg(APP)
#include "sys.h"
#include "PhotoBrowser.h"
#include "MusicPlayer.h"
#include "img_position.h"

uint16 file_curr_sel_item;
uint16 Folders,Files;
uint8 page,file_curr_sel_icon,file_pre_sel_icon;
uint8 root_order,file_repaint_flag,nand_sd_flag;
uint8 sfnPtr[13],lfnPtr[256];
uint16 total_page,total_item;
uint8 next_task;

void _photo_event_init(void);
void _photo_update_sel_item(void);
void _photo_sel_up(void);
void _photo_sel_down(void);
void _photo_sel_left(void);
void _photo_sel_right(void);
void _photo_sel_play(void);
void _photo_stop_thu(uint8 task);

//***************************************************************************
// Func:        void _photo_event_init(void)
// Input:       none
// Output:      none
//
// Description: get parameter from RAM_SHARING_ADR and calculate "total_item" and "total_page"       
//
//***************************************************************************
void _photo_event_init(void)
{
 // init varible
  //for photo browser and photo event
  file_repaint_flag = API_SysReadValue(RAM_SHARING_ADR,PHO_PAINT_FLAG);
  file_curr_sel_icon = API_SysReadValue(RAM_SHARING_ADR,PHO_CUR_SEL);       //0~9
  file_pre_sel_icon = API_SysReadValue(RAM_SHARING_ADR,PHO_PRE_SEL);        //0~9   
  page = API_SysReadValue(RAM_SHARING_ADR,PHO_PAGE);                        //0~
  root_order = API_SysReadValue(RAM_SHARING_ADR,ROOT_ORDER);
  nand_sd_flag = API_SysReadValue(RAM_SHARING_ADR,IS_NAND_SD);
  next_task = 0;
  
  API_FATGetItemAmountInFolder(&Folders,&Files,FF_PHOTO_FORM);
  
  if(root_order)
   total_item = Folders+Files+1; //need add return item
  else
   total_item = Folders+Files;
   
  if( (total_item)%PHOBRO_ITEM != 0)
   total_page = (total_item/PHOBRO_ITEM) + 1;
  else 
   total_page = (total_item/PHOBRO_ITEM);
}

//***************************************************************************
// Func:        void _photo_sel_up(void)
// Input:       none
// Output:      none
//
// Description: When press "UP" key, calculate "file_curr_sel_icon", "file_pre_sel_icon", "page" 
//              and "file_repaint_flag"
//
//***************************************************************************
void _photo_sel_up(void)
{
        uint8 temp_file_pre_sel_icon,temp_file_repaint_flag,i;
        temp_file_repaint_flag = 0;
        
        temp_file_pre_sel_icon = file_curr_sel_icon;
        
       if(file_curr_sel_icon == 0 && page == 0)
       {
          if(total_item > 0)
          {
           page = total_page-1;
           file_curr_sel_icon = (total_item-1)%PHOBRO_ITEM;
          }
          else
          {
           page = 0;
           file_curr_sel_icon = 0;
          }
          temp_file_repaint_flag = 2;
          _photo_update_sel_item();
       }
       else
       {
        for(i=0;i<3;i++)
        {
         if( !(file_curr_sel_icon == 0 && page == 0) )
         {
          _photo_sel_left();
          temp_file_repaint_flag = temp_file_repaint_flag | file_repaint_flag;   
         }
        }
       }
        
        file_repaint_flag = temp_file_repaint_flag;
        file_pre_sel_icon = temp_file_pre_sel_icon;
        
        if( (API_PhotoGetThreadState() == TS_PLAY) && file_repaint_flag)
        {
         _photo_stop_thu(TASKID_PHOTOBROWSER);
        }
        else
        {
         //API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_0_7,0);
         //API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_8,0);
         API_OsSetCurrentTask(TASKID_PHOTOBROWSER);
        }
        
}

//***************************************************************************
// Func:        void _photo_sel_down(void)
// Input:       none
// Output:      none
//
// Description: When press "DOWN" key, calculate "file_curr_sel_icon", "file_pre_sel_icon", "page" 
//              and "file_repaint_flag"
//
//***************************************************************************
void _photo_sel_down(void)
{
        uint8 temp_file_pre_sel_icon,temp_file_repaint_flag,i;
        temp_file_repaint_flag = 0;
        
        temp_file_pre_sel_icon = file_curr_sel_icon;
        
       if(file_curr_sel_item == (Folders+Files))
       {
          page = 0;
          file_curr_sel_icon = 0;
          temp_file_repaint_flag = 2;
          _photo_update_sel_item();
       }
       else
       {
        for(i=0;i<3;i++)
        {
         if(file_curr_sel_item < (Folders+Files))
         {
          _photo_sel_right();
          temp_file_repaint_flag = temp_file_repaint_flag | file_repaint_flag;   
         }
        }
       }
        
        file_repaint_flag = temp_file_repaint_flag;
        file_pre_sel_icon = temp_file_pre_sel_icon;

        if( (API_PhotoGetThreadState() == TS_PLAY) && file_repaint_flag)
        {
         _photo_stop_thu(TASKID_PHOTOBROWSER);         
         //API_LcmShowNumber(0,304,POS_PHOBRO_ICON_Y-20,0);  
        }
        else
        {
         //API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_0_7,0);
         //API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_8,0);
         //API_LcmShowNumber(1,304,POS_PHOBRO_ICON_Y-20,0);  
         API_OsSetCurrentTask(TASKID_PHOTOBROWSER);
        }

}


//***************************************************************************
// Func:        void _photo_sel_left(void)
// Input:       none
// Output:      none
//
// Description: When press "LEFT" key, calculate "file_curr_sel_icon", "file_pre_sel_icon", "page" 
//              and "file_repaint_flag"
//
//***************************************************************************
void _photo_sel_left(void)
{
        file_pre_sel_icon=file_curr_sel_icon;
        file_repaint_flag = 0;
        if(file_curr_sel_icon == 0)// last page
        {
         if(page>0) 
         {
          page--;
          file_curr_sel_icon = PHOBRO_ITEM-1;
          file_repaint_flag = 2;
         }
         else // in page 0
         {
          
          if(total_item > 0)
          {
           page = total_page-1;
           file_curr_sel_icon = (total_item-1)%PHOBRO_ITEM;
          }
          else
          {
           page = 0;
           file_curr_sel_icon = 0;
          }
          file_repaint_flag = 2;
         }
        }
        else
        {
         file_curr_sel_icon--;
        }
        //update file_curr_sel_item
        _photo_update_sel_item();

        if( (API_PhotoGetThreadState() == TS_PLAY) && file_repaint_flag)
        {
         _photo_stop_thu(TASKID_PHOTOBROWSER);        
        }
        else
        {
         //API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_0_7,0);
         //API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_8,0);
         API_OsSetCurrentTask(TASKID_PHOTOBROWSER);
        }
}

//***************************************************************************
// Func:        void _photo_sel_right(void)
// Input:       none
// Output:      none
//
// Description: When press "RIGHT" key, calculate "file_curr_sel_icon", "file_pre_sel_icon", "page" 
//              and "file_repaint_flag"
//
//***************************************************************************
void _photo_sel_right(void)
{
        file_pre_sel_icon=file_curr_sel_icon;
        file_repaint_flag = 0;

        if(file_curr_sel_item == (Folders+Files)) //go to first
        {
          page = 0;
          file_curr_sel_icon = 0;
          file_repaint_flag = 2;
        }
        else if(file_curr_sel_icon == PHOBRO_ITEM-1)
        {
         if(page < total_page-1)
         {
          page++;
          file_curr_sel_icon = 0;
          file_repaint_flag = 2;
         }
        }
        else
        {
         if( file_curr_sel_item < Folders+Files )
          file_curr_sel_icon++;
        }
        //update file_curr_sel_item
        _photo_update_sel_item();
        
        if( (API_PhotoGetThreadState() == TS_PLAY) && file_repaint_flag)
        {
         _photo_stop_thu(TASKID_PHOTOBROWSER);        
        }
        else
        {
        //API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_0_7,0);
         //API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_8,0);
         API_OsSetCurrentTask(TASKID_PHOTOBROWSER);
        }
}

//***************************************************************************
// Func:        void _photo_sel_play(void)
// Input:       none
// Output:      none
//
// Description: When press "PLAY" key, do appropriate operation
//
//***************************************************************************
void _photo_sel_play(void)
{
        uint8 i;
        uint16 cur_item_amount;
        
        //return uper layer
        if(file_curr_sel_item == 0)
        {
          if(root_order)
          {
           API_FATExitFolder();
           API_SysWriteValue2B(RAM_CUR_PATH_ADR,root_order*2,0);  
           API_SysWriteValue(RAM_SHARING_ADR,ROOT_ORDER,--root_order); 
          }
           file_repaint_flag = 2;
           cur_item_amount = API_SysReadValue2B(RAM_CUR_PATH_ADR,root_order*2);
           if(root_order) // add return last layer icon
            cur_item_amount++;
           file_curr_sel_icon = (cur_item_amount-1)%PHOBRO_ITEM; 
           file_pre_sel_icon = 0;
           
           if((cur_item_amount%PHOBRO_ITEM)!=0 )
            page = (cur_item_amount/PHOBRO_ITEM);
           else
            page = (cur_item_amount/PHOBRO_ITEM)-1;

         if(API_PhotoGetThreadState() == TS_PLAY)
         {
          _photo_stop_thu(TASKID_PHOTOBROWSER);
         }
         else
         {
          API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_0_7,0);
          API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_8,0);
          API_OsSetCurrentTask(TASKID_PHOTOBROWSER);
         }
                    
        }
        // enter folder
        else if(file_curr_sel_item >=1 && file_curr_sel_item<=Folders)
        {
         API_FATEnterFolder(file_curr_sel_item);
         if(root_order<8) //only record 8 order path
          API_SysWriteValue2B(RAM_CUR_PATH_ADR,root_order*2,file_curr_sel_item);  
         API_SysWriteValue(RAM_SHARING_ADR,ROOT_ORDER,++root_order); 
         file_repaint_flag = 2;
         file_pre_sel_icon = file_curr_sel_icon;
         file_curr_sel_icon = 0;
         page = 0;
         
         if(API_PhotoGetThreadState() == TS_PLAY)
         {
          _photo_stop_thu(TASKID_PHOTOBROWSER);
         }
         else
         {
          API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_0_7,0);
          API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_8,0);
          API_OsSetCurrentTask(TASKID_PHOTOBROWSER);
         }
         
        }
        // play photo
        else if( file_curr_sel_item > Folders && file_curr_sel_item<=Folders+Files)
        {
         if(root_order<8) //only record 8 order path
          API_SysWriteValue2B(RAM_CUR_PATH_ADR,root_order*2,(file_curr_sel_item-Folders));
         for(i=0;i<8;i++)
          API_SysWriteValue2B(RAM_PHO_PATH_ADR,i*2,API_SysReadValue2B(RAM_CUR_PATH_ADR,i*2));
         API_SysWriteValue2B(RAM_SHARING_ADR,CUR_FILE_L,file_curr_sel_item-Folders); 
         file_repaint_flag = 2;
         file_pre_sel_icon = file_curr_sel_icon;
         file_curr_sel_icon = 0;
         page = 0;

         if(API_PhotoGetThreadState() == TS_PLAY)
         {
          _photo_stop_thu(TASKID_PHOTOSHOW);
         }
         else
         {
          API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_0_7,0);
          API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_8,0);
          API_OsSetCurrentTask(TASKID_PHOTOSHOW);
         }
        }
}

//***************************************************************************
// Func:        void _photo_update_sel_item(void)
// Input:       none
// Output:      none
//
// Description: update "file_curr_sel_item" by "page" and "file_curr_sel_icon"
//
//***************************************************************************
void _photo_update_sel_item(void)
{
 if(root_order)
  file_curr_sel_item = (page*PHOBRO_ITEM) + file_curr_sel_icon;
 else
  file_curr_sel_item = (page*PHOBRO_ITEM) + file_curr_sel_icon+1;
 if(file_curr_sel_item > Folders+Files)
 {
   #if DEBUG
    API_LcmSetStringLenth(35);
    API_LcmShowString("calculate file_curr_sel_item error",0,0);
   #endif
 }
}

//***************************************************************************
// Func:        _photo_stop_thu(uint8 next_task)
// Input:       next task
// Output:      none
//
// Description: stop photo thumb and set next task
//
//***************************************************************************
void _photo_stop_thu(uint8 task)
{
          API_PhotoAbort();
          next_task = task;
          API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_0_7,0);
          API_SysWriteValue(RAM_SHARING_ADR,PHOTO_THU_8,0);
          API_OsReleaseEvent(EVID_BT_32HZ);
}


⌨️ 快捷键说明

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