This file contains the beginnings of a "library" (not in the true
sense) of functions to be used by drivers. Things like freeing a framebuffer, creating a frame buffer, andding characters or strings to a framebuffer, et al, are here...
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/errno.h>
|
||||
#include "lcd.h"
|
||||
|
||||
// ==================================================
|
||||
// LCD library of useful functions for drivers
|
||||
// ==================================================
|
||||
|
||||
// Drawn from the "base driver" which really was the precursor
|
||||
// to this library....
|
||||
|
||||
void
|
||||
free_framebuf (struct lcd_logical_driver *driver) {
|
||||
if (!driver)
|
||||
return;
|
||||
|
||||
if (driver->framebuf != NULL)
|
||||
free (driver->framebuf);
|
||||
|
||||
driver->framebuf = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
clear_framebuf (struct lcd_logical_driver *driver) {
|
||||
int framebuf_size;
|
||||
|
||||
if (!driver)
|
||||
return;
|
||||
|
||||
framebuf_size = driver->wid * driver->hgt;
|
||||
memset (driver->framebuf, ' ', framebuf_size);
|
||||
}
|
||||
|
||||
int
|
||||
new_framebuf (struct lcd_logical_driver *driver, char *oldbuf) {
|
||||
if (driver->framebuf == NULL)
|
||||
return 1;
|
||||
if (oldbuf == NULL)
|
||||
return 1;
|
||||
return (strncpy(driver->framebuf, oldbuf, driver->wid * driver->hgt) != 0);
|
||||
}
|
||||
|
||||
void
|
||||
insert_str_framebuf (struct lcd_logical_driver *driver, int x, int y, char *string) {
|
||||
int i;
|
||||
char buf[64];
|
||||
char *pos;
|
||||
|
||||
if (!driver)
|
||||
return;
|
||||
|
||||
x--; y--; // convert to zero-indexing
|
||||
|
||||
if (x >= driver->wid) return;
|
||||
if (x < 0) x = 0;
|
||||
|
||||
if (y >= driver->hgt) y = driver->hgt;
|
||||
if (y < 0) y = 0;
|
||||
|
||||
if ((x + strlen(string)) > driver->wid)
|
||||
strncpy(buf, string, driver->wid - x - 1);
|
||||
else
|
||||
strncpy(buf, string, sizeof(string));
|
||||
|
||||
pos = (driver->framebuf + (y * driver->wid) + x);
|
||||
strcpy(pos, buf);
|
||||
}
|
||||
|
||||
void
|
||||
insert_chr_framebuf (struct lcd_logical_driver *driver, int x, int y, char c) {
|
||||
if (!driver)
|
||||
return;
|
||||
|
||||
x--; y--;
|
||||
|
||||
if (x >= driver->wid) driver->wid;
|
||||
if (x < 0) x = 0;
|
||||
|
||||
if (y >= driver->hgt) y = driver->hgt;
|
||||
if (y < 0) y = 0;
|
||||
|
||||
driver->framebuf[(y * driver->wid) + x] = c;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user