48 int rows; /* Height in characters */ |
48 int rows; /* Height in characters */ |
49 int cx; /* Cursor x position */ |
49 int cx; /* Cursor x position */ |
50 int cy; /* Cursor y position */ |
50 int cy; /* Cursor y position */ |
51 Uint8 cgram[8][8]; /* Characters in CGRAM */ |
51 Uint8 cgram[8][8]; /* Characters in CGRAM */ |
52 int control; /* Control register */ |
52 int control; /* Control register */ |
53 int backlight; /* Backlight */ |
|
54 }; |
53 }; |
55 struct slcdDataStruct *slcds [MAX_SLCDS] ; |
54 struct slcdDataStruct *slcds [MAX_SLCDS] ; |
56 |
55 |
57 |
56 |
58 |
57 |
59 |
58 |
60 void slcdHome(int fd) |
59 void slcdHome(SGOBJ *dlg, int fd) |
61 { |
60 { |
62 struct slcdDataStruct *lcd = slcds [fd]; |
61 struct slcdDataStruct *lcd = slcds [fd]; |
63 |
62 |
64 lcd->cx = lcd->cy = 0; |
63 lcd->cx = lcd->cy = 0; |
65 SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); |
64 SDLGui_Cursor(dlg, fd, lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); |
66 } |
65 } |
67 |
66 |
68 |
67 |
69 |
68 |
70 void slcdClear(int fd) |
69 void slcdClear(SGOBJ *dlg, int fd) |
71 { |
70 { |
72 struct slcdDataStruct *lcd = slcds [fd]; |
71 struct slcdDataStruct *lcd = slcds [fd]; |
73 int i; |
72 int i; |
74 |
73 |
75 lcd->cx = lcd->cy = 0; |
74 lcd->cx = lcd->cy = 0; |
76 for (i = 0; i < (lcd->cols * lcd->rows); i++) |
75 for (i = 0; i < (lcd->cols * lcd->rows); i++) |
77 slcdPutchar(fd, ' '); |
76 slcdPutchar(dlg, fd, ' '); |
78 lcd->cx = lcd->cy = 0; |
77 lcd->cx = lcd->cy = 0; |
79 SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); |
78 SDLGui_Cursor(dlg, fd, lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); |
80 } |
79 } |
81 |
80 |
82 |
81 |
83 |
82 |
84 void slcdDisplay(int fd, int state) |
83 void slcdDisplay(SGOBJ *dlg, int fd, int state) |
85 { |
84 { |
86 struct slcdDataStruct *lcd = slcds [fd]; |
85 struct slcdDataStruct *lcd = slcds [fd]; |
87 |
86 |
88 if (state) |
87 if (state) |
89 lcd->control |= SLCD_DISPLAY_CTRL; |
88 lcd->control |= SLCD_DISPLAY_CTRL; |
91 lcd->control &= ~SLCD_DISPLAY_CTRL; |
90 lcd->control &= ~SLCD_DISPLAY_CTRL; |
92 } |
91 } |
93 |
92 |
94 |
93 |
95 |
94 |
96 void slcdCursor(int fd, int state) |
95 void slcdCursor(SGOBJ *dlg, int fd, int state) |
97 { |
96 { |
98 struct slcdDataStruct *lcd = slcds [fd]; |
97 struct slcdDataStruct *lcd = slcds [fd]; |
99 |
98 |
100 if (state) |
99 if (state) |
101 lcd->control |= SLCD_CURSOR_CTRL; |
100 lcd->control |= SLCD_CURSOR_CTRL; |
102 else |
101 else |
103 lcd->control &= ~SLCD_CURSOR_CTRL; |
102 lcd->control &= ~SLCD_CURSOR_CTRL; |
104 SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); |
103 SDLGui_Cursor(dlg, fd, lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); |
105 } |
104 } |
106 |
105 |
107 |
106 |
108 |
107 |
109 void slcdCursorBlink(int fd, int state) |
108 void slcdCursorBlink(SGOBJ *dlg, int fd, int state) |
110 { |
109 { |
111 struct slcdDataStruct *lcd = slcds [fd]; |
110 struct slcdDataStruct *lcd = slcds [fd]; |
112 |
111 |
113 if (state) |
112 if (state) |
114 lcd->control |= SLCD_BLINK_CTRL; |
113 lcd->control |= SLCD_BLINK_CTRL; |
115 else |
114 else |
116 lcd->control &= ~SLCD_BLINK_CTRL; |
115 lcd->control &= ~SLCD_BLINK_CTRL; |
117 SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); |
116 SDLGui_Cursor(dlg, fd, lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); |
118 } |
117 } |
119 |
118 |
120 |
119 |
121 |
120 |
122 void slcdPosition(int fd, int x, int y) |
121 void slcdPosition(SGOBJ *dlg, int fd, int x, int y) |
123 { |
122 { |
124 struct slcdDataStruct *lcd = slcds [fd]; |
123 struct slcdDataStruct *lcd = slcds [fd]; |
125 |
124 |
126 if ((x > lcd->cols) || (x < 0)) |
125 if ((x > lcd->cols) || (x < 0)) |
127 return ; |
126 return ; |
128 if ((y > lcd->rows) || (y < 0)) |
127 if ((y > lcd->rows) || (y < 0)) |
129 return ; |
128 return ; |
130 |
129 |
131 lcd->cx = x ; |
130 lcd->cx = x ; |
132 lcd->cy = y ; |
131 lcd->cy = y ; |
133 SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); |
132 SDLGui_Cursor(dlg, fd, lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); |
134 } |
133 } |
135 |
134 |
136 |
135 |
137 |
136 |
138 void slcdCharDef(int fd, int index, Uint8 data[8]) |
137 void slcdCharDef(SGOBJ *dlg, int fd, int index, Uint8 data[8]) |
139 { |
138 { |
140 struct slcdDataStruct *lcd = slcds [fd]; |
139 struct slcdDataStruct *lcd = slcds [fd]; |
141 int i; |
140 int i; |
142 |
141 |
143 for (i = 0 ; i < 8 ; i++) |
142 for (i = 0 ; i < 8 ; i++) |
145 } |
144 } |
146 |
145 |
147 |
146 |
148 |
147 |
149 |
148 |
150 void slcdPutchar(int fd, Uint8 data) |
149 void slcdPutchar(SGOBJ *dlg, int fd, Uint8 data) |
151 { |
150 { |
152 struct slcdDataStruct *lcd = slcds [fd]; |
151 struct slcdDataStruct *lcd = slcds [fd]; |
153 |
152 |
154 SDLGui_Char(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, data, lcd->backlight); |
153 SDLGui_Char(dlg, fd, lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, data); |
155 |
154 |
156 if (++lcd->cx == lcd->cols) { |
155 if (++lcd->cx == lcd->cols) { |
157 lcd->cx = 0; |
156 lcd->cx = 0; |
158 if (++lcd->cy == lcd->rows) |
157 if (++lcd->cy == lcd->rows) |
159 lcd->cy = 0; |
158 lcd->cy = 0; |
160 } |
159 } |
161 SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); |
160 SDLGui_Cursor(dlg, fd, lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); |
162 } |
161 } |
163 |
162 |
164 |
163 |
165 |
164 |
166 void slcdPuts(int fd, const char *string) |
165 void slcdPuts(SGOBJ *dlg, int fd, const char *string) |
167 { |
166 { |
168 while (*string) |
167 while (*string) |
169 slcdPutchar(fd, *string++); |
168 slcdPutchar(dlg, fd, *string++); |
170 } |
169 } |
171 |
170 |
172 |
171 |
173 |
172 |
174 void slcdPrintf(int fd, const char *message, ...) |
173 void slcdPrintf(SGOBJ *dlg, int fd, const char *message, ...) |
175 { |
174 { |
176 va_list argp; |
175 va_list argp; |
177 char buffer[1024]; |
176 char buffer[1024]; |
178 |
177 |
179 va_start(argp, message); |
178 va_start(argp, message); |
180 vsnprintf(buffer, 1023, message, argp); |
179 vsnprintf(buffer, 1023, message, argp); |
181 va_end(argp); |
180 va_end(argp); |
182 slcdPuts(fd, buffer); |
181 slcdPuts(dlg, fd, buffer); |
183 } |
182 } |
184 |
183 |
185 |
184 |
186 |
185 |
187 void slcdBacklight(int fd, int bl) |
186 void slcdBacklight(SGOBJ *dlg, int fd, int bl) |
188 { |
187 { |
189 struct slcdDataStruct *lcd = slcds [fd]; |
188 fprintf(stdout, "slcdBacklight %d\n", bl); |
190 |
189 if (bl) |
191 lcd->backlight = bl; |
190 dlg[1].state |= SG_SELECTED; |
192 } |
191 else |
193 |
192 dlg[1].state &= ~SG_SELECTED; |
194 |
193 SDLGui_DrawLCD(dlg, 1); |
195 |
194 } |
196 int slcdInit(int fd, int x, int y, int w, int h, int cols, int rows) |
195 |
|
196 |
|
197 |
|
198 void slcdLED(SGOBJ *dlg, int fd, int color, int state) |
|
199 { |
|
200 SDLGui_LED(dlg, fd, color, state); |
|
201 } |
|
202 |
|
203 |
|
204 |
|
205 int slcdInit(SGOBJ *dlg, int fd, int x, int y, int w, int h, int cols, int rows) |
197 { |
206 { |
198 static int initialised = 0; |
207 static int initialised = 0; |
199 int i, j; |
208 int i, j; |
200 struct slcdDataStruct *lcd; |
209 struct slcdDataStruct *lcd; |
201 |
210 |
232 lcd->cy = 0; |
241 lcd->cy = 0; |
233 for (i = 0; i < 8; i++) |
242 for (i = 0; i < 8; i++) |
234 for (j = 0; j < 8; j++) |
243 for (j = 0; j < 8; j++) |
235 lcd->cgram[i][j] = 0; |
244 lcd->cgram[i][j] = 0; |
236 lcd->control = 0; |
245 lcd->control = 0; |
237 lcd->backlight = 0; |
|
238 |
246 |
239 slcds[fd] = lcd; |
247 slcds[fd] = lcd; |
240 |
248 |
241 slcdDisplay(fd, TRUE); |
249 slcdDisplay(dlg, fd, TRUE); |
242 slcdCursor(fd, FALSE); |
250 slcdCursor(dlg, fd, FALSE); |
243 slcdCursorBlink(fd, FALSE); |
251 slcdCursorBlink(dlg, fd, FALSE); |
244 slcdClear(fd); |
252 slcdClear(dlg, fd); |
245 |
253 |
246 /* |
254 /* |
247 * Most LCD's start with the top row filled with blocks. |
255 * Most LCD's start with the top row filled with blocks. |
248 */ |
256 */ |
249 for (i = 0; i < lcd->cols; i++) |
257 for (i = 0; i < lcd->cols; i++) |
250 slcdPutchar(fd, 0x0ff); |
258 slcdPutchar(dlg, fd, 0x0ff); |
251 |
259 |
252 slcdDisplay(fd, TRUE); |
260 slcdDisplay(dlg, fd, TRUE); |
253 slcdCursor(fd, FALSE); |
261 slcdCursor(dlg, fd, FALSE); |
254 slcdCursorBlink(fd, FALSE); |
262 slcdCursorBlink(dlg, fd, FALSE); |
255 slcdClear(fd); |
263 slcdClear(dlg, fd); |
256 |
264 |
257 return fd; |
265 return fd; |
258 } |
266 } |
259 |
267 |
260 |
268 |