From d4e78ec6c4aa7d82f85fb9a0473a86f6977def1f Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 27 Mar 2020 16:56:34 +0200 Subject: [PATCH] Add video demo --- Makefile | 3 +- core/bin/video.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 core/bin/video.c diff --git a/Makefile b/Makefile index a9a6235..e5d0784 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,8 @@ STAGE_BIN=$(STAGE)/init \ $(STAGE)/bin/mkdir \ $(STAGE)/bin/netctl \ $(STAGE)/bin/netmeow \ - $(STAGE)/bin/netdump + $(STAGE)/bin/netdump \ + $(STAGE)/bin/video # $(STAGE)/bin/com \ # $(STAGE)/bin/ase \ diff --git a/core/bin/video.c b/core/bin/video.c new file mode 100644 index 0000000..ee25cda --- /dev/null +++ b/core/bin/video.c @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int running = 1; + +static void signal_handler(int signum) { + running = 0; +} + +int main(int argc, char **argv) { + struct ioc_vmode mode; + int fd = open("/dev/fb0", O_RDONLY, 0); + if (fd < 0) { + perror("open()"); + return -1; + } + + if (ioctl(fd, IOC_GETVMODE, &mode) != 0) { + perror("ioctl()"); + goto end; + } + + signal(SIGINT, signal_handler); + + printf("Video mode: %dx%d\n", mode.width, mode.height); + + size_t size = mode.width * mode.height * 4; + size = (size + 0xFFF) & ~0xFFF; + printf("%u bytes\n", size); + + printf("You can exit by pressing ^C\n"); + printf("Starting video in 3 secs\n"); + usleep(3000000); + + int no = 0; + if (ioctl(fd, IOC_FBCON, &no) != 0) { + perror("ioctl()"); + goto end; + } + + uint32_t *data = mmap(NULL, size, 0, MAP_PRIVATE, fd, 0); + assert(data); + + struct timeval tv; + int c = 0; + int s = 0; + + while (running) { + usleep(10000); + gettimeofday(&tv, NULL); + if (s == 0) { + c += 2; + } else { + c -= 2; + } + if (c < 0) { + s = 0; + c = 0; + } else if (c >= 256) { + s = 1; + c = 255; + } + memset(data, c, size); + } + + munmap(data, size); + no = 1; + if (ioctl(fd, IOC_FBCON, &no) != 0) { + perror("ioctl()"); + goto end; + } + puts2("\033[2J\033[1;1f"); + printf("Goodbye\n"); +end: + close(fd); + + return 0; +}