-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
55 lines (43 loc) · 1.38 KB
/
main.cpp
File metadata and controls
55 lines (43 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <string>
#include <fcntl.h>
#include <unistd.h>
#include <chrono>
#include "device.h"
#include "graphics.h"
void demo_colourChangingScreen(Device& device, ScreenInfo& info) {
for (unsigned int i = 0; i < 256; i++) {
Pixel pixel = createPixel(info, 255-i, i, 255-i, 255);
fillRectangle(device, pixel, 0, 0, device.getWidth() - 1, device.getHeight() - 1);
device.renderBuffer();
}
}
void demo_gradualScreenFill(Device& device, ScreenInfo& info) {
Pixel pixel = createPixel(info, 255, 255, 255, 255);
for (int x = 0; x < device.getWidth(); x++) {
drawVerticalLine(device, pixel, x, 0, device.getHeight() - 1);
device.renderBuffer();
usleep(3000);
}
}
int main() {
hideConsoleCursor();
const char* devicePath = "/dev/fb0";
int fd = open(devicePath, O_RDWR);
ScreenInfo info{getScreenInfo(fd)};
activateScreen(fd, info);
Device device{info, std::string(devicePath)};
device.mapToMemory();
auto begin = std::chrono::high_resolution_clock::now();
demo_colourChangingScreen(device, info);
demo_gradualScreenFill(device, info);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
printf("Time measured: %.3f seconds.\n", elapsed.count() * 1e-9);
device.blankBuffer();
device.renderBuffer();
device.unmapFromMemory();
close(fd);
showConsoleCursor();
return 0;
}