📄 init_cursor.c
字号:
#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <fcntl.h>#include <unistd.h>#include <string.h>#include <sys/ioctl.h>#include <sys/mman.h>#include <asm/page.h>#include <linux/fb.h>#include <time.h>#include <sys/time.h>#include "davinci_fb.h"#undef DBG#define DBG(x,...)struct Cursor_Info{ int xp; int yp; int xl; int yl;};#define FBIO_MOVECURSOR _IOW('F', 0x24, struct Cursor_Info)enum {xlmax = 128};enum {ylmax = 64};enum {xpmax = 720 - xlmax};enum {ypmax = 480 - ylmax};int get_random(int maxvalue){ float ret; int randnum; struct timeval tv; gettimeofday(&tv, NULL); srandom(tv.tv_usec + maxvalue); randnum = random(); ret = 1 + (unsigned char) ((float)maxvalue * (float)randnum / (float)(RAND_MAX + 1.0)); DBG("randnum[%d]: %d -> %d\n", maxvalue, randnum, (int)ret); return (int)ret;}int init_cursor(int xp, int yp, int xl, int yl, int random){ int fd; struct Cursor_Info cur_; if(!random) { cur_.xp = xp; cur_.yp = yp; cur_.xl = xl; cur_.yl = yl; } else { cur_.xp = get_random(xpmax / 16) * 16; cur_.yp = get_random(ypmax / 16) * 16; cur_.xl = get_random(xlmax / 16) * 16; cur_.yl = get_random(ylmax / 16) * 16; } DBG("Cursor: (%d, %d) [%d, %d]\n", cur_.xp, cur_.yp, cur_.xl, cur_.yl); fd = open(OSD_DEVICE, O_RDWR); if (fd == -1) { ERR("Failed to open fb device %s (%s)\n", strerror(errno)); return FAILURE; } if (ioctl(fd, FBIO_MOVECURSOR, &cur_) == -1) { ERR("Failed to set cursor info.\n"); return FAILURE; } return SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -