fb-dash/fbdash.c

101 lines
2.3 KiB
C

/*
* fbdash.c
*
* Adapted by Florian Klemenz for use in the fb_dash project
*
* Source and all credit goes to
* http://raspberrycompote.blogspot.com/
* --------------------------------------------------------------------------------------------
*
* http://raspberrycompote.blogspot.ie/2014/03/low-level-graphics-on-raspberry-pi-part_14.html
*
* Original work by J-P Rosti (a.k.a -rst- and 'Raspberry Compote')
*
* Licensed under the Creative Commons Attribution 3.0 Unported License
* (http://creativecommons.org/licenses/by/3.0/deed.en_US)
*
* Distributed in the hope that this will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include "fblib.h"
#define WIDTH 240
#define HEIGHT 320
char *fbp = 0;
void draw() {
clear_screen(fbp);
// horizontal spacersint x_space = 10;
int y_step_width = HEIGHT / 4;
for (int i = 1; i < 4; i++) {
int x0 = 15;
int x1 = WIDTH - x0;
int y = y_step_width * i;
int r = 225;
int g = 32;
int b = 32;
draw_line(fbp, x0, y-1, x1, y-1, r, g, b);
draw_line(fbp, x0, y , x1, y , r, g, b);
draw_line(fbp, x0, y+1, x1, y+1, r, g, b);
}
char *text = "Hell O_o!";
render_string(fbp, ubuntu_mono_48, text, 15, 0, 255, 255, 255);
render_string(fbp, ubuntu_mono_24, text, 15, 50, 255, 255, 255);
render_string(fbp, basic_8, text, 15, 100, 255, 255, 255);
}
// application entry point
int main(int argc, char* argv[])
{
int fbfd = 0;
long int screensize = 0;
// Open the framebuffer file for reading and writing
fbfd = open("/dev/fb1", O_RDWR);
if (fbfd == -1) {
printf("Error: cannot open framebuffer device.\n");
return(1);
}
printf("The framebuffer device was opened successfully.\n");
// map fb to user mem
screensize = WIDTH*HEIGHT*2;
fbp = (char*)mmap(0,
screensize,
PROT_READ | PROT_WRITE,
MAP_SHARED,
fbfd,
0);
if ((int)fbp == -1) {
printf("Failed to mmap.\n");
}
else {
// draw...
draw();
}
// cleanup
//clear_screen(fbp);
munmap(fbp, screensize);
close(fbfd);
return 0;
}