Ejemplo n.º 1
0
int main(int argc, char **argv)
{
	int fd;
	__u32 mode;
	lirc_t data;
	lirc_t x1, y1, x2, y2;
	int result;
	int c = 10;
	char textbuffer[80];
	int div = 5;
	char *device = LIRC_DRIVER_DEVICE;
	char *progname;
	struct stat s;

	progname = "smode2";
	while (1) {
		int c;
		static struct option long_options[] = {
			{"help", no_argument, NULL, 'h'},
			{"version", no_argument, NULL, 'v'},
			{"device", required_argument, NULL, 'd'},
			{"timediv", required_argument, NULL, 't'},
			{0, 0, 0, 0}
		};
		c = getopt_long(argc, argv, "hvd:t:", long_options, NULL);
		if (c == -1)
			break;
		switch (c) {
		case 'h':
			printf("Usage: %s [options]\n", progname);
			printf("\t -h --help\t\tdisplay usage summary\n");
			printf("\t -v --version\t\tdisplay version\n");
			printf("\t -d --device=device\tread from given device\n");
			printf("\t -t --timediv=value\tms per unit\n");
			return (EXIT_SUCCESS);
		case 'v':
			printf("%s %s\n", progname, VERSION);
			return (EXIT_SUCCESS);
		case 'd':
			device = optarg;
			break;
		case 't':	/* timediv */
			div = strtol(optarg, NULL, 10);
			break;
		default:
			printf("Usage: %s [options]\n", progname);
			return (EXIT_FAILURE);
		}
	}
	if (optind < argc - 1) {
		fprintf(stderr, "%s: too many arguments\n", progname);
		return (EXIT_FAILURE);
	}

	fd = open(device, O_RDONLY);
	if (fd == -1) {
		perror(progname);
		fprintf(stderr, "%s: error opening %s\n", progname, device);
		exit(EXIT_FAILURE);
	};
	if ((fstat(fd, &s) != -1) && (S_ISFIFO(s.st_mode))) {
		/* can't do ioctls on a pipe */
	} else if (ioctl(fd, LIRC_GET_REC_MODE, &mode) == -1 || mode != LIRC_MODE_MODE2) {
		printf("This program is only intended for receivers supporting the pulse/space layer.\n");
		printf("Note that this is no error, but this program simply makes no sense for your\nreceiver.\n");
		printf("In order to test your setup run lircd with the "
		       "--nodaemon option and \n" "then check if the remote works with the irw tool.\n");
		close(fd);
		exit(EXIT_FAILURE);
	}

	initscreen();

	y1 = 20;
	x1 = x2 = 0;
	for (y2 = 0; y2 < 640; y2 += 20)
		gl_line(y2, 0, y2, 480, 1);
	sprintf(textbuffer, "%d ms/unit", div);
	gl_write(500, 10, textbuffer);
	gl_copyscreen(physicalscreen);

	while (1) {
		result = read(fd, &data, sizeof(data));
		if (result == sizeof(data)) {
//                  printf("%.8lx\t",(unsigned long) data);
			x2 = (data & PULSE_MASK) / (div * 50);
			if (x2 > 400) {
				y1 += 15;
				x1 = 0;
				gl_copyscreen(physicalscreen);
			} else {
				if (x1 < 640) {
					gl_line(x1, ((data & PULSE_BIT) ? y1 : y1 + 10), x1 + x2,
						((data & PULSE_BIT) ? y1 : y1 + 10), c);
					x1 += x2;
					gl_line(x1, ((data & PULSE_BIT) ? y1 : y1 + 10), x1,
						((data & PULSE_BIT) ? y1 + 10 : y1), c);
				}
			}
			if (y1 > 480) {
				y1 = 20;
				gl_clearscreen(0);
				for (y2 = 0; y2 < 640; y2 += 10)
					gl_line(y2, 0, y2, 480, 1);
				gl_write(500, 10, textbuffer);
			}
		}
//              gl_copyscreen(physicalscreen);
	};
	closescreen();
	exit(EXIT_SUCCESS);
}
void main(void)
{
    struct timeval timeout;
    fd_set inputs;
    char bitmap[16 * 16 * 4];	/* big enough for 10x10 bitmap in any mode */
    int vgamode, color, pipefd[2], x, y, button, event, cursorsize = 5;
    char loop = 1, drawcursor = 1;
#ifdef USE_RAWKEYBOARD
    char space_pressed = 0;
#endif

    puts("This is a demo showing the abilities of the new vga_waitevent() function\n"
	 "If something goes wrong it might hang your machine. Thus hit <ctrl>-C now\n"
	 "to bailout if in doubt.\n"
	 "Use mouse to move cursor. 1-9,0 to set the cursor size. Space to change the\n"
    "cursor color. Left button to draw. Right button or 'Q' to bailout.\n"
	 "The cursor goes on/off every half second by usage of a timeout passed to\n"
	 "vga_waitevent. Every 5 secs a string from a child process (the time) arrives\n"
	 "asynchronously and is displayed by the frontend.");
#ifdef USE_RAWKEYBOARD
    puts("\nBEWARE! This has been compiled to use the raw keyboard. A crash might\n"
	 "render the console unusable. (but shouldn't).");
#endif
    fputs("\nHit <Enter> if brave enough, else ^C to bailout: ", stdout);
    fflush(stdout);
    getchar();
    fflush(stdin);		/* clear I/O buffer */

    pipe(pipefd);
    if (fork() == 0) {		/* fork off b4 touching graphix to avoid side effects */
	close(pipefd[0]);	/* Important: close reading side, else it remains     */
	/* opened by child when parent exits and we don't get */
	/* a SIGPIPE!                                         */
	child(pipefd[1]);
    }
    vga_init();
    vgamode = vga_getdefaultmode();
    if (vgamode == -1)
	vgamode = G320x200x256;

    if (!vga_hasmode(vgamode)) {
	printf("Mode not available.\n");
	exit(-1);
    }
    /* Enable automatic mouse setup at mode set. */
    vga_setmousesupport(1);
    vga_setmode(vgamode);
    /* Disable wrapping (default). */
    /* mouse_setwrap(MOUSE_NOWRAP); */
    gl_setcontextvga(vgamode);
    gl_enableclipping();

    /* There might be some scrap data in the serial buffer
       from the mouse. It will make vga_waitevent block
       because it thinks the mouse wants to send data but
       then no mouse packet arrives. */
    color = newcolor();
    x = 0;
    y = 0;
    gl_setwritemode(WRITEMODE_OVERWRITE | FONT_COMPRESSED);
    gl_setfont(8, 8, gl_font8x8);
    gl_setfontcolors(0, newcolor());

#ifdef USE_RAWKEYBOARD
    if (keyboard_init()) {
	printf("Could not initialize keyboard.\n");
	exit(1);
    }
#endif

    while (loop) {
	gl_getbox(x, y, 10, 10, bitmap);
	if (drawcursor) {
	    gl_hline(x, y, x + cursorsize, color);
	    gl_hline(x, y + cursorsize, x + cursorsize, color);
	    gl_line(x, y, x, y + cursorsize, color);
	    gl_line(x + cursorsize, y, x + cursorsize, y + cursorsize, color);
	}
	FD_ZERO(&inputs);
	FD_SET(pipefd[0], &inputs);
	timeout.tv_sec = 0;
	timeout.tv_usec = 500000;	/* 0.5 second time out */
	event = vga_waitevent(VGA_MOUSEEVENT | VGA_KEYEVENT,
			      &inputs, NULL, NULL, &timeout);
	gl_putbox(x, y, 10, 10, bitmap);
	if (timeout.tv_sec || timeout.tv_usec) {
	    /* No timeout. An actual event occured. Reset to visible
	       cursor. Note:
	       This is actually a bug as the cursor will get visible on time
	       updates. However, it's better this way for demo/test
	       purposes. */
	    drawcursor = 1;
	} else {
	    drawcursor ^= 1;
	}
	if (FD_ISSET(pipefd[0], &inputs))
	    process_input(pipefd[0]);
	if (event & VGA_MOUSEEVENT) {
	    x = mouse_getx();
	    y = mouse_gety();
	    button = mouse_getbutton();
	    if (button & MOUSE_LEFTBUTTON)
		gl_fillbox(x, y, cursorsize + 1, cursorsize + 1, color);
	    if (button & MOUSE_RIGHTBUTTON)
		loop = 0;
	}
	if (event & VGA_KEYEVENT) {
#ifdef USE_RAWKEYBOARD
	    if (keyboard_keypressed(SCANCODE_1))
		cursorsize = 0;
	    if (keyboard_keypressed(SCANCODE_2))
		cursorsize = 1;
	    if (keyboard_keypressed(SCANCODE_3))
		cursorsize = 2;
	    if (keyboard_keypressed(SCANCODE_4))
		cursorsize = 3;
	    if (keyboard_keypressed(SCANCODE_5))
		cursorsize = 4;
	    if (keyboard_keypressed(SCANCODE_6))
		cursorsize = 5;
	    if (keyboard_keypressed(SCANCODE_7))
		cursorsize = 6;
	    if (keyboard_keypressed(SCANCODE_8))
		cursorsize = 7;
	    if (keyboard_keypressed(SCANCODE_9))
		cursorsize = 8;
	    if (keyboard_keypressed(SCANCODE_0))
		cursorsize = 9;
	    if (keyboard_keypressed(SCANCODE_Q))
		loop = 0;
	    if (keyboard_keypressed(SCANCODE_SPACE)) {
		if (!space_pressed) {
		    color = newcolor();
		    space_pressed = 1;
		}
	    } else {
		space_pressed = 0;
	    }
#else
	    switch (vga_getch()) {
	    case '1':
		cursorsize = 0;
		break;
	    case '2':
		cursorsize = 1;
		break;
	    case '3':
		cursorsize = 2;
		break;
	    case '4':
		cursorsize = 3;
		break;
	    case '5':
		cursorsize = 4;
		break;
	    case '6':
		cursorsize = 5;
		break;
	    case '7':
		cursorsize = 6;
		break;
	    case '8':
		cursorsize = 7;
		break;
	    case '9':
		cursorsize = 8;
		break;
	    case '0':
		cursorsize = 9;
		break;
	    case ' ':
		color = newcolor();
		break;
	    case 'q':
	    case 'Q':
		loop = 0;
		break;
	    default:
		ping();
		break;
	    }
#endif
	}
    }

#ifdef USE_RAWKEYBOARD
    keyboard_close();		/* Don't forget this! */
#endif
    vga_setmode(TEXT);
    exit(0);
}
Ejemplo n.º 3
0
void test(void)
{
    int i, j;
    unsigned char *bitmap;
    GraphicsContext *savedcontext;

    if (VIRTUAL)
	gl_setcontext(backscreen);

    gl_clearscreen(0);
    for (i = 0; i < 5; i++) {
	gl_clearscreen(0);
	for (j = 0; j < 20000; j++)
	    gl_setpixel(random() % WIDTH, random() % HEIGHT,
			random() % COLORS);
    }

    if (VIRTUAL)
	gl_copyscreen(physicalscreen);

    gl_clearscreen(0);
    for (i = 0; i < 5000; i++) {
	int x, y;
	x = random() % (WIDTH - 1);
	y = random() % (HEIGHT - 1);
	gl_fillbox(x, y, random() % (WIDTH - x), random()
		   % (HEIGHT - y), random() % COLORS);
    }

    if (VIRTUAL)
	gl_copyscreen(physicalscreen);

    gl_clearscreen(0);
    for (i = 0; i < 4000; i++)
	gl_line(random() % WIDTH, random() % HEIGHT,
		random() % WIDTH, random() % HEIGHT,
		random() % COLORS);

    if (VIRTUAL)
	gl_copyscreen(physicalscreen);

    /* Create bitmap. */
    bitmap = malloc(64 * 64 * BYTESPERPIXEL);
    /* Create temporary graphics context to create bitmap in. */
    savedcontext = gl_allocatecontext();
    gl_getcontext(savedcontext);
    gl_setcontextvirtual(64, 64, BYTESPERPIXEL, BITSPERPIXEL, bitmap);
    /* The rgb functions can be used to create nice bitmaps easily for */
    /* hicolor/truecolor modes. The 256 color 'emulated' truecolor */
    /* looks less impressive. */
    for (i = 0; i < 32; i++)
	for (j = 0; j < 32; j++) {
	    int c;
	    c = 255 - (i + j) * 4;
	    gl_setpixelrgb(31 - i, 31 - j, c, 0, 0);
	    gl_setpixelrgb(32 + i, 31 - j, c, c, 0);
	    gl_setpixelrgb(31 - i, 32 + j, c, 0, c);
	    gl_setpixelrgb(32 + i, 32 + j, c, c, c);
	}
    /* Restore previous context. */
    gl_setcontext(savedcontext);

    gl_clearscreen(0);
    for (i = 0; i < 4000; i++) {
	int x, y;
	x = random() % (WIDTH - 64 + 1);
	y = random() % (HEIGHT - 64 + 1);
	gl_putbox(x, y, 64, 64, bitmap);
    }

    free(bitmap);

    if (VIRTUAL)
	gl_copyscreen(physicalscreen);
}