ss_scanjet.c revision 1.28.8.1 1 1.28.8.1 he /* $NetBSD: ss_scanjet.c,v 1.28.8.1 2004/09/11 12:57:39 he Exp $ */
2 1.1 mycroft
3 1.1 mycroft /*
4 1.1 mycroft * Copyright (c) 1995 Kenneth Stailey. All rights reserved.
5 1.1 mycroft *
6 1.1 mycroft * Redistribution and use in source and binary forms, with or without
7 1.1 mycroft * modification, are permitted provided that the following conditions
8 1.1 mycroft * are met:
9 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
10 1.1 mycroft * notice, this list of conditions and the following disclaimer.
11 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
13 1.1 mycroft * documentation and/or other materials provided with the distribution.
14 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
15 1.1 mycroft * must display the following acknowledgement:
16 1.1 mycroft * This product includes software developed by Kenneth Stailey.
17 1.1 mycroft * 4. The name of the author may not be used to endorse or promote products
18 1.1 mycroft * derived from this software without specific prior written permission.
19 1.1 mycroft *
20 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 mycroft */
31 1.1 mycroft
32 1.1 mycroft /*
33 1.1 mycroft * special functions for the HP ScanJet IIc and IIcx
34 1.1 mycroft */
35 1.26 lukem
36 1.26 lukem #include <sys/cdefs.h>
37 1.28.8.1 he __KERNEL_RCSID(0, "$NetBSD: ss_scanjet.c,v 1.28.8.1 2004/09/11 12:57:39 he Exp $");
38 1.1 mycroft
39 1.1 mycroft #include <sys/param.h>
40 1.1 mycroft #include <sys/systm.h>
41 1.1 mycroft #include <sys/fcntl.h>
42 1.1 mycroft #include <sys/errno.h>
43 1.1 mycroft #include <sys/ioctl.h>
44 1.1 mycroft #include <sys/malloc.h>
45 1.1 mycroft #include <sys/buf.h>
46 1.1 mycroft #include <sys/proc.h>
47 1.1 mycroft #include <sys/user.h>
48 1.1 mycroft #include <sys/device.h>
49 1.1 mycroft #include <sys/conf.h> /* for cdevsw */
50 1.1 mycroft #include <sys/scanio.h>
51 1.28.8.1 he #include <sys/kernel.h>
52 1.1 mycroft
53 1.12 bouyer #include <dev/scsipi/scsi_all.h>
54 1.12 bouyer #include <dev/scsipi/scsipi_all.h>
55 1.12 bouyer #include <dev/scsipi/scsi_scanner.h>
56 1.12 bouyer #include <dev/scsipi/scsiconf.h>
57 1.28.8.1 he #include <dev/scsipi/scsipi_base.h>
58 1.12 bouyer #include <dev/scsipi/ssvar.h>
59 1.1 mycroft
60 1.1 mycroft #define SCANJET_RETRIES 4
61 1.1 mycroft
62 1.1 mycroft int scanjet_get_params __P((struct ss_softc *));
63 1.1 mycroft int scanjet_set_params __P((struct ss_softc *, struct scan_io *));
64 1.1 mycroft int scanjet_trigger_scanner __P((struct ss_softc *));
65 1.1 mycroft int scanjet_read __P((struct ss_softc *, struct buf *));
66 1.1 mycroft
67 1.1 mycroft /* only used internally */
68 1.17 mycroft int scanjet_ctl_write __P((struct ss_softc *, char *, u_int));
69 1.17 mycroft int scanjet_ctl_read __P((struct ss_softc *, char *, u_int));
70 1.5 mycroft int scanjet_set_window __P((struct ss_softc *));
71 1.5 mycroft int scanjet_compute_sizes __P((struct ss_softc *));
72 1.1 mycroft
73 1.1 mycroft /*
74 1.1 mycroft * structure for the special handlers
75 1.1 mycroft */
76 1.1 mycroft struct ss_special scanjet_special = {
77 1.1 mycroft scanjet_set_params,
78 1.1 mycroft scanjet_trigger_scanner,
79 1.1 mycroft scanjet_get_params,
80 1.1 mycroft NULL, /* no special minphys */
81 1.1 mycroft scanjet_read, /* scsi 6-byte read */
82 1.1 mycroft NULL, /* no "rewind" code (yet?) */
83 1.1 mycroft NULL, /* no adf support right now */
84 1.1 mycroft NULL /* no adf support right now */
85 1.1 mycroft };
86 1.1 mycroft
87 1.1 mycroft /*
88 1.1 mycroft * scanjet_attach: attach special functions to ss
89 1.1 mycroft */
90 1.1 mycroft void
91 1.1 mycroft scanjet_attach(ss, sa)
92 1.1 mycroft struct ss_softc *ss;
93 1.12 bouyer struct scsipibus_attach_args *sa;
94 1.1 mycroft {
95 1.5 mycroft int error;
96 1.1 mycroft
97 1.22 bouyer SC_DEBUG(ss->sc_periph, SCSIPI_DB1, ("scanjet_attach: start\n"));
98 1.1 mycroft ss->sio.scan_scanner_type = 0;
99 1.1 mycroft
100 1.19 augustss printf("%s: ", ss->sc_dev.dv_xname);
101 1.3 christos
102 1.1 mycroft /* first, check the model (which determines nothing yet) */
103 1.1 mycroft
104 1.25 thorpej if (!memcmp(sa->sa_inqbuf.product, "C1750A", 6)) {
105 1.1 mycroft ss->sio.scan_scanner_type = HP_SCANJET_IIC;
106 1.8 christos printf("HP ScanJet IIc");
107 1.28 chs } else if (!memcmp(sa->sa_inqbuf.product, "C2500A", 6)) {
108 1.1 mycroft ss->sio.scan_scanner_type = HP_SCANJET_IIC;
109 1.8 christos printf("HP ScanJet IIcx");
110 1.28 chs } else if (!memcmp(sa->sa_inqbuf.product, "C2520A", 6)) {
111 1.28 chs ss->sio.scan_scanner_type = HP_SCANJET_IIC;
112 1.28 chs printf("HP ScanJet 4c");
113 1.28 chs } else if (!memcmp(sa->sa_inqbuf.product, "C1130A", 6)) {
114 1.9 thorpej ss->sio.scan_scanner_type = HP_SCANJET_IIC;
115 1.9 thorpej printf("HP ScanJet 4p");
116 1.28 chs } else if (!memcmp(sa->sa_inqbuf.product, "C5110A", 6)) {
117 1.15 augustss ss->sio.scan_scanner_type = HP_SCANJET_IIC;
118 1.15 augustss printf("HP ScanJet 5p");
119 1.28 chs } else {
120 1.28 chs ss->sio.scan_scanner_type = HP_SCANJET_IIC;
121 1.28 chs printf("HP ScanJet (unknown model)");
122 1.1 mycroft }
123 1.1 mycroft
124 1.22 bouyer SC_DEBUG(ss->sc_periph, SCSIPI_DB1,
125 1.22 bouyer ("scanjet_attach: scanner_type = %d\n",
126 1.1 mycroft ss->sio.scan_scanner_type));
127 1.1 mycroft
128 1.1 mycroft /* now install special handlers */
129 1.1 mycroft ss->special = &scanjet_special;
130 1.1 mycroft
131 1.1 mycroft /*
132 1.1 mycroft * populate the scanio struct with legal values
133 1.1 mycroft */
134 1.1 mycroft ss->sio.scan_width = 1200;
135 1.1 mycroft ss->sio.scan_height = 1200;
136 1.1 mycroft ss->sio.scan_x_resolution = 100;
137 1.1 mycroft ss->sio.scan_y_resolution = 100;
138 1.1 mycroft ss->sio.scan_x_origin = 0;
139 1.1 mycroft ss->sio.scan_y_origin = 0;
140 1.3 christos ss->sio.scan_brightness = 128;
141 1.3 christos ss->sio.scan_contrast = 128;
142 1.1 mycroft ss->sio.scan_quality = 100;
143 1.1 mycroft ss->sio.scan_image_mode = SIM_GRAYSCALE;
144 1.1 mycroft
145 1.5 mycroft error = scanjet_set_window(ss);
146 1.5 mycroft if (error) {
147 1.8 christos printf(" set_window failed\n");
148 1.5 mycroft return;
149 1.5 mycroft }
150 1.5 mycroft error = scanjet_compute_sizes(ss);
151 1.5 mycroft if (error) {
152 1.8 christos printf(" compute_sizes failed\n");
153 1.5 mycroft return;
154 1.5 mycroft }
155 1.5 mycroft
156 1.8 christos printf("\n");
157 1.1 mycroft }
158 1.1 mycroft
159 1.1 mycroft int
160 1.1 mycroft scanjet_get_params(ss)
161 1.1 mycroft struct ss_softc *ss;
162 1.1 mycroft {
163 1.1 mycroft
164 1.1 mycroft return (0);
165 1.1 mycroft }
166 1.1 mycroft
167 1.1 mycroft /*
168 1.1 mycroft * check the parameters if the scanjet is capable of fulfilling it
169 1.1 mycroft * but don't send the command to the scanner in case the user wants
170 1.1 mycroft * to change parameters by more than one call
171 1.1 mycroft */
172 1.1 mycroft int
173 1.1 mycroft scanjet_set_params(ss, sio)
174 1.1 mycroft struct ss_softc *ss;
175 1.1 mycroft struct scan_io *sio;
176 1.1 mycroft {
177 1.1 mycroft int error;
178 1.1 mycroft
179 1.5 mycroft #if 0
180 1.1 mycroft /*
181 1.1 mycroft * if the scanner is triggered, then rewind it
182 1.1 mycroft */
183 1.1 mycroft if (ss->flags & SSF_TRIGGERED) {
184 1.1 mycroft error = scanjet_rewind_scanner(ss);
185 1.1 mycroft if (error)
186 1.1 mycroft return (error);
187 1.1 mycroft }
188 1.1 mycroft #endif
189 1.1 mycroft
190 1.1 mycroft /* size constraints... */
191 1.1 mycroft if (sio->scan_width == 0 ||
192 1.1 mycroft sio->scan_x_origin + sio->scan_width > 10200 || /* 8.5" */
193 1.1 mycroft sio->scan_height == 0 ||
194 1.1 mycroft sio->scan_y_origin + sio->scan_height > 16800) /* 14" */
195 1.1 mycroft return (EINVAL);
196 1.1 mycroft
197 1.1 mycroft /* resolution (dpi)... */
198 1.1 mycroft if (sio->scan_x_resolution < 100 ||
199 1.1 mycroft sio->scan_x_resolution > 400 ||
200 1.1 mycroft sio->scan_y_resolution < 100 ||
201 1.1 mycroft sio->scan_y_resolution > 400)
202 1.1 mycroft return (EINVAL);
203 1.1 mycroft
204 1.1 mycroft switch (sio->scan_image_mode) {
205 1.1 mycroft case SIM_BINARY_MONOCHROME:
206 1.1 mycroft case SIM_DITHERED_MONOCHROME:
207 1.1 mycroft case SIM_GRAYSCALE:
208 1.1 mycroft case SIM_COLOR:
209 1.1 mycroft break;
210 1.1 mycroft default:
211 1.1 mycroft return (EINVAL);
212 1.1 mycroft }
213 1.1 mycroft
214 1.1 mycroft /* change ss_softc to the new values, but save ro-variables */
215 1.1 mycroft sio->scan_scanner_type = ss->sio.scan_scanner_type;
216 1.24 thorpej memcpy(&ss->sio, sio, sizeof(struct scan_io));
217 1.1 mycroft
218 1.5 mycroft error = scanjet_set_window(ss);
219 1.5 mycroft if (error) {
220 1.5 mycroft uprintf("%s: set_window failed\n", ss->sc_dev.dv_xname);
221 1.5 mycroft return (error);
222 1.5 mycroft }
223 1.5 mycroft error = scanjet_compute_sizes(ss);
224 1.5 mycroft if (error) {
225 1.5 mycroft uprintf("%s: compute_sizes failed\n", ss->sc_dev.dv_xname);
226 1.5 mycroft return (error);
227 1.5 mycroft }
228 1.1 mycroft
229 1.1 mycroft return (0);
230 1.1 mycroft }
231 1.1 mycroft
232 1.1 mycroft /*
233 1.1 mycroft * trigger the scanner to start a scan operation
234 1.1 mycroft * this includes sending the mode- and window-data,
235 1.1 mycroft * and starting the scanner
236 1.1 mycroft */
237 1.1 mycroft int
238 1.1 mycroft scanjet_trigger_scanner(ss)
239 1.1 mycroft struct ss_softc *ss;
240 1.1 mycroft {
241 1.1 mycroft char escape_codes[20];
242 1.1 mycroft int error;
243 1.1 mycroft
244 1.1 mycroft error = scanjet_set_window(ss);
245 1.1 mycroft if (error) {
246 1.5 mycroft uprintf("%s: set_window failed\n", ss->sc_dev.dv_xname);
247 1.5 mycroft return (error);
248 1.5 mycroft }
249 1.5 mycroft error = scanjet_compute_sizes(ss);
250 1.5 mycroft if (error) {
251 1.5 mycroft uprintf("%s: compute_sizes failed\n", ss->sc_dev.dv_xname);
252 1.1 mycroft return (error);
253 1.1 mycroft }
254 1.1 mycroft
255 1.1 mycroft /* send "trigger" operation */
256 1.1 mycroft strcpy(escape_codes, "\033*f0S");
257 1.17 mycroft error = scanjet_ctl_write(ss, escape_codes, strlen(escape_codes));
258 1.1 mycroft if (error) {
259 1.5 mycroft uprintf("%s: trigger_scanner failed\n", ss->sc_dev.dv_xname);
260 1.1 mycroft return (error);
261 1.1 mycroft }
262 1.1 mycroft
263 1.1 mycroft return (0);
264 1.1 mycroft }
265 1.1 mycroft
266 1.1 mycroft int
267 1.1 mycroft scanjet_read(ss, bp)
268 1.1 mycroft struct ss_softc *ss;
269 1.1 mycroft struct buf *bp;
270 1.1 mycroft {
271 1.1 mycroft struct scsi_rw_scanner cmd;
272 1.28.8.1 he struct scsipi_xfer *xs;
273 1.22 bouyer struct scsipi_periph *periph = ss->sc_periph;
274 1.17 mycroft int error;
275 1.1 mycroft
276 1.1 mycroft /*
277 1.1 mycroft * Fill out the scsi command
278 1.1 mycroft */
279 1.23 thorpej memset(&cmd, 0, sizeof(cmd));
280 1.1 mycroft cmd.opcode = READ;
281 1.1 mycroft
282 1.1 mycroft /*
283 1.1 mycroft * Handle "fixed-block-mode" tape drives by using the
284 1.1 mycroft * block count instead of the length.
285 1.1 mycroft */
286 1.2 mycroft _lto3b(bp->b_bcount, cmd.len);
287 1.1 mycroft
288 1.1 mycroft /*
289 1.1 mycroft * go ask the adapter to do all this for us
290 1.1 mycroft */
291 1.28.8.1 he xs = scsipi_make_xs(periph,
292 1.28.8.1 he (struct scsipi_generic *) &cmd, sizeof(cmd),
293 1.28.8.1 he (u_char *) bp->b_data, bp->b_bcount,
294 1.28.8.1 he SCANJET_RETRIES, 100000, bp,
295 1.28.8.1 he XS_CTL_NOSLEEP | XS_CTL_ASYNC | XS_CTL_DATA_IN);
296 1.28.8.1 he if (xs == NULL) {
297 1.28.8.1 he /*
298 1.28.8.1 he * out of memory. Keep this buffer in the queue, and
299 1.28.8.1 he * retry later.
300 1.28.8.1 he */
301 1.28.8.1 he callout_reset(&ss->sc_callout, hz / 2, ssrestart,
302 1.28.8.1 he periph);
303 1.28.8.1 he return(0);
304 1.28.8.1 he }
305 1.28.8.1 he #ifdef DIAGNOSTIC
306 1.28.8.1 he if (BUFQ_GET(&ss->buf_queue) != bp)
307 1.28.8.1 he panic("ssstart(): dequeued wrong buf");
308 1.28.8.1 he #else
309 1.28.8.1 he BUFQ_GET(&ss->buf_queue);
310 1.28.8.1 he #endif
311 1.28.8.1 he error = scsipi_command(periph, xs,
312 1.13 enami (struct scsipi_generic *) &cmd, sizeof(cmd),
313 1.1 mycroft (u_char *) bp->b_data, bp->b_bcount, SCANJET_RETRIES, 100000, bp,
314 1.18 thorpej XS_CTL_NOSLEEP | XS_CTL_ASYNC | XS_CTL_DATA_IN);
315 1.28.8.1 he /* with a scsipi_xfer preallocated, scsipi_command can't fail */
316 1.28.8.1 he KASSERT(error == 0);
317 1.28.8.1 he ss->sio.scan_window_size -= bp->b_bcount;
318 1.28.8.1 he if (ss->sio.scan_window_size < 0)
319 1.28.8.1 he ss->sio.scan_window_size = 0;
320 1.1 mycroft return (0);
321 1.1 mycroft }
322 1.1 mycroft
323 1.1 mycroft
324 1.1 mycroft /*
325 1.1 mycroft * Do a synchronous write. Used to send control messages.
326 1.1 mycroft */
327 1.1 mycroft int
328 1.17 mycroft scanjet_ctl_write(ss, buf, size)
329 1.1 mycroft struct ss_softc *ss;
330 1.1 mycroft char *buf;
331 1.1 mycroft u_int size;
332 1.1 mycroft {
333 1.1 mycroft struct scsi_rw_scanner cmd;
334 1.17 mycroft int flags;
335 1.1 mycroft
336 1.17 mycroft flags = 0;
337 1.16 pk if ((ss->flags & SSF_AUTOCONF) != 0)
338 1.18 thorpej flags |= XS_CTL_DISCOVERY;
339 1.16 pk
340 1.23 thorpej memset(&cmd, 0, sizeof(cmd));
341 1.1 mycroft cmd.opcode = WRITE;
342 1.2 mycroft _lto3b(size, cmd.len);
343 1.28.8.1 he return (scsipi_command(ss->sc_periph, NULL,
344 1.13 enami (struct scsipi_generic *) &cmd,
345 1.1 mycroft sizeof(cmd), (u_char *) buf, size, 0, 100000, NULL,
346 1.20 enami flags | XS_CTL_DATA_OUT | XS_CTL_DATA_ONSTACK));
347 1.1 mycroft }
348 1.1 mycroft
349 1.5 mycroft
350 1.5 mycroft /*
351 1.5 mycroft * Do a synchronous read. Used to read responses to control messages.
352 1.5 mycroft */
353 1.5 mycroft int
354 1.17 mycroft scanjet_ctl_read(ss, buf, size)
355 1.5 mycroft struct ss_softc *ss;
356 1.5 mycroft char *buf;
357 1.5 mycroft u_int size;
358 1.5 mycroft {
359 1.5 mycroft struct scsi_rw_scanner cmd;
360 1.17 mycroft int flags;
361 1.16 pk
362 1.17 mycroft flags = 0;
363 1.16 pk if ((ss->flags & SSF_AUTOCONF) != 0)
364 1.18 thorpej flags |= XS_CTL_DISCOVERY;
365 1.5 mycroft
366 1.23 thorpej memset(&cmd, 0, sizeof(cmd));
367 1.5 mycroft cmd.opcode = READ;
368 1.5 mycroft _lto3b(size, cmd.len);
369 1.28.8.1 he return (scsipi_command(ss->sc_periph, NULL,
370 1.13 enami (struct scsipi_generic *) &cmd,
371 1.5 mycroft sizeof(cmd), (u_char *) buf, size, 0, 100000, NULL,
372 1.20 enami flags | XS_CTL_DATA_IN | XS_CTL_DATA_ONSTACK));
373 1.5 mycroft }
374 1.5 mycroft
375 1.5 mycroft
376 1.1 mycroft #ifdef SCANJETDEBUG
377 1.1 mycroft static void show_es(char *es)
378 1.1 mycroft {
379 1.13 enami char *p = es;
380 1.13 enami while (*p) {
381 1.13 enami if (*p == '\033')
382 1.13 enami printf("[Esc]");
383 1.13 enami else
384 1.13 enami printf("%c", *p);
385 1.13 enami ++p;
386 1.13 enami }
387 1.13 enami printf("\n");
388 1.1 mycroft }
389 1.1 mycroft #endif
390 1.1 mycroft
391 1.1 mycroft /*
392 1.1 mycroft * simulate SCSI_SET_WINDOW for ScanJets
393 1.1 mycroft */
394 1.1 mycroft int
395 1.1 mycroft scanjet_set_window(ss)
396 1.1 mycroft struct ss_softc *ss;
397 1.1 mycroft {
398 1.1 mycroft char escape_codes[128], *p;
399 1.1 mycroft
400 1.1 mycroft p = escape_codes;
401 1.1 mycroft
402 1.8 christos p += sprintf(p, "\033*f%ldP", ss->sio.scan_width / 4);
403 1.8 christos p += sprintf(p, "\033*f%ldQ", ss->sio.scan_height / 4);
404 1.8 christos p += sprintf(p, "\033*f%ldX", ss->sio.scan_x_origin / 4);
405 1.8 christos p += sprintf(p, "\033*f%ldY", ss->sio.scan_y_origin / 4);
406 1.8 christos p += sprintf(p, "\033*a%dR", ss->sio.scan_x_resolution);
407 1.8 christos p += sprintf(p, "\033*a%dS", ss->sio.scan_y_resolution);
408 1.1 mycroft
409 1.1 mycroft switch (ss->sio.scan_image_mode) {
410 1.1 mycroft case SIM_BINARY_MONOCHROME:
411 1.5 mycroft ss->sio.scan_bits_per_pixel = 1;
412 1.1 mycroft /* use "line art" mode */
413 1.1 mycroft strcpy(p, "\033*a0T");
414 1.1 mycroft p += strlen(p);
415 1.1 mycroft /* make image data be "min-is-white ala PBM */
416 1.1 mycroft strcpy(p, "\033*a0I");
417 1.1 mycroft p += strlen(p);
418 1.1 mycroft break;
419 1.1 mycroft case SIM_DITHERED_MONOCHROME:
420 1.5 mycroft ss->sio.scan_bits_per_pixel = 1;
421 1.1 mycroft /* use dithered mode */
422 1.1 mycroft strcpy(p, "\033*a3T");
423 1.1 mycroft p += strlen(p);
424 1.1 mycroft /* make image data be "min-is-white ala PBM */
425 1.1 mycroft strcpy(p, "\033*a0I");
426 1.1 mycroft p += strlen(p);
427 1.1 mycroft break;
428 1.1 mycroft case SIM_GRAYSCALE:
429 1.5 mycroft ss->sio.scan_bits_per_pixel = 8;
430 1.1 mycroft /* use grayscale mode */
431 1.1 mycroft strcpy(p, "\033*a4T");
432 1.1 mycroft p += strlen(p);
433 1.1 mycroft /* make image data be "min-is-black ala PGM */
434 1.1 mycroft strcpy(p, "\033*a1I");
435 1.1 mycroft p += strlen(p);
436 1.1 mycroft break;
437 1.1 mycroft case SIM_COLOR:
438 1.5 mycroft ss->sio.scan_bits_per_pixel = 24;
439 1.1 mycroft /* use RGB color mode */
440 1.1 mycroft strcpy(p, "\033*a5T");
441 1.1 mycroft p += strlen(p);
442 1.1 mycroft /* make image data be "min-is-black ala PPM */
443 1.1 mycroft strcpy(p, "\033*a1I");
444 1.1 mycroft p += strlen(p);
445 1.1 mycroft /* use pass-through matrix (disable NTSC) */
446 1.1 mycroft strcpy(p, "\033*u2T");
447 1.1 mycroft p += strlen(p);
448 1.5 mycroft break;
449 1.1 mycroft }
450 1.1 mycroft
451 1.8 christos p += sprintf(p, "\033*a%dG", ss->sio.scan_bits_per_pixel);
452 1.8 christos p += sprintf(p, "\033*a%dL", (int)(ss->sio.scan_brightness) - 128);
453 1.8 christos p += sprintf(p, "\033*a%dK", (int)(ss->sio.scan_contrast) - 128);
454 1.1 mycroft
455 1.17 mycroft return (scanjet_ctl_write(ss, escape_codes, p - escape_codes));
456 1.5 mycroft }
457 1.5 mycroft
458 1.5 mycroft int
459 1.1 mycroft scanjet_compute_sizes(ss)
460 1.1 mycroft struct ss_softc *ss;
461 1.1 mycroft {
462 1.5 mycroft int error;
463 1.22 bouyer static const char *wfail = "%s: interrogate write failed\n";
464 1.22 bouyer static const char *rfail = "%s: interrogate read failed\n";
465 1.22 bouyer static const char *dfail = "%s: bad data returned\n";
466 1.5 mycroft char escape_codes[20];
467 1.5 mycroft char response[20];
468 1.5 mycroft char *p;
469 1.1 mycroft
470 1.1 mycroft /*
471 1.1 mycroft * Deal with the fact that the HP ScanJet IIc uses 1/300" not 1/1200"
472 1.1 mycroft * as its base unit of measurement. PINT uses 1/1200" (yes I know
473 1.1 mycroft * ScanJet II's use decipoints as well but 1200 % 720 != 0)
474 1.1 mycroft */
475 1.1 mycroft ss->sio.scan_width = (ss->sio.scan_width + 3) & 0xfffffffc;
476 1.1 mycroft ss->sio.scan_height = (ss->sio.scan_height + 3) & 0xfffffffc;
477 1.1 mycroft
478 1.1 mycroft switch (ss->sio.scan_image_mode) {
479 1.1 mycroft case SIM_BINARY_MONOCHROME:
480 1.1 mycroft case SIM_DITHERED_MONOCHROME:
481 1.5 mycroft strcpy(escape_codes, "\033*s1025E"); /* bytes wide */
482 1.1 mycroft break;
483 1.1 mycroft case SIM_GRAYSCALE:
484 1.1 mycroft case SIM_COLOR:
485 1.5 mycroft strcpy(escape_codes, "\033*s1024E"); /* pixels wide */
486 1.1 mycroft break;
487 1.1 mycroft }
488 1.17 mycroft error = scanjet_ctl_write(ss, escape_codes, strlen(escape_codes));
489 1.5 mycroft if (error) {
490 1.5 mycroft uprintf(wfail, ss->sc_dev.dv_xname);
491 1.5 mycroft return (error);
492 1.5 mycroft }
493 1.17 mycroft error = scanjet_ctl_read(ss, response, 20);
494 1.5 mycroft if (error) {
495 1.5 mycroft uprintf(rfail, ss->sc_dev.dv_xname);
496 1.5 mycroft return (error);
497 1.5 mycroft }
498 1.5 mycroft p = strchr(response, 'd');
499 1.5 mycroft if (p == 0) {
500 1.5 mycroft uprintf(dfail, ss->sc_dev.dv_xname);
501 1.5 mycroft return (EIO);
502 1.5 mycroft }
503 1.28 chs ss->sio.scan_pixels_per_line = strtoul(p + 1, NULL, 10);
504 1.5 mycroft if (ss->sio.scan_image_mode < SIM_GRAYSCALE)
505 1.5 mycroft ss->sio.scan_pixels_per_line *= 8;
506 1.1 mycroft
507 1.5 mycroft strcpy(escape_codes, "\033*s1026E"); /* pixels high */
508 1.17 mycroft error = scanjet_ctl_write(ss, escape_codes, strlen(escape_codes));
509 1.5 mycroft if (error) {
510 1.5 mycroft uprintf(wfail, ss->sc_dev.dv_xname);
511 1.5 mycroft return (error);
512 1.5 mycroft }
513 1.17 mycroft error = scanjet_ctl_read(ss, response, 20);
514 1.5 mycroft if (error) {
515 1.5 mycroft uprintf(rfail, ss->sc_dev.dv_xname);
516 1.5 mycroft return (error);
517 1.5 mycroft }
518 1.5 mycroft p = strchr(response, 'd');
519 1.5 mycroft if (p == 0) {
520 1.5 mycroft uprintf(dfail, ss->sc_dev.dv_xname);
521 1.5 mycroft return (EIO);
522 1.5 mycroft }
523 1.28 chs ss->sio.scan_lines = strtoul(p + 1, NULL, 10);
524 1.1 mycroft
525 1.1 mycroft ss->sio.scan_window_size = ss->sio.scan_lines *
526 1.1 mycroft ((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8);
527 1.5 mycroft
528 1.5 mycroft return (0);
529 1.1 mycroft }
530