完整代碼下載地址:http://www.zg4o1577.cn/f/29782212PDA.rar
#include <stm32f10x_lib.h>
#include "theme.h"
#include "ff.h"http://包含文件系統(tǒng),更新主題用
#include "w25x16.h"http://包含F(xiàn)lash驅(qū)動,讀取主題用
#include "ILI9320.h"http://包含LCD驅(qū)動,顯示文本用
#include "ui.h"http://包含ui,顯示窗體用
#include "touch.h"http://包含觸摸屏,控制用
#include "delay.h"http://包含延時(shí),觸摸屏連續(xù)讀坐標(biāo)用
#include "app.h"http://包含軟件包,檢測SD卡用
#include "picdecoder.h"http://包含圖像解碼,更新圖標(biāo)用
#include "string.h"http://更新圖標(biāo)用
#include "readme.h"http://引用readme
////////////////////////////////////////////////
//地址說明
//對話框指示圖標(biāo):32×32
//主界面圖標(biāo):56×56
//文件管理圖標(biāo):16×16
////////////////////////////////////////////////
//此文件實(shí)現(xiàn)和主題有關(guān)的功能
//包括:
//更新圖標(biāo)
//更新字庫
//待機(jī)畫面延時(shí)
//屏幕關(guān)閉延時(shí)
////////////////////////////////////////////////
u8 bootup_font_update=0;//開機(jī)強(qiáng)制更新字庫標(biāo)志
#if ICO_TO_SD==0//圖標(biāo)存放在flash時(shí)候需要判斷是否更新圖標(biāo)
u8 bootup_ico_update=0;//開機(jī)強(qiáng)制更新圖標(biāo)標(biāo)志
#endif
//字庫地址
ico fon12;//font12地址:0-7
ico fon16;//font16地址:8-15
ico oem2uni;//oem2uni地址:16-23
ico uni2oem;//uni2oem地址:24-31
//主界面圖標(biāo)地址
ico setup;//設(shè)置圖標(biāo)地址:16-23
ico music;//音樂圖標(biāo)地址:24-31
ico radio;//收音機(jī)圖標(biāo)地址:32-39
ico drawing;//繪圖板圖標(biāo)地址:40-47
ico notebook;//記事本圖標(biāo)地址:48-55
ico source;//資源管理器圖標(biāo)地址:56-63
ico others;//附加功能圖標(biāo)地址:64-71
ico date;//日歷圖標(biāo)地址:72-79
ico pic;//圖庫圖標(biāo)地址:80-87
//文件管理器圖標(biāo)地址
ico filejak;//文件夾圖標(biāo)地址:88-95
ico shutdown;//關(guān)機(jī)微標(biāo)圖片地址:96-103
ico sound;//音樂圖標(biāo)地址:104-111
ico txt;//txt文檔圖標(biāo)地址:112-119
ico picture;//圖片圖標(biāo)地址:120-127
ico files;//文件圖標(biāo)地址:128-135
ico drive;//驅(qū)動器圖標(biāo)地址:136-143
//告示圖標(biāo)地址
ico right;//對號圖標(biāo)地址:144-151
ico wrong;//錯號圖標(biāo)地址:152-159
ico sigh;//感嘆號圖標(biāo)地址:160-167
ico question;//問號圖標(biāo)地址:168-175
ico recycle;//垃圾桶圖標(biāo)地址:176-183
//設(shè)置菜單下的圖標(biāo)
ico tmd;//時(shí)間與日期圖標(biāo)
ico font;//更新字庫圖標(biāo)地址
ico icon;//更新圖標(biāo)圖標(biāo)地址
ico scrsaver;//屏保圖標(biāo)地址
ico about;//關(guān)于圖標(biāo)地址
ico sd;//SD卡圖標(biāo)地址
ico scroff;//屏幕關(guān)閉圖標(biāo)地址
ico target;//屏幕校準(zhǔn)圖標(biāo)地址
//開機(jī)畫面圖標(biāo)
ico bootup;//開機(jī)畫面圖標(biāo)地址
//調(diào)色板
ico colorpad;//調(diào)色板地址
//主題初始化,讀取Flash中的相應(yīng)項(xiàng)目地址
void Theme_Init(void)
{
u32 temp[2];
u8 t[2];
//主界面圖標(biāo)地址
//12字體
SPI_Flash_Read((u8*)temp,2,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
fon12.addr=temp[0];
fon12.size=temp[1];
//16字體
SPI_Flash_Read((u8*)temp,10,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
fon16.addr=temp[0];
fon16.size=temp[1];
//oem2uni地址
SPI_Flash_Read((u8*)temp,18,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
oem2uni.addr=temp[0];
oem2uni.size=temp[1];
//uni2oem地址
SPI_Flash_Read((u8*)temp,26,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
uni2oem.addr=temp[0];
uni2oem.size=temp[1];
#if ICO_TO_SD==0//圖標(biāo)放flash的操作
//設(shè)置圖標(biāo)
SPI_Flash_Read((u8*)temp,34,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
setup.addr=temp[0];
setup.size=temp[1];
//音樂圖標(biāo)
SPI_Flash_Read((u8*)temp,42,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
music.addr=temp[0];
music.size=temp[1];
//收音機(jī)圖標(biāo)
SPI_Flash_Read((u8*)temp,50,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
radio.addr=temp[0];
radio.size=temp[1];
//繪圖板圖標(biāo)
SPI_Flash_Read((u8*)temp,58,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
drawing.addr=temp[0];
drawing.size=temp[1];
//記事本圖標(biāo)
SPI_Flash_Read((u8*)temp,66,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
notebook.addr=temp[0];
notebook.size=temp[1];
//資源管理器圖標(biāo)地址
SPI_Flash_Read((u8*)temp,74,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
source.addr=temp[0];
source.size=temp[1];
//附加功能圖標(biāo)地址
SPI_Flash_Read((u8*)temp,82,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
others.addr=temp[0];
others.size=temp[1];
//日歷圖標(biāo)地址
SPI_Flash_Read((u8*)temp,90,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
date.addr=temp[0];
date.size=temp[1];
//圖庫圖標(biāo)地址
SPI_Flash_Read((u8*)temp,98,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
pic.addr=temp[0];
pic.size=temp[1];
//文件管理器圖標(biāo)地址
//文件夾圖標(biāo)地址
SPI_Flash_Read((u8*)temp,106,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
filejak.addr=temp[0];
filejak.size=temp[1];
//關(guān)機(jī)微標(biāo)圖片地址
SPI_Flash_Read((u8*)temp,114,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
shutdown.addr=temp[0];
shutdown.size=temp[1];
//音樂圖標(biāo)地址
SPI_Flash_Read((u8*)temp,122,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
sound.addr=temp[0];
sound.size=temp[1];
//txt文檔圖標(biāo)地址
SPI_Flash_Read((u8*)temp,130,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
txt.addr=temp[0];
txt.size=temp[1];
//圖片圖標(biāo)地址
SPI_Flash_Read((u8*)temp,138,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
picture.addr=temp[0];
picture.size=temp[1];
//文件圖標(biāo)地址
SPI_Flash_Read((u8*)temp,146,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
files.addr=temp[0];
files.size=temp[1];
//驅(qū)動器圖標(biāo)地址
SPI_Flash_Read((u8*)temp,154,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
drive.addr=temp[0];
drive.size=temp[1];
//告示圖標(biāo)地址
//對號圖標(biāo)地址
SPI_Flash_Read((u8*)temp,162,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
right.addr=temp[0];
right.size=temp[1];
//錯號圖標(biāo)地址
SPI_Flash_Read((u8*)temp,170,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
wrong.addr=temp[0];
wrong.size=temp[1];
//感嘆號圖標(biāo)地址
SPI_Flash_Read((u8*)temp,178,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
sigh.addr=temp[0];
sigh.size=temp[1];
//問號圖標(biāo)地址
SPI_Flash_Read((u8*)temp,186,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
question.addr=temp[0];
question.size=temp[1];
//垃圾桶圖標(biāo)地址
SPI_Flash_Read((u8*)temp,194,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
recycle.addr=temp[0];
recycle.size=temp[1];
//設(shè)置功能下圖標(biāo)地址
//時(shí)間與日期圖標(biāo)地址
SPI_Flash_Read((u8*)temp,202,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
tmd.addr=temp[0];
tmd.size=temp[1];
//更新字庫圖標(biāo)地址
SPI_Flash_Read((u8*)temp,210,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
font.addr=temp[0];
font.size=temp[1];
//更新圖標(biāo)圖標(biāo)地址
SPI_Flash_Read((u8*)temp,218,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
icon.addr=temp[0];
icon.size=temp[1];
//屏保圖標(biāo)地址
SPI_Flash_Read((u8*)temp,226,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
scrsaver.addr=temp[0];
scrsaver.size=temp[1];
//關(guān)于圖標(biāo)地址
SPI_Flash_Read((u8*)temp,234,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
about.addr=temp[0];
about.size=temp[1];
//sd卡圖標(biāo)地址
SPI_Flash_Read((u8*)temp,242,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
sd.addr=temp[0];
sd.size=temp[1];
//屏幕關(guān)閉延時(shí)圖標(biāo)地址
SPI_Flash_Read((u8*)temp,250,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
scroff.addr=temp[0];
scroff.size=temp[1];
//屏幕校準(zhǔn)圖標(biāo)地址
SPI_Flash_Read((u8*)temp,258,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
target.addr=temp[0];
target.size=temp[1];
//開機(jī)畫面圖標(biāo)地址
SPI_Flash_Read((u8*)temp,266,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
bootup.addr=temp[0];
bootup.size=temp[1];
//調(diào)色板地址
SPI_Flash_Read((u8*)temp,274,8);//從0開始讀出8字節(jié)地址數(shù)據(jù)
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
//檢查字庫圖標(biāo)是否存在
SPI_Flash_Read(t,0,2);//讀取字庫,圖標(biāo)存在標(biāo)記
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())//顯示藍(lán)屏錯誤界面
{
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);//藍(lán)屏死機(jī)
}
}
#if ICO_TO_SD==0
if(t[1]!=0xbb)//圖標(biāo)不存在
{
bootup_ico_update=1;
if(Ico_Update())//顯示藍(lán)屏錯誤界面
{
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);//藍(lán)屏死機(jī)
}
}
#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')//復(fù)制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[]=
{"此操作將更新系統(tǒng)字庫,"\
"請務(wù)必確認(rèn)字庫來源,"\
"未知來源的字庫可能會導(dǎo)致文本顯示大面積亂碼,是否繼續(xù)?"\
"如果繼續(xù),請把相關(guān)文件命名為指定名稱后存放在SD卡根目錄的FONT文件夾里,"\
"并點(diǎn)擊'是(Y)',取消請點(diǎn)擊'否(N)'。詳情參閱readme.txt。"\
};
u8 Font_Update(void)
{
u8 *buffer=jpg_buffer;//字庫更新緩存,大小為2扇區(qū),引用圖片解碼緩存
u32 temp[2];//用以緩存文件地址和大小
u8 t[1];
u32 i=0,offset=2048;//字節(jié)數(shù)緩存,offset為Flash數(shù)據(jù)起始地址
u8 sta=0;//操作緩存
FIL file;//文件讀取緩存
UINT b_left;//文件剩余字節(jié)數(shù)
u16 byte_to_read=1024;//需要讀取的文件字節(jié)數(shù)
//界面提示
//先還原坐標(biāo),避免上一次數(shù)據(jù)的影響
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);//顯示窗體,標(biāo)題欄高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);//顯示疑問圖標(biāo)(這個(gè)注釋掉,避免在圖標(biāo)還沒更新的情況下顯示圖標(biāo)導(dǎo)致死機(jī))
while(sta==0)
{
if(Pen_Point.Key_Sta==Key_Down)
{
Pen_Int_Set(0);//關(guān)閉中斷
Pen_Point.Key_Sta=Key_Up;
do//連續(xù)讀取數(shù)據(jù)
{
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);//顯示窗體,標(biāo)題欄高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
//進(jìn)度條
Progress_Bar(20,155,200,i,file.fsize,1);//進(jìn)度條長度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;//還原要讀字節(jié)數(shù)
f_close(&file);//關(guān)閉fon12.dzk
SPI_Flash_Write((u8*)temp,2,8);//寫入地址數(shù)據(jù)
//更新16字體
//更新過程
Windows(10,80,230,240,"字庫更新中……",12);//顯示窗體,標(biāo)題欄高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
//進(jìn)度條
Progress_Bar(20,155,200,i,file.fsize,1);//進(jìn)度條長度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;//重新獲得下一個(gè)文件的偏移地址
i=0;
byte_to_read=1024;//還原要讀字節(jié)數(shù)
f_close(&file);
SPI_Flash_Write((u8*)temp,10,8);//寫入fon16地址信息
//更新oem2uni
//更新過程
Windows(10,80,230,240,"字庫更新中……",12);//顯示窗體,標(biāo)題欄高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
//進(jìn)度條
Progress_Bar(20,155,200,i,file.fsize,1);//進(jìn)度條長度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;//重新獲得下一個(gè)文件的偏移地址
i=0;
byte_to_read=1024;//還原要讀字節(jié)數(shù)
f_close(&file);
SPI_Flash_Write((u8*)temp,18,8);//寫入oem2uni地址信息
//更新uni2oem
//更新過程
Windows(10,80,230,240,"字庫更新中……",12);//顯示窗體,標(biāo)題欄高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
//進(jìn)度條
Progress_Bar(20,155,200,i,file.fsize,1);//進(jìn)度條長度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;//重新獲得下一個(gè)文件的偏移地址
i=0;
byte_to_read=1024;//還原要讀字節(jié)數(shù)
f_close(&file);
SPI_Flash_Write((u8*)temp,26,8);//寫入uni2oem地址信息
//更新完成,寫入字庫存在標(biāo)志
t[0]=0xaa;
SPI_Flash_Write(t,0,1);//寫入0xaa為字庫存在標(biāo)志
bootup_font_update=0;//還原開機(jī)更新標(biāo)志
sta=0;
goto END;//退出
}
NOFILE:
Windows(10,80,230,240,"注意——更新字庫失敗",12);//顯示窗體,標(biāo)題欄高18
Button(98,208,146,232,UNPRESS,"確定",24,12);//顯示取消按鈕,居中
//提示字體(居中顯示)
show_string(41,153,200,"未找到相應(yīng)文件,更新失敗!",12,color(0,0,0));//文本框高度28,文本框長180
// show_ico(15,137,59,181,wrong.addr,wrong.size);//顯示錯誤圖標(biāo)(注釋掉,避免圖標(biāo)未更新之前顯示圖標(biāo)導(dǎo)致死機(jī))
goto OUT;
END:
Windows(10,80,230,240,"注意——更新字庫成功",12);//顯示窗體,標(biāo)題欄高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);//顯示正確圖標(biāo)(注釋掉,避免圖標(biāo)未更新之前顯示圖標(biāo)導(dǎo)致死機(jī))
goto OUT;
CANCEL:
Windows(10,80,230,240,"注意——更新字庫失敗",12);//顯示窗體,標(biāo)題欄高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);//顯示感嘆號圖標(biāo)(注釋掉,避免圖標(biāo)未更新之前顯示圖標(biāo)導(dǎo)致死機(jī))
goto OUT;
OUT:
while(1)
{
if(Pen_Point.Key_Sta==Key_Down)
{
Pen_Int_Set(0);//關(guān)閉中斷
Pen_Point.Key_Sta=Key_Up;
do//連續(xù)讀取數(shù)據(jù)
{
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
//圖片更新程序
//對話框指示圖標(biāo):32×32
//主界面圖標(biāo):56×56
//文件管理圖標(biāo):16×16
const u8 ico_warming[]=
{
"注意,此操作將會替換系統(tǒng)內(nèi)置圖標(biāo),"\
"一般用于自定義用戶圖標(biāo),"\
"請用戶在更新前將圖標(biāo)按照指定文件名存放在SD卡根目錄下的ico文件夾里,"\
"點(diǎn)擊'是(Y)'更新,點(diǎn)擊'否(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扇區(qū),引用圖片解碼緩存
u8 key=0;
u32 temp[2];//用來存放咚咚的起始地址和大小
u8 t[1];
u32 total_size=0;//需要更新的圖標(biāo)總大小
u32 progress_size=0;//總進(jìn)度大小
u32 progress_size_index=0;//當(dāng)前進(jìn)度大小
//文件系統(tǒng)所需
FILINFO icoinfo;
FIL ico;
DIR dir;//搜索文件所用
UINT byteleft;
u32 byteread=1024;
u32 offset;
//更新圖標(biāo)所用,用來記錄flash地址以及更新到的圖標(biāo)號數(shù)
u8 ico_count=0;
TCHAR direction[20];
u32 addr;
//先還原坐標(biāo),避免上一次數(shù)據(jù)的影響
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,"注意——更新圖標(biāo)",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);//顯示疑問圖標(biāo)(這個(gè)注釋掉,避免圖標(biāo)未更新之前顯示圖標(biāo)導(dǎo)致死機(jī))
while(key==0)
{
if(Pen_Point.Key_Sta==Key_Down)
{
Pen_Int_Set(0);//關(guān)閉中斷
Pen_Point.Key_Sta=Key_Up;
do//連續(xù)讀取數(shù)據(jù)
{
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,"更新圖標(biāo)中……",12);//顯示窗體
Button(95,209,143,233,INVALID,"取消",24,12);//顯示取消按鈕
show_string(19,157,199,"總進(jìn)度:",12,color(0,0,0));
show_string(19,127,199,"當(dāng)前進(jìn)度:",12,color(0,0,0));
show_string(19,115,199,"復(fù)制:",12,color(0,0,0));
//計(jì)算需要更新的圖標(biāo)的總大小
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;
//設(shè)置菜單下圖標(biāo)
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;
//開機(jī)畫面圖標(biāo)
else if(strcmp(icoinfo.fname,fn_bootup)==0)total_size+=icoinfo.fsize;
//調(diào)色板
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;
//設(shè)置菜單下的圖標(biāo)
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;
//開機(jī)畫面圖標(biāo)
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;//讀取文件狀態(tài),文件不存在則失敗
}
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);//讀出上一個(gè)元素地址
if(ico_count==0)addr=temp[0]+temp[1]+500000;//制作要寫入元素的首地址,第一個(gè)圖標(biāo)和字庫錯開50000個(gè)地址,防止更新字庫時(shí)候錯殺圖標(biāo)
else addr=temp[0]+temp[1];
temp[0]=addr;//記錄要寫入元素首地址
temp[1]=icoinfo.fsize;//記錄要寫入元素大小
offset=0;//清空偏移值
while(1)//開始復(fù)制信息
{
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;//還原要讀取的字節(jié)數(shù)
progress_size_index=0;//還原當(dāng)前進(jìn)度計(jì)數(shù)
SPI_Flash_Write((u8*)temp,(34+(ico_count*8)),8);//記錄地址標(biāo)志
f_close(&ico);//關(guān)閉文件s
break;//讀取完畢,退出
}
progress_size_index+=byteread;
progress_size+=byteread;
}
ico_count++;
}
//圖標(biāo)更新完畢,記錄圖標(biāo)存在標(biāo)志
t[0]=0xbb;
SPI_Flash_Write(t,1,1);
bootup_ico_update=0;//還原強(qiáng)制更新標(biāo)志
Theme_Init();//復(fù)制完畢,初始化一次主題
Windows(10,79,229,241,"注意——圖標(biāo)更新成功",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,"注意——圖標(biāo)更新失敗",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);//(注釋掉,避免圖標(biāo)未更新之前顯示圖標(biāo)導(dǎo)致死機(jī))
goto OUT;
CANCEL:
Windows(10,79,229,241,"注意——圖標(biāo)更新失敗",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);//(注釋掉,避免圖標(biāo)未更新之前顯示圖標(biāo)導(dǎo)致死機(jī))
goto OUT;
OUT:
while(key==0)
{
if(Pen_Point.Key_Sta==Key_Down)
{
Pen_Int_Set(0);//關(guān)閉中斷
Pen_Point.Key_Sta=Key_Up;
do//連續(xù)讀取數(shù)據(jù)
{
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,"更新圖標(biāo)",12);//顯示窗體
Button(95,209,143,233,UNPRESS,"確定",24,12);//顯示取消按鈕
show_string(74,153,158,"圖標(biāo)存放位置被設(shè)置為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);//關(guān)閉中斷
Pen_Point.Key_Sta=Key_Up;
do//連續(xù)讀取數(shù)據(jù)
{
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 |