久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5855|回復: 0
收起左側

stm32單片機自制pda之theme.c源代碼

[復制鏈接]
ID:37685 發表于 2013-9-5 14:35 | 顯示全部樓層 |閱讀模式
完整代碼下載地址:http://www.zg4o1577.cn/f/29782212PDA.rar
#include <stm32f10x_lib.h>
#include "theme.h"
#include "ff.h"http://包含文件系統,更新主題用
#include "w25x16.h"http://包含Flash驅動,讀取主題用
#include "ILI9320.h"http://包含LCD驅動,顯示文本用
#include "ui.h"http://包含ui,顯示窗體用
#include "touch.h"http://包含觸摸屏,控制用
#include "delay.h"http://包含延時,觸摸屏連續讀坐標用
#include "app.h"http://包含軟件包,檢測SD卡用
#include "picdecoder.h"http://包含圖像解碼,更新圖標用
#include "string.h"http://更新圖標用
#include "readme.h"http://引用readme
////////////////////////////////////////////////
//地址說明
//對話框指示圖標:32×32
//主界面圖標:56×56
//文件管理圖標:16×16
////////////////////////////////////////////////
//此文件實現和主題有關的功能
//包括:
//更新圖標
//更新字庫
//待機畫面延時
//屏幕關閉延時
////////////////////////////////////////////////
u8 bootup_font_update=0;//開機強制更新字庫標志
#if ICO_TO_SD==0//圖標存放在flash時候需要判斷是否更新圖標
u8 bootup_ico_update=0;//開機強制更新圖標標志
#endif
//字庫地址
ico fon12;//font12地址:0-7
ico fon16;//font16地址:8-15
ico oem2uni;//oem2uni地址:16-23
ico uni2oem;//uni2oem地址:24-31
//主界面圖標地址
ico setup;//設置圖標地址:16-23
ico music;//音樂圖標地址:24-31
ico radio;//收音機圖標地址:32-39
ico drawing;//繪圖板圖標地址:40-47
ico notebook;//記事本圖標地址:48-55
ico source;//資源管理器圖標地址:56-63
ico others;//附加功能圖標地址:64-71
ico date;//日歷圖標地址:72-79
ico pic;//圖庫圖標地址:80-87
//文件管理器圖標地址
ico filejak;//文件夾圖標地址:88-95
ico shutdown;//關機微標圖片地址:96-103
ico sound;//音樂圖標地址:104-111
ico txt;//txt文檔圖標地址:112-119
ico picture;//圖片圖標地址:120-127
ico files;//文件圖標地址:128-135
ico drive;//驅動器圖標地址:136-143
//告示圖標地址
ico right;//對號圖標地址:144-151
ico wrong;//錯號圖標地址:152-159
ico sigh;//感嘆號圖標地址:160-167
ico question;//問號圖標地址:168-175
ico recycle;//垃圾桶圖標地址:176-183
//設置菜單下的圖標
ico tmd;//時間與日期圖標
ico font;//更新字庫圖標地址
ico icon;//更新圖標圖標地址
ico scrsaver;//屏保圖標地址
ico about;//關于圖標地址
ico sd;//SD卡圖標地址
ico scroff;//屏幕關閉圖標地址
ico target;//屏幕校準圖標地址
//開機畫面圖標
ico bootup;//開機畫面圖標地址
//調色板
ico colorpad;//調色板地址
//主題初始化,讀取Flash中的相應項目地址
void Theme_Init(void)
{
u32 temp[2];
u8 t[2];
//主界面圖標地址
//12字體
SPI_Flash_Read((u8*)temp,2,8);//從0開始讀出8字節地址數據
fon12.addr=temp[0];
fon12.size=temp[1];
//16字體
SPI_Flash_Read((u8*)temp,10,8);//從0開始讀出8字節地址數據
fon16.addr=temp[0];
fon16.size=temp[1];
//oem2uni地址
SPI_Flash_Read((u8*)temp,18,8);//從0開始讀出8字節地址數據
oem2uni.addr=temp[0];
oem2uni.size=temp[1];
//uni2oem地址
SPI_Flash_Read((u8*)temp,26,8);//從0開始讀出8字節地址數據
uni2oem.addr=temp[0];
uni2oem.size=temp[1];

#if ICO_TO_SD==0//圖標放flash的操作
//設置圖標
SPI_Flash_Read((u8*)temp,34,8);//從0開始讀出8字節地址數據
setup.addr=temp[0];
setup.size=temp[1];
//音樂圖標
SPI_Flash_Read((u8*)temp,42,8);//從0開始讀出8字節地址數據
music.addr=temp[0];
music.size=temp[1];
//收音機圖標
SPI_Flash_Read((u8*)temp,50,8);//從0開始讀出8字節地址數據
radio.addr=temp[0];
radio.size=temp[1];
//繪圖板圖標
SPI_Flash_Read((u8*)temp,58,8);//從0開始讀出8字節地址數據
drawing.addr=temp[0];
drawing.size=temp[1];
//記事本圖標
SPI_Flash_Read((u8*)temp,66,8);//從0開始讀出8字節地址數據
notebook.addr=temp[0];
notebook.size=temp[1];
//資源管理器圖標地址
SPI_Flash_Read((u8*)temp,74,8);//從0開始讀出8字節地址數據
source.addr=temp[0];
source.size=temp[1];
//附加功能圖標地址
SPI_Flash_Read((u8*)temp,82,8);//從0開始讀出8字節地址數據
others.addr=temp[0];
others.size=temp[1];
//日歷圖標地址
SPI_Flash_Read((u8*)temp,90,8);//從0開始讀出8字節地址數據
date.addr=temp[0];
date.size=temp[1];
//圖庫圖標地址
SPI_Flash_Read((u8*)temp,98,8);//從0開始讀出8字節地址數據
pic.addr=temp[0];
pic.size=temp[1];
//文件管理器圖標地址
//文件夾圖標地址
SPI_Flash_Read((u8*)temp,106,8);//從0開始讀出8字節地址數據
filejak.addr=temp[0];
filejak.size=temp[1];
//關機微標圖片地址
SPI_Flash_Read((u8*)temp,114,8);//從0開始讀出8字節地址數據
shutdown.addr=temp[0];
shutdown.size=temp[1];
//音樂圖標地址
SPI_Flash_Read((u8*)temp,122,8);//從0開始讀出8字節地址數據
sound.addr=temp[0];
sound.size=temp[1];
//txt文檔圖標地址
SPI_Flash_Read((u8*)temp,130,8);//從0開始讀出8字節地址數據
txt.addr=temp[0];
txt.size=temp[1];
//圖片圖標地址
SPI_Flash_Read((u8*)temp,138,8);//從0開始讀出8字節地址數據
picture.addr=temp[0];
picture.size=temp[1];
//文件圖標地址
SPI_Flash_Read((u8*)temp,146,8);//從0開始讀出8字節地址數據
files.addr=temp[0];
files.size=temp[1];
//驅動器圖標地址
SPI_Flash_Read((u8*)temp,154,8);//從0開始讀出8字節地址數據
drive.addr=temp[0];
drive.size=temp[1];

//告示圖標地址
//對號圖標地址
SPI_Flash_Read((u8*)temp,162,8);//從0開始讀出8字節地址數據
right.addr=temp[0];
right.size=temp[1];
//錯號圖標地址
SPI_Flash_Read((u8*)temp,170,8);//從0開始讀出8字節地址數據
wrong.addr=temp[0];
wrong.size=temp[1];
//感嘆號圖標地址
SPI_Flash_Read((u8*)temp,178,8);//從0開始讀出8字節地址數據
sigh.addr=temp[0];
sigh.size=temp[1];
//問號圖標地址
SPI_Flash_Read((u8*)temp,186,8);//從0開始讀出8字節地址數據
question.addr=temp[0];
question.size=temp[1];
//垃圾桶圖標地址
SPI_Flash_Read((u8*)temp,194,8);//從0開始讀出8字節地址數據
recycle.addr=temp[0];
recycle.size=temp[1];
//設置功能下圖標地址
//時間與日期圖標地址
SPI_Flash_Read((u8*)temp,202,8);//從0開始讀出8字節地址數據
tmd.addr=temp[0];
tmd.size=temp[1];
//更新字庫圖標地址
SPI_Flash_Read((u8*)temp,210,8);//從0開始讀出8字節地址數據
font.addr=temp[0];
font.size=temp[1];
//更新圖標圖標地址
SPI_Flash_Read((u8*)temp,218,8);//從0開始讀出8字節地址數據
icon.addr=temp[0];
icon.size=temp[1];
//屏保圖標地址
SPI_Flash_Read((u8*)temp,226,8);//從0開始讀出8字節地址數據
scrsaver.addr=temp[0];
scrsaver.size=temp[1];
//關于圖標地址
SPI_Flash_Read((u8*)temp,234,8);//從0開始讀出8字節地址數據
about.addr=temp[0];
about.size=temp[1];
//sd卡圖標地址
SPI_Flash_Read((u8*)temp,242,8);//從0開始讀出8字節地址數據
sd.addr=temp[0];
sd.size=temp[1];
//屏幕關閉延時圖標地址
SPI_Flash_Read((u8*)temp,250,8);//從0開始讀出8字節地址數據
scroff.addr=temp[0];
scroff.size=temp[1];
//屏幕校準圖標地址
SPI_Flash_Read((u8*)temp,258,8);//從0開始讀出8字節地址數據
target.addr=temp[0];
target.size=temp[1];
//開機畫面圖標地址
SPI_Flash_Read((u8*)temp,266,8);//從0開始讀出8字節地址數據
bootup.addr=temp[0];
bootup.size=temp[1];
//調色板地址
SPI_Flash_Read((u8*)temp,274,8);//從0開始讀出8字節地址數據
colorpad.addr=temp[0];
colorpad.size=temp[1];
#else
setup.addr=1;
music.addr=2;
radio.addr=3;
drawing.addr=4;
notebook.addr=5;
source.addr=6;
others.addr=7;
date.addr=8;
pic.addr=9;
filejak.addr=10;
shutdown.addr=11;
sound.addr=12;
txt.addr=13;
picture.addr=14;
files.addr=15;
drive.addr=16;
right.addr=17;
wrong.addr=18;
sigh.addr=19;
question.addr=20;
recycle.addr=21;
tmd.addr=22;
font.addr=23;
icon.addr=24;
scrsaver.addr=25;
about.addr=26;
sd.addr=27;
scroff.addr=28;
target.addr=29;
bootup.addr=30;
colorpad.addr=31;
#endif
//檢查字庫圖標是否存在
SPI_Flash_Read(t,0,2);//讀取字庫,圖標存在標記
if(t[0]!=0xaa)//字庫不存在
{
  bootup_font_update=1;
  clear(0,0,240,320,0);
  show_string(0,0,240,"Updating system Font...",16,color(255,0,0));
  if(Font_Update())//顯示藍屏錯誤界面
  {
   show_string(0,16,240,"Information:",12,color(255,255,255));
   show_string(0,32,240,"System Font lost!",12,color(255,255,255));
   show_string(0,48,240,"Direction:",12,color(255,255,255));
   show_string(0,64,240,"0:/font/fon12.dzk",12,color(255,255,255));
   show_string(0,80,240,"0:/font/fon16.dzk",12,color(255,255,255));
   show_string(0,96,240,"0:/font/uni2oem.bin",12,color(255,255,255));
   show_string(0,112,240,"0:/font/oem2uni.bin",12,color(255,255,255));
   while(1);//藍屏死機
  }
}
#if ICO_TO_SD==0
if(t[1]!=0xbb)//圖標不存在
{
  bootup_ico_update=1;
  if(Ico_Update())//顯示藍屏錯誤界面
  {
   clear(0,0,240,320,color(0,0,255));
   show_string(0,0,240,"System Error!!",12,color(255,255,255));
   show_string(0,16,240,"Information:",12,color(255,255,255));
   show_string(0,32,240,"System Icon lost!",12,color(255,255,255));
   show_string(0,48,240,"Direction:",12,color(255,255,255));
   show_string(0,64,240,"\"0:/ico\"[Include about 30 icons.]",12,color(255,255,255));
   while(1);//藍屏死機
  }
}
#endif
}
extern u8 SPI_FLASH_BUF[4096];
//生成readme文件
void Creat_Readme(void)
{
FIL readme;
UINT bytewrite;
u32 count=0;
u8 *buf=SPI_FLASH_BUF;
if(f_open(&readme,"0:/readme.txt",FA_OPEN_EXISTING)==FR_NO_FILE)
{
  f_open(&readme,"0:/readme.txt",FA_OPEN_ALWAYS|FA_WRITE);
  while(read_me[count]!='\0')//復制readme
  {
   if((read_me[count]!='[')&&(read_me[count]!=']'))buf[count]=read_me[count];
   else//寫入回車符
   {
    if(read_me[count]=='[')buf[count]=0x0d;
    if(read_me[count]==']')buf[count]=0x0a;
   }
   count++;
  }
  f_write(&readme,SPI_FLASH_BUF,count,&bytewrite);
  f_close(&readme);
}
}
//字庫更新
extern u8 jpg_buffer[1024];//引用圖片解碼緩存
const u8 font_warming[]=
{"此操作將更新系統字庫,"\
"請務必確認字庫來源,"\
"未知來源的字庫可能會導致文本顯示大面積亂碼,是否繼續?"\
"如果繼續,請把相關文件命名為指定名稱后存放在SD卡根目錄的FONT文件夾里,"\
"并點擊'是(Y)',取消請點擊'否(N)'。詳情參閱readme.txt。"\
};
u8 Font_Update(void)
{
u8 *buffer=jpg_buffer;//字庫更新緩存,大小為2扇區,引用圖片解碼緩存
u32 temp[2];//用以緩存文件地址和大小
u8 t[1];
u32 i=0,offset=2048;//字節數緩存,offset為Flash數據起始地址
u8 sta=0;//操作緩存
FIL file;//文件讀取緩存
UINT b_left;//文件剩余字節數
u16 byte_to_read=1024;//需要讀取的文件字節數
//界面提示
//先還原坐標,避免上一次數據的影響
Pen_Point.x0=0;
Pen_Point.y0=0;
if(Reflash_SD())
{
  if(bootup_font_update)
  {
   clear(0,0,240,320,0);
   show_string(0,0,240,"Updating system font...",16,color(255,0,0));
   goto BOOTUP_RENEW;
  }
  Windows(10,80,230,240,"注意——更新字庫",12);//顯示窗體,標題欄高18
  show_string(23,106,200,font_warming,12,color(0,0,0));//文本框高度28,文本框長180
  Button(20,208,68,232,UNPRESS,"是(Y)",30,12);//顯示是按鈕
  Button(172,208,220,232,UNPRESS,"否(N)",30,12);//顯示否按鈕
//  show_ico(15,107,59,151,question.addr,question.size);//顯示疑問圖標(這個注釋掉,避免在圖標還沒更新的情況下顯示圖標導致死機)
  while(sta==0)
  {
   if(Pen_Point.Key_Sta==Key_Down)
   {
    Pen_Int_Set(0);//關閉中斷
    Pen_Point.Key_Sta=Key_Up;
    do//連續讀取數據
    {
     Convert_Pos();
     if(Is_In_Area(20,208,68,232))//((Pen_Point.x0>20)&&(Pen_Point.x0<68))&&((Pen_Point.y0>208)&&(Pen_Point.y0<232)))
     sta=1;
     else if(Is_In_Area(172,208,220,232))//((Pen_Point.x0>172)&&(Pen_Point.x0<220))&&((Pen_Point.y0>208)&&(Pen_Point.y0<232)))
     sta=2;
     else sta=0;
     if(sta==1)Button(20,208,68,232,PRESS,"是(Y)",30,12);//顯示是按鈕
     else if(sta==2)Button(172,208,220,232,PRESS,"否(N)",30,12);//顯示否按鈕
     else if(sta==0)
     {
      Button(20,208,68,232,UNPRESS,"是(Y)",30,12);//顯示是按鈕
      Button(172,208,220,232,UNPRESS,"否(N)",30,12);//顯示否按鈕
     }
     Delay_us(50);
    }while(T_PEN==0);
    Pen_Int_Set(1);//開啟中斷
   }
  }
  if(sta==2)goto CANCEL;
  if(sta==1)
  {
BOOTUP_RENEW:
   //更新12字體
   //更新過程
   Windows(10,80,230,240,"字庫更新中……",12);//顯示窗體,標題欄高18
   Button(98,208,146,232,INVALID,"取消",24,12);//顯示取消按鈕,居中
   //提示字體(居中顯示)
   show_string(70,135,240,"更新fon12.dzk……",12,color(0,0,0));
   if(f_open(&file,"0:/font/fon12.dzk",FA_READ)!=FR_OK)
   {
    if(bootup_font_update)return 1;
    else goto NOFILE;
   }
   while(1)
   {
    f_read(&file,buffer,byte_to_read,&b_left);//從SD卡中讀取
    SPI_Flash_Write(buffer,i+offset,byte_to_read);//寫入Flash
    //進度條
    Progress_Bar(20,155,200,i,file.fsize,1);//進度條長度200
    if((b_left<byte_to_read)&&(b_left!=0))byte_to_read=b_left;
    else if(b_left==0)break;//讀取完畢,退出
    i+=1024;
   }
   fon12.addr=2048;//記錄字庫地址
   temp[0]=fon12.addr;
   temp[1]=file.fsize;
   offset=file.fsize+fon12.addr;//獲取偏移值
   i=0;
   byte_to_read=1024;//還原要讀字節數
   f_close(&file);//關閉fon12.dzk
   SPI_Flash_Write((u8*)temp,2,8);//寫入地址數據
   
   //更新16字體
   //更新過程
   Windows(10,80,230,240,"字庫更新中……",12);//顯示窗體,標題欄高18
   Button(98,208,146,232,INVALID,"取消",24,12);//顯示取消按鈕,居中
   //提示字體(居中顯示)
   show_string(70,135,240,"更新fon16.dzk……",12,color(0,0,0));
   if(f_open(&file,"0:/font/fon16.dzk",FA_READ)!=FR_OK)
   {
    if(bootup_font_update)return 1;
    else goto NOFILE;
   }
   while(1)
   {
    f_read(&file,buffer,byte_to_read,&b_left);//從SD卡中讀取
    SPI_Flash_Write(buffer,i+offset,byte_to_read);//寫入Flash
    //進度條
    Progress_Bar(20,155,200,i,file.fsize,1);//進度條長度200
    if((b_left<byte_to_read)&&(b_left!=0))byte_to_read=b_left;
    else if(b_left==0)break;//讀取完畢,退出
    i+=1024;
   }
   fon16.addr=offset;
   temp[0]=fon16.addr;
   temp[1]=file.fsize;
   offset=file.fsize+fon16.addr;//重新獲得下一個文件的偏移地址
   i=0;
   byte_to_read=1024;//還原要讀字節數
   f_close(&file);
   SPI_Flash_Write((u8*)temp,10,8);//寫入fon16地址信息
   //更新oem2uni
   //更新過程
   Windows(10,80,230,240,"字庫更新中……",12);//顯示窗體,標題欄高18
   Button(98,208,146,232,INVALID,"取消",24,12);//顯示取消按鈕,居中
   //提示字體(居中顯示)
   show_string(70,135,240,"更新oem2uni.bin……",12,color(0,0,0));
   if(f_open(&file,"0:/font/oem2uni.bin",FA_READ)!=FR_OK)
   {
    if(bootup_font_update)return 1;
    else goto NOFILE;
   }
   while(1)
   {
    f_read(&file,buffer,byte_to_read,&b_left);//從SD卡中讀取
    SPI_Flash_Write(buffer,i+offset,byte_to_read);//寫入Flash
    //進度條
    Progress_Bar(20,155,200,i,file.fsize,1);//進度條長度200
    if((b_left<byte_to_read)&&(b_left!=0))byte_to_read=b_left;
    else if(b_left==0)break;//讀取完畢,退出
    i+=1024;
   }
   oem2uni.addr=offset;
   temp[0]=oem2uni.addr;
   temp[1]=file.fsize;
   offset=file.fsize+oem2uni.addr;//重新獲得下一個文件的偏移地址
   i=0;
   byte_to_read=1024;//還原要讀字節數
   f_close(&file);
   SPI_Flash_Write((u8*)temp,18,8);//寫入oem2uni地址信息

   //更新uni2oem
   //更新過程
   Windows(10,80,230,240,"字庫更新中……",12);//顯示窗體,標題欄高18
   Button(98,208,146,232,INVALID,"取消",24,12);//顯示取消按鈕,居中
   //提示字體(居中顯示)
   show_string(70,135,240,"更新uni2oem.bin……",12,color(0,0,0));
   if(f_open(&file,"0:/font/uni2oem.bin",FA_READ)!=FR_OK)
   {
    if(bootup_font_update)return 1;
    else goto NOFILE;
   }
   while(1)
   {
    f_read(&file,buffer,byte_to_read,&b_left);//從SD卡中讀取
    SPI_Flash_Write(buffer,i+offset,byte_to_read);//寫入Flash
    //進度條
    Progress_Bar(20,155,200,i,file.fsize,1);//進度條長度200
    if((b_left<byte_to_read)&&(b_left!=0))byte_to_read=b_left;
    else if(b_left==0)break;//讀取完畢,退出
    i+=1024;
   }
   uni2oem.addr=offset;
   temp[0]=uni2oem.addr;
   temp[1]=file.fsize;
   offset=file.fsize+uni2oem.addr;//重新獲得下一個文件的偏移地址
   i=0;
   byte_to_read=1024;//還原要讀字節數
   f_close(&file);
   SPI_Flash_Write((u8*)temp,26,8);//寫入uni2oem地址信息
   //更新完成,寫入字庫存在標志
   t[0]=0xaa;
   SPI_Flash_Write(t,0,1);//寫入0xaa為字庫存在標志
   bootup_font_update=0;//還原開機更新標志
   sta=0;
   goto END;//退出
  }
NOFILE:
  Windows(10,80,230,240,"注意——更新字庫失敗",12);//顯示窗體,標題欄高18
  Button(98,208,146,232,UNPRESS,"確定",24,12);//顯示取消按鈕,居中
  //提示字體(居中顯示)
  show_string(41,153,200,"未找到相應文件,更新失敗!",12,color(0,0,0));//文本框高度28,文本框長180
//  show_ico(15,137,59,181,wrong.addr,wrong.size);//顯示錯誤圖標(注釋掉,避免圖標未更新之前顯示圖標導致死機)
  goto OUT;
END:
  Windows(10,80,230,240,"注意——更新字庫成功",12);//顯示窗體,標題欄高18
  Button(98,208,146,232,UNPRESS,"確定",24,12);//顯示取消按鈕,居中
  //提示字體(居中顯示)
  show_string(89,153,200,"更新完成!",12,color(0,0,0));//文本框高度28,文本框長180
//  show_ico(15,137,59,181,right.addr,right.size);//顯示正確圖標(注釋掉,避免圖標未更新之前顯示圖標導致死機)
  goto OUT;
CANCEL:
  Windows(10,80,230,240,"注意——更新字庫失敗",12);//顯示窗體,標題欄高18
  Button(98,208,146,232,UNPRESS,"確定",24,12);//顯示取消按鈕,居中
  //提示字體(居中顯示)
  show_string(71,153,200,"操作被用戶取消!",12,color(0,0,0));//文本框高度28,文本框長180
//  show_ico(15,137,59,181,sigh.addr,sigh.size);//顯示感嘆號圖標(注釋掉,避免圖標未更新之前顯示圖標導致死機)
  goto OUT;
OUT:
  while(1)
  {
   if(Pen_Point.Key_Sta==Key_Down)
   {
    Pen_Int_Set(0);//關閉中斷
    Pen_Point.Key_Sta=Key_Up;
    do//連續讀取數據
    {
     Convert_Pos();
     if(Is_In_Area(98,208,146,232))//((Pen_Point.x0>98)&&(Pen_Point.x0<146))&&((Pen_Point.y0>208)&&(Pen_Point.y0<232)))
     {
      sta=1;
      Button(98,208,146,232,PRESS,"確定",24,12);//顯示取消按鈕,居中
     }
     else
     {
      sta=0;
      Button(98,208,146,232,UNPRESS,"確定",24,12);//顯示取消按鈕,居中
     }
     Delay_us(50);
    }while(T_PEN==0);
    Pen_Int_Set(1);//開啟中斷
    if(sta==1)break;
   }
  }
}
return 0;
}
#if ICO_TO_SD==0
//圖片更新程序
//對話框指示圖標:32×32
//主界面圖標:56×56
//文件管理圖標:16×16
const u8 ico_warming[]=
{
"注意,此操作將會替換系統內置圖標,"\
"一般用于自定義用戶圖標,"\
"請用戶在更新前將圖標按照指定文件名存放在SD卡根目錄下的ico文件夾里,"\
"點擊'是(Y)'更新,點擊'否(N)'退出,詳情請查看SD卡根目錄下的readme.txt文件。"\
};
const char fn_date[]={"DATE.BMP"};
const char fn_drawing[]={"DRAWING.BMP"};
const char fn_drive[]={"DRIVE.BMP"};
const char fn_filejak[]={"FILEJAK.BMP"};
const char fn_files[]={"FILES.BMP"};
const char fn_music[]={"MUSIC.BMP"};
const char fn_sound[]={"SOUND.BMP"};
const char fn_notebook[]={"NOTEBOOK.BMP"};
const char fn_txt[]={"TXT.BMP"};
const char fn_others[]={"OTHERS.BMP"};
const char fn_pic[]={"PIC.BMP"};
const char fn_picture[]={"PICTURE.BMP"};
const char fn_question[]={"QUESTION.BMP"};
const char fn_radio[]={"RADIO.BMP"};
const char fn_recycle[]={"RECYCLE.BMP"};
const char fn_source[]={"SOURCE.BMP"};
const char fn_right[]={"RIGHT.BMP"};
const char fn_setup[]={"SETUP.BMP"};
const char fn_shutdown[]={"SHUTDOWN.BMP"};
const char fn_sigh[]={"SIGH.BMP"};
const char fn_wrong[]={"WRONG.BMP"};
const char fn_tmd[]={"TMD.BMP"};
const char fn_font[]={"FONT.BMP"};
const char fn_ico[]={"ICO.BMP"};
const char fn_scrsaver[]={"SCRSAVER.BMP"};
const char fn_about[]={"ABOUT.BMP"};
const char fn_sd[]={"SD.BMP"};
const char fn_scroff[]={"SCROFF.BMP"};
const char fn_target[]={"TARGET.BMP"};
const char fn_bootup[]={"BOOTUP.BMP"};
const char fn_colorpad[]={"COLORPAD.BMP"};
const TCHAR ico_dir[]={"0:/ICO"};
const TCHAR _dir_[]={"/"};
u8 Ico_Update(void)
{
u8 *buffer=jpg_buffer;//圖像讀回緩存,大小為2扇區,引用圖片解碼緩存
u8 key=0;
u32 temp[2];//用來存放咚咚的起始地址和大小
u8 t[1];
u32 total_size=0;//需要更新的圖標總大小
u32 progress_size=0;//總進度大小
u32 progress_size_index=0;//當前進度大小
//文件系統所需
FILINFO icoinfo;
FIL ico;
DIR dir;//搜索文件所用
UINT byteleft;
u32 byteread=1024;
u32 offset;
//更新圖標所用,用來記錄flash地址以及更新到的圖標號數
u8 ico_count=0;
TCHAR direction[20];
u32 addr;
//先還原坐標,避免上一次數據的影響
Pen_Point.x0=0;
Pen_Point.y0=0;
if(Reflash_SD())
{
  if(bootup_ico_update)
  {
   clear(0,0,240,320,0);
   show_string(0,0,240,"Updating system icons...",16,color(255,0,0));
   goto REFLASH_ICO;
  }
  Windows(10,79,229,241,"注意——更新圖標",12);//顯示窗體
  show_string(23,105,200,ico_warming,12,color(0,0,0));//文本框高度28,文本框長180
  Button(19,209,67,233,UNPRESS,"是(Y)",30,12);//顯示是按鈕
  Button(171,209,219,233,UNPRESS,"否(N)",30,12);//顯示否按鈕
//  show_ico(10,107,64,151,question.addr,question.size);//顯示疑問圖標(這個注釋掉,避免圖標未更新之前顯示圖標導致死機)
  while(key==0)
  {
   if(Pen_Point.Key_Sta==Key_Down)
   {
    Pen_Int_Set(0);//關閉中斷
    Pen_Point.Key_Sta=Key_Up;
    do//連續讀取數據
    {
     Convert_Pos();
     if(Is_In_Area(19,209,67,233))key=1;//((Pen_Point.x0>19)&&(Pen_Point.x0<67))&&((Pen_Point.y0>209)&&(Pen_Point.y0<233)))key=1;//是
     else if(Is_In_Area(171,209,219,233))key=2;//((Pen_Point.x0>171)&&(Pen_Point.x0<219))&&((Pen_Point.y0>209)&&(Pen_Point.y0<233)))key=2;//否
     else key=0;
     if(key==1)Button(19,209,67,233,PRESS,"是(Y)",30,12);//顯示是按鈕
     else Button(19,209,67,233,UNPRESS,"是(Y)",30,12);//顯示是按鈕
     if(key==2)Button(171,209,219,233,PRESS,"否(N)",30,12);//顯示否按鈕
     else Button(171,209,219,233,UNPRESS,"否(N)",30,12);//顯示否按鈕
     Delay_us(50);
    }while(T_PEN==0);
    Pen_Int_Set(1);//開啟中斷
   }
  }
  if(key==1)
  {
   key=0;
   goto REFLASH_ICO;
  }
  if(key==2)
  {
   key=0;
   goto CANCEL;
  }
REFLASH_ICO:
  Windows(10,79,229,241,"更新圖標中……",12);//顯示窗體
  Button(95,209,143,233,INVALID,"取消",24,12);//顯示取消按鈕
  show_string(19,157,199,"總進度:",12,color(0,0,0));
  show_string(19,127,199,"當前進度:",12,color(0,0,0));
  show_string(19,115,199,"復制:",12,color(0,0,0));
  //計算需要更新的圖標的總大小
  if(f_opendir(&dir,ico_dir)==FR_OK)
  {
   while(1)
   {
    f_readdir(&dir,&icoinfo);
    if(strcmp(icoinfo.fname,fn_date)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_drawing)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_drive)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_filejak)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_files)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_music)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_sound)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_notebook)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_txt)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_others)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_pic)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_picture)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_question)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_radio)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_recycle)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_source)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_right)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_setup)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_shutdown)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_sigh)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_wrong)==0)total_size+=icoinfo.fsize;
    //設置菜單下圖標
    else if(strcmp(icoinfo.fname,fn_tmd)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_font)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_ico)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_scrsaver)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_about)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_sd)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_scroff)==0)total_size+=icoinfo.fsize;
    else if(strcmp(icoinfo.fname,fn_target)==0)total_size+=icoinfo.fsize;
    //開機畫面圖標
    else if(strcmp(icoinfo.fname,fn_bootup)==0)total_size+=icoinfo.fsize;
    //調色板
    else if(strcmp(icoinfo.fname,fn_colorpad)==0)total_size+=icoinfo.fsize;
    if(icoinfo.fname[0]==NULL)break;
   }
  }
  else
  {
   if(bootup_ico_update)return 1;
   else goto FAIL;
  }
  while(ico_count<31)
  {
   strcpy((char*)direction,(char*)ico_dir);
   strcat((char*)direction,(char*)_dir_);
   switch(ico_count)
   {
    case 0:strcat((char*)direction,fn_setup);break;
    case 1:strcat((char*)direction,fn_music);break;
    case 2:strcat((char*)direction,fn_radio);break;
    case 3:strcat((char*)direction,fn_drawing);break;
    case 4:strcat((char*)direction,fn_notebook);break;
    case 5:strcat((char*)direction,fn_source);break;
    case 6:strcat((char*)direction,fn_others);break;
    case 7:strcat((char*)direction,fn_date);break;
    case 8:strcat((char*)direction,fn_pic);break;
    case 9:strcat((char*)direction,fn_filejak);break;
    case 10:strcat((char*)direction,fn_shutdown);break;
    case 11:strcat((char*)direction,fn_sound);break;
    case 12:strcat((char*)direction,fn_txt);break;
    case 13:strcat((char*)direction,fn_picture);break;
    case 14:strcat((char*)direction,fn_files);break;
    case 15:strcat((char*)direction,fn_drive);break;
    case 16:strcat((char*)direction,fn_right);break;
    case 17:strcat((char*)direction,fn_wrong);break;
    case 18:strcat((char*)direction,fn_sigh);break;
    case 19:strcat((char*)direction,fn_question);break;
    case 20:strcat((char*)direction,fn_recycle);break;
    //設置菜單下的圖標
    case 21:strcat((char*)direction,fn_tmd);break;
    case 22:strcat((char*)direction,fn_font);break;
    case 23:strcat((char*)direction,fn_ico);break;
    case 24:strcat((char*)direction,fn_scrsaver);break;
    case 25:strcat((char*)direction,fn_about);break;
    case 26:strcat((char*)direction,fn_sd);break;
    case 27:strcat((char*)direction,fn_scroff);break;
    case 28:strcat((char*)direction,fn_target);break;
    //開機畫面圖標
    case 29:strcat((char*)direction,fn_bootup);break;
    case 30:strcat((char*)direction,fn_colorpad);break;
   }
   if(f_stat(direction,&icoinfo)!=FR_OK)
   {
    if(bootup_ico_update)return 1;
    else goto FAIL;//讀取文件狀態,文件不存在則失敗
   }
   if(f_open(&ico,direction,FA_READ)!=FR_OK)
   {
    if(bootup_ico_update)return 1;
    else goto FAIL;//打開文件,如果打開不到,則失敗
   }
   f_lseek(&ico,0);
   clear(55,115,200,127,color(0xd4,0xd0,0xc8));//清空提示字符串位置
   show_string(55,115,199,(u8*)direction,12,color(0,0,0));//顯示提示字符串
   SPI_Flash_Read((u8*)temp,(26+(ico_count*8)),8);//讀出上一個元素地址
   if(ico_count==0)addr=temp[0]+temp[1]+500000;//制作要寫入元素的首地址,第一個圖標和字庫錯開50000個地址,防止更新字庫時候錯殺圖標
   else addr=temp[0]+temp[1];
   temp[0]=addr;//記錄要寫入元素首地址
   temp[1]=icoinfo.fsize;//記錄要寫入元素大小
   offset=0;//清空偏移值
   while(1)//開始復制信息
   {
    f_read(&ico,buffer,byteread,&byteleft);
    SPI_Flash_Write(buffer,addr+offset,byteread);
    offset+=byteread;
    Progress_Bar(19,141,200,progress_size_index,icoinfo.fsize,1);
    Progress_Bar(19,171,200,progress_size,total_size,1);
    if((byteread>byteleft)&&(byteleft!=0))byteread=byteleft;
    else if(byteleft==0)
    {
     byteread=1024;//還原要讀取的字節數
     progress_size_index=0;//還原當前進度計數
     SPI_Flash_Write((u8*)temp,(34+(ico_count*8)),8);//記錄地址標志
     f_close(&ico);//關閉文件s
     break;//讀取完畢,退出
    }
    progress_size_index+=byteread;
    progress_size+=byteread;
   }
   ico_count++;
  }
  //圖標更新完畢,記錄圖標存在標志
  t[0]=0xbb;
  SPI_Flash_Write(t,1,1);
  bootup_ico_update=0;//還原強制更新標志
  Theme_Init();//復制完畢,初始化一次主題
  Windows(10,79,229,241,"注意——圖標更新成功",12);//顯示窗體
  Button(95,209,143,233,UNPRESS,"確定",24,12);//顯示取消按鈕
  show_string(74,153,158,"更新完成!",12,color(0,0,0));//文本框高度28,文本框長180
  show_ico(20,137,64,181,right.addr,right.size);
  goto OUT;
FAIL:
  Windows(10,79,229,241,"注意——圖標更新失敗",12);//顯示窗體
  Button(95,209,143,233,UNPRESS,"確定",24,12);//顯示取消按鈕
  show_string(47,153,200,"主要文件丟失,更新失敗!",12,color(0,0,0));//文本框高度28,文本框長180
//  show_ico(20,137,64,181,wrong.addr,wrong.size);//(注釋掉,避免圖標未更新之前顯示圖標導致死機)
  goto OUT;
CANCEL:
  Windows(10,79,229,241,"注意——圖標更新失敗",12);//顯示窗體
  Button(95,209,143,233,UNPRESS,"確定",24,12);//顯示取消按鈕
  show_string(77,153,200,"用戶取消操作!",12,color(0,0,0));//文本框高度28,文本框長180
//  show_ico(20,137,64,181,sigh.addr,sigh.size);//(注釋掉,避免圖標未更新之前顯示圖標導致死機)
  goto OUT;
OUT:
  while(key==0)
  {
   if(Pen_Point.Key_Sta==Key_Down)
   {
    Pen_Int_Set(0);//關閉中斷
    Pen_Point.Key_Sta=Key_Up;
    do//連續讀取數據
    {
     Convert_Pos();
     if(Is_In_Area(95,209,143,233))key=1;//((Pen_Point.x0>95)&&(Pen_Point.x0<143))&&((Pen_Point.y0>209)&&(Pen_Point.y0<233)))key=1;
     else key=0;
     if(key)Button(95,209,143,233,PRESS,"確定",24,12);//顯示取消按鈕
     else Button(95,209,143,233,UNPRESS,"確定",24,12);//顯示取消按鈕
     Delay_us(50);
    }while(T_PEN==0);
    Pen_Int_Set(1);//開啟中斷
   }
  }
}
return 0;
}
#else
u8 Ico_Update(void)
{
u8 key=0;
Windows(10,79,229,241,"更新圖標",12);//顯示窗體
Button(95,209,143,233,UNPRESS,"確定",24,12);//顯示取消按鈕
show_string(74,153,158,"圖標存放位置被設置為SD卡,無需更新!",12,color(0,0,0));//文本框高度28,文本框長180
show_ico(20,137,64,181,sigh.addr,sigh.size);
while(key==0)
{
  if(Pen_Point.Key_Sta==Key_Down)
  {
   Pen_Int_Set(0);//關閉中斷
   Pen_Point.Key_Sta=Key_Up;
   do//連續讀取數據
   {
    Convert_Pos();
    if(Is_In_Area(95,209,143,233))key=1;//((Pen_Point.x0>95)&&(Pen_Point.x0<143))&&((Pen_Point.y0>209)&&(Pen_Point.y0<233)))key=1;
    else key=0;
    if(key)Button(95,209,143,233,PRESS,"確定",24,12);//顯示取消按鈕
    else Button(95,209,143,233,UNPRESS,"確定",24,12);//顯示取消按鈕
    Delay_us(50);
   }while(T_PEN==0);
   Pen_Int_Set(1);//開啟中斷
  }
}
return 0;
}
#endif
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产精品久久久久久 | 久久伊人一区二区 | 国产精品久久久久久久久大全 | 涩涩视频网站在线观看 | 久久九精品 | 欧美日韩在线视频一区 | 天堂网中文 | 亚洲乱码国产乱码精品精98午夜 | 男女羞羞视频免费 | 免费在线h视频 | www.天天操.com| 成人在线免费观看 | 国产精久久久久久久 | www.夜夜骑| 日韩精品免费一区 | 国产91av视频在线观看 | 婷婷综合网| 狠狠操狠狠操 | 久久99精品久久久久久 | 久久黄色网 | 国产精品亚洲一区二区三区在线 | 亚洲国产精品久久久久秋霞不卡 | 欧美aaa级 | 国产成人免费视频网站视频社区 | 精品久久国产老人久久综合 | 九九热九九 | 免费性视频 | 日韩一区二区三区精品 | 欧美国产日韩一区二区三区 | 一级毛片,一级毛片 | 日韩精品成人在线 | 国产精品精品视频一区二区三区 | 国产精品美女久久久av超清 | 久久人人网 | 日韩中文字幕在线播放 | 欧美一区二区三区四区视频 | 国产精品久久久久久久三级 | 亚洲国产视频一区二区 | 免费的av网站 | 国产成人免费 | 一呦二呦三呦国产精品 |