brewpanel/slcd.c

Sun, 08 Nov 2015 17:49:29 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 08 Nov 2015 17:49:29 +0100
changeset 412
f1a042a59b61
child 415
d9b7e0705f56
permissions
-rw-r--r--

Basic ideas to write to the simulated LCD display are in place.

412
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * Copyright (C) 2015
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * mbsePi-apps is free software; you can redistribute it and/or modify it
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * mbsePi-apps is distributed in the hope that it will be useful, but
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * along with mbsePi-apps; see the file COPYING. If not, write to the Free
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 /*
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 * Simulated LCD driver based on HD44780U displays.
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 */
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 #include "brewpanel.h"
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 #include "slcd.h"
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 #include "sdlgui.h"
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 #ifdef HAVE_SDL_SDL_H
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 // HD44780U Commands
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 #define SLCD_CLEAR 0x01
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 #define SLCD_HOME 0x02
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 #define SLCD_ENTRY 0x04
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 #define SLCD_CTRL 0x08
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 #define SLCD_CDSHIFT 0x10
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 #define SLCD_FUNC 0x20
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 #define SLCD_CGRAM 0x40
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 #define SLCD_DGRAM 0x80
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 // // Bits in the entry register
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 //
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 // #define LCD_ENTRY_SH 0x01
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 // #define LCD_ENTRY_ID 0x02
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 //
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 // // Bits in the control register
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 //
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 // #define LCD_BLINK_CTRL 0x01
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 // #define LCD_CURSOR_CTRL 0x02
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 // #define LCD_DISPLAY_CTRL 0x04
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 struct slcdDataStruct
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 int x; /* Start x pixels */
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 int y; /* Start y pixels */
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 int w; /* Width in pixels */
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 int h; /* Height in pixels */
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 int cols; /* Width in characters */
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 int rows; /* Height in characters */
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 int cx; /* Cursor x position */
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 int cy; /* Cursor y position */
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 Uint8 cgram[8][8]; /* Characters in CGRAM */
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 };
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 struct slcdDataStruct *slcds [MAX_SLCDS] ;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 /* Low level */
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 void sendDataCmd (struct slcdDataStruct *slcd, unsigned char data)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 void putCommand (struct slcdDataStruct *slcd, unsigned char command)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 void slcdHome(int fd)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 struct slcdDataStruct *lcd = slcds [fd];
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 lcd->cx = lcd->cy = 0;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 void slcdClear(int fd)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 struct slcdDataStruct *lcd = slcds [fd];
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 lcd->cx = lcd->cy = 0;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 void slcdDisplay(int fd, int state)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 void slcdCursor(int fd, int state)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 void slcdCursorBlink(int fd, int state)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 void slcdSendCommand(int fd, Uint8 command)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 void slcdPosition(int fd, int x, int y)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 struct slcdDataStruct *lcd = slcds [fd];
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 if ((x > lcd->cols) || (x < 0))
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 return ;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 if ((y > lcd->rows) || (y < 0))
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 return ;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 // putCommand (lcd, x + (LCD_DGRAM | rowOff [y])) ;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 lcd->cx = x ;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 lcd->cy = y ;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 void slcdCharDef(int fd, int index, Uint8 data[8])
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 struct slcdDataStruct *lcd = slcds [fd];
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 int i;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 for (i = 0 ; i < 8 ; i++)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 lcd->cgram[index][i] = data[i];
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 void slcdPutchar(int fd, Uint8 data)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 struct slcdDataStruct *lcd = slcds [fd];
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 SDLGui_Char(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, data, 0);
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 if (++lcd->cx == lcd->cols) {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 lcd->cx = 0;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 if (++lcd->cy == lcd->rows)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 lcd->cy = 0;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8);
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 void slcdPuts(int fd, const char *string)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 while (*string)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 slcdPutchar(fd, *string++);
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 void slcdPrintf(int fd, const char *message, ...)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 va_list argp;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 char buffer[1024];
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 va_start(argp, message);
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 vsnprintf(buffer, 1023, message, argp);
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 va_end(argp);
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 slcdPuts(fd, buffer);
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 int slcdInit(int fd, int x, int y, int w, int h, int cols, int rows)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 static int initialised = 0;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 int i, j;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 struct slcdDataStruct *lcd;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 if (initialised == 0) {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 initialised = 1 ;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201 for (i = 0 ; i < MAX_SLCDS ; ++i)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 slcds[i] = NULL ;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 if ((rows < 0) || (rows > 20))
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 return -1 ;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208 if ((cols < 0) || (cols > 20))
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209 return -1 ;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211 /*
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 * Create LCD
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 */
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 if (slcds[fd] != NULL) {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215 syslog(LOG_NOTICE, "slcdInit fd=%d already in use", fd);
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 return -1;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218 if ((lcd = (struct slcdDataStruct *)malloc (sizeof (struct slcdDataStruct))) == NULL) {
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219 return -1;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 lcd->x = x;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 lcd->y = y;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 lcd->w = w;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 lcd->h = h;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 lcd->cols = cols;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 lcd->rows = rows;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 lcd->cx = 0;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 lcd->cy = 0;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 for (i = 0; i < 8; i++)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 for (j = 0; j < 8; j++)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 lcd->cgram[i][j] = 0;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 slcds[fd] = lcd;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 slcdDisplay(fd, TRUE);
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 slcdCursor(fd, FALSE);
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 slcdCursorBlink(fd, FALSE);
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 slcdClear(fd);
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 /*
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 * Most LCD's start with the top row filled with blocks.
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243 */
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 for (i = 0; i < lcd->cols; i++)
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245 slcdPutchar(fd, 0x0ff);
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 return fd;
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 }
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250
f1a042a59b61 Basic ideas to write to the simulated LCD display are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251 #endif

mercurial