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