#include <stdio.h>
#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/mman.h>
#include<linux/fb.h>
#include <math.h>
/*
字模设置为,横向,字节倒序
*/
char hanzi[4][48*48/8]={
/*-- 文字: 电 --*/
/*-- 华文隶书36; 此字体下对应的点阵为:宽x高=48x48 --*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xE0,0x01,0x00,0x00,0x00,0x00,0xF0,0x01,0x00,0x00,0x00,0x00,
0xF0,0x03,0x00,0x00,0x00,0x00,0xF0,0x07,0x00,0x00,0x00,0x00,0xFE,0xFF,0x0F,0x00,
0xC0,0xFF,0xFF,0xFF,0xFF,0x03,0xC0,0xFF,0xFF,0xFF,0xFF,0x03,0xE0,0xFF,0xFF,0xFF,
0xFF,0x03,0xE0,0xFF,0xFF,0xFF,0xFF,0x01,0xC0,0xFF,0xFF,0xFF,0xFF,0x01,0xC0,0xFF,
0xFF,0x07,0xFC,0x00,0x80,0xFF,0xF1,0x03,0x7C,0x00,0x00,0x7F,0xF8,0x03,0x3C,0x00,
0x00,0x3F,0xFE,0xFF,0x3F,0x00,0x00,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0xFF,0xFF,0xFF,
0x3F,0x00,0x00,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0xFF,0xFF,0xC1,0x1F,0x00,0x00,0xFF,
0xFF,0x01,0x1F,0x00,0x80,0x3F,0xFC,0x00,0x1F,0x00,0x80,0x1F,0xFC,0x00,0x0F,0x00,
0x80,0x0F,0xFC,0xFF,0x0F,0x00,0xC0,0xCF,0xFF,0xFF,0x0F,0x00,0xC0,0xFF,0xFF,0xFF,
0x07,0x00,0xC0,0xFF,0xFF,0xF8,0x03,0x00,0xC0,0xFF,0x7D,0x00,0x00,0x00,0xC0,0x0F,
0x7C,0x00,0x00,0x20,0xC0,0x01,0x7C,0x00,0x00,0x78,0x00,0x00,0x7C,0x00,0x00,0x7E,
0x00,0x00,0xFC,0xFE,0x81,0x3F,0x00,0x00,0xFC,0xFF,0xFF,0x3F,0x00,0x00,0xFC,0xFF,
0xFF,0x3F,0x00,0x00,0xF8,0xFF,0xFF,0x1F,0x00,0x00,0x70,0xF8,0xFF,0x1F,0x00,0x00,
0x00,0x80,0xFF,0x0F,0x00,0x00,0x00,0x00,0xFC,0x07,0x00,0x00,0x00,0x00,0xE0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
},
/*-- 文字: 信 --*/
/*-- 华文隶书36; 此字体下对应的点阵为:宽x高=48x48 --*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xF8,0x01,0x00,0x00,0xC0,0x01,0xF8,0x03,0x00,0x00,0xF8,0x03,0xF0,0x07,0x00,
0xC0,0xFF,0x01,0xF8,0x7F,0x00,0xF8,0xFF,0xE1,0xFF,0xFF,0xFF,0xF0,0xFF,0xFF,0xFF,
0xFF,0x7F,0xF0,0xFF,0xFF,0x0F,0xFE,0x3F,0xF0,0xFF,0x3F,0x00,0xC0,0x1F,0xF0,0x3F,
0x0F,0x00,0x00,0x07,0xE0,0x3F,0x00,0x00,0x00,0x00,0x80,0x1F,0x80,0xFF,0x7F,0x00,
0x00,0x1E,0xF8,0xFF,0xFF,0x01,0x00,0x1E,0xF8,0xFF,0xFF,0x01,0x00,0x1E,0xF0,0x07,
0xFC,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x1E,
0xE0,0xFF,0xFF,0x00,0x00,0x1E,0xFF,0xFF,0xFF,0x07,0x00,0x1E,0xFF,0xFF,0xFF,0x07,
0x00,0x1E,0xFE,0x07,0xFE,0x03,0x00,0x1E,0x3C,0x00,0x00,0x00,0x00,0x1E,0x00,0xFF,
0xFF,0x01,0x00,0x1F,0xF0,0xFF,0xFF,0x03,0x00,0x1F,0xF8,0xFF,0xFF,0x01,0x00,0x0F,
0xF8,0x0F,0xFF,0x01,0x00,0x0F,0xF8,0x00,0xF0,0x01,0x00,0x0F,0xFC,0x00,0xF0,0x00,
0x00,0x0E,0xFC,0xFE,0xFF,0x00,0x00,0x0E,0xFC,0xFF,0xFF,0x01,0x00,0x0E,0xFE,0xFF,
0xFF,0x01,0x00,0x0E,0xFF,0xDF,0xFF,0x01,0x00,0x0E,0x0F,0x00,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
},
/*-- 文字: 2 --*/
/*-- 华文隶书36; 此字体下对应的点阵为:宽x高=21x48 --*/
/*-- 宽度不是8的倍数,现调整为:宽度x高度=24x48 --*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x0F,0x00,0xF8,0x1F,0x00,0xFC,
0x1F,0x00,0x3C,0x1F,0x00,0x1E,0x1E,0x00,0x0F,0x1C,0x00,0x07,0x1C,0x00,0x03,0x1C,
0x00,0x00,0x1C,0x00,0x00,0x1C,0x00,0x00,0x1C,0x00,0x00,0x1E,0x00,0x00,0x1F,0x00,
0x00,0x0F,0x00,0x80,0x07,0x00,0xC0,0x03,0x00,0xE0,0x01,0x00,0xF0,0x00,0x00,0x38,
0x00,0x00,0x1C,0x00,0x00,0x0E,0x00,0x00,0x07,0x10,0x80,0x03,0x18,0xC0,0x01,0x1C,
0xE0,0xC0,0x1F,0xF0,0xFF,0x0F,0xF0,0xFF,0x0F,0xF8,0xFF,0x07,0x70,0xC0,0x07,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
},
/*-- 文字: 1 --*/
/*-- 华文隶书36; 此字体下对应的点阵为:宽x高=21x48 --*/
/*-- 宽度不是8的倍数,现调整为:宽度x高度=24x48 --*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x1C,0x00,0x00,0x1E,0x00,0x80,
0x1F,0x00,0xE0,0x1F,0x00,0xF8,0x0F,0x00,0xFE,0x0F,0x00,0x8E,0x0F,0x00,0x80,0x0F,
0x00,0xC0,0x07,0x00,0xC0,0x07,0x00,0xC0,0x07,0x00,0xC0,0x03,0x00,0xC0,0x03,0x00,
0xE0,0x03,0x00,0xE0,0x03,0x00,0xE0,0x03,0x00,0xF0,0x01,0x00,0xF0,0x01,0x00,0xF0,
0x01,0x00,0xF0,0x01,0x00,0xF8,0x00,0x00,0xF8,0x00,0x00,0xF8,0x00,0x00,0xF8,0x00,
0x00,0xFC,0x00,0x00,0x7C,0x00,0x80,0xFF,0x00,0xE0,0xFF,0x07,0xF0,0xC1,0x07,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
}
};
//背景色数组
int color[3]={0x2D39FC,0x0AFC47,0xFCF30A};
int *plcd = NULL ;
void draw_point(int x,int y,int color)
{
if(x>=0 && x<800 && y>=0 && y<480 )
{
*(plcd+800*y+x) = color ;
}
}
void draw_word(unsigned char word16[],int w,int h,int x0,int y0,int color)
{
int i,j;
for(j=0;j<w*h/8;j++)
{
for(i=0;i <8;i++)
{
if((word16[j]>>i)&0x80 != 0)
{
draw_point(x0+(j*8+i)%w,y0+j/(w/8),color);
}
}
}
}
/*
全屏显示
*/
void clear(int color)
{
int x,y;
for(y=0;y<480;y++)
{
for(x=0;x<800;x++)
{
draw_point(x,y,color);
}
}
}
/*
字体显示
*/
void extd(int color)
{
clear(color);
int i=0;
//i为显示几个汉字
for(i;i<2;i++){
draw_word(hanzi[i],48,48,100+i*48,240,0xff0000);
}
int temp=100+i*48;
/*此处显示汉字后面的数字,为了使数字看起来紧凑而将数字的宽度改变 ,即与数组中数字实际宽度一致,若数字也同为48*48,则draw_word(hanzi[i],48,48,temp+(i-2)*24,240,0xff0000)
*/
for(i;i<4;i++){
draw_word(hanzi[i],24,48,temp+(i-2)*24,240,0xff0000);
}
}
int imp=0;
int main()
{
int fd = open("/dev/fb0",O_RDWR);
plcd = mmap(NULL, 800 * 480 * 4, PROT_READ | PROT_WRITE, MAP_SHARED,fd,0);
extd(0x00FDF1FF);
int touch_fd = open("/dev/input/event0",O_RDONLY);
struct input_event ev;
int x=-1,y=-1;
while(1)
{
while(1)
{
read(touch_fd,&ev,sizeof(ev));
if(ev.type == EV_ABS && ev.code == ABS_X)
{
x = ev.value;
}
if(ev.type == EV_ABS && ev.code == ABS_Y)
{
y = ev.value;
}
if(ev.type == EV_KEY && ev.code == BTN_TOUCH)
{
if(ev.value == 0)
{
break;
}
}
}
//在文本区域周围 点击时会变换背景色
if ((x>140 && x<700) && (y<340 && y>140))
{
if(imp==0){
extd(color[0]);
}
else if(imp==1){
extd(color[1]);
}
else if(imp==2)
{ extd(color[2]);
}
else if(imp>2)
{ extd(0x00FDF1FF);
imp=-1;
//若跳出循环则只能循环一次
//break;
}
imp++;
}
}
close(touch_fd);
close(fd);
munmap(plcd,800*480*4);
return 0;
}
实际展示效果