/* liblcd.h ----------------------------------------------------------
   Copyright 1999, 2000 by Nathan Anderson, ALL RIGHTS RESERVED
   See the comments in liblcd.c for more information about your rights
   under the license that this code has been placed under.             */

#ifndef LIBLCD_H
# define LIBLCD_H

# include <fcntl.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <termios.h>
# include <unistd.h>

/* supported serial LCD protocols */
# define TERMINAL 1
# define BACKPACK 2
# define FRSTTYPE 1
# define LASTTYPE 2

/* constants */
# define ON    1
# define OFF   0
# define BLACK 1
# define WHITE 0
# define SMALL 0
# define WIDE  1
# define TALL  2
# define LARGE 3
# define ROW1  1
# define ROW2  2
# define ROW3  4
# define ROW4  8

/* init possible settings */
# define BACKLIGHT  1
# define INVERSETXT 2
# define CLEARSCR   4
# define CURS_ULINE 8
# define CURS_BLOCK 16
# define CURS_NONE  32

typedef struct termios termios;

/* error codes */
# define NUM_ERR   9

# define ELCDBAUD  1
# define ELCDOPEN  2
# define ELCDNOPN  3
# define ELCDNINI  4
# define ELCDINIT  5
# define ELCDWRIT  6
# define ELCDVOOB  7
# define ELCDTYPE  8
# define ELCDUNSP  9
# define ELCDFAKE 10

/* status codes */
# define SLCDOPEN 1 /* port has been opened */
# define SLCDINIT 2 /* LCD has been init'd */

# ifdef LIBLCD_C

#  define BUFSIZE 255

const int _liblcd_majorv = 1;
const int _liblcd_minorv = 1;
const int _liblcd_revv   = 0;

const char * err_str[ NUM_ERR + 1 ] =
{
  "speed set fail",               /* ELCDBAUD */
  "open port fail",               /* ELCDOPEN */
  "LCD port not open fail",       /* ELCDNOPN */
  "LCD not initialized fail",     /* ELCDNINI */
  "initialization fail",          /* ELCDINIT */
  "write to port fail",           /* ELCDWRIT */
  "values out-of-bounds fail",    /* ELCDLPOS */
  "unknown LCD type fail",        /* ELCDTYPE */
  "unsupported by this hardware", /* ELCDUNSP */
  "undefined failure"             /* ELCDFAKE */
};

int     lcd_type = TERMINAL;
int     status   = 0;
int     fd_com;
termios oldtio;
char    buf[ BUFSIZE + 1 ];

# endif

/* LCD port control functions */
int lcd_open( const char *, const speed_t, int );
int liblcd_init( char );
# ifndef LCDPROC_DRIVER
#  define lcd_init liblcd_init
# endif
int lcd_reopen( const char * );
int lcd_close( );
int lcd_err( int, const char * );

/* LCD text manipulation functions */
int lcd_clear( );
int lcd_gotoxy( int, int );
int lcd_write( const char * );
int lcd_flush( );

/* LCD feature control functions */
int lcd_backlight( int );
int lcd_inversetxt( int );
int lcd_textsize( int );

/* LCD graphics manipulation functions */
int lcd_g_setcolor( int );
int lcd_g_loadimg( int );
int lcd_g_drawline( int, int, int, int );
int lcd_g_drawbox( int, int, int, int );
int lcd_g_plotdot( int, int );
int lcd_g_revline( int );

#endif
