brewpanel/slcd.c

changeset 412
f1a042a59b61
child 415
d9b7e0705f56
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/brewpanel/slcd.c	Sun Nov 08 17:49:29 2015 +0100
@@ -0,0 +1,251 @@
+/*****************************************************************************
+ * Copyright (C) 2015
+ *   
+ * Michiel Broek <mbroek at mbse dot eu>
+ *
+ * This file is part of the mbsePi-apps
+ *
+ * mbsePi-apps is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * mbsePi-apps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with mbsePi-apps; see the file COPYING.  If not, write to the Free
+ * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *****************************************************************************/
+
+/*
+ * Simulated LCD driver based on HD44780U displays.
+ */
+
+#include "brewpanel.h"
+#include "slcd.h"
+#include "sdlgui.h"
+
+
+#ifdef HAVE_SDL_SDL_H
+
+// HD44780U Commands
+
+#define SLCD_CLEAR       0x01
+#define SLCD_HOME        0x02
+#define SLCD_ENTRY       0x04
+#define SLCD_CTRL        0x08
+#define SLCD_CDSHIFT     0x10
+#define SLCD_FUNC        0x20
+#define SLCD_CGRAM       0x40
+#define SLCD_DGRAM       0x80
+
+// // Bits in the entry register
+//
+// #define LCD_ENTRY_SH            0x01
+// #define LCD_ENTRY_ID            0x02
+//
+// // Bits in the control register
+//
+// #define LCD_BLINK_CTRL          0x01
+// #define LCD_CURSOR_CTRL         0x02
+// #define LCD_DISPLAY_CTRL        0x04
+
+
+struct slcdDataStruct
+{
+    int 	x;		/* Start x pixels		*/
+    int		y;		/* Start y pixels		*/
+    int		w;		/* Width in pixels		*/
+    int		h;		/* Height in pixels		*/
+    int		cols;		/* Width in characters		*/
+    int		rows;		/* Height in characters		*/
+    int		cx;		/* Cursor x position		*/
+    int		cy;		/* Cursor y position		*/
+    Uint8	cgram[8][8];	/* Characters in CGRAM		*/
+};
+struct slcdDataStruct *slcds [MAX_SLCDS] ;
+
+
+/* Low level */
+
+void sendDataCmd (struct slcdDataStruct *slcd, unsigned char data)
+{
+}
+
+
+void putCommand (struct slcdDataStruct *slcd, unsigned char command)
+{
+}
+
+
+
+void slcdHome(int fd)
+{
+    struct slcdDataStruct *lcd = slcds [fd];
+
+    lcd->cx = lcd->cy = 0;
+}
+
+
+
+void slcdClear(int fd)
+{
+    struct slcdDataStruct *lcd = slcds [fd];
+
+    lcd->cx = lcd->cy = 0;
+}
+
+
+
+void slcdDisplay(int fd, int state)
+{
+}
+
+
+
+void slcdCursor(int fd, int state)
+{
+}
+
+
+
+void slcdCursorBlink(int fd, int state)
+{
+}
+
+
+
+void slcdSendCommand(int fd, Uint8 command)
+{
+}
+
+
+
+void slcdPosition(int fd, int x, int y)
+{
+    struct slcdDataStruct *lcd = slcds [fd];
+
+    if ((x > lcd->cols) || (x < 0))
+	return ;
+    if ((y > lcd->rows) || (y < 0))
+	return ;
+
+    // putCommand (lcd, x + (LCD_DGRAM | rowOff [y])) ;
+
+    lcd->cx = x ;
+    lcd->cy = y ;
+}
+
+
+
+void slcdCharDef(int fd, int index, Uint8 data[8])
+{
+    struct slcdDataStruct *lcd = slcds [fd];
+    int i;
+
+    for (i = 0 ; i < 8 ; i++)
+	lcd->cgram[index][i] = data[i];
+}
+
+
+
+
+void slcdPutchar(int fd, Uint8 data)
+{
+    struct slcdDataStruct *lcd = slcds [fd];
+
+    SDLGui_Char(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, data, 0);
+
+    if (++lcd->cx == lcd->cols) {
+	lcd->cx = 0;
+	if (++lcd->cy == lcd->rows)
+	    lcd->cy = 0;
+    }
+    SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8);
+}
+
+
+
+void slcdPuts(int fd, const char *string)
+{
+    while (*string)
+	slcdPutchar(fd, *string++);
+}
+
+
+
+void slcdPrintf(int fd, const char *message, ...)
+{
+    va_list	argp;
+    char	buffer[1024];
+
+    va_start(argp, message);
+    vsnprintf(buffer, 1023, message, argp);
+    va_end(argp);
+    slcdPuts(fd, buffer);
+}
+
+
+
+int slcdInit(int fd, int x, int y, int w, int h, int cols, int rows)
+{
+    static int			initialised = 0;
+    int				i, j;
+    struct slcdDataStruct	*lcd;
+
+    if (initialised == 0) {
+	initialised = 1 ;
+	for (i = 0 ; i < MAX_SLCDS ; ++i)
+	    slcds[i] = NULL ;
+    }
+
+    if ((rows < 0) || (rows > 20))
+	return -1 ;
+
+    if ((cols < 0) || (cols > 20))
+	return -1 ;
+
+    /*
+     * Create LCD
+     */
+    if (slcds[fd] != NULL) {
+	syslog(LOG_NOTICE, "slcdInit fd=%d already in use", fd);
+	return -1;
+    }
+    if ((lcd = (struct slcdDataStruct *)malloc (sizeof (struct slcdDataStruct))) == NULL) {
+	return -1;
+    }
+
+    lcd->x = x;
+    lcd->y = y;
+    lcd->w = w;
+    lcd->h = h;
+    lcd->cols = cols;
+    lcd->rows = rows;
+    lcd->cx = 0;
+    lcd->cy = 0;
+    for (i = 0; i < 8; i++)
+	for (j = 0; j < 8; j++)
+	    lcd->cgram[i][j] = 0;
+
+    slcds[fd] = lcd;
+
+    slcdDisplay(fd, TRUE);
+    slcdCursor(fd, FALSE);
+    slcdCursorBlink(fd, FALSE);
+    slcdClear(fd);
+
+    /*
+     * Most LCD's start with the top row filled with blocks.
+     */
+    for (i = 0; i < lcd->cols; i++)
+	slcdPutchar(fd, 0x0ff);
+
+    return fd;
+}
+
+
+#endif

mercurial