2024-06-18 21:43:41 +00:00
|
|
|
#include "framebuffer.hpp"
|
2024-06-18 16:09:11 +00:00
|
|
|
#include <unistd.h>
|
2024-06-18 21:43:41 +00:00
|
|
|
#include <signal.h>
|
2024-06-18 16:09:11 +00:00
|
|
|
|
|
|
|
const unsigned int SECOND = 1000000;
|
|
|
|
|
2024-06-18 21:43:41 +00:00
|
|
|
Framebuffer fb{"/dev/fb0"};
|
2024-06-18 16:09:11 +00:00
|
|
|
|
2024-06-18 21:43:41 +00:00
|
|
|
void exitHandler(int s) {
|
|
|
|
printf("Caught signal %d\n", s);
|
|
|
|
fb.done();
|
|
|
|
exit(-1);
|
2024-06-18 16:09:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2024-06-18 21:43:41 +00:00
|
|
|
if(fb.init() != 0) return -1;
|
2024-06-18 16:09:11 +00:00
|
|
|
|
2024-06-18 21:43:41 +00:00
|
|
|
struct sigaction sigIntHandler;
|
2024-06-18 16:09:11 +00:00
|
|
|
|
2024-06-18 21:43:41 +00:00
|
|
|
sigIntHandler.sa_handler = exitHandler;
|
|
|
|
sigemptyset(&sigIntHandler.sa_mask);
|
|
|
|
sigIntHandler.sa_flags = 0;
|
|
|
|
sigaction(SIGINT, &sigIntHandler, NULL);
|
2024-06-18 16:09:11 +00:00
|
|
|
|
|
|
|
int counter = 0;
|
|
|
|
while(true) {
|
2024-06-18 21:43:41 +00:00
|
|
|
unsigned int color = (counter == 0) ? COLOR_RED :
|
|
|
|
((counter == 1) ? COLOR_GREEN : COLOR_BLUE);
|
|
|
|
|
|
|
|
int success = fb.clear(color);
|
|
|
|
|
|
|
|
if(success != 0) {
|
|
|
|
fb.done();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-06-18 16:09:11 +00:00
|
|
|
if(counter < 2)
|
|
|
|
counter++;
|
|
|
|
else
|
|
|
|
counter = 0;
|
2024-06-18 21:43:41 +00:00
|
|
|
|
2024-06-18 16:09:11 +00:00
|
|
|
usleep(SECOND);
|
|
|
|
}
|
|
|
|
|
2024-06-18 21:43:41 +00:00
|
|
|
fb.done();
|
2024-06-18 16:09:11 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|