/* User space interface to LCD driver */
/* Steven J. Merrifield, July 2005 */

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "lcd.h"

int lcdfd;	/* LCD file descriptor */

/************************************************************/ 
void LCDWriteStr(char *s)
{
	static struct lcd_display display;
	strcpy(display.str,s);
	if (ioctl(lcdfd, LCD_String, &display) != 0)
		printf("ioctl LCD_String failed -  %s\n",strerror(errno));
}

/************************************************************/ 
void LCDClrScr()
{
	if (ioctl(lcdfd, LCD_Clear, 0) != 0)
		printf("ioctl LCD_Clear failed -  %s\n",strerror(errno));
}

/************************************************************/ 
void LCDLine(int i)
{
	if (ioctl(lcdfd, LCD_Line, i) != 0)
		printf("ioctl LCD_Line failed -  %s\n",strerror(errno));
}

/************************************************************/ 
/* Returns 1 if the button was pressed, 0 if not pressed */
int CheckButton(void)
{
	struct lcd_display display;
	if (ioctl(lcdfd, LCD_Button, &display) != 0)
		printf("ioctl LCD_Button failed -  %s\n",strerror(errno));
	return(display.button);
}


