⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fb.c

📁 在字符终端显示时钟 fb
💻 C
字号:
#include <unistd.h>#include <stdio.h>#include <fcntl.h>#include <assert.h>#include <linux/fb.h>#include <sys/mman.h>#include "fb.h"#include "fbnum.h"int fb_fd = 0;int max_text_line, max_text_row;struct fb_var_screeninfo fb_vsinfo;struct fb_fix_screeninfo fb_fsinfo;long int fb_scrsize = 0;char *fb_mp = 0;fb_color_t fb_text_color = {255, 255, 255, 0};fb_color_t fb_back_color = {0, 0, 0, 0};voidfb_open(){	/* Open the file for reading and writing */	fb_fd = open ("/dev/fb0", O_RDWR);	if (!fb_fd)	{		 printf ("Error: cannot open framebuffer device.\n");		 exit (1);	}	printf ("The framebuffer device was opened successfully.\n");	/* Get fixed screen information */	if (ioctl (fb_fd, FBIOGET_FSCREENINFO, &fb_fsinfo))	{		 printf ("Error reading fixed information.\n");		 exit (2);	}	/* Get variable screen information */	if (ioctl (fb_fd, FBIOGET_VSCREENINFO, &fb_vsinfo))	{		 printf ("Error reading variable information.\n");		 exit (3);	}	/* Figure out the size of the screen in bytes */	fb_scrsize = fb_vsinfo.xres * fb_vsinfo.yres * fb_vsinfo.bits_per_pixel / 8;	/* Map the device to memory */	fb_mp = (char *) mmap (0, fb_scrsize, PROT_READ | PROT_WRITE, MAP_SHARED,			    fb_fd, 0);	if ((int) fb_mp == -1)	{		 printf ("Error: failed to map framebuffer device to memory.\n");		 exit (4);	}	printf ("The framebuffer device was mapped to memory successfully.\n");	/* Count the max line and row of texts */	max_text_line = fb_vsinfo.yres / NUM_HEIGHT;	max_text_row = fb_vsinfo.xres / NUM_WIDTH;	return;}voidfb_close(){	munmap (fb_mp, fb_scrsize);	close (fb_fd);	return;}voidfb_pixel(int x, int y, fb_color_t *color){	long location = 0;	assert(color != NULL);	/* Figure out where in memory to put the pixel */	location = (x + fb_vsinfo.xoffset) * (fb_vsinfo.bits_per_pixel / 8) +	  (y + fb_vsinfo.yoffset) * fb_fsinfo.line_length;	*(fb_mp + location + 3) = color->t; /* If transparency */	*(fb_mp + location + 2) = color->r; /* Red */	*(fb_mp + location + 1) = color->g; /* Green */	*(fb_mp + location) = color->b;     /* Blue */	return;}voidfb_set_text_color(fb_color_t *color){	memcpy(&fb_text_color, color, sizeof(fb_color_t));	return;	}voidfb_set_back_color(fb_color_t *color){	memcpy(&fb_back_color, color, sizeof(fb_color_t));	return;	}static voiddraw_char(int x, int y, const char *led_set){	int i, j;	for (i=0; i<NUM_WIDTH; i++)	{		for (j=0; j<NUM_HEIGHT; j++)		{			if (strchr(led_set, num_map[j][i]))				fb_pixel(x+i, y+j, &fb_text_color);			else				fb_pixel(x+i, y+j, &fb_back_color);		}	}	return;}intfb_putc(int x, int y, char c){	int i;	int pixel_x = x * NUM_WIDTH;	int pixel_y = y * NUM_HEIGHT;	for (i=0; num_table[i]; i++)	{		if (*num_table[i] == c)		{			draw_char(pixel_x, pixel_y, num_table[i]+1);			break;		}	}		if (num_table[i])		return (int)c;	else	{		printf("fb_putc: no font infomation for '%c'.\n", c);		return -1;	}}intfb_puts(int x, int y, const char *str){	int i;	int ret = 0;	assert(str);	for (i=0; str[i]; i++, x++)		if (fb_putc(x, y, str[i]) == -1)			ret = -1;	if (ret = -1)		return ret;	else		return i;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -