📄 show_char.c
字号:
/*
* test.c --- Primary header file for
* LCD Device Driver with Framebuffer
* (C)opyright 2004 Bit 920 Labs
*
* Written by: Tangliting <dawn@bit.edu.cn>
* Created on: Sat. Mar 7 14:33:45 GMT +8:00 2004
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>
#include <linux/fb.h>
#include <linux/kd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <termios.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include "keyboard_zlg.h"
//#include "lcd.h"
#include "lcd.c"
#include "ascii.lib"
FILE *hzkFile = NULL;
unsigned short all;
short xx,yy;
// Default file name of configuration
#define TOUCHSCREEN_CONF "./touchscreen.conf"
#define TOUCHSCREEN_DEV "/dev/touchscreen/0"
// TouchScreen input data structure
typedef struct
{
unsigned short pressure;
unsigned short y;
unsigned short x;
unsigned short pad;
} ts_event_t;
// TouchScreen configuration structure
typedef struct
{
unsigned int xFactor;
unsigned int yFactor;
unsigned int xOffset;
unsigned int yOffset;
unsigned char scale;
} TS_CONFIG;
// Common data type definitions
typedef unsigned int U32;
typedef unsigned short U16;
typedef unsigned char U8;
typedef int S32;
typedef short S16;
typedef char S8;
// Screen rectangle structure
typedef struct
{
S32 left;
S32 right;
S32 top;
S32 bottom;
} RECT, * P_RECT;
// Screen point structure
typedef struct
{
unsigned short x;
unsigned short y;
} Point;
int touchscreen_fd = 0; /* touch screen device handle */
TS_CONFIG tsConfig; /* touch screen configuration data */
ts_event_t current_data;
unsigned short x1_max, y1_max;
S16 _ConvertX(U16 x);
S16 _ConvertY(U16 y);
// Retrieve an average data from touch screen input device
int _GetPenDataAvg(int ts_handler, ts_event_t * ts_avg, unsigned short max_num)
{
ts_event_t *tmpDataArr;
unsigned short bp;
unsigned short count;
long tempX, tempY;
int ret;
// Allocate a buffer for input data
tmpDataArr = (ts_event_t *)malloc(2 * sizeof(ts_event_t));
if (tmpDataArr == NULL)
{
printf("Error: malloc failed.\n");
return -1;
}
// Read a set of data into buffer
count = 0;
do
{
bp = 0;
while (1)
{
if(bp>1)
{
if(max_num > abs(tmpDataArr[bp-2].x-tmpDataArr[bp-1].x) &&
max_num > abs(tmpDataArr[bp-2].y-tmpDataArr[bp-1].y))
{
// printf("tmpDataArr[bp-1]=%d\n",tmpDataArr[bp-1].pressure);
break;
}
else
bp=0;
}
//printf("before read, ts_handler is %d\n",ts_handler);
//printf("bp=%d\n",bp);
ret = read(ts_handler, &tmpDataArr[bp], sizeof(ts_event_t));
//printf("ret =%d, sizeof(ts_event_t)=%d\n",ret,sizeof(ts_event_t));
// printf("x = 0x%4x, y = 0x%4x, Press = 0x%4x\n", tmpDataArr[bp].x,
// tmpDataArr[bp].y,
// tmpDataArr[bp].pressure);
bp++;
}//while
count=bp;
} while (count == 0);
tempX = tempY = 0;
for (bp = 0; bp < count; bp++)
{
tempX += tmpDataArr[bp].x;
tempY += tmpDataArr[bp].y;
}
// Calculate an average value
ts_avg->x = tempX / count;
ts_avg->y = tempY / count;
ts_avg->pressure = tmpDataArr[1].pressure;
// printf("%d\n",tmpDataArr[1].pressure);
// Release
free(tmpDataArr);
}
// Convert touch screen point to Screen Point
S16 _TouchpadConvertLCD(U16 value, U32 factor, U32 offset)
{
S32 temp;
temp = value;
temp -= offset;
if ( temp < 0)
{
/* outside LCD area ... */
temp = -temp;
}
return ((S16)((temp * factor) >> tsConfig.scale));
}
// Convert X-coordinate
S16 _ConvertX(U16 x)
{
return _TouchpadConvertLCD(x, tsConfig.xFactor, tsConfig.xOffset);
}
// Convert Y-coordinate
S16 _ConvertY(U16 y)//**************************************//
{
//y = 4240 - y;
return _TouchpadConvertLCD(y, tsConfig.yFactor, tsConfig.yOffset);// + 16;
}
int check(int x,int y, RECT range)
{
//printf("%d %d %d %d \n",range.left,range.right,range.top,range.bottom);
//printf("%d %d ",x,y);
//printf("\n\n");
if(x < range.left || x > range.right)
return 1;
if(y > range.bottom || y < range.top)
return 1;
return 0;
}
Point get_ts_xy(int ts_handler,int max_x,int max_y)
{
Point temp;
//printf("before of function _GetPenDataAvg\n");
_GetPenDataAvg(ts_handler, ¤t_data, 50);//max_num=10
//printf("out of function _GetPenDataAvg\n");
//printf("current_data.x = %d\n", current_data.x);
//printf("current_data.y = %d\n", current_data.y);
temp.x = _ConvertX(current_data.x);
temp.y = abs(480-_ConvertY(current_data.y));
printf("you click: x = %d, y = %d",temp.x,temp.y);
printf("\n\n");
return temp;
}
void DrawCharEN(short x, short y, unsigned char c, ColorType color)
{
unsigned char codes[16];
short i;
for (i = 0; i < 16; i++)
codes[i] = ascii_codes[c][i];
fb_Text_8x16(x, y, codes, color);
}
void DrawCharCHS(int x, int y, unsigned char c[2], ColorType color)
{
unsigned char codes[32];
short i;
unsigned char ch, cl;
unsigned long offset;
if (hzkFile == NULL)
{
printf("No Chinese Character Library opened.\n");
exit(1);
}
ch = c[0];
cl = c[1];
offset = ((ch - 0xa1) * 94L + (cl - 0xa1)) * 32L;
fseek(hzkFile, offset, SEEK_SET);
fread(codes, 32, 1, hzkFile);
fb_Text_16x16(x, y, codes, color);
}
void DRAWGRAPH()
{FILE *fp;
int i,j,a;
fb_DrawRect(4, 4,636, 456, GRAY);
fp=fopen("mazepath.txt","r");
for(i=0;i<21*all;i++)
for(j=0;j<15*all;j++)
{fscanf(fp,"%d ",&a);
if(a==-1)
fb_FillRect(5+i*30, 5+j*30,5+(i+1)*30, 5+(j+1)*30, GRAY);
if(a==1)
fb_FillRect(5+i*30, 5+j*30,5+(i+1)*30, 5+(j+1)*30, RED);xx=i;yy=j;
}
fclose(fp);
}
void DRAWGRAPHs( short x, short y)
{ fb_Clear(SYS_BLACK);
DRAWGRAPH();
fb_FillRect(5+x, 5+y, 35+x, 35+y, BLUE);
}
unsigned short amme(unsigned short x,unsigned short y)
{FILE *fp;
int i,j,a;
fb_DrawRect(4, 4,636, 456, GRAY);
fp=fopen("mazepath.txt","r");
for(i=0;i<21;i++)
for(j=0;j<15;j++)
{fscanf(fp,"%d ",&a);
if(a==-1)
if(x/30==i&&y/30==j)
{fclose(fp);
return 0;}
}
fclose(fp);
return 1;
}
// Initialize Mx1 input devices
int main()
{
char * tsconf_name;
FILE * tsconf_fp;
unsigned short x1,x2,y1,y2;
Point clPoint;
// RECT tempRange;
short x, y;
short i;
ColorType color0 = SYS_WHITE;
//ColorType color1=RED,color2=GREEN,color3=BLUE,color4=ORANGE;
short colorPage;
short endFlag;
unsigned char * ascTxt1 = "Beijing Institute of Technology";
unsigned char * ascTxt2 = "ARM S3C 2410";
unsigned char * ascTxt3 = "20053484";
unsigned char * ascTxt4 = "12110503";
unsigned char * chsTxt1 = "北京理工大学";
unsigned char * chsTxt2 = "嵌入式实验室";
unsigned char * chsTxt3 = "北京理工大学计算教学实验中心";
unsigned char * chsTxt4 = "王永辉";
unsigned char bufferTxt[2];
unsigned short keypress;
short x_max, y_max;
ColorType color_max;
short x_car, y_car;
if (fb_Init() == -1)
{
printf("Initialize Framebuffer LCD failed.\n");
exit(1);
}
x_max = fb_GetScreenWidth() - 1;
y_max = fb_GetScreenHeight() - 1;
color_max = fb_GetScreenColors() - 1;
fb_Clear(0x0);
printf(”输入游戏等级 (1-4)”);
zlg7290_init();
while(1)
if(!(zlg7290_getkey(&all)))
{
keypress-=1;
printf("all=%d\n\n",all);
break;
}
else
zlg7290_sndcmd(0x70,1<<(keypress-1));
DRAWGRAPH();
x_car=0;
y_car=0;
DRAWGRAPHs(x_car,y_car);
while(1){
while(1)
if(!(zlg7290_getkey(&keypress)))
{
keypress-=1;
printf("keypress=%d\n\n",keypress);
break;
}
else
zlg7290_sndcmd(0x70,1<<(keypress-1));
if(keypress==3)if(x_car+30<=605) {if(amme(x_car+30,y_car)){x_car+=30;DRAWGRAPHs(x_car,y_car);}}
if(keypress==1)if(x_car-30>=0) {if(amme(x_car-30,y_car)){x_car-=30;DRAWGRAPHs(x_car,y_car);}}
if(keypress==2)if(y_car+30<=425){ if(amme(x_car,y_car+30)){y_car+=30;DRAWGRAPHs(x_car,y_car);}}
if(keypress==5)if(y_car-30>=0){if(amme(x_car,y_car-30)) {y_car-=30;DRAWGRAPHs(x_car,y_car);}}
if(xx*30==x_car&&yy*30==y_car)
{
break;
}
zlg7290_sndcmd(0x70,1<<(keypress-1));
usleep(99999);
keypress=99999;
}
printf(”游戏结束”);
//显示英文和中文
// Test Text functions
printf("Test text_16x8:\t\t");
x = 10, y = 10;
for (i = 0; i < strlen(ascTxt1); i++)
{
DrawCharEN(x, y, ascTxt1[i], SYS_WHITE);
x += 8;
}
x = 10, y = 40;
for (i = 0; i < strlen(ascTxt2); i++)
{
DrawCharEN(x, y, ascTxt2[i], RED);
x += 8;
}
x = 10, y = 70;
for (i = 0; i < strlen(ascTxt3); i++)
{
DrawCharEN(x, y, ascTxt3[i], RED);
x += 8;
}
x = 10, y = 100;
for (i = 0; i < strlen(ascTxt4); i++)
{
DrawCharEN(x, y, ascTxt4[i], RED);
x += 8;
}
printf("Press any key to continue...\n");
getchar();
printf("Test text_16x16:\t");
hzkFile = fopen("./hzk", "rb"); //change from hz16 to hzk
x = 10, y = 140;
for (i = 0; i < strlen(chsTxt4); i += 2)
{
bufferTxt[0] = chsTxt4[i];
bufferTxt[1] = chsTxt4[i + 1];
DrawCharCHS(x, y, bufferTxt, RED);
x += 16;
}
x = 10, y = 180;
for (i = 0; i < strlen(chsTxt1); i += 2)
{
bufferTxt[0] = chsTxt1[i];
bufferTxt[1] = chsTxt1[i + 1];
DrawCharCHS(x, y, bufferTxt, GREEN);
x += 16;
}
x = 10, y = 220;
for (i = 0; i < strlen(chsTxt2); i += 2)
{
bufferTxt[0] = chsTxt2[i];
bufferTxt[1] = chsTxt2[i + 1];
DrawCharCHS(x, y, bufferTxt, BLUE);
x += 16;
}
x = 10, y = 260;
for (i = 0; i < strlen(chsTxt3); i += 2)
{
bufferTxt[0] = chsTxt3[i];
bufferTxt[1] = chsTxt3[i + 1];
DrawCharCHS(x, y, bufferTxt, ORANGE);
x += 16;
}
fclose(hzkFile);
printf("\nFinished Test. Press any key to exit.\n");
getchar();
fb_Clear(SYS_BLACK);
fb_Release();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -