123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445 |
- /****************************************Copyright (c)**************************************************
- * File Name: GUI.c
- * Function Describe:
- * Explain:
- * Writer: ShiLiangWen
- * Date: 2016-1-8
- ********************************************************************************************************/
- #include "includes.h"
- extern const unsigned char g_apucLetter16[];
- extern const unsigned char g_apucCLetter16[];
- extern const unsigned char g_apucLetter24[];
- extern const unsigned char g_apucCLetter24[];
- extern const unsigned char g_apucFonts16[];
- extern const unsigned char g_apucCFonts16[];
- extern const unsigned char g_apucFonts24[];
- extern const unsigned char g_apucCFonts24[];
- SUT_HZK sutHzk16;
- unsigned char g_Palette[256*4];//调色板
- /****************************************************************************
- *设置调色板为默认调色板
- ****************************************************************************/
- void SetDefaultPalette(void)
- {
- int i,j;
- j=0;
- for(i=0;i<256;i++){
- g_Palette[i]=g_cucPalette[j++];
- g_Palette[i+1]=g_cucPalette[j++];
- g_Palette[i+2]=g_cucPalette[j++];
- g_Palette[i+3]=0;
- }
- }
- /****************************************************************************
- GUI_Color565
- 将RGB888转为RGB565
- ****************************************************************************/
- u16 GUI_Color565(unsigned char R,unsigned char G, unsigned char B)
- {
- u8 r, g, b;
- r = R>>3; // 取R色的高5位
- g = G>>2; // 取G色的高6位
- b = B>>3; // 取B色的高5位
- return( (r<<11) + (g<<5) + (b<<0) );
- }
- /****************************************************************************
- GuiShowPic
- 显示一张图片
- 此函数只能显示在程序区中的图片数据,采用默认调色板
- ****************************************************************************/
- void GuiShowPic(u8 x,u8 y,const unsigned char *pic)
- {
- int i,len;
- u8 R,G,B;
- u16 RGB565;
- const unsigned char *data;
- HEADGRAY headgray;
- memcpy(&headgray,pic,sizeof(HEADGRAY));
- LcdBlockWrite(x,y,x+headgray.w-1,y+headgray.h-1);
- len=headgray.w * headgray.h;
- data=pic+sizeof(HEADGRAY);
- for(i=0;i<len;i++){
- R=data[i];
- R=g_cucPalette[R*3];
- G=data[i+1];
- G=g_cucPalette[G*3+1];
- B=data[i+2];
- B=g_cucPalette[B*3+2];
-
- RGB565=GUI_Color565(R,G,B);
- LcdSendData(RGB565 >> 8);
- LcdSendData(RGB565 & 0xff);
- }
- }
- /*****************************************
- 从字库文件HZK16中提取某汉子的字库数据
- 输入:hiByte--汉字的高字节 loByte--汉字的低字节
- 字库文件存储在sFlash中,字库文件名为HZK16
- 输出:pHzk--提取到的字库数据,需要预留足够空间存储。如果是16*16 则应该是16*16/8=32Byte
- 返回:失败返回0 成功返回长度
- ******************************************/
- int GetHzk16(u8 hiByte,u8 loByte,u8 *pHzk)
- {
- u8 Q,W;
- u32 offset;
- if(hiByte<0xa0 || loByte<0xa0)return 0;
-
- Q=hiByte-0xa0;
- W=loByte-0xa0;
- //offset=(94*(区码-1)+(位码-1))*32
- offset=(94 * (Q-1) + (W-1))* 32;
-
- return ReadFileData(sutHzk16.FileIndex,offset,32,pHzk);
- }
- /******************************************
- *汉子库初始化
- *输入:汉字库文件名
- *输出:汉字库数据首地址存放在sHZK16中
- *返回:1--成功 0--失败,找不到文件
- *******************************************/
- int HzkInit(const char *filename)
- {
- int i;
- if(g_sutFilesList.FileCount==0)return 0;
- memset(&sutHzk16,0,sizeof(SUT_HZK));
- i=GetFileIndex(filename);
- if(i<0)return 0;
- sutHzk16.width=16;
- sutHzk16.heigh=16;
- sutHzk16.len=(sutHzk16.width * sutHzk16.heigh)/8;
- sutHzk16.FileIndex=i;
- sutHzk16.FileLen=g_sutFilesList.FileInfo[i].FileLen;
- return 1;
- }
- /******************************************
- GuiInit
- *******************************************/
- void GuiInit(void)
- {
- if(!HzkInit(HZK16_FILE_NAME))
- {
- printf("Can't find the HzkFile(%s)!\r\n",HZK16_FILE_NAME);
- }
- }
- /***************************************************************************
- *在LCD上显示一个字符
- ****************************************************************************/
- void GuiShowChar(u16 x,u16 y,u8 hiByte,u8 loByte,u8 mode)
- {
- unsigned short i,j,k,m;
- unsigned short width,height;
- unsigned char ByteWidth,data;
- unsigned char colorH,colorL;
- unsigned char bgcolorH,bgcolorL;
- const unsigned char *l_pucFont,*l_pucLetter;
- unsigned char *p;
- unsigned char font;//字体
- unsigned char cover;//覆盖方式
- unsigned char sucHzk16[32];
- font=mode&0xf0;
- cover=mode&0x0f;
-
- k = 0;
- if(!hiByte) //english
- {
- if(font==0x00) //8 * 16
- {
- width=8;
- height = 16;
- ByteWidth = 1;
- l_pucFont = g_apucFonts16;
- l_pucLetter = g_apucLetter16;
- }else{ //16 * 24
- width=16;
- height = 24;
- ByteWidth = 2;
- l_pucFont = g_apucFonts24;
- l_pucLetter = g_apucLetter24;
- }
- //
- while(*l_pucLetter)
- {
- if(loByte == *l_pucLetter)break;
- l_pucLetter ++;
- k ++;
- }
- //查找到字库的开始位置
- l_pucFont += k * ByteWidth * height;
- }
- else
- { //chinese
- if(font == 0x00)//16 * 16
- {
- width=16;
- height = 16;
- ByteWidth = 2;
- l_pucFont = sucHzk16;
- l_pucLetter = 0;
- k=0;
- if(32!=GetHzk16(hiByte,loByte,sucHzk16)){//从sFlash的HZK16文件中读取字库数据
- //找不到字库,显示"口"
- l_pucFont=g_apucCLetter16;
- }
- }else{//24 * 24
- width=24;
- height = 24;
- ByteWidth = 3;
- l_pucFont = g_apucCFonts24;
- l_pucLetter = g_apucCLetter24;
- while(*l_pucLetter)
- {
- if(hiByte == *l_pucLetter && loByte == *(l_pucLetter + 1))break;
- l_pucLetter += 2;
- k ++;
- }
- //查找到字库的开始位置
- l_pucFont += k * ByteWidth * height;
- }
- //
- }
- //刷屏显示
- colorH=g_usColor>>8;
- colorL=g_usColor&0xff;
- bgcolorH=g_usBackColor>>8;
- bgcolorL=g_usBackColor&0xff;
-
- LcdBlockWrite(x,y,x+width-1,y+height-1);
- for(j=0;j<height;j++){
- for(i=0;i<ByteWidth;i++){
- data=*l_pucFont++;
- for(k=0;k<8;k++){
- if(data & (0x80>>k)){
- LcdSendData(colorH);
- LcdSendData(colorL);
- }else{
- //if(cover){
- LcdSendData(bgcolorH);
- LcdSendData(bgcolorH);
- //}
- }
- }
- }
- }
- }
- /******************************************************************************
- GuiShowStr
- 指定位置显示字符串
- 左上角坐标:x,y
- 显示内容:string
- 模式:mode 高4位代表字体,低4位为模式
- ******************************************************************************/
- void GuiShowStr(u16 x, u16 y,const char *string,u8 mode)
- {
- unsigned char width1,width2;
- unsigned char *p;
- unsigned short i;
- unsigned char font;//字体
- font=mode&0xf0;
-
- if(font == 0x00) //16bit font
- {
- width1 = 2;
- width2 = 1;
- }
- else //24bit font
- {
- width1 = 3;
- width2 = 1;
- }
- p = (unsigned char *)string;
- i = 0;
- while(*p)
- {
- if (*p > 0x9f) //chinese letter
- {
- GuiShowChar(x+i,y,*p, *(p+1),mode);
- i += width1 * 8;
- p += 2;
- }
- else //english letter
- {
- GuiShowChar(x + i,y,0,*p,mode);
- if(font==0){
- i += width2 * 8;
- }else{
- i += width2 * 16;
- }
- p ++;
- }
- }
- }
- /************************************************************
- *
- *************************************************************/
- void GuPaintLcd(u16 x,u16 y,u16 width,u16 heigh,u8 *buf)
- {
- int i,j;
- unsigned short RGB565;
- unsigned char data;
- unsigned char R,G,B;
- unsigned short temp;
- LcdBlockWrite(x,y,x+width-1,y+heigh-1);
- for(j=0;j<heigh;j++){
- for(i=0;i<width;i++){
- data=buf[j*width+i];
- temp=data*4;
- B=g_Palette[temp];
- G=g_Palette[temp+1];
- R=g_Palette[temp+2];
- RGB565=GUI_Color565(R,G,B);
- LcdSendData(RGB565 >> 8);
- LcdSendData(RGB565 & 0xff);
- }
- }
- }
- /************************************************************
- *
- *************************************************************/
- void GuiShowBMP(u16 x,u16 y,const char * filename)
- {
- int i,w,l;
- int index;
- int FileLen;
- unsigned short type;
- unsigned int width,heigh,SizeImage,bfOffBits;
- unsigned char temp[160];
-
-
- index=GetFileIndex(filename);
- FileLen=GetFileLen(index);
- if(FileLen==0)return;//找不到文件,直接返回不处理
- //读出位图类型
- ReadFileData(index,28,2,(u8 *)&type);//读出int biBitCount ; // 每个像素所需的位数,必须是或 1,4,8 24(// 真彩色 ) 之一 (28-29 字节 )
- if(type!=0x0008)return;//非256色的BMP图,直接返回不处理。
- //读出位图的宽度
- ReadFileData(index,18,4,(u8 *)&width); //int image_width ; // 位图的宽度,以像素为单位 (18-21 字节 )
- printf("width=%u\r\n",width);
- //读出位图的高度
- ReadFileData(index,22,4,(u8 *)&heigh); //int image_heigh ; // 位图的高度,以像素为单位 (22-25 字节 )
- printf("heigh=%u\r\n",heigh);
- if(width>LCD_WIDTH || heigh>LCD_HIGH)return;//超过LCD显示范围,不处理
-
- //#if 0 //有此代码 会处理掉图片 不显示
- // //读出位图数据大小
- // ReadFileData(index,34,4,(u8 *)&SizeImage); //int SizeImage ; // 位图 数据 的大小,以字节为单位 (34-37 字节 )
- // printf("SizeImage=%u\r\n",SizeImage);
- // if((width*heigh)!=SizeImage)return;//位图数据不合理,可能图片经过压缩,不处理
- //#endif
- //读位图数据起始地址
- ReadFileData(index,10,4,(u8 *)&bfOffBits); //int bfOffBits ; // 位图数据的起始位置,以相对于位图 (10-13 字节 )
-
- //读取调色板数据
- ReadFileData(index,54,1024,g_Palette);
- //以下读位图数据并刷屏
- i= width%4;
- if(i > 0){
- w=width + (4-width%4);//每行字节数为4的倍数,不够的补齐
- }else{
- w=width;
- }
-
- l=heigh-1;//BMP扫描顺序是:从下往上,从左往右扫描,因此先从最后一行开始读数据
- for(i=0;i<heigh;i++){
- ReadFileData(index,bfOffBits+w*l,width,temp);
- GuPaintLcd(x,y+i,width,1,temp);
- l--;
- }
- //恢复调色板到默认调色板
- SetDefaultPalette();
- }
- void GuiShowLogoGIF(void)
- {
- int x,y,t;
- x=0;y=58;
- t=100;
- GuiShowBMP(x,y,"logo1.bmp");
- DelayMs(t);
- GuiShowBMP(x,y,"logo2.bmp");
- DelayMs(t);
- GuiShowBMP(x,y,"logo3.bmp");
- }
- /**************************************************/
- //信号量
- /****************************************************/
- /***********************************
- ??????
- **********************************/
- void GuiShowSingle(int CSQ)
- {
- static int siCSQ=123456;
- if(siCSQ!=CSQ){
- siCSQ=CSQ;
- }else return;
-
- GuiShowBMP(0,0,"Single.bmp");
- if(CSQ<1 || CSQ==99){
- LcdClearRect(7,4,21,14);
- }else if(CSQ<8){
- LcdDrawVLine(12,14,7,2);
- LcdClearRect(11,4,21,14);
- }else if(CSQ<16){
- LcdDrawVLine(12,14,7,2);
- LcdDrawVLine(9,14,11,2);
- LcdClearRect(15,4,21,14);
- }else if(CSQ<22){
- LcdDrawVLine(12,14,7,2);
- LcdDrawVLine(9,14,11,2);
- LcdDrawVLine(7,14,15,2);
- LcdClearRect(19,4,21,14);
- }else{
- LcdDrawVLine(12,14,7,2);
- LcdDrawVLine(9,14,11,2);
- LcdDrawVLine(7,14,15,2);
- LcdDrawVLine(4,14,19,2);
- }
- }
- void GuiShowBat(int bat)
- {
- static int Vbat=600;
- if(Vbat!=bat){
- Vbat=bat;
- }else return;
- GuiShowBMP(40,0,"VBAT1.bmp");
-
- if(bat<330){
- LcdDrawVLine(5,12,47,0);
- LcdDrawVLine(5,12,52,0);
- LcdDrawVLine(5,12,57,0);
- LcdDrawVLine(5,12,62,0);
- }
- else if(bat<350){//335-350
- LcdDrawVLine(5,12,62,4);
- }
- else if(bat<377){//351-377
- LcdDrawVLine(5,12,57,4);
- LcdDrawVLine(5,12,62,4);
- }
- else if(bat<392){//378-392
- LcdDrawVLine(5,12,52,4);
- LcdDrawVLine(5,12,57,4);
- LcdDrawVLine(5,12,62,4);
- }
-
- else if(bat>410){//400
- LcdDrawVLine(5,12,47,4);
- LcdDrawVLine(5,12,52,4);
- LcdDrawVLine(5,12,57,4);
- LcdDrawVLine(5,12,62,4);
- }
- }
|