1 /* sane - Scanner Access Now Easy.
2 
3    BACKEND canon_lide70
4 
5    Copyright (C) 2019-2021 Juergen Ernst and pimvantend.
6 
7    This file is part of the SANE package.
8 
9    This program is free software; you can redistribute it and/or
10    modify it under the terms of the GNU General Public License as
11    published by the Free Software Foundation; either version 2 of the
12    License, or (at your option) any later version.
13 
14    This program is distributed in the hope that it will be useful, but
15    WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17    General Public License for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <https://www.gnu.org/licenses/>.
21 
22    This file implements a SANE backend for the Canon CanoScan LiDE 70 and 600 */
23 
24 #include <errno.h>
25 #include <fcntl.h>		/* open */
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <unistd.h>		/* usleep */
30 #include <time.h>
31 #include <math.h>		/* pow() */
32 #ifdef HAVE_OS2_H
33 #include <sys/types.h>		/* mode_t */
34 #endif
35 #include <sys/stat.h>
36 
37 #define USB_TYPE_VENDOR   (0x02 << 5)
38 #define USB_RECIP_DEVICE   0x00
39 #define USB_DIR_OUT        0x00
40 #define USB_DIR_IN         0x80
41 
42 #define MSEC               1000	/* 1ms = 1000us */
43 
44 /* Assign status and verify a good return code */
45 #define CHK(A) {if ((status = A) != SANE_STATUS_GOOD) {\
46                 DBG (1, "Failure on line of %s: %d\n", \
47                      __FILE__, __LINE__ ); return A; }}
48 
49 typedef SANE_Byte byte;
50 
51 /*****************************************************
52            Canon LiDE70 calibration and scan
53 ******************************************************/
54 
55 /* at 600 dpi */
56 #define CANON_MAX_WIDTH    5104	/* 8.5in */
57 /* this may not be right */
58 #define CANON_MAX_HEIGHT   7300	/* 11.66in */
59 /* Just for my scanner, or is this universal?  Calibrate? */
60 
61 /* data structures and constants */
62 typedef struct CANON_Handle
63 {
64   /* options */
65   SANE_Option_Descriptor opt[num_options];
66   Option_Value val[num_options];
67   SANE_Parameters params;
68 
69   SANE_Word graymode;
70   char *product;		/* product name */
71   int productcode;		/* product code, 0x2224 or 0x2225 */
72   int fd;			/* scanner fd */
73   int x1, x2, y1, y2;		/* in pixels, at 600 dpi */
74   long width, height;		/* at scan resolution */
75   unsigned char value_08, value_09;	/* left */
76   unsigned char value_0a, value_0b;	/* right */
77   unsigned char value_66, value_67, value_68;	/* bottom */
78   unsigned char value_51;	/* lamp colors */
79   unsigned char value_90;	/* motor mode */
80   int resolution;		/* dpi */
81   char *fname;			/* output file name */
82   FILE *fp;			/* output file pointer (for reading) */
83   unsigned char absolute_threshold;
84   double table_gamma;
85   double table_gamma_blue;
86   unsigned char highlight_red_enhanced;
87   unsigned char highlight_blue_reduced;
88   unsigned char highlight_other;
89 }
90 CANON_Handle;
91 
92 /*****************************************************
93             CP2155 communication primitives
94    Provides I/O routines to Philips CP2155BE chip
95 ******************************************************/
96 
97 typedef int CP2155_Register;
98 
99 /* Write single byte to CP2155 register */
100 static SANE_Status
cp2155_set(int fd, CP2155_Register reg, byte data)101 cp2155_set (int fd, CP2155_Register reg, byte data)
102 {
103   SANE_Status status;
104   byte cmd_buffer[5];
105   size_t count = 5 /* = sizeof(cmd_buffer) */ ;
106 
107   cmd_buffer[0] = (reg >> 8) & 0xff;
108   cmd_buffer[1] = (reg) & 0xff;
109   cmd_buffer[2] = 0x01;
110   cmd_buffer[3] = 0x00;
111   cmd_buffer[4] = data;
112 
113 /*  if (cmd_buffer[0]==0 && cmd_buffer[1]>0x21 && cmd_buffer[1]<0x44)
114     { */
115   DBG (1, "cp2155_set %02x %02x %02x %02x %02x\n",
116        cmd_buffer[0], cmd_buffer[1], cmd_buffer[2],
117        cmd_buffer[3], cmd_buffer[4]);
118 /*    } */
119 /* */
120   usleep (0.0 * MSEC);
121 /* */
122   status = sanei_usb_write_bulk (fd, cmd_buffer, &count);
123 
124   if (status != SANE_STATUS_GOOD)
125     {
126       DBG (1, "cp2155_set: sanei_usb_write_bulk error\n");
127 /*      exit(0); */
128     }
129 
130   return status;
131 }
132 
133 /* Read single byte from CP2155 register */
134 static SANE_Status
cp2155_get(int fd, CP2155_Register reg, byte * data)135 cp2155_get (int fd, CP2155_Register reg, byte * data)
136 {
137   SANE_Status status;
138   byte cmd_buffer[4];
139   size_t count = 4;		/* = sizeof(cmd_buffer) */
140 
141   cmd_buffer[0] = 0x01;
142   cmd_buffer[1] = (reg) & 0xff;
143   cmd_buffer[2] = 0x01;
144   cmd_buffer[3] = 0x00;
145 
146   status = sanei_usb_write_bulk (fd, cmd_buffer, &count);
147 
148   if (status != SANE_STATUS_GOOD)
149     {
150       DBG (1, "cp2155_get: sanei_usb_write_bulk error\n");
151       return status;
152     }
153 
154   usleep (1 * MSEC);
155 
156   count = 1;
157   status = sanei_usb_read_bulk (fd, data, &count);
158 
159   if (status != SANE_STATUS_GOOD)
160     {
161       DBG (1, "cp2155_get: sanei_usb_read_bulk error\n");
162     }
163 
164   return status;
165 }
166 
167 /* Read a block of data from CP2155 chip */
168 static SANE_Status
cp2155_read(int fd, byte * data, size_t size)169 cp2155_read (int fd, byte * data, size_t size)
170 {
171   SANE_Status status;
172   byte cmd_buffer[4];
173   size_t count = 4;		/* = sizeof(cmd_buffer) */
174 
175   cmd_buffer[0] = 0x05;
176   cmd_buffer[1] = 0x70;
177   cmd_buffer[2] = (size) & 0xff;
178   cmd_buffer[3] = (size >> 8) & 0xff;
179 
180   status = sanei_usb_write_bulk (fd, cmd_buffer, &count);
181 
182   if (status != SANE_STATUS_GOOD)
183     {
184       DBG (1, "cp2155_read: sanei_usb_write_bulk error\n");
185       return status;
186     }
187 
188   usleep (1 * MSEC);
189 
190   count = size;
191   status = sanei_usb_read_bulk (fd, data, &count);
192 /*
193   if (status != SANE_STATUS_GOOD)
194     {
195       DBG (1, "cp2155_read: sanei_usb_read_bulk error %lu\n", (u_long) count);
196     }
197 */
198   return status;
199 }
200 
201 /*****************************************************/
202 
203 static void
cp2155_write_gamma_block(int fd, unsigned int addr, byte * data)204 cp2155_write_gamma_block (int fd, unsigned int addr, byte * data)
205 {
206   byte value_71 = 0x16;
207   size_t count = 0x100;
208 
209   while ((count & 0x0f) != 0)
210     {
211       count++;
212     }
213 
214   byte pgLO = (count) & 0xff;
215   byte pgHI = (count >> 8) & 0xff;
216 /*
217   DBG (1, "cp2155_write_gamma_block %06x %02x %04lx %04lx\n", addr, v001, (u_long) size,
218        (u_long) count);
219 */
220   cp2155_set (fd, 0x71, 0x01);
221   cp2155_set (fd, 0x0230, 0x11);
222   cp2155_set (fd, 0x71, value_71);
223   cp2155_set (fd, 0x72, pgHI);
224   cp2155_set (fd, 0x73, pgLO);
225   cp2155_set (fd, 0x74, (addr >> 16) & 0xff);
226   cp2155_set (fd, 0x75, (addr >> 8) & 0xff);
227   cp2155_set (fd, 0x76, (addr) & 0xff);
228   cp2155_set (fd, 0x0239, 0x40);
229   cp2155_set (fd, 0x0238, 0x89);
230   cp2155_set (fd, 0x023c, 0x2f);
231   cp2155_set (fd, 0x0264, 0x20);
232 
233   count = count + 4;
234   sanei_usb_write_bulk (fd, data, &count);
235 }
236 
237 void
makegammatable(double gamma, int highlight, unsigned char *buf)238 makegammatable (double gamma, int highlight, unsigned char *buf)
239 {
240   int maxin = 255;		/* 8 bit gamma input */
241   int maxout = 255;		/* 8 bit gamma output */
242   int in = 0;
243   int out;
244 
245   buf[0] = 0x04;
246   buf[1] = 0x70;
247   buf[2] = 0x00;
248   buf[3] = 0x01;
249 
250   while (in < highlight)
251     {
252       out = maxout * pow ((double) in / highlight, (1.0 / gamma));
253       buf[in + 4] = (unsigned char) out;
254       in++;
255     }
256 
257   while (in <= maxin)
258     {
259       buf[in + 4] = maxout;
260       in++;
261     }
262 
263   return;
264 }
265 
266 static void
cp2155_set_gamma(int fd, CANON_Handle * chndl)267 cp2155_set_gamma (int fd, CANON_Handle * chndl)
268 {
269   DBG (1, "cp2155_set_gamma\n");
270   unsigned char buf[260];
271 /* gamma tables */
272   makegammatable (chndl->table_gamma, chndl->highlight_other, buf);
273   cp2155_write_gamma_block (fd, 0x000, buf);
274   cp2155_write_gamma_block (fd, 0x100, buf);
275   cp2155_write_gamma_block (fd, 0x200, buf);
276 }
277 
278 static void
cp2155_set_gamma_red_enhanced(int fd, CANON_Handle * chndl)279 cp2155_set_gamma_red_enhanced (int fd, CANON_Handle * chndl)
280 {
281   DBG (1, "cp2155_set_gamma\n");
282   unsigned char buf[260];
283 /* gamma tables */
284   makegammatable (chndl->table_gamma, chndl->highlight_red_enhanced, buf);
285   cp2155_write_gamma_block (fd, 0x000, buf);
286   makegammatable (chndl->table_gamma, chndl->highlight_other, buf);
287   cp2155_write_gamma_block (fd, 0x100, buf);
288   makegammatable (chndl->table_gamma_blue, chndl->highlight_blue_reduced,
289 		  buf);
290   cp2155_write_gamma_block (fd, 0x200, buf);
291 }
292 
293 void
make_descending_slope(size_t start_descent, double coefficient, unsigned char *buf)294 make_descending_slope (size_t start_descent, double coefficient,
295 		       unsigned char *buf)
296 {
297   size_t count, position;
298   int top_value;
299   int value;
300   unsigned char value_lo, value_hi;
301   DBG (1, "start_descent = %lx\n", start_descent);
302   top_value = buf[start_descent - 2] + 256 * buf[start_descent - 1];
303   DBG (1, "buf[start_descent-2] = %02x buf[start_descent-1] = %02x\n",
304        buf[start_descent - 2], buf[start_descent - 1]);
305   count = buf[2] + 256 * buf[3];
306   position = start_descent;
307   DBG (1, "count = %ld top_value = %d\n", count, top_value);
308   while (position < count + 4)
309     {
310       value =
311 	(int) (top_value /
312 	       (1.0 + coefficient * (position + 2 - start_descent)));
313       value_lo = value & 0xff;
314       value_hi = (value >> 8) & 0xff;
315       buf[position] = value_lo;
316       buf[position + 1] = value_hi;
317       DBG (1,
318 	   "position = %03lx  buf[position]= %02x buf[position+1] = %02x\n",
319 	   position, buf[position], buf[position + 1]);
320       position += 2;
321     }
322 }
323 
324 void
make_constant_buf(size_t count, unsigned int hiword, unsigned int loword, unsigned char *buf)325 make_constant_buf (size_t count, unsigned int hiword, unsigned int loword,
326 		   unsigned char *buf)
327 {
328   size_t i = 4;
329   unsigned char hihi = (hiword >> 8) & 0xff;
330   unsigned char hilo = (hiword) & 0xff;
331   unsigned char lohi = (loword >> 8) & 0xff;
332   unsigned char lolo = (loword) & 0xff;
333   buf[0] = 0x04;
334   buf[1] = 0x70;
335   buf[2] = (count - 4) & 0xff;
336   buf[3] = ((count - 4) >> 8) & 0xff;
337   while (i < count)
338     {
339       buf[i] = hilo;
340       i++;
341       buf[i] = hihi;
342       i++;
343       buf[i] = lolo;
344       i++;
345       buf[i] = lohi;
346       i++;
347     }
348 }
349 
350 void
make_slope_table(size_t count, unsigned int word, size_t start_descent, double coefficient, unsigned char *buf)351 make_slope_table (size_t count, unsigned int word, size_t start_descent,
352 		  double coefficient, unsigned char *buf)
353 {
354   size_t i = 4;
355   unsigned char hi = (word >> 8) & 0xff;
356   unsigned char lo = (word) & 0xff;
357   buf[0] = 0x04;
358   buf[1] = 0x70;
359   buf[2] = (count - 4) & 0xff;
360   buf[3] = ((count - 4) >> 8) & 0xff;
361   while (i < start_descent)
362     {
363       buf[i] = lo;
364       i++;
365       buf[i] = hi;
366       i++;
367     }
368   make_descending_slope (start_descent, coefficient, buf);
369 }
370 
371 void
write_buf(int fd, size_t count, unsigned char *buf, unsigned char value_74, unsigned char value_75)372 write_buf (int fd, size_t count, unsigned char *buf,
373 	   unsigned char value_74, unsigned char value_75)
374 {
375   unsigned char value_72, value_73;
376   value_72 = ((count - 4) >> 8) & 0xff;
377   value_73 = (count - 4) & 0xff;
378   cp2155_set (fd, 0x71, 0x01);
379   cp2155_set (fd, 0x0230, 0x11);
380   cp2155_set (fd, 0x71, 0x14);
381   cp2155_set (fd, 0x72, value_72);
382   cp2155_set (fd, 0x73, value_73);
383   cp2155_set (fd, 0x74, value_74);
384   cp2155_set (fd, 0x75, value_75);
385   cp2155_set (fd, 0x76, 0x00);
386   cp2155_set (fd, 0x0239, 0x40);
387   cp2155_set (fd, 0x0238, 0x89);
388   cp2155_set (fd, 0x023c, 0x2f);
389   cp2155_set (fd, 0x0264, 0x20);
390   sanei_usb_write_bulk (fd, buf, &count);
391 }
392 
393 void
big_write(int fd, size_t count, unsigned char *buf)394 big_write (int fd, size_t count, unsigned char *buf)
395 {
396   make_constant_buf (count, 62756, 20918, buf);
397   write_buf (fd, count, buf, 0x00, 0x00);
398   write_buf (fd, count, buf, 0x00, 0xb0);
399   write_buf (fd, count, buf, 0x01, 0x60);
400   write_buf (fd, count, buf, 0x02, 0x10);
401 }
402 
403 void
big_write_2224(int fd, size_t count, unsigned char *buf)404 big_write_2224 (int fd, size_t count, unsigned char *buf)
405 {
406   make_constant_buf (count, 62756, 30918, buf);
407   write_buf (fd, count, buf, 0x00, 0x00);
408   write_buf (fd, count, buf, 0x00, 0xb0);
409   write_buf (fd, count, buf, 0x01, 0x60);
410   write_buf (fd, count, buf, 0x02, 0x10);
411 }
412 
413 void
big_write_film(int fd, size_t count, unsigned char *buf)414 big_write_film (int fd, size_t count, unsigned char *buf)
415 {
416   make_constant_buf (count, 62756, 20918, buf);
417   write_buf (fd, count, buf, 0x00, 0x00);
418   write_buf (fd, count, buf, 0x02, 0x00);
419   write_buf (fd, count, buf, 0x04, 0x00);
420   write_buf (fd, count, buf, 0x06, 0x00);
421 }
422 
423 void
general_motor_2225(int fd)424 general_motor_2225 (int fd)
425 {
426   cp2155_set (fd, 0x9b, 0x02);
427   cp2155_set (fd, 0x10, 0x05);
428   cp2155_set (fd, 0x11, 0x91);
429   cp2155_set (fd, 0x60, 0x15);
430   cp2155_set (fd, 0x80, 0x12);
431   cp2155_set (fd, 0x03, 0x01);
432   cp2155_set (fd, 0x71, 0x01);
433   cp2155_set (fd, 0x0230, 0x11);
434   cp2155_set (fd, 0x71, 0x18);
435   cp2155_set (fd, 0x72, 0x00);
436   cp2155_set (fd, 0x73, 0x10);
437   cp2155_set (fd, 0x0239, 0x40);
438   cp2155_set (fd, 0x0238, 0x89);
439   cp2155_set (fd, 0x023c, 0x2f);
440   cp2155_set (fd, 0x0264, 0x20);
441 }
442 
443 void
general_motor_2224(int fd)444 general_motor_2224 (int fd)
445 {
446   cp2155_set (fd, 0x90, 0xfa);
447   cp2155_set (fd, 0x10, 0x05);
448   cp2155_set (fd, 0x11, 0x91);
449   cp2155_set (fd, 0x60, 0x01);
450   cp2155_set (fd, 0x80, 0x12);
451   cp2155_set (fd, 0x03, 0x01);
452   cp2155_set (fd, 0x71, 0x01);
453   cp2155_set (fd, 0x0230, 0x11);
454   cp2155_set (fd, 0x71, 0x18);
455   cp2155_set (fd, 0x72, 0x00);
456   cp2155_set (fd, 0x73, 0x10);
457   cp2155_set (fd, 0x0239, 0x40);
458   cp2155_set (fd, 0x0238, 0x89);
459   cp2155_set (fd, 0x023c, 0x2f);
460   cp2155_set (fd, 0x0264, 0x20);
461 }
462 
463 void
register_table(int fd, unsigned char register_value, unsigned char *buf)464 register_table (int fd, unsigned char register_value, unsigned char *buf)
465 {
466   cp2155_set (fd, 0x1a, 0x00);
467   cp2155_set (fd, 0x1b, 0x00);
468   cp2155_set (fd, 0x1c, 0x02);
469   cp2155_set (fd, 0x15, 0x80);
470   cp2155_set (fd, 0x14, 0x7c);
471   cp2155_set (fd, 0x17, 0x01);
472   cp2155_set (fd, 0x43, 0x1c);
473   cp2155_set (fd, 0x44, 0x9c);
474   cp2155_set (fd, 0x45, 0x38);
475   if (register_value > 0)
476     {
477       unsigned char register_number = 0x23;
478       while (register_number < 0x43)
479 	{
480 	  cp2155_set (fd, register_number, register_value);
481 	  register_number++;
482 	}
483     }
484   else
485     {
486       int buffer_index = 0;
487       cp2155_set (fd, 0x23 + buffer_index, buf[buffer_index]);
488       cp2155_set (fd, 0x33 + buffer_index, buf[buffer_index]);
489       buffer_index++;
490       while (buffer_index < 9)
491 	{
492 	  cp2155_set (fd, 0x23 + buffer_index, buf[buffer_index]);
493 	  cp2155_set (fd, 0x33 + buffer_index, buf[buffer_index]);
494 	  cp2155_set (fd, 0x43 - buffer_index, buf[buffer_index]);
495 	  cp2155_set (fd, 0x33 - buffer_index, buf[buffer_index]);
496 	  buffer_index++;
497 	}
498     }
499 
500   cp2155_set (fd, 0xca, 0x00);
501   cp2155_set (fd, 0xca, 0x00);
502   cp2155_set (fd, 0xca, 0x00);
503 
504 }
505 
506 void
register_table_4800(int fd, unsigned char register_value, unsigned char *buf)507 register_table_4800 (int fd, unsigned char register_value, unsigned char *buf)
508 {
509   cp2155_set (fd, 0x1a, 0x00);
510   cp2155_set (fd, 0x1b, 0x00);
511   cp2155_set (fd, 0x1c, 0x02);
512   cp2155_set (fd, 0x15, 0x80);
513   cp2155_set (fd, 0x14, 0x7a);
514   cp2155_set (fd, 0x17, 0x02);
515   cp2155_set (fd, 0x43, 0x1c);
516   cp2155_set (fd, 0x44, 0x9c);
517   cp2155_set (fd, 0x45, 0x38);
518   if (register_value > 0)
519     {
520       unsigned char register_number = 0x23;
521       while (register_number < 0x43)
522 	{
523 	  cp2155_set (fd, register_number, register_value);
524 	  register_number++;
525 	}
526     }
527   else
528     {
529       int buffer_index = 0;
530       cp2155_set (fd, 0x23 + buffer_index, buf[buffer_index]);
531       cp2155_set (fd, 0x33 + buffer_index, buf[buffer_index]);
532       buffer_index++;
533       while (buffer_index < 9)
534 	{
535 	  cp2155_set (fd, 0x23 + buffer_index, buf[buffer_index]);
536 	  cp2155_set (fd, 0x33 + buffer_index, buf[buffer_index]);
537 	  cp2155_set (fd, 0x43 - buffer_index, buf[buffer_index]);
538 	  cp2155_set (fd, 0x33 - buffer_index, buf[buffer_index]);
539 	  buffer_index++;
540 	}
541     }
542 
543   cp2155_set (fd, 0xca, 0x00);
544   cp2155_set (fd, 0xca, 0x00);
545   cp2155_set (fd, 0xca, 0x00);
546 
547 }
548 
549 void
startblob_2225_0075(CANON_Handle * chndl, unsigned char *buf)550 startblob_2225_0075 (CANON_Handle * chndl, unsigned char *buf)
551 {
552 
553   int fd;
554   fd = chndl->fd;
555   size_t count;
556 
557   unsigned int top_value = 0x2580;
558   unsigned char value_62 = 0x2e;
559 
560 /* original:
561   unsigned int top_value = 0x2580;
562   unsigned char value_62 = 0x2e;
563   ratio 320 decimal
564 
565 */
566   cp2155_set (fd, 0x90, 0xd8);
567   cp2155_set (fd, 0x90, 0xd8);
568   cp2155_set (fd, 0xb0, 0x03);
569   cp2155_set (fd, 0x07, 0x00);
570   cp2155_set (fd, 0x07, 0x00);
571   cp2155_set (fd, 0x08, chndl->value_08);
572   cp2155_set (fd, 0x09, chndl->value_09);
573   cp2155_set (fd, 0x0a, chndl->value_0a);
574   cp2155_set (fd, 0x0b, chndl->value_0b);
575   cp2155_set (fd, 0xa0, 0x1d);
576   cp2155_set (fd, 0xa1, 0x00);
577   cp2155_set (fd, 0xa2, 0x06);
578   cp2155_set (fd, 0xa3, 0x70);
579   cp2155_set (fd, 0x64, 0x00);
580   cp2155_set (fd, 0x65, 0x00);
581   cp2155_set (fd, 0x61, 0x00);
582   cp2155_set (fd, 0x62, value_62);
583   cp2155_set (fd, 0x63, 0x00);
584   cp2155_set (fd, 0x50, 0x04);
585   cp2155_set (fd, 0x50, 0x04);
586   cp2155_set (fd, 0x51, chndl->value_51);
587   cp2155_set (fd, 0x5a, 0x32);
588   cp2155_set (fd, 0x5b, 0x32);
589   cp2155_set (fd, 0x5c, 0x32);
590   cp2155_set (fd, 0x5d, 0x32);
591   cp2155_set (fd, 0x52, 0x09);
592   cp2155_set (fd, 0x53, 0x5a);
593   cp2155_set (fd, 0x54, 0x06);
594   cp2155_set (fd, 0x55, 0x08);
595   cp2155_set (fd, 0x56, 0x05);
596   cp2155_set (fd, 0x57, 0x5f);
597   cp2155_set (fd, 0x58, 0xa9);
598   cp2155_set (fd, 0x59, 0xce);
599   cp2155_set (fd, 0x5e, 0x02);
600   cp2155_set (fd, 0x5f, 0x00);
601   cp2155_set (fd, 0x5f, 0x03);
602   cp2155_set (fd, 0x60, 0x15);
603   cp2155_set (fd, 0x60, 0x15);
604   cp2155_set (fd, 0x60, 0x15);
605   cp2155_set (fd, 0x60, 0x15);
606   cp2155_set (fd, 0x50, 0x04);
607   cp2155_set (fd, 0x51, chndl->value_51);
608   cp2155_set (fd, 0x81, 0x29);
609   cp2155_set (fd, 0x81, 0x29);
610   cp2155_set (fd, 0x82, 0x09);
611   cp2155_set (fd, 0x82, 0x09);
612   cp2155_set (fd, 0x83, 0x02);
613   cp2155_set (fd, 0x84, 0x06);
614   cp2155_set (fd, 0x80, 0x12);
615   cp2155_set (fd, 0x80, 0x12);
616   cp2155_set (fd, 0xb0, 0x0b);
617 
618   big_write (fd, 0x5174, buf);
619 
620   cp2155_set (fd, 0x10, 0x05);
621   cp2155_set (fd, 0x10, 0x05);
622   cp2155_set (fd, 0x9b, 0x03);
623   cp2155_set (fd, 0x10, 0x05);
624   cp2155_set (fd, 0x11, 0xc1);
625   cp2155_set (fd, 0x11, 0xc1);
626   cp2155_set (fd, 0x11, 0x81);
627   cp2155_set (fd, 0x11, 0x81);
628   cp2155_set (fd, 0x11, 0x81);
629   cp2155_set (fd, 0x11, 0x81);
630   cp2155_set (fd, 0x11, 0x81);
631   cp2155_set (fd, 0x12, 0x40);
632   cp2155_set (fd, 0x13, 0x40);
633   cp2155_set (fd, 0x16, 0x40);
634   cp2155_set (fd, 0x21, 0x06);
635   cp2155_set (fd, 0x22, 0x40);
636   cp2155_set (fd, 0x20, 0x06);
637   cp2155_set (fd, 0x1d, 0x00);
638   cp2155_set (fd, 0x1e, 0x00);
639   cp2155_set (fd, 0x1f, 0xf0);
640   cp2155_set (fd, 0x66, 0x00);
641   cp2155_set (fd, 0x67, chndl->value_67);
642   cp2155_set (fd, 0x68, chndl->value_68);
643 
644   memcpy (buf, "\x28\x27\x25\x21\x1c\x16\x0f\x08\x00", 9);
645   register_table (fd, 0, buf);
646   cp2155_set (fd, 0x18, 0x00);
647 
648   count = 260;
649   make_slope_table (count, top_value, 0x6a, 0.021739, buf);
650 
651   write_buf (fd, count, buf, 0x03, 0x00);
652   write_buf (fd, count, buf, 0x03, 0x02);
653   write_buf (fd, count, buf, 0x03, 0x06);
654 
655   count = 36;
656   make_slope_table (count, top_value, 0x06, 0.15217, buf);
657 
658   write_buf (fd, count, buf, 0x03, 0x04);
659   write_buf (fd, count, buf, 0x03, 0x08);
660 
661   general_motor_2225 (fd);
662 }
663 
664 void
startblob_2225_0150(CANON_Handle * chndl, unsigned char *buf)665 startblob_2225_0150 (CANON_Handle * chndl, unsigned char *buf)
666 {
667 
668   int fd;
669   fd = chndl->fd;
670   size_t count;
671 
672   unsigned int top_value = 0x2580;
673   unsigned char value_62 = 0x1e;
674 
675 /* original:
676   unsigned int top_value = 0x2580;
677   unsigned char value_62 = 0x1e;
678   ratio 320 decimal
679 */
680   cp2155_set (fd, 0x90, 0xd8);
681   cp2155_set (fd, 0x90, 0xd8);
682   cp2155_set (fd, 0xb0, 0x02);
683   cp2155_set (fd, 0x07, 0x00);
684   cp2155_set (fd, 0x07, 0x00);
685   cp2155_set (fd, 0x08, chndl->value_08);
686   cp2155_set (fd, 0x09, chndl->value_09);
687   cp2155_set (fd, 0x0a, chndl->value_0a);
688   cp2155_set (fd, 0x0b, chndl->value_0b);
689   cp2155_set (fd, 0xa0, 0x1d);
690   cp2155_set (fd, 0xa1, 0x00);
691   cp2155_set (fd, 0xa2, 0x0c);
692   cp2155_set (fd, 0xa3, 0xd0);
693   cp2155_set (fd, 0x64, 0x00);
694   cp2155_set (fd, 0x65, 0x00);
695   cp2155_set (fd, 0x61, 0x00);
696   cp2155_set (fd, 0x62, value_62);
697   cp2155_set (fd, 0x63, 0xa0);
698   cp2155_set (fd, 0x50, 0x04);
699   cp2155_set (fd, 0x50, 0x04);
700   cp2155_set (fd, 0x51, chndl->value_51);
701   cp2155_set (fd, 0x5a, 0x32);
702   cp2155_set (fd, 0x5b, 0x32);
703   cp2155_set (fd, 0x5c, 0x32);
704   cp2155_set (fd, 0x5d, 0x32);
705   cp2155_set (fd, 0x52, 0x09);
706   cp2155_set (fd, 0x53, 0x5a);
707   cp2155_set (fd, 0x54, 0x06);
708   cp2155_set (fd, 0x55, 0x08);
709   cp2155_set (fd, 0x56, 0x05);
710   cp2155_set (fd, 0x57, 0x5f);
711   cp2155_set (fd, 0x58, 0xa9);
712   cp2155_set (fd, 0x59, 0xce);
713   cp2155_set (fd, 0x5e, 0x02);
714   cp2155_set (fd, 0x5f, 0x00);
715   cp2155_set (fd, 0x5f, 0x03);
716   cp2155_set (fd, 0x60, 0x15);
717   cp2155_set (fd, 0x60, 0x15);
718   cp2155_set (fd, 0x60, 0x15);
719   cp2155_set (fd, 0x60, 0x15);
720   cp2155_set (fd, 0x50, 0x04);
721   cp2155_set (fd, 0x51, chndl->value_51);
722   cp2155_set (fd, 0x81, 0x29);
723   cp2155_set (fd, 0x81, 0x29);
724   cp2155_set (fd, 0x82, 0x09);
725   cp2155_set (fd, 0x82, 0x09);
726   cp2155_set (fd, 0x83, 0x02);
727   cp2155_set (fd, 0x84, 0x06);
728   cp2155_set (fd, 0x80, 0x12);
729   cp2155_set (fd, 0x80, 0x12);
730   cp2155_set (fd, 0xb0, 0x0a);
731 
732   big_write (fd, 0x5174, buf);
733 
734   cp2155_set (fd, 0x10, 0x05);
735   cp2155_set (fd, 0x10, 0x05);
736   cp2155_set (fd, 0x9b, 0x03);
737   cp2155_set (fd, 0x10, 0x05);
738   cp2155_set (fd, 0x11, 0x81);
739   cp2155_set (fd, 0x11, 0x81);
740   cp2155_set (fd, 0x11, 0x81);
741   cp2155_set (fd, 0x11, 0x81);
742   cp2155_set (fd, 0x11, 0x81);
743   cp2155_set (fd, 0x11, 0x81);
744   cp2155_set (fd, 0x11, 0x81);
745   cp2155_set (fd, 0x12, 0x40);
746   cp2155_set (fd, 0x13, 0x40);
747   cp2155_set (fd, 0x16, 0x40);
748   cp2155_set (fd, 0x21, 0x06);
749   cp2155_set (fd, 0x22, 0x40);
750   cp2155_set (fd, 0x20, 0x06);
751   cp2155_set (fd, 0x1d, 0x00);
752   cp2155_set (fd, 0x1e, 0x00);
753   cp2155_set (fd, 0x1f, 0x04);
754   cp2155_set (fd, 0x66, 0x00);
755   cp2155_set (fd, 0x67, chndl->value_67);
756   cp2155_set (fd, 0x68, chndl->value_68);
757 
758   memcpy (buf, "\x28\x27\x25\x21\x1c\x16\x0f\x08\x00", 9);
759   register_table (fd, 0, buf);
760   cp2155_set (fd, 0x18, 0x00);
761 
762   count = 260;
763   make_slope_table (count, top_value, 0x06, 0.0089185, buf);
764 
765   write_buf (fd, count, buf, 0x03, 0x00);
766   write_buf (fd, count, buf, 0x03, 0x02);
767   write_buf (fd, count, buf, 0x03, 0x06);
768 
769   count = 36;
770   make_slope_table (count, top_value, 0x06, 0.102968, buf);
771 
772   write_buf (fd, count, buf, 0x03, 0x04);
773   write_buf (fd, count, buf, 0x03, 0x08);
774 
775   general_motor_2225 (fd);
776 }
777 
778 void
startblob_2225_0300(CANON_Handle * chndl, unsigned char *buf)779 startblob_2225_0300 (CANON_Handle * chndl, unsigned char *buf)
780 {
781 
782   int fd;
783   fd = chndl->fd;
784   size_t count;
785 
786   unsigned int top_value = 0x2580;
787   unsigned char value_62 = 0x2a;
788 
789 /* original:
790   unsigned int top_value = 0x2580;
791   unsigned char value_62 = 0x2a;
792   ratio 228 decimal
793 */
794   cp2155_set (fd, 0x90, 0xd8);
795   cp2155_set (fd, 0x90, 0xd8);
796   cp2155_set (fd, 0xb0, 0x01);
797   cp2155_set (fd, 0x07, 0x00);
798   cp2155_set (fd, 0x07, 0x00);
799   cp2155_set (fd, 0x08, chndl->value_08);
800   cp2155_set (fd, 0x09, chndl->value_09);
801   cp2155_set (fd, 0x0a, chndl->value_0a);
802   cp2155_set (fd, 0x0b, chndl->value_0b);
803   cp2155_set (fd, 0xa0, 0x1d);
804   cp2155_set (fd, 0xa1, 0x00);
805   cp2155_set (fd, 0xa2, 0x19);
806   cp2155_set (fd, 0xa3, 0x30);
807   cp2155_set (fd, 0x64, 0x00);
808   cp2155_set (fd, 0x65, 0x00);
809   cp2155_set (fd, 0x61, 0x00);
810   cp2155_set (fd, 0x62, value_62);
811   cp2155_set (fd, 0x63, 0x80);
812   cp2155_set (fd, 0x50, 0x04);
813   cp2155_set (fd, 0x50, 0x04);
814   cp2155_set (fd, 0x51, chndl->value_51);
815   cp2155_set (fd, 0x5a, 0x32);
816   cp2155_set (fd, 0x5b, 0x32);
817   cp2155_set (fd, 0x5c, 0x32);
818   cp2155_set (fd, 0x5d, 0x32);
819   cp2155_set (fd, 0x52, 0x09);
820   cp2155_set (fd, 0x53, 0x5a);
821   cp2155_set (fd, 0x54, 0x06);
822   cp2155_set (fd, 0x55, 0x08);
823   cp2155_set (fd, 0x56, 0x05);
824   cp2155_set (fd, 0x57, 0x5f);
825   cp2155_set (fd, 0x58, 0xa9);
826   cp2155_set (fd, 0x59, 0xce);
827   cp2155_set (fd, 0x5e, 0x02);
828   cp2155_set (fd, 0x5f, 0x00);
829   cp2155_set (fd, 0x5f, 0x03);
830   cp2155_set (fd, 0x60, 0x15);
831   cp2155_set (fd, 0x60, 0x15);
832   cp2155_set (fd, 0x60, 0x15);
833   cp2155_set (fd, 0x60, 0x15);
834   cp2155_set (fd, 0x50, 0x04);
835   cp2155_set (fd, 0x51, chndl->value_51);
836   cp2155_set (fd, 0x81, 0x29);
837   cp2155_set (fd, 0x81, 0x29);
838   cp2155_set (fd, 0x82, 0x09);
839   cp2155_set (fd, 0x82, 0x09);
840   cp2155_set (fd, 0x83, 0x02);
841   cp2155_set (fd, 0x84, 0x06);
842   cp2155_set (fd, 0x80, 0x12);
843   cp2155_set (fd, 0x80, 0x12);
844   cp2155_set (fd, 0xb0, 0x09);
845 
846   big_write (fd, 0x5174, buf);
847 
848   cp2155_set (fd, 0x10, 0x05);
849   cp2155_set (fd, 0x10, 0x05);
850   cp2155_set (fd, 0x9b, 0x01);
851   cp2155_set (fd, 0x10, 0x05);
852   cp2155_set (fd, 0x11, 0x81);
853   cp2155_set (fd, 0x11, 0x81);
854   cp2155_set (fd, 0x11, 0x81);
855   cp2155_set (fd, 0x11, 0x81);
856   cp2155_set (fd, 0x11, 0x81);
857   cp2155_set (fd, 0x11, 0x81);
858   cp2155_set (fd, 0x11, 0x81);
859   cp2155_set (fd, 0x12, 0x0c);
860   cp2155_set (fd, 0x13, 0x0c);
861   cp2155_set (fd, 0x16, 0x0c);
862   cp2155_set (fd, 0x21, 0x06);
863   cp2155_set (fd, 0x22, 0x0c);
864   cp2155_set (fd, 0x20, 0x06);
865   cp2155_set (fd, 0x1d, 0x00);
866   cp2155_set (fd, 0x1e, 0x00);
867   cp2155_set (fd, 0x1f, 0x04);
868   cp2155_set (fd, 0x66, 0x00);
869   cp2155_set (fd, 0x67, chndl->value_67);
870   cp2155_set (fd, 0x68, chndl->value_68);
871 
872   register_table (fd, 0x14, buf);
873   cp2155_set (fd, 0x18, 0x00);
874 
875   count = 52;
876   make_slope_table (count, top_value, 0x06, 0.0038363, buf);
877 
878   write_buf (fd, count, buf, 0x03, 0x00);
879   write_buf (fd, count, buf, 0x03, 0x02);
880   write_buf (fd, count, buf, 0x03, 0x06);
881 
882   count = 36;
883   make_slope_table (count, top_value, 0x06, 0.0080213, buf);
884 
885   write_buf (fd, count, buf, 0x03, 0x04);
886   write_buf (fd, count, buf, 0x03, 0x08);
887 
888   general_motor_2225 (fd);
889 }
890 
891 void
startblob_2225_0600(CANON_Handle * chndl, unsigned char *buf)892 startblob_2225_0600 (CANON_Handle * chndl, unsigned char *buf)
893 {
894 
895   int fd;
896   fd = chndl->fd;
897   size_t count;
898 
899   unsigned int top_value = 0x2580;
900   unsigned char value_62 = 0x15;
901 
902 /* original:
903   unsigned int top_value = 0x2580;
904   unsigned char value_62 = 0x15;
905   ratio 457 decimal
906 */
907   cp2155_set (fd, 0x90, 0xd8);
908   cp2155_set (fd, 0x90, 0xd8);
909   cp2155_set (fd, 0xb0, 0x00);
910   cp2155_set (fd, 0x07, 0x00);
911   cp2155_set (fd, 0x07, 0x00);
912   cp2155_set (fd, 0x08, chndl->value_08);
913   cp2155_set (fd, 0x09, chndl->value_09);
914   cp2155_set (fd, 0x0a, chndl->value_0a);
915   cp2155_set (fd, 0x0b, chndl->value_0b);
916   cp2155_set (fd, 0xa0, 0x1d);
917   cp2155_set (fd, 0xa1, 0x00);
918   cp2155_set (fd, 0xa2, 0x77);
919   cp2155_set (fd, 0xa3, 0xb0);
920   cp2155_set (fd, 0x64, 0x00);
921   cp2155_set (fd, 0x65, 0x00);
922   cp2155_set (fd, 0x61, 0x00);
923   cp2155_set (fd, 0x62, value_62);
924   cp2155_set (fd, 0x63, 0xe0);
925   cp2155_set (fd, 0x50, 0x04);
926   cp2155_set (fd, 0x50, 0x04);
927   cp2155_set (fd, 0x51, chndl->value_51);
928   cp2155_set (fd, 0x5a, 0x32);
929   cp2155_set (fd, 0x5b, 0x32);
930   cp2155_set (fd, 0x5c, 0x32);
931   cp2155_set (fd, 0x5d, 0x32);
932   cp2155_set (fd, 0x52, 0x07);
933   cp2155_set (fd, 0x53, 0xd0);
934   cp2155_set (fd, 0x54, 0x07);
935   cp2155_set (fd, 0x55, 0xd0);
936   cp2155_set (fd, 0x56, 0x07);
937   cp2155_set (fd, 0x57, 0xd0);
938   cp2155_set (fd, 0x58, 0x00);
939   cp2155_set (fd, 0x59, 0x01);
940   cp2155_set (fd, 0x5e, 0x02);
941   cp2155_set (fd, 0x5f, 0x00);
942   cp2155_set (fd, 0x5f, 0x03);
943   cp2155_set (fd, 0x60, 0x15);
944   cp2155_set (fd, 0x60, 0x15);
945   cp2155_set (fd, 0x60, 0x15);
946   cp2155_set (fd, 0x60, 0x15);
947   cp2155_set (fd, 0x50, 0x04);
948   cp2155_set (fd, 0x51, chndl->value_51);
949   cp2155_set (fd, 0x81, 0x29);
950   cp2155_set (fd, 0x81, 0x29);
951   cp2155_set (fd, 0x82, 0x09);
952   cp2155_set (fd, 0x82, 0x09);
953   cp2155_set (fd, 0x83, 0x02);
954   cp2155_set (fd, 0x84, 0x06);
955   cp2155_set (fd, 0x80, 0x12);
956   cp2155_set (fd, 0x80, 0x12);
957   cp2155_set (fd, 0xb0, 0x00);
958   cp2155_set (fd, 0x10, 0x05);
959   cp2155_set (fd, 0x10, 0x05);
960   cp2155_set (fd, 0x9b, 0x01);
961   cp2155_set (fd, 0x10, 0x05);
962   cp2155_set (fd, 0x11, 0x83);
963   cp2155_set (fd, 0x11, 0x83);
964   cp2155_set (fd, 0x11, 0xc3);
965   cp2155_set (fd, 0x11, 0xc3);
966   cp2155_set (fd, 0x11, 0xc3);
967   cp2155_set (fd, 0x11, 0xc1);
968   cp2155_set (fd, 0x11, 0xc1);
969   cp2155_set (fd, 0x12, 0x12);
970   cp2155_set (fd, 0x13, 0x00);
971   cp2155_set (fd, 0x16, 0x12);
972   cp2155_set (fd, 0x21, 0x06);
973   cp2155_set (fd, 0x22, 0x12);
974   cp2155_set (fd, 0x20, 0x06);
975   cp2155_set (fd, 0x1d, 0x00);
976   cp2155_set (fd, 0x1e, 0x00);
977   cp2155_set (fd, 0x1f, 0x04);
978   cp2155_set (fd, 0x66, 0x00);
979   cp2155_set (fd, 0x67, chndl->value_67);
980   cp2155_set (fd, 0x68, chndl->value_68);
981 
982   register_table (fd, 0x14, buf);
983   cp2155_set (fd, 0x18, 0x00);
984 
985   count = 84;
986   make_slope_table (count, top_value, 0x06, 0.0020408, buf);
987 
988   write_buf (fd, count, buf, 0x03, 0x00);
989   write_buf (fd, count, buf, 0x03, 0x02);
990   write_buf (fd, count, buf, 0x03, 0x06);
991 
992   count = 36;
993   make_slope_table (count, top_value, 0x06, 0.0064935, buf);
994 
995   write_buf (fd, count, buf, 0x03, 0x04);
996   write_buf (fd, count, buf, 0x03, 0x08);
997 
998   general_motor_2225 (fd);
999 }
1000 
1001 void
startblob_2225_1200(CANON_Handle * chndl, unsigned char *buf)1002 startblob_2225_1200 (CANON_Handle * chndl, unsigned char *buf)
1003 {
1004 
1005   int fd;
1006   fd = chndl->fd;
1007   size_t count;
1008 
1009   unsigned int top_value = 0xff00;
1010   unsigned char value_62 = 0xaa;
1011 
1012 /* original:
1013   unsigned int top_value = 0xff00;
1014   unsigned char value_62 = 0xaa;
1015 */
1016   cp2155_set (fd, 0x90, 0xc8);
1017   cp2155_set (fd, 0x90, 0xe8);
1018   cp2155_set (fd, 0xb0, 0x00);
1019   cp2155_set (fd, 0x07, 0x00);
1020   cp2155_set (fd, 0x07, 0x00);
1021   cp2155_set (fd, 0x08, chndl->value_08);
1022   cp2155_set (fd, 0x09, chndl->value_09);
1023   cp2155_set (fd, 0x0a, chndl->value_0a);
1024   cp2155_set (fd, 0x0b, chndl->value_0b);
1025   cp2155_set (fd, 0xa0, 0x1d);
1026   cp2155_set (fd, 0xa1, 0x00);
1027   cp2155_set (fd, 0xa2, 0x63);
1028   cp2155_set (fd, 0xa3, 0xd0);
1029   cp2155_set (fd, 0x64, 0x00);
1030   cp2155_set (fd, 0x65, 0x00);
1031   cp2155_set (fd, 0x61, 0x00);
1032   cp2155_set (fd, 0x62, value_62);
1033   cp2155_set (fd, 0x63, 0x00);
1034   cp2155_set (fd, 0x50, 0x04);
1035   cp2155_set (fd, 0x50, 0x04);
1036   cp2155_set (fd, 0x51, chndl->value_51);
1037   cp2155_set (fd, 0x5a, 0x32);
1038   cp2155_set (fd, 0x5b, 0x32);
1039   cp2155_set (fd, 0x5c, 0x32);
1040   cp2155_set (fd, 0x5d, 0x32);
1041   cp2155_set (fd, 0x52, 0x11);
1042   cp2155_set (fd, 0x53, 0x50);
1043   cp2155_set (fd, 0x54, 0x0c);
1044   cp2155_set (fd, 0x55, 0x01);
1045   cp2155_set (fd, 0x56, 0x0a);
1046   cp2155_set (fd, 0x57, 0xae);
1047   cp2155_set (fd, 0x58, 0xa9);
1048   cp2155_set (fd, 0x59, 0xce);
1049   cp2155_set (fd, 0x5e, 0x02);
1050   cp2155_set (fd, 0x5f, 0x00);
1051   cp2155_set (fd, 0x5f, 0x03);
1052   cp2155_set (fd, 0x60, 0x15);
1053   cp2155_set (fd, 0x60, 0x15);
1054   cp2155_set (fd, 0x60, 0x15);
1055   cp2155_set (fd, 0x60, 0x15);
1056   cp2155_set (fd, 0x50, 0x04);
1057   cp2155_set (fd, 0x51, chndl->value_51);
1058   cp2155_set (fd, 0x81, 0x29);
1059   cp2155_set (fd, 0x81, 0x29);
1060   cp2155_set (fd, 0x82, 0x09);
1061   cp2155_set (fd, 0x82, 0x09);
1062   cp2155_set (fd, 0x83, 0x02);
1063   cp2155_set (fd, 0x84, 0x06);
1064   cp2155_set (fd, 0x80, 0x12);
1065   cp2155_set (fd, 0x80, 0x12);
1066   cp2155_set (fd, 0xb0, 0x08);
1067 
1068   big_write (fd, 0xa1a4, buf);
1069 
1070   cp2155_set (fd, 0x10, 0x05);
1071   cp2155_set (fd, 0x10, 0x05);
1072   cp2155_set (fd, 0x9b, 0x01);
1073   cp2155_set (fd, 0x10, 0x05);
1074   cp2155_set (fd, 0x11, 0x81);
1075   cp2155_set (fd, 0x11, 0x81);
1076   cp2155_set (fd, 0x11, 0x81);
1077   cp2155_set (fd, 0x11, 0x81);
1078   cp2155_set (fd, 0x11, 0x81);
1079   cp2155_set (fd, 0x11, 0x81);
1080   cp2155_set (fd, 0x11, 0x81);
1081   cp2155_set (fd, 0x12, 0x06);
1082   cp2155_set (fd, 0x13, 0x06);
1083   cp2155_set (fd, 0x16, 0x06);
1084   cp2155_set (fd, 0x21, 0x06);
1085   cp2155_set (fd, 0x22, 0x06);
1086   cp2155_set (fd, 0x20, 0x06);
1087   cp2155_set (fd, 0x1d, 0x00);
1088   cp2155_set (fd, 0x1e, 0x00);
1089   cp2155_set (fd, 0x1f, 0x04);
1090   cp2155_set (fd, 0x66, 0x00);
1091   cp2155_set (fd, 0x67, chndl->value_67);
1092   cp2155_set (fd, 0x68, chndl->value_68);
1093 
1094   memcpy (buf, "\x14\x14\x12\x11\x0e\x0b\x08\x04\x00", 9);
1095   register_table (fd, 0, buf);
1096   cp2155_set (fd, 0x18, 0x01);
1097 
1098   count = 36;
1099   make_slope_table (count, top_value, 0x06, 0.0, buf);
1100 
1101   write_buf (fd, count, buf, 0x03, 0x00);
1102   write_buf (fd, count, buf, 0x03, 0x02);
1103   write_buf (fd, count, buf, 0x03, 0x06);
1104   write_buf (fd, count, buf, 0x03, 0x04);
1105   write_buf (fd, count, buf, 0x03, 0x08);
1106 
1107   general_motor_2225 (fd);
1108 }
1109 
1110 void
startblob_2224_0075(CANON_Handle * chndl, unsigned char *buf)1111 startblob_2224_0075 (CANON_Handle * chndl, unsigned char *buf)
1112 {
1113 
1114   int fd;
1115   fd = chndl->fd;
1116   size_t count;
1117 
1118   unsigned int top_value = 0x2580;
1119   unsigned char value_62 = 0x2e;
1120 
1121 /* original:
1122   unsigned int top_value = 0x2580;
1123   unsigned char value_62 = 0x2e;
1124   ratio 208 decimal
1125 */
1126   cp2155_set (fd, 0x90, 0xe8);
1127   cp2155_set (fd, 0x9b, 0x06);
1128   cp2155_set (fd, 0x9b, 0x04);
1129   cp2155_set (fd, 0x90, 0xf8);
1130   cp2155_set (fd, 0xb0, 0x03);
1131   cp2155_set (fd, 0x07, 0x00);
1132   cp2155_set (fd, 0x07, 0x00);
1133   cp2155_set (fd, 0x08, chndl->value_08);
1134   cp2155_set (fd, 0x09, chndl->value_09);
1135   cp2155_set (fd, 0x0a, chndl->value_0a);
1136   cp2155_set (fd, 0x0b, chndl->value_0b);
1137   cp2155_set (fd, 0xa0, 0x1d);
1138   cp2155_set (fd, 0xa1, 0x00);
1139   cp2155_set (fd, 0xa2, 0x06);
1140   cp2155_set (fd, 0xa3, 0x70);
1141   cp2155_set (fd, 0x64, 0x00);
1142   cp2155_set (fd, 0x65, 0x00);
1143   cp2155_set (fd, 0x61, 0x00);
1144   cp2155_set (fd, 0x62, value_62);
1145   cp2155_set (fd, 0x63, 0x00);
1146   cp2155_set (fd, 0x50, 0x04);
1147   cp2155_set (fd, 0x50, 0x04);
1148   cp2155_set (fd, 0x90, 0xf8);
1149   cp2155_set (fd, 0x51, chndl->value_51);
1150   cp2155_set (fd, 0x5a, 0xff);
1151   cp2155_set (fd, 0x5b, 0xff);
1152   cp2155_set (fd, 0x5c, 0xff);
1153   cp2155_set (fd, 0x5d, 0xff);
1154   cp2155_set (fd, 0x52, 0x0c);
1155   cp2155_set (fd, 0x53, 0xda);
1156   cp2155_set (fd, 0x54, 0x0c);
1157   cp2155_set (fd, 0x55, 0x44);
1158   cp2155_set (fd, 0x56, 0x08);
1159   cp2155_set (fd, 0x57, 0xbb);
1160   cp2155_set (fd, 0x58, 0x1d);
1161   cp2155_set (fd, 0x59, 0xa1);
1162   cp2155_set (fd, 0x5e, 0x02);
1163   cp2155_set (fd, 0x5f, 0x00);
1164   cp2155_set (fd, 0x5f, 0x03);
1165   cp2155_set (fd, 0x60, 0x01);
1166   cp2155_set (fd, 0x60, 0x01);
1167   cp2155_set (fd, 0x60, 0x01);
1168   cp2155_set (fd, 0x60, 0x01);
1169   cp2155_set (fd, 0x50, 0x04);
1170   cp2155_set (fd, 0x51, chndl->value_51);
1171   cp2155_set (fd, 0x81, 0x31);
1172   cp2155_set (fd, 0x81, 0x31);
1173   cp2155_set (fd, 0x82, 0x11);
1174   cp2155_set (fd, 0x82, 0x11);
1175   cp2155_set (fd, 0x83, 0x01);
1176   cp2155_set (fd, 0x84, 0x05);
1177   cp2155_set (fd, 0x80, 0x12);
1178   cp2155_set (fd, 0x80, 0x12);
1179   cp2155_set (fd, 0xb0, 0x0b);
1180 
1181   big_write (fd, 0x5694, buf);
1182 
1183   cp2155_set (fd, 0x10, 0x05);
1184   cp2155_set (fd, 0x10, 0x05);
1185   cp2155_set (fd, 0x10, 0x05);
1186   cp2155_set (fd, 0x10, 0x05);
1187   cp2155_set (fd, 0x11, 0xc1);
1188   cp2155_set (fd, 0x11, 0xc1);
1189   cp2155_set (fd, 0x11, 0x81);
1190   cp2155_set (fd, 0x11, 0x81);
1191   cp2155_set (fd, 0x11, 0x81);
1192   cp2155_set (fd, 0x11, 0x81);
1193   cp2155_set (fd, 0x11, 0x81);
1194   cp2155_set (fd, 0x12, 0x7d);
1195   cp2155_set (fd, 0x13, 0x7d);
1196   cp2155_set (fd, 0x16, 0x7d);
1197   cp2155_set (fd, 0x21, 0x06);
1198   cp2155_set (fd, 0x22, 0x7d);
1199   cp2155_set (fd, 0x20, 0x06);
1200   cp2155_set (fd, 0x1d, 0x00);
1201   cp2155_set (fd, 0x1e, 0x00);
1202   cp2155_set (fd, 0x1f, 0x71);
1203   cp2155_set (fd, 0x66, 0x00);
1204   cp2155_set (fd, 0x67, chndl->value_67);
1205   cp2155_set (fd, 0x68, chndl->value_68);
1206 
1207   register_table (fd, 0x0f, buf);
1208   cp2155_set (fd, 0x18, 0x00);
1209 
1210   count = 516;
1211   make_slope_table (count, top_value, 0x6a, 0.0084116, buf);
1212 
1213   write_buf (fd, count, buf, 0x03, 0x00);
1214   write_buf (fd, count, buf, 0x03, 0x02);
1215   write_buf (fd, count, buf, 0x03, 0x06);
1216 
1217   count = 36;
1218   make_slope_table (count, top_value, 0x06, 0.15217, buf);
1219 
1220   write_buf (fd, count, buf, 0x03, 0x04);
1221   write_buf (fd, count, buf, 0x03, 0x08);
1222 
1223   general_motor_2224 (fd);
1224 
1225 }
1226 
1227 void
startblob_2224_0150(CANON_Handle * chndl, unsigned char *buf)1228 startblob_2224_0150 (CANON_Handle * chndl, unsigned char *buf)
1229 {
1230 
1231   int fd;
1232   fd = chndl->fd;
1233   size_t count;
1234 
1235   unsigned int top_value = 0x2580;
1236   unsigned char value_62 = 0x1e;
1237 
1238 /* original:
1239   unsigned int top_value = 0x2580;
1240   unsigned char value_62 = 0x1e;
1241   ratio 320 decimal
1242 */
1243   cp2155_set (fd, 0x90, 0xe8);
1244   cp2155_set (fd, 0x9b, 0x06);
1245   cp2155_set (fd, 0x9b, 0x04);
1246   cp2155_set (fd, 0x90, 0xf8);
1247   cp2155_set (fd, 0xb0, 0x02);
1248   cp2155_set (fd, 0x07, 0x00);
1249   cp2155_set (fd, 0x07, 0x00);
1250   cp2155_set (fd, 0x08, chndl->value_08);
1251   cp2155_set (fd, 0x09, chndl->value_09);
1252   cp2155_set (fd, 0x0a, chndl->value_0a);
1253   cp2155_set (fd, 0x0b, chndl->value_0b);
1254   cp2155_set (fd, 0xa0, 0x1d);
1255   cp2155_set (fd, 0xa1, 0x00);
1256   cp2155_set (fd, 0xa2, 0x0c);
1257   cp2155_set (fd, 0xa3, 0xd0);
1258   cp2155_set (fd, 0x64, 0x00);
1259   cp2155_set (fd, 0x65, 0x00);
1260   cp2155_set (fd, 0x61, 0x00);
1261   cp2155_set (fd, 0x62, value_62);
1262   cp2155_set (fd, 0x63, 0xa0);
1263   cp2155_set (fd, 0x50, 0x04);
1264   cp2155_set (fd, 0x50, 0x04);
1265   cp2155_set (fd, 0x90, 0xf8);
1266   cp2155_set (fd, 0x51, chndl->value_51);
1267   cp2155_set (fd, 0x5a, 0xff);
1268   cp2155_set (fd, 0x5b, 0xff);
1269   cp2155_set (fd, 0x5c, 0xff);
1270   cp2155_set (fd, 0x5d, 0xff);
1271   cp2155_set (fd, 0x52, 0x0c);
1272   cp2155_set (fd, 0x53, 0xda);
1273   cp2155_set (fd, 0x54, 0x0c);
1274   cp2155_set (fd, 0x55, 0x44);
1275   cp2155_set (fd, 0x56, 0x08);
1276   cp2155_set (fd, 0x57, 0xbb);
1277   cp2155_set (fd, 0x58, 0x1d);
1278   cp2155_set (fd, 0x59, 0xa1);
1279   cp2155_set (fd, 0x5e, 0x02);
1280   cp2155_set (fd, 0x5f, 0x00);
1281   cp2155_set (fd, 0x5f, 0x03);
1282   cp2155_set (fd, 0x60, 0x01);
1283   cp2155_set (fd, 0x60, 0x01);
1284   cp2155_set (fd, 0x60, 0x01);
1285   cp2155_set (fd, 0x60, 0x01);
1286   cp2155_set (fd, 0x50, 0x04);
1287   cp2155_set (fd, 0x51, chndl->value_51);
1288   cp2155_set (fd, 0x81, 0x31);
1289   cp2155_set (fd, 0x81, 0x31);
1290   cp2155_set (fd, 0x82, 0x11);
1291   cp2155_set (fd, 0x82, 0x11);
1292   cp2155_set (fd, 0x83, 0x01);
1293   cp2155_set (fd, 0x84, 0x05);
1294   cp2155_set (fd, 0x80, 0x12);
1295   cp2155_set (fd, 0x80, 0x12);
1296   cp2155_set (fd, 0xb0, 0x0a);
1297 
1298   big_write (fd, 0x5694, buf);
1299 
1300   cp2155_set (fd, 0x10, 0x05);
1301   cp2155_set (fd, 0x10, 0x05);
1302   cp2155_set (fd, 0x10, 0x05);
1303   cp2155_set (fd, 0x10, 0x05);
1304   cp2155_set (fd, 0x11, 0x81);
1305   cp2155_set (fd, 0x11, 0x81);
1306   cp2155_set (fd, 0x11, 0x81);
1307   cp2155_set (fd, 0x11, 0x81);
1308   cp2155_set (fd, 0x11, 0x81);
1309   cp2155_set (fd, 0x11, 0x81);
1310   cp2155_set (fd, 0x11, 0x81);
1311   cp2155_set (fd, 0x12, 0x40);
1312   cp2155_set (fd, 0x13, 0x40);
1313   cp2155_set (fd, 0x16, 0x40);
1314   cp2155_set (fd, 0x21, 0x06);
1315   cp2155_set (fd, 0x22, 0x40);
1316   cp2155_set (fd, 0x20, 0x06);
1317   cp2155_set (fd, 0x1d, 0x00);
1318   cp2155_set (fd, 0x1e, 0x00);
1319   cp2155_set (fd, 0x1f, 0x04);
1320   cp2155_set (fd, 0x66, 0x00);
1321   cp2155_set (fd, 0x67, chndl->value_67);
1322   cp2155_set (fd, 0x68, chndl->value_68);
1323 
1324   register_table (fd, 0x0d, buf);
1325   cp2155_set (fd, 0x18, 0x00);
1326 
1327   count = 260;
1328   make_slope_table (count, top_value, 0x86, 0.017979, buf);
1329 
1330   write_buf (fd, count, buf, 0x03, 0x00);
1331   write_buf (fd, count, buf, 0x03, 0x02);
1332   write_buf (fd, count, buf, 0x03, 0x06);
1333 
1334   count = 36;
1335   make_slope_table (count, top_value, 0x06, 0.102968, buf);
1336 
1337   write_buf (fd, count, buf, 0x03, 0x04);
1338   write_buf (fd, count, buf, 0x03, 0x08);
1339 
1340   general_motor_2224 (fd);
1341 
1342 }
1343 
1344 void
startblob_2224_0300(CANON_Handle * chndl, unsigned char *buf)1345 startblob_2224_0300 (CANON_Handle * chndl, unsigned char *buf)
1346 {
1347   int fd;
1348   fd = chndl->fd;
1349   size_t count;
1350 
1351   unsigned int top_value = 0x3200;
1352   unsigned char value_62 = 0x15;
1353 
1354 /* original:
1355   unsigned int top_value = 0x3200;
1356   unsigned char value_62 = 0x15;
1357   ratio 609.52 decimal
1358 */
1359   cp2155_set (fd, 0x90, 0xe8);
1360   cp2155_set (fd, 0x9b, 0x06);
1361   cp2155_set (fd, 0x9b, 0x04);
1362   cp2155_set (fd, 0x90, 0xf8);
1363   cp2155_set (fd, 0xb0, 0x01);
1364   cp2155_set (fd, 0x07, 0x00);
1365   cp2155_set (fd, 0x07, 0x00);
1366   cp2155_set (fd, 0x08, chndl->value_08);
1367   cp2155_set (fd, 0x09, chndl->value_09);
1368   cp2155_set (fd, 0x0a, chndl->value_0a);
1369   cp2155_set (fd, 0x0b, chndl->value_0b);
1370   cp2155_set (fd, 0xa0, 0x1d);
1371   cp2155_set (fd, 0xa1, 0x00);
1372   cp2155_set (fd, 0xa2, 0x03);
1373   cp2155_set (fd, 0xa3, 0x10);
1374   cp2155_set (fd, 0x64, 0x00);
1375   cp2155_set (fd, 0x65, 0x00);
1376   cp2155_set (fd, 0x61, 0x00);
1377   cp2155_set (fd, 0x62, value_62);
1378   cp2155_set (fd, 0x63, 0xe0);
1379   cp2155_set (fd, 0x50, 0x04);
1380   cp2155_set (fd, 0x50, 0x04);
1381   cp2155_set (fd, 0x90, 0xf8);
1382   cp2155_set (fd, 0x51, chndl->value_51);
1383   cp2155_set (fd, 0x5a, 0xff);
1384   cp2155_set (fd, 0x5b, 0xff);
1385   cp2155_set (fd, 0x5c, 0xff);
1386   cp2155_set (fd, 0x5d, 0xff);
1387   cp2155_set (fd, 0x52, 0x0a);
1388   cp2155_set (fd, 0x53, 0xf0);
1389   cp2155_set (fd, 0x54, 0x0a);
1390   cp2155_set (fd, 0x55, 0xf0);
1391   cp2155_set (fd, 0x56, 0x0a);
1392   cp2155_set (fd, 0x57, 0xf0);
1393   cp2155_set (fd, 0x58, 0x00);
1394   cp2155_set (fd, 0x59, 0x01);
1395   cp2155_set (fd, 0x5e, 0x02);
1396   cp2155_set (fd, 0x5f, 0x00);
1397   cp2155_set (fd, 0x5f, 0x03);
1398   cp2155_set (fd, 0x60, 0x01);
1399   cp2155_set (fd, 0x60, 0x01);
1400   cp2155_set (fd, 0x60, 0x01);
1401   cp2155_set (fd, 0x60, 0x01);
1402   cp2155_set (fd, 0x50, 0x04);
1403   cp2155_set (fd, 0x51, chndl->value_51);
1404   cp2155_set (fd, 0x81, 0x31);
1405   cp2155_set (fd, 0x81, 0x31);
1406   cp2155_set (fd, 0x82, 0x11);
1407   cp2155_set (fd, 0x82, 0x11);
1408   cp2155_set (fd, 0x83, 0x01);
1409   cp2155_set (fd, 0x84, 0x05);
1410   cp2155_set (fd, 0x80, 0x12);
1411   cp2155_set (fd, 0x80, 0x12);
1412   cp2155_set (fd, 0xb0, 0x01);
1413   cp2155_set (fd, 0x10, 0x05);
1414   cp2155_set (fd, 0x10, 0x05);
1415   cp2155_set (fd, 0x10, 0x05);
1416   cp2155_set (fd, 0x10, 0x05);
1417   cp2155_set (fd, 0x11, 0x83);
1418   cp2155_set (fd, 0x11, 0x83);
1419   cp2155_set (fd, 0x11, 0xc3);
1420   cp2155_set (fd, 0x11, 0xc3);
1421   cp2155_set (fd, 0x11, 0xc3);
1422   cp2155_set (fd, 0x11, 0xc1);
1423   cp2155_set (fd, 0x11, 0xc1);
1424   cp2155_set (fd, 0x12, 0x40);
1425   cp2155_set (fd, 0x13, 0x00);
1426   cp2155_set (fd, 0x16, 0x40);
1427   cp2155_set (fd, 0x21, 0x06);
1428   cp2155_set (fd, 0x22, 0x40);
1429   cp2155_set (fd, 0x20, 0x06);
1430   cp2155_set (fd, 0x1d, 0x00);
1431   cp2155_set (fd, 0x1e, 0x00);
1432   cp2155_set (fd, 0x1f, 0x04);
1433   cp2155_set (fd, 0x66, 0x00);
1434   cp2155_set (fd, 0x67, chndl->value_67);
1435   cp2155_set (fd, 0x68, chndl->value_68);
1436 
1437   register_table (fd, 0x0a, buf);
1438   cp2155_set (fd, 0x18, 0x00);
1439 
1440   count = 260;
1441   make_slope_table (count, top_value, 0x66, 0.0129596, buf);
1442 
1443   write_buf (fd, count, buf, 0x03, 0x00);
1444   write_buf (fd, count, buf, 0x03, 0x02);
1445   write_buf (fd, count, buf, 0x03, 0x06);
1446 
1447   count = 36;
1448   make_slope_table (count, top_value, 0x06, 0.09307359, buf);
1449 
1450   write_buf (fd, count, buf, 0x03, 0x04);
1451   write_buf (fd, count, buf, 0x03, 0x08);
1452 
1453   general_motor_2224 (fd);
1454 
1455 }
1456 
1457 void
startblob_2224_0600(CANON_Handle * chndl, unsigned char *buf)1458 startblob_2224_0600 (CANON_Handle * chndl, unsigned char *buf)
1459 {
1460 
1461   int fd;
1462   fd = chndl->fd;
1463   size_t count;
1464 
1465   unsigned int top_value = 0x2580;
1466   unsigned char value_62 = 0x19;
1467 
1468 /* original:
1469   unsigned int top_value = 0x7f80;
1470   unsigned char value_62 = 0x55;
1471   ratio 384 decimal
1472 */
1473   cp2155_set (fd, 0x90, 0xe8);
1474   cp2155_set (fd, 0x9b, 0x06);
1475   cp2155_set (fd, 0x9b, 0x04);
1476   cp2155_set (fd, 0x90, 0xf8);
1477   cp2155_set (fd, 0xb0, 0x00);
1478   cp2155_set (fd, 0x07, 0x00);
1479   cp2155_set (fd, 0x07, 0x00);
1480   cp2155_set (fd, 0x08, chndl->value_08);
1481   cp2155_set (fd, 0x09, chndl->value_09);
1482   cp2155_set (fd, 0x0a, chndl->value_0a);
1483   cp2155_set (fd, 0x0b, chndl->value_0b);
1484   cp2155_set (fd, 0xa0, 0x1d);
1485   cp2155_set (fd, 0xa1, 0x00);
1486   cp2155_set (fd, 0xa2, 0x31);
1487   cp2155_set (fd, 0xa3, 0xf0);
1488   cp2155_set (fd, 0x64, 0x00);
1489   cp2155_set (fd, 0x65, 0x00);
1490   cp2155_set (fd, 0x61, 0x00);
1491   cp2155_set (fd, 0x62, value_62);
1492   cp2155_set (fd, 0x63, 0x00);
1493   cp2155_set (fd, 0x50, 0x04);
1494   cp2155_set (fd, 0x50, 0x04);
1495   cp2155_set (fd, 0x90, 0xf8);
1496   cp2155_set (fd, 0x51, chndl->value_51);
1497   cp2155_set (fd, 0x5a, 0xff);
1498   cp2155_set (fd, 0x5b, 0xff);
1499   cp2155_set (fd, 0x5c, 0xff);
1500   cp2155_set (fd, 0x5d, 0xff);
1501   cp2155_set (fd, 0x52, 0x0c);
1502   cp2155_set (fd, 0x53, 0xda);
1503   cp2155_set (fd, 0x54, 0x0c);
1504   cp2155_set (fd, 0x55, 0x44);
1505   cp2155_set (fd, 0x56, 0x08);
1506   cp2155_set (fd, 0x57, 0xbb);
1507   cp2155_set (fd, 0x58, 0x1d);
1508   cp2155_set (fd, 0x59, 0xa1);
1509   cp2155_set (fd, 0x5e, 0x02);
1510   cp2155_set (fd, 0x5f, 0x00);
1511   cp2155_set (fd, 0x5f, 0x03);
1512   cp2155_set (fd, 0x60, 0x01);
1513   cp2155_set (fd, 0x60, 0x01);
1514   cp2155_set (fd, 0x60, 0x01);
1515   cp2155_set (fd, 0x60, 0x01);
1516   cp2155_set (fd, 0x50, 0x04);
1517   cp2155_set (fd, 0x51, chndl->value_51);
1518   cp2155_set (fd, 0x81, 0x31);
1519   cp2155_set (fd, 0x81, 0x31);
1520   cp2155_set (fd, 0x82, 0x11);
1521   cp2155_set (fd, 0x82, 0x11);
1522   cp2155_set (fd, 0x83, 0x01);
1523   cp2155_set (fd, 0x84, 0x05);
1524   cp2155_set (fd, 0x80, 0x12);
1525   cp2155_set (fd, 0x80, 0x12);
1526   cp2155_set (fd, 0xb0, 0x08);
1527 
1528   big_write_2224 (fd, 0x5694, buf);
1529 
1530   cp2155_set (fd, 0x10, 0x05);
1531   cp2155_set (fd, 0x10, 0x05);
1532   cp2155_set (fd, 0x10, 0x05);
1533   cp2155_set (fd, 0x10, 0x05);
1534   cp2155_set (fd, 0x11, 0x81);
1535   cp2155_set (fd, 0x11, 0x81);
1536   cp2155_set (fd, 0x11, 0x81);
1537   cp2155_set (fd, 0x11, 0x81);
1538   cp2155_set (fd, 0x11, 0x81);
1539   cp2155_set (fd, 0x11, 0x81);
1540   cp2155_set (fd, 0x11, 0x81);
1541   cp2155_set (fd, 0x12, 0x06);
1542   cp2155_set (fd, 0x13, 0x06);
1543   cp2155_set (fd, 0x16, 0x06);
1544   cp2155_set (fd, 0x21, 0x06);
1545   cp2155_set (fd, 0x22, 0x06);
1546   cp2155_set (fd, 0x20, 0x06);
1547   cp2155_set (fd, 0x1d, 0x00);
1548   cp2155_set (fd, 0x1e, 0x00);
1549   cp2155_set (fd, 0x1f, 0x04);
1550   cp2155_set (fd, 0x66, 0x00);
1551   cp2155_set (fd, 0x67, chndl->value_67);
1552   cp2155_set (fd, 0x68, chndl->value_68);
1553 
1554   register_table (fd, 0x0c, buf);
1555   cp2155_set (fd, 0x18, 0x00);
1556 
1557   count = 36;
1558   make_slope_table (count, top_value, 0x06, 0.0, buf);
1559 
1560   write_buf (fd, count, buf, 0x03, 0x00);
1561   write_buf (fd, count, buf, 0x03, 0x02);
1562   write_buf (fd, count, buf, 0x03, 0x06);
1563   write_buf (fd, count, buf, 0x03, 0x04);
1564   write_buf (fd, count, buf, 0x03, 0x08);
1565 
1566   general_motor_2224 (fd);
1567 
1568 }
1569 
1570 void
startblob_2224_1200(CANON_Handle * chndl, unsigned char *buf)1571 startblob_2224_1200 (CANON_Handle * chndl, unsigned char *buf)
1572 {
1573 /*
1574   chndl->value_51 = 0x0f;
1575 */
1576   int fd;
1577   fd = chndl->fd;
1578   size_t count;
1579 
1580   unsigned int top_value = 0x7c71;
1581   unsigned char value_62 = 0x29;
1582 
1583 /*
1584   unsigned int top_value = 0x3fc7;
1585   unsigned char value_62 = 0x15;
1586   ratio 777 decimal
1587 */
1588 
1589   cp2155_set (fd, 0x90, 0xe0);	/* e8 */
1590 
1591   double n_msec = 10.0;
1592   int n_9b = 10;		/* 2 */
1593   while (n_9b > 0)
1594     {
1595       cp2155_set (fd, 0x9b, 0x06);
1596       usleep (n_msec * MSEC);
1597       cp2155_set (fd, 0x9b, 0x04);
1598       usleep (n_msec * MSEC);
1599       n_9b--;
1600     }
1601 
1602   cp2155_set (fd, 0x90, 0xf0);	/* f8 */
1603   cp2155_set (fd, 0xb0, 0x00);
1604   cp2155_set (fd, 0x07, 0x00);
1605   cp2155_set (fd, 0x07, 0x00);
1606   cp2155_set (fd, 0x08, chndl->value_08);
1607   cp2155_set (fd, 0x09, chndl->value_09);
1608   cp2155_set (fd, 0x0a, chndl->value_0a);
1609   cp2155_set (fd, 0x0b, chndl->value_0b);
1610   cp2155_set (fd, 0xa0, 0x1d);
1611   cp2155_set (fd, 0xa1, 0x00);
1612   cp2155_set (fd, 0xa2, 0x63);
1613   cp2155_set (fd, 0xa3, 0xd0);
1614   cp2155_set (fd, 0x64, 0x00);
1615   cp2155_set (fd, 0x65, 0x00);
1616   cp2155_set (fd, 0x61, 0x00);
1617   cp2155_set (fd, 0x62, value_62);
1618   cp2155_set (fd, 0x63, 0x00);
1619   cp2155_set (fd, 0x50, 0x04);
1620   cp2155_set (fd, 0x50, 0x04);
1621   cp2155_set (fd, 0x90, 0xf8);
1622   cp2155_set (fd, 0x51, chndl->value_51);
1623   cp2155_set (fd, 0x5a, 0xff);
1624   cp2155_set (fd, 0x5b, 0xff);
1625   cp2155_set (fd, 0x5c, 0xff);
1626   cp2155_set (fd, 0x5d, 0xff);
1627   cp2155_set (fd, 0x52, 0x19);
1628   cp2155_set (fd, 0x53, 0x5a);
1629   cp2155_set (fd, 0x54, 0x17);
1630   cp2155_set (fd, 0x55, 0x98);
1631   cp2155_set (fd, 0x56, 0x11);
1632   cp2155_set (fd, 0x57, 0xae);
1633   cp2155_set (fd, 0x58, 0xa9);
1634   cp2155_set (fd, 0x59, 0x01);
1635   cp2155_set (fd, 0x5e, 0x02);
1636   cp2155_set (fd, 0x5f, 0x00);
1637   cp2155_set (fd, 0x5f, 0x03);
1638   cp2155_set (fd, 0x60, 0x01);
1639   cp2155_set (fd, 0x60, 0x01);
1640   cp2155_set (fd, 0x60, 0x01);
1641   cp2155_set (fd, 0x60, 0x01);
1642   cp2155_set (fd, 0x50, 0x04);
1643   cp2155_set (fd, 0x51, chndl->value_51);
1644   cp2155_set (fd, 0x81, 0x31);
1645   cp2155_set (fd, 0x81, 0x31);
1646   cp2155_set (fd, 0x82, 0x11);
1647   cp2155_set (fd, 0x82, 0x11);
1648   cp2155_set (fd, 0x83, 0x01);
1649   cp2155_set (fd, 0x84, 0x05);
1650   cp2155_set (fd, 0x80, 0x12);
1651   cp2155_set (fd, 0x80, 0x12);
1652   cp2155_set (fd, 0xb0, 0x08);
1653 
1654   big_write (fd, 0xa1a4, buf);
1655 /*  big_write_film (fd, 0xf004, buf); */
1656 
1657   cp2155_set (fd, 0x10, 0x05);
1658   cp2155_set (fd, 0x10, 0x05);
1659   cp2155_set (fd, 0x10, 0x05);
1660   cp2155_set (fd, 0x10, 0x05);
1661   cp2155_set (fd, 0x11, 0x83);
1662   cp2155_set (fd, 0x11, 0x83);
1663   cp2155_set (fd, 0x11, 0x83);
1664   cp2155_set (fd, 0x11, 0x83);
1665   cp2155_set (fd, 0x11, 0x83);
1666   cp2155_set (fd, 0x11, 0x81);
1667   cp2155_set (fd, 0x11, 0x81);
1668   cp2155_set (fd, 0x12, 0x50);
1669   cp2155_set (fd, 0x13, 0x50);
1670   cp2155_set (fd, 0x16, 0x50);
1671   cp2155_set (fd, 0x21, 0x06);
1672   cp2155_set (fd, 0x22, 0x50);
1673   cp2155_set (fd, 0x20, 0x06);
1674   cp2155_set (fd, 0x1d, 0x00);
1675   cp2155_set (fd, 0x1e, 0x00);
1676   cp2155_set (fd, 0x1f, 0x04);
1677   cp2155_set (fd, 0x66, 0x00);
1678   cp2155_set (fd, 0x67, chndl->value_67);
1679   cp2155_set (fd, 0x68, chndl->value_68);
1680 
1681   memcpy (buf, "\x01\x03\x05\x07\x09\x0a\x0b\x0c\x0c", 9);
1682   register_table (fd, 0, buf);
1683   cp2155_set (fd, 0x18, 0x00);
1684 
1685   count = 324;
1686   make_slope_table (count, top_value, 0x06, 0.0, buf);
1687 
1688   write_buf (fd, count, buf, 0x03, 0x00);
1689   write_buf (fd, count, buf, 0x03, 0x02);
1690   write_buf (fd, count, buf, 0x03, 0x06);
1691 
1692   count = 36;
1693   make_slope_table (count, top_value, 0x06, 0.0, buf);
1694 
1695   write_buf (fd, count, buf, 0x03, 0x04);
1696   write_buf (fd, count, buf, 0x03, 0x08);
1697 
1698   general_motor_2224 (fd);
1699 
1700 }
1701 
1702 void
startblob_2224_2400(CANON_Handle * chndl, unsigned char *buf)1703 startblob_2224_2400 (CANON_Handle * chndl, unsigned char *buf)
1704 {
1705 
1706   int fd;
1707   fd = chndl->fd;
1708   size_t count;
1709 
1710   unsigned int top_value = 0x5555;	/* was 0x7c71 */
1711   unsigned char value_62 = 0x0e;	/* at 0x15 ratio 1517 decimal, value_62 was 0x29 */
1712 
1713   cp2155_set (fd, 0x80, 0x12);
1714   cp2155_set (fd, 0x11, 0x83);
1715   cp2155_set (fd, 0x80, 0x12);
1716   cp2155_set (fd, 0x11, 0x83);
1717 /*
1718   unsigned int top_value = 0x3fc7;
1719   unsigned char value_62 = 0x15;
1720   ratio 777 decimal
1721 
1722   cp2155_set (fd, 0x01, 0x2b);
1723   cp2155_set (fd, 0x04, 0x08);
1724   cp2155_set (fd, 0x05, 0x00);
1725   cp2155_set (fd, 0x06, 0x00);
1726 */
1727   cp2155_set (fd, 0x90, 0xe0);
1728 
1729   double n_msec = 10.0;
1730   int n_9b = 11;
1731   while (n_9b > 0)
1732     {
1733       cp2155_set (fd, 0x9b, 0x06);
1734       usleep (n_msec * MSEC);
1735       cp2155_set (fd, 0x9b, 0x04);
1736       usleep (n_msec * MSEC);
1737       n_9b--;
1738     }
1739 
1740   cp2155_set (fd, 0x90, 0xf0);
1741   cp2155_set (fd, 0xb0, 0x00);
1742   cp2155_set (fd, 0x07, 0x00);
1743   cp2155_set (fd, 0x07, 0x00);
1744   cp2155_set (fd, 0x08, chndl->value_08);
1745   cp2155_set (fd, 0x09, chndl->value_09);
1746   cp2155_set (fd, 0x0a, chndl->value_0a);
1747   cp2155_set (fd, 0x0b, chndl->value_0b);
1748   cp2155_set (fd, 0xa0, 0x25);
1749   cp2155_set (fd, 0xa1, 0x00);
1750   cp2155_set (fd, 0xa2, 0x92);
1751   cp2155_set (fd, 0xa3, 0x10);
1752   cp2155_set (fd, 0x64, 0x00);
1753   cp2155_set (fd, 0x65, 0x00);
1754   cp2155_set (fd, 0x61, 0x00);
1755   cp2155_set (fd, 0x62, value_62);
1756   cp2155_set (fd, 0x63, 0x00);
1757   cp2155_set (fd, 0x50, 0x04);
1758   cp2155_set (fd, 0x50, 0x04);
1759   cp2155_set (fd, 0x90, 0xf1);
1760   cp2155_set (fd, 0x51, chndl->value_51);
1761   cp2155_set (fd, 0x5a, 0xff);
1762   cp2155_set (fd, 0x5b, 0xff);
1763   cp2155_set (fd, 0x5c, 0xff);
1764   cp2155_set (fd, 0x5d, 0xff);
1765   cp2155_set (fd, 0x52, 0x47);
1766   cp2155_set (fd, 0x53, 0x3d);
1767   cp2155_set (fd, 0x54, 0x2b);
1768   cp2155_set (fd, 0x55, 0xd1);
1769   cp2155_set (fd, 0x56, 0x20);
1770   cp2155_set (fd, 0x57, 0x3d);
1771   cp2155_set (fd, 0x58, 0x13);
1772   cp2155_set (fd, 0x59, 0x25);
1773   cp2155_set (fd, 0x5e, 0x02);
1774   cp2155_set (fd, 0x5f, 0x00);
1775   cp2155_set (fd, 0x5f, 0x03);
1776   cp2155_set (fd, 0x60, 0x01);
1777   cp2155_set (fd, 0x60, 0x01);
1778   cp2155_set (fd, 0x60, 0x01);
1779   cp2155_set (fd, 0x60, 0x01);
1780   cp2155_set (fd, 0x50, 0x04);
1781   cp2155_set (fd, 0x51, chndl->value_51);
1782   cp2155_set (fd, 0x81, 0x31);	/* 0x29); = darker */
1783   cp2155_set (fd, 0x81, 0x31);	/* 0x29); */
1784   cp2155_set (fd, 0x82, 0x11);
1785   cp2155_set (fd, 0x82, 0x11);
1786   cp2155_set (fd, 0x83, 0x01);
1787   cp2155_set (fd, 0x84, 0x05);
1788   cp2155_set (fd, 0x80, 0x12);
1789   cp2155_set (fd, 0x80, 0x12);
1790   cp2155_set (fd, 0xb0, 0x08);
1791 
1792   big_write (fd, 0xa1a4, buf);
1793   big_write_film (fd, 0xf004, buf);
1794 
1795   cp2155_set (fd, 0x10, 0x05);
1796   cp2155_set (fd, 0x10, 0x05);
1797   cp2155_set (fd, 0x10, 0x05);
1798   cp2155_set (fd, 0x10, 0x05);
1799   cp2155_set (fd, 0x11, 0x83);
1800   cp2155_set (fd, 0x11, 0x83);
1801   cp2155_set (fd, 0x11, 0x83);
1802   cp2155_set (fd, 0x11, 0x83);
1803   cp2155_set (fd, 0x11, 0x83);
1804   cp2155_set (fd, 0x11, 0x81);
1805   cp2155_set (fd, 0x11, 0x81);
1806   cp2155_set (fd, 0x12, 0x50);
1807   cp2155_set (fd, 0x13, 0x50);
1808   cp2155_set (fd, 0x16, 0x50);
1809   cp2155_set (fd, 0x21, 0x06);
1810   cp2155_set (fd, 0x22, 0x50);
1811   cp2155_set (fd, 0x20, 0x06);
1812   cp2155_set (fd, 0x1d, 0x00);
1813   cp2155_set (fd, 0x1e, 0x00);
1814   cp2155_set (fd, 0x1f, 0x04);
1815   cp2155_set (fd, 0x66, chndl->value_66);
1816   cp2155_set (fd, 0x67, chndl->value_67);
1817   cp2155_set (fd, 0x68, chndl->value_68);
1818 
1819   memcpy (buf, "\x02\x04\x04\x06\x06\x08\x08\x0a\x0a", 9);
1820   register_table (fd, 0, buf);
1821   cp2155_set (fd, 0x18, 0x00);
1822 
1823   count = 324;
1824   make_slope_table (count, top_value, 0x06, 0.0, buf);
1825 
1826   write_buf (fd, count, buf, 0x03, 0x00);
1827   write_buf (fd, count, buf, 0x03, 0x02);
1828   write_buf (fd, count, buf, 0x03, 0x06);
1829 
1830   count = 36;
1831   make_slope_table (count, top_value, 0x06, 0.0, buf);
1832 
1833   write_buf (fd, count, buf, 0x03, 0x04);
1834   write_buf (fd, count, buf, 0x03, 0x08);
1835 
1836   general_motor_2224 (fd);
1837 
1838 }
1839 
1840 void
startblob_2224_4800(CANON_Handle * chndl, unsigned char *buf)1841 startblob_2224_4800 (CANON_Handle * chndl, unsigned char *buf)
1842 {
1843 
1844   int fd;
1845   fd = chndl->fd;
1846   size_t count;
1847 
1848   unsigned int top_value = 0x3fc7;	/* was 0x7c71 */
1849   unsigned char value_62 = 0x15;	/* at 0x15 ratio 1517 decimal, value_62 was 0x29 */
1850 
1851   cp2155_set (fd, 0x80, 0x12);
1852   cp2155_set (fd, 0x11, 0x83);
1853   cp2155_set (fd, 0x80, 0x12);
1854   cp2155_set (fd, 0x11, 0x83);
1855 /*
1856   unsigned int top_value = 0x3fc7;
1857   unsigned char value_62 = 0x15;
1858   ratio 777 decimal
1859 
1860   cp2155_set (fd, 0x01, 0x2b);
1861   cp2155_set (fd, 0x04, 0x08);
1862   cp2155_set (fd, 0x05, 0x00);
1863   cp2155_set (fd, 0x06, 0x00);
1864 */
1865   cp2155_set (fd, 0x90, 0xe0);
1866 
1867   double n_msec = 10.0;
1868   int n_9b = 12;
1869   while (n_9b > 0)
1870     {
1871       cp2155_set (fd, 0x9b, 0x06);
1872       usleep (n_msec * MSEC);
1873       cp2155_set (fd, 0x9b, 0x04);
1874       usleep (n_msec * MSEC);
1875       n_9b--;
1876     }
1877 
1878   cp2155_set (fd, 0x90, 0xf0);
1879   cp2155_set (fd, 0xb0, 0x00);
1880   cp2155_set (fd, 0x07, 0x00);
1881   cp2155_set (fd, 0x07, 0x00);
1882   cp2155_set (fd, 0x08, chndl->value_08);
1883   cp2155_set (fd, 0x09, chndl->value_09);
1884   cp2155_set (fd, 0x0a, chndl->value_0a);
1885   cp2155_set (fd, 0x0b, chndl->value_0b);
1886   cp2155_set (fd, 0xa0, 0x25);
1887   cp2155_set (fd, 0xa1, 0x00);
1888   cp2155_set (fd, 0xa2, 0x92);
1889   cp2155_set (fd, 0xa3, 0x10);
1890   cp2155_set (fd, 0x64, 0x00);
1891   cp2155_set (fd, 0x65, 0x00);
1892   cp2155_set (fd, 0x61, 0x00);
1893   cp2155_set (fd, 0x62, value_62);
1894   cp2155_set (fd, 0x63, 0x00);
1895   cp2155_set (fd, 0x50, 0x04);
1896   cp2155_set (fd, 0x50, 0x04);
1897   cp2155_set (fd, 0x90, 0xf1);
1898   cp2155_set (fd, 0x51, chndl->value_51);
1899   cp2155_set (fd, 0x5a, 0xff);
1900   cp2155_set (fd, 0x5b, 0xff);
1901   cp2155_set (fd, 0x5c, 0xff);
1902   cp2155_set (fd, 0x5d, 0xff);
1903   cp2155_set (fd, 0x52, 0x47);
1904   cp2155_set (fd, 0x53, 0x3d);
1905   cp2155_set (fd, 0x54, 0x2b);
1906   cp2155_set (fd, 0x55, 0xd1);
1907   cp2155_set (fd, 0x56, 0x20);
1908   cp2155_set (fd, 0x57, 0x3d);
1909   cp2155_set (fd, 0x58, 0x13);
1910   cp2155_set (fd, 0x59, 0x25);
1911   cp2155_set (fd, 0x5e, 0x02);
1912   cp2155_set (fd, 0x5f, 0x00);
1913   cp2155_set (fd, 0x5f, 0x03);
1914   cp2155_set (fd, 0x60, 0x01);
1915   cp2155_set (fd, 0x60, 0x01);
1916   cp2155_set (fd, 0x60, 0x01);
1917   cp2155_set (fd, 0x60, 0x01);
1918   cp2155_set (fd, 0x50, 0x04);
1919   cp2155_set (fd, 0x51, chndl->value_51);
1920   cp2155_set (fd, 0x81, 0x31);	/* 0x29); = darker */
1921   cp2155_set (fd, 0x81, 0x31);	/* 0x29); */
1922   cp2155_set (fd, 0x82, 0x11);
1923   cp2155_set (fd, 0x82, 0x11);
1924   cp2155_set (fd, 0x83, 0x01);
1925   cp2155_set (fd, 0x84, 0x05);
1926   cp2155_set (fd, 0x80, 0x12);
1927   cp2155_set (fd, 0x80, 0x12);
1928   cp2155_set (fd, 0xb0, 0x08);
1929 
1930   big_write (fd, 0xa1a4, buf);
1931   big_write_film (fd, 0xf004, buf);
1932 
1933   cp2155_set (fd, 0x10, 0x05);
1934   cp2155_set (fd, 0x10, 0x05);
1935   cp2155_set (fd, 0x10, 0x05);
1936   cp2155_set (fd, 0x10, 0x05);
1937   cp2155_set (fd, 0x11, 0x83);
1938   cp2155_set (fd, 0x11, 0x83);
1939   cp2155_set (fd, 0x11, 0x83);
1940   cp2155_set (fd, 0x11, 0x83);
1941   cp2155_set (fd, 0x11, 0x83);
1942   cp2155_set (fd, 0x11, 0x81);
1943   cp2155_set (fd, 0x11, 0x81);
1944   cp2155_set (fd, 0x12, 0x50);
1945   cp2155_set (fd, 0x13, 0x50);
1946   cp2155_set (fd, 0x16, 0x50);
1947   cp2155_set (fd, 0x21, 0x06);
1948   cp2155_set (fd, 0x22, 0x50);
1949   cp2155_set (fd, 0x20, 0x06);
1950   cp2155_set (fd, 0x1d, 0x00);
1951   cp2155_set (fd, 0x1e, 0x00);
1952   cp2155_set (fd, 0x1f, 0x04);
1953   cp2155_set (fd, 0x66, chndl->value_66);
1954   cp2155_set (fd, 0x67, chndl->value_67);
1955   cp2155_set (fd, 0x68, chndl->value_68);
1956 
1957   memcpy (buf, "\x02\x04\x04\x06\x06\x08\x08\x0a\x0a", 9);
1958   register_table (fd, 0, buf);
1959   cp2155_set (fd, 0x18, 0x00);
1960 
1961   count = 324;
1962   make_slope_table (count, top_value, 0x06, 0.0, buf);
1963 
1964   write_buf (fd, count, buf, 0x03, 0x00);
1965   write_buf (fd, count, buf, 0x03, 0x02);
1966   write_buf (fd, count, buf, 0x03, 0x06);
1967 
1968   count = 36;
1969   make_slope_table (count, top_value, 0x06, 0.0, buf);
1970 
1971   write_buf (fd, count, buf, 0x03, 0x04);
1972   write_buf (fd, count, buf, 0x03, 0x08);
1973 
1974   general_motor_2224 (fd);
1975 
1976 }
1977 
1978 void
startblob_2224_4799(CANON_Handle * chndl, unsigned char *buf)1979 startblob_2224_4799 (CANON_Handle * chndl, unsigned char *buf)
1980 {
1981 
1982   int fd;
1983   fd = chndl->fd;
1984   size_t count;
1985 
1986   unsigned int top_value = 0x1400;	/* was 0x7c71 */
1987   unsigned char value_62 = 0x14;	/* at 0x15 ratio 1517 decimal, value_62 was 0x29 */
1988 
1989   cp2155_set (fd, 0x80, 0x12);
1990   cp2155_set (fd, 0x11, 0x83);
1991   cp2155_set (fd, 0x80, 0x12);
1992   cp2155_set (fd, 0x11, 0x83);
1993 
1994 /*
1995   unsigned int top_value = 0x3fc7;
1996   unsigned char value_62 = 0x15;
1997   ratio 777 decimal
1998 
1999   cp2155_set (fd, 0x01, 0x2b);
2000   cp2155_set (fd, 0x04, 0x08);
2001   cp2155_set (fd, 0x05, 0x00);
2002   cp2155_set (fd, 0x06, 0x00);
2003 */
2004   cp2155_set (fd, 0x90, 0xe0);
2005 
2006   double n_msec = 10.0;
2007   int n_9b = 12;
2008   while (n_9b > 0)
2009     {
2010       cp2155_set (fd, 0x9b, 0x06);
2011       usleep (n_msec * MSEC);
2012       cp2155_set (fd, 0x9b, 0x04);
2013       usleep (n_msec * MSEC);
2014       n_9b--;
2015     }
2016 
2017   cp2155_set (fd, 0x90, 0xf0);
2018   cp2155_set (fd, 0xb0, 0x00);
2019   cp2155_set (fd, 0x07, 0x00);
2020   cp2155_set (fd, 0x07, 0x00);
2021   cp2155_set (fd, 0x08, chndl->value_08);
2022   cp2155_set (fd, 0x09, chndl->value_09);
2023   cp2155_set (fd, 0x0a, chndl->value_0a);
2024   cp2155_set (fd, 0x0b, chndl->value_0b);
2025   cp2155_set (fd, 0xa0, 0x25);
2026   cp2155_set (fd, 0xa1, 0x01);
2027   cp2155_set (fd, 0xa2, 0x23);
2028   cp2155_set (fd, 0xa3, 0x10);
2029   cp2155_set (fd, 0x64, 0x00);
2030   cp2155_set (fd, 0x65, 0x00);
2031   cp2155_set (fd, 0x61, 0x00);
2032   cp2155_set (fd, 0x62, value_62);
2033   cp2155_set (fd, 0x63, 0x00);
2034   cp2155_set (fd, 0x50, 0x04);
2035   cp2155_set (fd, 0x50, 0x04);
2036   cp2155_set (fd, 0x90, 0xf1);
2037   cp2155_set (fd, 0x51, chndl->value_51);
2038   cp2155_set (fd, 0x5a, 0xff);
2039   cp2155_set (fd, 0x5b, 0xff);
2040   cp2155_set (fd, 0x5c, 0xff);
2041   cp2155_set (fd, 0x5d, 0xff);
2042   cp2155_set (fd, 0x52, 0x92);
2043   cp2155_set (fd, 0x53, 0xa0);
2044   cp2155_set (fd, 0x54, 0x58);
2045   cp2155_set (fd, 0x55, 0x29);
2046   cp2155_set (fd, 0x56, 0x40);
2047   cp2155_set (fd, 0x57, 0x08);
2048   cp2155_set (fd, 0x58, 0x27);
2049   cp2155_set (fd, 0x59, 0xc7);
2050   cp2155_set (fd, 0x5e, 0x02);
2051   cp2155_set (fd, 0x5f, 0x00);
2052   cp2155_set (fd, 0x5f, 0x03);
2053   cp2155_set (fd, 0x60, 0x01);
2054   cp2155_set (fd, 0x60, 0x01);
2055   cp2155_set (fd, 0x60, 0x01);
2056   cp2155_set (fd, 0x60, 0x01);
2057   cp2155_set (fd, 0x50, 0x04);
2058   cp2155_set (fd, 0x51, chndl->value_51);
2059   cp2155_set (fd, 0x81, 0x29);
2060   cp2155_set (fd, 0x81, 0x29);
2061   cp2155_set (fd, 0x82, 0x11);
2062   cp2155_set (fd, 0x82, 0x11);
2063   cp2155_set (fd, 0x83, 0x01);
2064   cp2155_set (fd, 0x84, 0x05);
2065   cp2155_set (fd, 0x80, 0x12);
2066   cp2155_set (fd, 0x80, 0x12);
2067   cp2155_set (fd, 0xb0, 0x08);
2068 
2069   big_write (fd, 0xa1a4, buf);
2070   big_write_film (fd, 0xf004, buf);
2071 
2072   cp2155_set (fd, 0x10, 0x05);
2073   cp2155_set (fd, 0x10, 0x05);
2074   cp2155_set (fd, 0x10, 0x05);
2075   cp2155_set (fd, 0x10, 0x05);
2076   cp2155_set (fd, 0x11, 0x83);
2077   cp2155_set (fd, 0x11, 0x83);
2078   cp2155_set (fd, 0x11, 0x83);
2079   cp2155_set (fd, 0x11, 0x83);
2080   cp2155_set (fd, 0x11, 0x83);
2081   cp2155_set (fd, 0x11, 0x81);
2082   cp2155_set (fd, 0x11, 0x81);
2083   cp2155_set (fd, 0x12, 0x50);
2084   cp2155_set (fd, 0x13, 0x50);
2085   cp2155_set (fd, 0x16, 0x50);
2086   cp2155_set (fd, 0x21, 0x06);
2087   cp2155_set (fd, 0x22, 0x50);
2088   cp2155_set (fd, 0x20, 0x06);
2089   cp2155_set (fd, 0x1d, 0x00);
2090   cp2155_set (fd, 0x1e, 0x00);
2091   cp2155_set (fd, 0x1f, 0x04);
2092   cp2155_set (fd, 0x66, chndl->value_66);
2093   cp2155_set (fd, 0x67, chndl->value_67);
2094   cp2155_set (fd, 0x68, chndl->value_68);
2095 
2096   register_table_4800 (fd, 0x05, buf);
2097   cp2155_set (fd, 0x18, 0x02);
2098 
2099   count = 324;
2100   make_slope_table (count, top_value, 0x06, 0.0, buf);
2101 
2102   write_buf (fd, count, buf, 0x03, 0x00);
2103   write_buf (fd, count, buf, 0x03, 0x02);
2104   write_buf (fd, count, buf, 0x03, 0x06);
2105 
2106   count = 36;
2107   make_slope_table (count, top_value, 0x06, 0.0, buf);
2108 
2109   write_buf (fd, count, buf, 0x03, 0x04);
2110   write_buf (fd, count, buf, 0x03, 0x08);
2111 
2112   general_motor_2224 (fd);
2113 
2114 }
2115 
2116 void
send_start_blob(CANON_Handle * chndl)2117 send_start_blob (CANON_Handle * chndl)
2118 {
2119   unsigned char buf[0xfff0];
2120 
2121   int fd;
2122   fd = chndl->fd;
2123 
2124 /* value_51: lamp colors
2125    bit 0 set: red on, bit 1 set: green on, bit 2 set: blue on,
2126    bit 3 set: infrared on
2127    all bits off: no scan is made
2128 */
2129   chndl->value_51 = 0x07;
2130   chndl->value_66 = 0x00;
2131 
2132   switch (chndl->val[opt_resolution].w)
2133     {
2134     case 75:
2135       chndl->value_67 = 0x0a;	/* 3*7300/8 */
2136       chndl->value_68 = 0xb1;
2137       break;
2138     case 150:
2139       chndl->value_67 = 0x15;	/* 3*7300/4 */
2140       chndl->value_68 = 0x63;
2141       break;
2142     case 300:
2143       chndl->value_67 = 0x2a;	/* 3*7300/2 */
2144       chndl->value_68 = 0xc6;
2145       break;
2146     case 600:
2147       chndl->value_67 = 0x55;	/* 3*7300 */
2148       chndl->value_68 = 0x8c;
2149       break;
2150     case 1200:
2151       chndl->value_67 = 0xab;	/* 6*7300 */
2152       chndl->value_68 = 0x18;
2153       break;
2154     case 2400:
2155       chndl->value_66 = 0x01;
2156       chndl->value_67 = 0x56;	/* 12*7300 */
2157       chndl->value_68 = 0x30;
2158       break;
2159     case 4800:
2160       chndl->value_66 = 0x02;
2161       chndl->value_67 = 0xac;	/* 24*7300 */
2162       chndl->value_68 = 0x60;
2163     }
2164 
2165   unsigned char value_11 = 0xc1;	/* 0x00; */
2166 
2167   cp2155_set (fd, 0x80, 0x12);
2168   cp2155_set (fd, 0x11, value_11);
2169   cp2155_set (fd, 0x80, 0x12);
2170   cp2155_set (fd, 0x11, value_11);
2171   cp2155_set (fd, 0x90, 0xf8);
2172   cp2155_set (fd, 0x80, 0x12);
2173   cp2155_set (fd, 0x11, value_11);
2174   cp2155_set (fd, 0x01, 0x29);
2175   cp2155_set (fd, 0x04, 0x0c);
2176   cp2155_set (fd, 0x05, 0x00);
2177   cp2155_set (fd, 0x06, 0x00);
2178   cp2155_set (fd, 0x01, 0x29);
2179   cp2155_set_gamma (fd, chndl);
2180 
2181   switch (chndl->val[opt_resolution].w)
2182     {
2183     case 75:
2184       if (chndl->productcode == 0x2225)
2185 	{
2186 	  startblob_2225_0075 (chndl, buf);
2187 	}
2188       else
2189 	{
2190 	  startblob_2224_0075 (chndl, buf);
2191 	}
2192       break;
2193     case 150:
2194       if (chndl->productcode == 0x2225)
2195 	{
2196 	  startblob_2225_0150 (chndl, buf);
2197 	}
2198       else
2199 	{
2200 	  startblob_2224_0150 (chndl, buf);
2201 	}
2202       break;
2203     case 300:
2204       if (chndl->productcode == 0x2225)
2205 	{
2206 	  startblob_2225_0300 (chndl, buf);
2207 	}
2208       else
2209 	{
2210 	  cp2155_set_gamma_red_enhanced (fd, chndl);
2211 	  startblob_2224_0300 (chndl, buf);
2212 	}
2213       break;
2214     case 600:
2215       if (chndl->productcode == 0x2225)
2216 	{
2217 	  cp2155_set_gamma_red_enhanced (fd, chndl);
2218 	  startblob_2225_0600 (chndl, buf);
2219 /*
2220           startblob_2225_0600_extra (chndl, buf);
2221 */
2222 	}
2223       else
2224 	{
2225 	  startblob_2224_0600 (chndl, buf);
2226 	}
2227       break;
2228     case 1200:
2229       if (chndl->productcode == 0x2225)
2230 	{
2231 	  startblob_2225_1200 (chndl, buf);
2232 	}
2233       else
2234 	{
2235 	  startblob_2224_1200 (chndl, buf);
2236 	}
2237       break;
2238     case 2400:
2239       if (chndl->productcode == 0x2225)
2240 	{
2241 	  startblob_2225_1200 (chndl, buf);
2242 	}
2243       else
2244 	{
2245 	  startblob_2224_2400 (chndl, buf);
2246 	}
2247       break;
2248     case 4800:
2249       if (chndl->productcode == 0x2225)
2250 	{
2251 	  startblob_2225_1200 (chndl, buf);
2252 	}
2253       else
2254 	{
2255 	  startblob_2224_4800 (chndl, buf);
2256 	}
2257       break;
2258     }
2259 }
2260 
2261 /* Wait until data ready */
2262 static long
wait_for_data(CANON_Handle * chndl)2263 wait_for_data (CANON_Handle * chndl)
2264 {
2265   int fd;
2266   fd = chndl->fd;
2267   time_t start_time = time (NULL);
2268   long size;
2269   byte value;
2270 
2271   DBG (12, "waiting...\n");
2272 
2273   while (1)
2274     {
2275       size = 0;
2276       cp2155_get (fd, 0x46, &value);
2277       DBG (1, "home sensor: %02x\n", value);
2278       if (value == 0)
2279 	{
2280 	  send_start_blob (chndl);
2281 	  cp2155_get (fd, 0x46, &value);
2282 	  DBG (1, "home sensor: %02x\n", value);
2283 	}
2284 
2285       if (cp2155_get (fd, 0xa5, &value) != SANE_STATUS_GOOD)
2286 	{
2287 	  return -1;
2288 	}
2289 
2290       size += value;
2291 
2292       if (cp2155_get (fd, 0xa6, &value) != SANE_STATUS_GOOD)
2293 	{
2294 	  return -1;
2295 	}
2296 
2297       size <<= 8;
2298       size += value;
2299 
2300       if (cp2155_get (fd, 0xa7, &value) != SANE_STATUS_GOOD)
2301 	{
2302 	  return -1;
2303 	}
2304 
2305       size <<= 8;
2306       size += value;
2307 
2308       if (size != 0)
2309 	{
2310 	  return 2 * size;
2311 	}
2312 
2313       /* Give it 5 seconds */
2314       if ((time (NULL) - start_time) > 5)
2315 	{
2316 	  DBG (1, "wait_for_data: timed out (%ld)\n", size);
2317 	  return -1;
2318 	}
2319 
2320       usleep (1 * MSEC);
2321     }
2322 }
2323 
2324 static int
init_2225(CANON_Handle * chndl)2325 init_2225 (CANON_Handle * chndl)
2326 {
2327   int fd = chndl->fd;
2328   byte value;
2329   int result = 0;
2330 
2331   cp2155_get (fd, 0xd0, &value);
2332   /* Detect if scanner is plugged in */
2333   if (value != 0x81 && value != 0x40)
2334     {
2335       DBG (1, "INIT: unexpected value: %x\n", value);
2336     }
2337 
2338   if (value == 0x00)
2339     {
2340       return -1;
2341     }
2342 
2343   cp2155_set (fd, 0x02, 0x01);
2344   cp2155_set (fd, 0x02, 0x00);
2345   cp2155_set (fd, 0x01, 0x00);
2346   cp2155_set (fd, 0x01, 0x28);
2347   cp2155_set (fd, 0x90, 0x4f);
2348   cp2155_set (fd, 0x92, 0xff);
2349   cp2155_set (fd, 0x93, 0x00);
2350   cp2155_set (fd, 0x91, 0x1f);
2351   cp2155_set (fd, 0x95, 0x1f);
2352   cp2155_set (fd, 0x97, 0x1f);
2353   cp2155_set (fd, 0x9b, 0x00);
2354   cp2155_set (fd, 0x9c, 0x07);
2355   cp2155_set (fd, 0x90, 0x4d);
2356   cp2155_set (fd, 0x90, 0xcd);
2357   cp2155_set (fd, 0x90, 0xcc);
2358   cp2155_set (fd, 0x9b, 0x01);
2359   cp2155_set (fd, 0xa0, 0x04);
2360   cp2155_set (fd, 0xa0, 0x05);
2361   cp2155_set (fd, 0x01, 0x28);
2362   cp2155_set (fd, 0x04, 0x0c);
2363   cp2155_set (fd, 0x05, 0x00);
2364   cp2155_set (fd, 0x06, 0x00);
2365   cp2155_set (fd, 0x98, 0x00);
2366   cp2155_set (fd, 0x98, 0x00);
2367   cp2155_set (fd, 0x98, 0x02);
2368   cp2155_set (fd, 0x99, 0x28);
2369   cp2155_set (fd, 0x9a, 0x03);
2370   cp2155_set (fd, 0x80, 0x10);
2371   cp2155_set (fd, 0x8d, 0x00);
2372   cp2155_set (fd, 0x8d, 0x04);
2373 
2374   cp2155_set (fd, 0x85, 0x00);
2375   cp2155_set (fd, 0x87, 0x00);
2376   cp2155_set (fd, 0x88, 0x70);
2377 
2378   cp2155_set (fd, 0x85, 0x03);
2379   cp2155_set (fd, 0x87, 0x00);
2380   cp2155_set (fd, 0x88, 0x28);
2381 
2382   cp2155_set (fd, 0x85, 0x06);
2383   cp2155_set (fd, 0x87, 0x00);
2384   cp2155_set (fd, 0x88, 0x28);
2385 
2386 
2387   DBG (1, "INIT state: %0d\n", result);
2388   return result;
2389 }
2390 
2391 static int
init_2224(CANON_Handle * chndl)2392 init_2224 (CANON_Handle * chndl)
2393 {
2394   int fd = chndl->fd;
2395   byte value;
2396   int result = 0;
2397 
2398   cp2155_get (fd, 0xd0, &value);
2399   /* Detect if scanner is plugged in */
2400   if (value != 0x81 && value != 0x40)
2401     {
2402       DBG (1, "INIT: unexpected value: %x\n", value);
2403     }
2404 
2405   if (value == 0x00)
2406     {
2407       return -1;
2408     }
2409 
2410   cp2155_set (fd, 0x02, 0x01);
2411   cp2155_set (fd, 0x02, 0x00);
2412   cp2155_set (fd, 0x01, 0x00);
2413   cp2155_set (fd, 0x01, 0x28);
2414   cp2155_set (fd, 0xa0, 0x04);
2415   cp2155_set (fd, 0xa0, 0x05);
2416   cp2155_set (fd, 0x01, 0x28);
2417   cp2155_set (fd, 0x04, 0x0c);
2418   cp2155_set (fd, 0x05, 0x00);
2419   cp2155_set (fd, 0x06, 0x00);
2420   cp2155_set (fd, 0x90, 0x27);
2421   cp2155_set (fd, 0x92, 0xf7);
2422   cp2155_set (fd, 0x94, 0xf7);
2423   cp2155_set (fd, 0x93, 0x00);
2424   cp2155_set (fd, 0x91, 0x1f);
2425   cp2155_set (fd, 0x95, 0x0f);
2426   cp2155_set (fd, 0x97, 0x0f);
2427   cp2155_set (fd, 0x9b, 0x00);
2428   cp2155_set (fd, 0x9c, 0x07);
2429   cp2155_set (fd, 0x90, 0xf0);
2430   cp2155_set (fd, 0x9b, 0x04);
2431   cp2155_set (fd, 0x98, 0x00);
2432   cp2155_set (fd, 0x98, 0x00);
2433   cp2155_set (fd, 0x98, 0x02);
2434   cp2155_set (fd, 0x99, 0x3b);
2435   cp2155_set (fd, 0x9a, 0x03);
2436   cp2155_set (fd, 0x80, 0x10);
2437   cp2155_set (fd, 0x8d, 0x00);
2438   cp2155_set (fd, 0x8d, 0x04);
2439 
2440   DBG (1, "INIT state: %0d\n", result);
2441 
2442   return result;
2443 }
2444 
2445 static int
init(CANON_Handle * chndl)2446 init (CANON_Handle * chndl)
2447 {
2448   int result;
2449   if (chndl->productcode == 0x2225)
2450     {
2451       chndl->table_gamma = 2.2;
2452       chndl->table_gamma_blue = 2.2;
2453       chndl->highlight_red_enhanced = 190;
2454       chndl->highlight_other = 240;
2455       chndl->highlight_blue_reduced = 240;
2456       result = init_2225 (chndl);
2457     }
2458   else
2459     {
2460       chndl->table_gamma = 2.2;
2461       chndl->table_gamma_blue = 1.95;
2462       chndl->highlight_red_enhanced = 190;
2463       chndl->highlight_other = 215;
2464       chndl->highlight_blue_reduced = 255;
2465       result = init_2224 (chndl);
2466     }
2467   return result;
2468 }
2469 
2470 void
back2225(int fd, unsigned char *buf)2471 back2225 (int fd, unsigned char *buf)
2472 {
2473   size_t count;
2474   unsigned int top_value = 0x2580;
2475   unsigned char value_62 = 0x2e;
2476 
2477 /* original:
2478   unsigned int top_value = 0x2580;
2479   unsigned char value_62 = 0x2e;
2480   ratio 320 decimal
2481 */
2482   cp2155_set (fd, 0x90, 0xc8);
2483   cp2155_set (fd, 0x90, 0xc8);
2484   cp2155_set (fd, 0xb0, 0x03);
2485   cp2155_set (fd, 0x07, 0x00);
2486   cp2155_set (fd, 0x07, 0x00);
2487   cp2155_set (fd, 0x08, 0x00);
2488   cp2155_set (fd, 0x09, 0x69);
2489   cp2155_set (fd, 0x0a, 0x00);
2490   cp2155_set (fd, 0x0b, 0xe8);
2491   cp2155_set (fd, 0xa0, 0x1d);
2492   cp2155_set (fd, 0xa1, 0x00);
2493   cp2155_set (fd, 0xa2, 0x00);
2494   cp2155_set (fd, 0xa3, 0x70);
2495   cp2155_set (fd, 0x64, 0x00);
2496   cp2155_set (fd, 0x65, 0x00);
2497   cp2155_set (fd, 0x61, 0x00);
2498   cp2155_set (fd, 0x62, value_62);
2499   cp2155_set (fd, 0x63, 0x00);
2500   cp2155_set (fd, 0x50, 0x04);
2501   cp2155_set (fd, 0x50, 0x04);
2502   cp2155_set (fd, 0x51, 0x07);
2503   cp2155_set (fd, 0x5a, 0x32);
2504   cp2155_set (fd, 0x5b, 0x32);
2505   cp2155_set (fd, 0x5c, 0x32);
2506   cp2155_set (fd, 0x5d, 0x32);
2507   cp2155_set (fd, 0x52, 0x00);
2508   cp2155_set (fd, 0x53, 0x01);
2509   cp2155_set (fd, 0x54, 0x00);
2510   cp2155_set (fd, 0x55, 0x01);
2511   cp2155_set (fd, 0x56, 0x00);
2512   cp2155_set (fd, 0x57, 0x01);
2513   cp2155_set (fd, 0x58, 0x00);
2514   cp2155_set (fd, 0x59, 0x01);
2515   cp2155_set (fd, 0x5e, 0x02);
2516   cp2155_set (fd, 0x5f, 0x00);
2517   cp2155_set (fd, 0x5f, 0x03);
2518   cp2155_set (fd, 0x60, 0x15);
2519   cp2155_set (fd, 0x60, 0x15);
2520   cp2155_set (fd, 0x60, 0x15);
2521   cp2155_set (fd, 0x60, 0x15);
2522   cp2155_set (fd, 0x50, 0x04);
2523   cp2155_set (fd, 0x51, 0x07);
2524   cp2155_set (fd, 0x81, 0x29);
2525   cp2155_set (fd, 0x81, 0x29);
2526   cp2155_set (fd, 0x82, 0x09);
2527   cp2155_set (fd, 0x82, 0x09);
2528   cp2155_set (fd, 0x83, 0x02);
2529   cp2155_set (fd, 0x84, 0x06);
2530   cp2155_set (fd, 0x80, 0x12);
2531   cp2155_set (fd, 0x80, 0x12);
2532   cp2155_set (fd, 0xb0, 0x03);
2533   cp2155_set (fd, 0x10, 0x05);
2534   cp2155_set (fd, 0x10, 0x05);
2535   cp2155_set (fd, 0x9b, 0x03);
2536   cp2155_set (fd, 0x10, 0x05);
2537   cp2155_set (fd, 0x11, 0x41);
2538   cp2155_set (fd, 0x11, 0x61);
2539   cp2155_set (fd, 0x11, 0x21);
2540   cp2155_set (fd, 0x11, 0x21);
2541   cp2155_set (fd, 0x11, 0x25);
2542   cp2155_set (fd, 0x11, 0x25);
2543   cp2155_set (fd, 0x11, 0x25);
2544   cp2155_set (fd, 0x12, 0x40);
2545   cp2155_set (fd, 0x13, 0x40);
2546   cp2155_set (fd, 0x16, 0x40);
2547   cp2155_set (fd, 0x21, 0x06);
2548   cp2155_set (fd, 0x22, 0x40);
2549   cp2155_set (fd, 0x20, 0x06);
2550   cp2155_set (fd, 0x1d, 0x00);
2551   cp2155_set (fd, 0x1e, 0x36);
2552   cp2155_set (fd, 0x1f, 0xd0);
2553   cp2155_set (fd, 0x66, 0x00);
2554   cp2155_set (fd, 0x67, 0x00);
2555   cp2155_set (fd, 0x68, 0x06);
2556 
2557   memcpy (buf, "\x28\x27\x25\x21\x1c\x16\x0f\x08\x00", 9);
2558   register_table (fd, 0, buf);
2559   cp2155_set (fd, 0x18, 0x00);
2560 
2561   count = 260;
2562   make_slope_table (count, top_value, 0x6a, 0.021739, buf);
2563 
2564   write_buf (fd, count, buf, 0x03, 0x00);
2565   write_buf (fd, count, buf, 0x03, 0x02);
2566   write_buf (fd, count, buf, 0x03, 0x06);
2567 
2568   count = 36;
2569   make_slope_table (count, top_value, 0x06, 0.15217, buf);
2570 
2571   write_buf (fd, count, buf, 0x03, 0x04);
2572   write_buf (fd, count, buf, 0x03, 0x08);
2573 
2574   cp2155_set (fd, 0x10, 0x05);
2575   cp2155_set (fd, 0x11, 0x35);
2576   cp2155_set (fd, 0x60, 0x15);
2577   cp2155_set (fd, 0x80, 0x12);
2578   cp2155_set (fd, 0x03, 0x01);
2579 
2580 }
2581 
2582 void
back2224(int fd, unsigned char *buf)2583 back2224 (int fd, unsigned char *buf)
2584 {
2585   size_t count;
2586 
2587   unsigned int top_value = 0x2580;
2588   unsigned char value_62 = 0x2e;
2589 
2590 /* original:
2591   unsigned int top_value = 0x2580;
2592   unsigned char value_62 = 0x2e;
2593   ratio 320 decimal
2594 */
2595   cp2155_set (fd, 0x90, 0xe8);
2596   cp2155_set (fd, 0x9b, 0x06);
2597   cp2155_set (fd, 0x9b, 0x04);
2598   cp2155_set (fd, 0x90, 0xf8);
2599   cp2155_set (fd, 0xb0, 0x03);
2600   cp2155_set (fd, 0x07, 0x00);
2601   cp2155_set (fd, 0x07, 0x00);
2602   cp2155_set (fd, 0x08, 0x01);
2603   cp2155_set (fd, 0x09, 0xb3);
2604   cp2155_set (fd, 0x0a, 0x02);
2605   cp2155_set (fd, 0x0b, 0x32);
2606   cp2155_set (fd, 0xa0, 0x1d);
2607   cp2155_set (fd, 0xa1, 0x00);
2608   cp2155_set (fd, 0xa2, 0x00);
2609   cp2155_set (fd, 0xa3, 0x70);
2610   cp2155_set (fd, 0x64, 0x00);
2611   cp2155_set (fd, 0x65, 0x00);
2612   cp2155_set (fd, 0x61, 0x00);
2613   cp2155_set (fd, 0x62, value_62);
2614   cp2155_set (fd, 0x63, 0x00);
2615   cp2155_set (fd, 0x50, 0x04);
2616   cp2155_set (fd, 0x50, 0x04);
2617 /*  cp2155_set (fd, 0x90, 0xf8); */
2618   cp2155_set (fd, 0x51, 0x07);
2619   cp2155_set (fd, 0x5a, 0xff);
2620   cp2155_set (fd, 0x5b, 0xff);
2621   cp2155_set (fd, 0x5c, 0xff);
2622   cp2155_set (fd, 0x5d, 0xff);
2623   cp2155_set (fd, 0x52, 0x00);
2624   cp2155_set (fd, 0x53, 0x01);
2625   cp2155_set (fd, 0x54, 0x00);
2626   cp2155_set (fd, 0x55, 0x01);
2627   cp2155_set (fd, 0x56, 0x00);
2628   cp2155_set (fd, 0x57, 0x01);
2629   cp2155_set (fd, 0x58, 0x00);
2630   cp2155_set (fd, 0x59, 0x01);
2631   cp2155_set (fd, 0x5e, 0x02);
2632   cp2155_set (fd, 0x5f, 0x00);
2633   cp2155_set (fd, 0x5f, 0x03);
2634   cp2155_set (fd, 0x60, 0x01);
2635   cp2155_set (fd, 0x60, 0x01);
2636   cp2155_set (fd, 0x60, 0x01);
2637   cp2155_set (fd, 0x60, 0x01);
2638   cp2155_set (fd, 0x50, 0x04);
2639   cp2155_set (fd, 0x51, 0x07);
2640   cp2155_set (fd, 0x81, 0x31);
2641   cp2155_set (fd, 0x81, 0x31);
2642   cp2155_set (fd, 0x82, 0x11);
2643   cp2155_set (fd, 0x82, 0x11);
2644   cp2155_set (fd, 0x83, 0x01);
2645   cp2155_set (fd, 0x84, 0x05);
2646   cp2155_set (fd, 0x80, 0x12);
2647   cp2155_set (fd, 0x80, 0x12);
2648   cp2155_set (fd, 0xb0, 0x03);
2649   cp2155_set (fd, 0x10, 0x05);
2650   cp2155_set (fd, 0x10, 0x05);
2651   cp2155_set (fd, 0x10, 0x05);
2652   cp2155_set (fd, 0x10, 0x05);
2653   cp2155_set (fd, 0x11, 0x41);
2654   cp2155_set (fd, 0x11, 0x61);
2655   cp2155_set (fd, 0x11, 0x21);
2656   cp2155_set (fd, 0x11, 0x21);
2657   cp2155_set (fd, 0x11, 0x25);
2658   cp2155_set (fd, 0x11, 0x25);
2659   cp2155_set (fd, 0x11, 0x25);
2660   cp2155_set (fd, 0x12, 0x7d);
2661   cp2155_set (fd, 0x13, 0x7d);
2662   cp2155_set (fd, 0x16, 0x7d);
2663   cp2155_set (fd, 0x21, 0x06);
2664   cp2155_set (fd, 0x22, 0x7d);
2665   cp2155_set (fd, 0x20, 0x06);
2666   cp2155_set (fd, 0x1d, 0x00);
2667   cp2155_set (fd, 0x1e, 0x36);
2668   cp2155_set (fd, 0x1f, 0xd0);
2669   cp2155_set (fd, 0x66, 0x00);
2670   cp2155_set (fd, 0x67, 0x00);
2671   cp2155_set (fd, 0x68, 0x06);
2672 
2673   register_table (fd, 0x0d, buf);
2674   cp2155_set (fd, 0x18, 0x00);
2675 
2676   count = 516;
2677   make_slope_table (count, top_value, 0x06, 0.0067225, buf);
2678 
2679   write_buf (fd, count, buf, 0x03, 0x00);
2680   write_buf (fd, count, buf, 0x03, 0x02);
2681   write_buf (fd, count, buf, 0x03, 0x06);
2682 
2683   count = 36;
2684   make_slope_table (count, top_value, 0x06, 0.15217, buf);
2685 
2686   write_buf (fd, count, buf, 0x03, 0x04);
2687   write_buf (fd, count, buf, 0x03, 0x08);
2688 
2689   cp2155_set (fd, 0x10, 0x05);
2690   cp2155_set (fd, 0x11, 0x35);
2691   cp2155_set (fd, 0x60, 0x01);
2692   cp2155_set (fd, 0x80, 0x12);
2693   cp2155_set (fd, 0x03, 0x01);
2694 
2695 }
2696 
2697 static void
go_home_without_wait(CANON_Handle * chndl)2698 go_home_without_wait (CANON_Handle * chndl)
2699 {
2700   unsigned char buf[0x400];
2701   int fd = chndl->fd;
2702   byte value;
2703   cp2155_get (fd, 0x46, &value);
2704   if (value == 0x08)
2705     {
2706       return;
2707     }
2708 
2709   DBG (1, "go_home_without_wait: product code: %x\n", chndl->productcode);
2710   if (chndl->productcode == 0x2225)
2711     {
2712       back2225 (fd, buf);
2713     }
2714   else
2715     {
2716       back2224 (fd, buf);
2717     }
2718 }
2719 
2720 
2721 static int
go_home(CANON_Handle * chndl)2722 go_home (CANON_Handle * chndl)
2723 {
2724   int fd = chndl->fd;
2725   byte value;
2726   cp2155_get (fd, 0x46, &value);
2727   DBG (1, "state sensor: %02x\n", value);
2728   if (value == 0x08)
2729     {
2730       return 0;
2731     }
2732 
2733   go_home_without_wait (chndl);
2734 
2735   while (1)
2736     {
2737       usleep (200 * MSEC);
2738       cp2155_get (fd, 0x46, &value);
2739       DBG (1, "state sensor: %02x\n", value);
2740 
2741       if (value == 0x08)
2742 	{
2743 	  break;
2744 	}
2745     }
2746   return 0;
2747 }
2748 
2749 /* Scan and save the resulting image as r,g,b non-interleaved PPM file */
2750 static SANE_Status
preread(CANON_Handle * chndl, SANE_Byte * data, FILE * fp)2751 preread (CANON_Handle * chndl, SANE_Byte * data, FILE * fp)
2752 {
2753   SANE_Status status = SANE_STATUS_GOOD;
2754 
2755   static byte linebuf[0x40000];
2756   byte readbuf[0xf000];
2757   int fd = chndl->fd;
2758   long width = chndl->params.pixels_per_line;
2759   /* set width to next multiple of 0x10 */
2760   while ((width % 0x10) != 0xf)
2761     {
2762       width++;
2763     }
2764 
2765   width++;
2766 
2767   byte *srcptr = readbuf;
2768   static byte *dstptr = linebuf;
2769   byte *endptr = linebuf + 3 * width;	/* Red line + Green line + Blue line */
2770   long datasize = 0;
2771   static long line = 0;
2772   size_t offset = 0;
2773   size_t bytes_written;
2774   static byte slot = 0;
2775 
2776   /* Data coming back is "width" bytes Red data, width bytes Green,
2777      width bytes Blue, repeat for "height" lines. */
2778 /*  while (line < height)  process one buffer from the scanner */
2779   long startline = line;
2780 
2781   if (line >= (chndl->y1) * chndl->val[opt_resolution].w / 600
2782       + chndl->params.lines)
2783     {
2784       status = SANE_STATUS_EOF;
2785       init (chndl);
2786       line = 0;
2787       slot = 0;
2788       dstptr = linebuf;
2789       return status;
2790     }
2791   datasize = wait_for_data (chndl);
2792 
2793   if (datasize < 0)
2794     {
2795       DBG (1, "no data\n");
2796       status = SANE_STATUS_EOF;
2797       return status;
2798     }
2799 
2800   if (datasize > 0xf000)
2801     {
2802       datasize = 0xf000;
2803     }
2804 
2805   DBG (12, "scan line %ld %ld\n", line, datasize);
2806 
2807   cp2155_set (fd, 0x72, (datasize >> 8) & 0xff);
2808   cp2155_set (fd, 0x73, (datasize) & 0xff);
2809 
2810   status = cp2155_read (fd, readbuf, datasize);
2811 
2812   if (status != SANE_STATUS_GOOD)
2813     {
2814       status = SANE_STATUS_INVAL;
2815       return status;
2816     }
2817 
2818   /* Contorsions to convert data from line-by-line RGB to byte-by-byte RGB,
2819      without reading in the whole buffer first.  One image line is
2820      constructed in buffer linebuf and written to temp file if complete. */
2821   int idx = 0;
2822   srcptr = readbuf;
2823 
2824   while (idx < datasize)
2825     {
2826       *dstptr = (byte) * srcptr;
2827       idx++;
2828       srcptr += 1;
2829       dstptr += 3;
2830 
2831       if (dstptr >= endptr)	/* line of one color complete */
2832 	{
2833 	  slot++;		/* next color for this line */
2834 	  dstptr = linebuf + slot;	/* restart shortly after beginning */
2835 	  if (slot == 3)	/* all colors done */
2836 	    {
2837 	      slot = 0;		/* back to first color */
2838 	      dstptr = linebuf;	/* back to beginning of line */
2839 	      line++;		/* number of line just completed */
2840 	      /* use scanner->width instead of width to remove pad bytes */
2841 	      if (line > (chndl->y1) * chndl->val[opt_resolution].w / 600)
2842 		{
2843 		  if (chndl->params.format == SANE_FRAME_RGB)
2844 		    {
2845 		      memcpy (data + offset, linebuf, 3 * chndl->width);
2846 		      offset += 3 * chndl->width;
2847 		    }
2848 		  else
2849 		    {
2850 		      int grayvalue;
2851 		      int lineelement = 0;
2852 		      while (lineelement < chndl->width)
2853 			{
2854 			  grayvalue = linebuf[3 * lineelement] +
2855 			    linebuf[3 * lineelement + 1] +
2856 			    linebuf[3 * lineelement + 2];
2857 			  grayvalue /= 3;
2858 			  if (chndl->params.depth == 8)	/* gray */
2859 			    {
2860 			      data[offset + lineelement] = (byte) grayvalue;
2861 			    }
2862 			  else	/* lineart */
2863 			    {
2864 			      if (lineelement % 8 == 0)
2865 				{
2866 				  data[offset + (lineelement >> 3)] = 0;
2867 				}
2868 			      if ((byte) grayvalue <
2869 				  chndl->absolute_threshold)
2870 				{
2871 				  data[offset + (lineelement >> 3)] |=
2872 				    (1 << (7 - lineelement % 8));
2873 				}
2874 			    }
2875 			  lineelement++;
2876 			}
2877 		      offset += chndl->params.bytes_per_line;
2878 		    }
2879 		  DBG (6, "line %ld written...\n", line);
2880 		}
2881 
2882 	      if (line == (chndl->y1) * chndl->val[opt_resolution].w / 600
2883 		  + chndl->params.lines)
2884 		{
2885 		  break;
2886 		}
2887 
2888 	    }
2889 	}
2890     }				/* one readbuf processed */
2891   bytes_written = fwrite (data, 1, offset, fp);
2892   DBG (6, "%ld bytes written\n", bytes_written);
2893   if (bytes_written != offset)
2894     {
2895       status = SANE_STATUS_IO_ERROR;
2896     }
2897   DBG (6, "%ld lines from readbuf\n", line - startline);
2898   return status;		/*  to escape from this loop
2899 				   after processing only one data buffer */
2900 }
2901 
2902 /* Scan and save the resulting image as r,g,b non-interleaved PPM file */
2903 static SANE_Status
do_scan(CANON_Handle * chndl)2904 do_scan (CANON_Handle * chndl)
2905 {
2906   SANE_Status status = SANE_STATUS_GOOD;
2907   SANE_Byte outbuf[0x40000];
2908   FILE *fp;
2909   fp = fopen (chndl->fname, "w");
2910   if (!fp)
2911     {
2912       DBG (1, "err:%s when opening %s\n", strerror (errno), chndl->fname);
2913       return SANE_STATUS_IO_ERROR;
2914     }
2915   long width = chndl->params.pixels_per_line;
2916   if (chndl->val[opt_resolution].w < 600)
2917     {
2918       width = width * 600 / chndl->val[opt_resolution].w;
2919     }
2920   /* set width to next multiple of 0x10 */
2921   while ((width % 0x10) != 0xf)
2922     {
2923       width++;
2924     }
2925 
2926   long x_start;
2927   long x_end;
2928   long left_edge = 0x69;
2929   switch (chndl->val[opt_resolution].w)
2930     {
2931     case 75:
2932     case 150:
2933     case 300:
2934     case 600:
2935       if (chndl->productcode == 0x2224)
2936 	{
2937 	  left_edge = 0x1b3;
2938 	}
2939       else
2940 	{
2941 	  left_edge = 0x69;
2942 	}
2943       break;
2944     case 1200:
2945       if (chndl->productcode == 0x2224)
2946 	{
2947 	  left_edge = 0x1b2;
2948 	}
2949       else
2950 	{
2951 	  left_edge = 0x87;
2952 	}
2953       break;
2954     case 2400:
2955       if (chndl->productcode == 0x2224)
2956 	{
2957 	  left_edge = 0x287;	/* 0x2eb; */
2958 	}
2959       else
2960 	{
2961 	  left_edge = 0x87;
2962 	}
2963       break;
2964     case 4800:
2965       if (chndl->productcode == 0x2224)
2966 	{
2967 	  left_edge = 0x2e3;	/* should be adjusted; 0x23e; 0x2eb; */
2968 	}
2969       else
2970 	{
2971 	  left_edge = 0x87;
2972 	}
2973     }
2974   x_start = left_edge + chndl->x1 * chndl->val[opt_resolution].w / 600;
2975   if (chndl->val[opt_resolution].w < 600)
2976     {
2977       x_start = left_edge + chndl->x1;
2978     }
2979   x_end = x_start + (width);
2980   width++;
2981 
2982   chndl->value_08 = (x_start >> 8) & 0xff;
2983   chndl->value_09 = (x_start) & 0xff;
2984   chndl->value_0a = (x_end >> 8) & 0xff;
2985   chndl->value_0b = (x_end) & 0xff;
2986 
2987   DBG (3, "val_08: %02x\n", chndl->value_08);
2988   DBG (3, "val_09: %02x\n", chndl->value_09);
2989   DBG (3, "val_0a: %02x\n", chndl->value_0a);
2990   DBG (3, "val_0b: %02x\n", chndl->value_0b);
2991   DBG (3, "chndl->width: %04lx\n", chndl->width);
2992 
2993   send_start_blob (chndl);
2994 
2995   while (status == SANE_STATUS_GOOD)
2996     {
2997       status = preread (chndl, outbuf, fp);
2998     }
2999   go_home_without_wait (chndl);
3000 
3001   if (status == SANE_STATUS_EOF)
3002     {
3003       status = SANE_STATUS_GOOD;
3004     }
3005 
3006   fclose (fp);
3007   DBG (6, "created scan file %s\n", chndl->fname);
3008 
3009   return status;
3010 }
3011 
3012 /* Scan sequence */
3013 /* resolution is 75,150,300,600,1200,2400,4800
3014    scan coordinates in 600-dpi pixels */
3015 
3016 static SANE_Status
scan(CANON_Handle * chndl)3017 scan (CANON_Handle * chndl)
3018 {
3019   SANE_Status status = SANE_STATUS_GOOD;
3020   /* Resolution: dpi 75, 150, 300, 600, 1200, 2400, 4800 */
3021   switch (chndl->val[opt_resolution].w)
3022     {
3023     case 75:
3024     case 150:
3025     case 300:
3026     case 600:
3027     case 1200:
3028     case 2400:
3029     case 4800:
3030       break;
3031     default:
3032       chndl->val[opt_resolution].w = 600;
3033     }
3034 
3035   chndl->width = chndl->params.pixels_per_line;
3036   chndl->height =
3037     (chndl->y2 - chndl->y1) * chndl->val[opt_resolution].w / 600;
3038   DBG (1, "dpi=%d\n", chndl->val[opt_resolution].w);
3039   DBG (1, "x1=%d y1=%d\n", chndl->x1, chndl->y1);
3040   DBG (1, "x2=%d y2=%d\n", chndl->x2, chndl->y2);
3041   DBG (1, "width=%ld height=%ld\n", chndl->width, chndl->height);
3042 
3043   CHK (do_scan (chndl));
3044   return status;
3045 }
3046 
3047 
3048 static SANE_Status
CANON_set_scan_parameters(CANON_Handle * chndl)3049 CANON_set_scan_parameters (CANON_Handle * chndl)
3050 {
3051   int left;
3052   int top;
3053   int right;
3054   int bottom;
3055 
3056   double leftf;
3057   double rightf;
3058   double topf;
3059   double bottomf;
3060 
3061   double widthf;
3062   double heightf;
3063   int widthi;
3064   int heighti;
3065 
3066   int top_edge = 7;		/* in mm */
3067   if (chndl->val[opt_resolution].w < 300)
3068     {
3069       top_edge = 0;
3070     }
3071   if (chndl->val[opt_resolution].w == 300 && chndl->productcode == 0x2224)
3072     {
3073       top_edge = 0;
3074     }
3075 
3076   left = SANE_UNFIX (chndl->val[opt_tl_x].w) / MM_IN_INCH * 600;
3077   top = (top_edge + SANE_UNFIX (chndl->val[opt_tl_y].w)) / MM_IN_INCH * 600;
3078   right = SANE_UNFIX (chndl->val[opt_br_x].w) / MM_IN_INCH * 600;
3079   bottom =
3080     (top_edge + SANE_UNFIX (chndl->val[opt_br_y].w)) / MM_IN_INCH * 600;
3081 
3082   leftf = SANE_UNFIX (chndl->val[opt_tl_x].w);
3083   rightf = SANE_UNFIX (chndl->val[opt_br_x].w);
3084   topf = SANE_UNFIX (chndl->val[opt_tl_y].w);
3085   bottomf = SANE_UNFIX (chndl->val[opt_br_y].w);
3086 
3087   widthf = (rightf - leftf) / MM_PER_INCH * 600;
3088   widthi = (int) widthf;
3089   heightf = (bottomf - topf) / MM_PER_INCH * 600;
3090   heighti = (int) heightf;
3091 
3092   DBG (2, "CANON_set_scan_parameters:\n");
3093   DBG (2, "widthf = %f\n", widthf);
3094   DBG (2, "widthi = %d\n", widthi);
3095   DBG (2, "in 600dpi pixels:\n");
3096   DBG (2, "left  = %d, top    = %d\n", left, top);
3097   DBG (2, "right = %d, bottom = %d\n", right, bottom);
3098 
3099   /* Validate the input parameters */
3100   if ((left < 0) || (right > CANON_MAX_WIDTH))
3101     {
3102       return SANE_STATUS_INVAL;
3103     }
3104 
3105   if ((top < 0) || (bottom > CANON_MAX_HEIGHT))
3106     {
3107       return SANE_STATUS_INVAL;
3108     }
3109 
3110   if (((right - left) < 10) || ((bottom - top) < 10))
3111     {
3112       return SANE_STATUS_INVAL;
3113     }
3114 
3115   if ((chndl->val[opt_resolution].w != 75) &&
3116       (chndl->val[opt_resolution].w != 150) &&
3117       (chndl->val[opt_resolution].w != 300) &&
3118       (chndl->val[opt_resolution].w != 600) &&
3119       (chndl->val[opt_resolution].w != 1200) &&
3120       (chndl->val[opt_resolution].w != 2400) &&
3121       (chndl->val[opt_resolution].w != 4800))
3122     {
3123       return SANE_STATUS_INVAL;
3124     }
3125 
3126   /* Store params */
3127   chndl->x1 = left;
3128   chndl->x2 = left + widthi;
3129   chndl->y1 = top;
3130   chndl->y2 = top + heighti;
3131   chndl->absolute_threshold = (chndl->val[opt_threshold].w * 255) / 100;
3132   return SANE_STATUS_GOOD;
3133 }
3134 
3135 
3136 static SANE_Status
CANON_close_device(CANON_Handle * scan)3137 CANON_close_device (CANON_Handle * scan)
3138 {
3139   DBG (3, "CANON_close_device:\n");
3140   sanei_usb_close (scan->fd);
3141   return SANE_STATUS_GOOD;
3142 }
3143 
3144 
3145 static SANE_Status
CANON_open_device(CANON_Handle * scan, const char *dev)3146 CANON_open_device (CANON_Handle * scan, const char *dev)
3147 {
3148   SANE_Word vendor;
3149   SANE_Word product;
3150   SANE_Status res;
3151 
3152   DBG (3, "CANON_open_device: `%s'\n", dev);
3153 
3154   scan->fname = NULL;
3155   scan->fp = NULL;
3156 
3157   res = sanei_usb_open (dev, &scan->fd);
3158 
3159   if (res != SANE_STATUS_GOOD)
3160     {
3161       DBG (1, "CANON_open_device: couldn't open device `%s': %s\n", dev,
3162 	   sane_strstatus (res));
3163       return res;
3164     }
3165 
3166   scan->product = "unknown";
3167 
3168 #ifndef NO_AUTODETECT
3169   /* We have opened the device. Check that it is a USB scanner. */
3170   if (sanei_usb_get_vendor_product (scan->fd, &vendor, &product) !=
3171       SANE_STATUS_GOOD)
3172     {
3173       DBG (1, "CANON_open_device: sanei_usb_get_vendor_product failed\n");
3174       /* This is not a USB scanner, or SANE or the OS doesn't support it. */
3175       sanei_usb_close (scan->fd);
3176       scan->fd = -1;
3177       return SANE_STATUS_UNSUPPORTED;
3178     }
3179 
3180   /* Make sure we have a CANON scanner */
3181   if (vendor == 0x04a9)
3182     {
3183       scan->product = "Canon";
3184       scan->productcode = product;
3185       if (product == 0x2224)
3186 	{
3187 	  scan->product = "CanoScan LiDE 600F";
3188 	}
3189       else if (product == 0x2225)
3190 	{
3191 	  scan->product = "CanoScan LiDE 70";
3192 	}
3193       else
3194 	{
3195 	  DBG (1, "CANON_open_device: incorrect vendor/product (0x%x/0x%x)\n",
3196 	       vendor, product);
3197 	  sanei_usb_close (scan->fd);
3198 	  scan->fd = -1;
3199 	  return SANE_STATUS_UNSUPPORTED;
3200 	}
3201     }
3202 #endif
3203 
3204   return SANE_STATUS_GOOD;
3205 }
3206 
3207 
3208 static const char *
CANON_get_device_name(CANON_Handle * chndl)3209 CANON_get_device_name (CANON_Handle * chndl)
3210 {
3211   return chndl->product;
3212 }
3213 
3214 
3215 static SANE_Status
CANON_finish_scan(CANON_Handle * chndl)3216 CANON_finish_scan (CANON_Handle * chndl)
3217 {
3218   DBG (3, "CANON_finish_scan:\n");
3219 
3220   if (chndl->fp)
3221     {
3222       fclose (chndl->fp);
3223     }
3224 
3225   chndl->fp = NULL;
3226 
3227   /* remove temp file */
3228   if (chndl->fname)
3229     {
3230       DBG (4, "removing temp file %s\n", chndl->fname);
3231       unlink (chndl->fname);
3232       free (chndl->fname);
3233     }
3234 
3235   chndl->fname = NULL;
3236   return SANE_STATUS_GOOD;
3237 }
3238 
3239 
3240 static SANE_Status
CANON_start_scan(CANON_Handle * chndl)3241 CANON_start_scan (CANON_Handle * chndl)
3242 {
3243   SANE_Status status;
3244   int result;
3245   int fd;
3246   DBG (3, "CANON_start_scan called\n");
3247 
3248   /* choose a temp file name for scan data */
3249   chndl->fname = strdup ("/tmp/scan.XXXXXX");
3250   fd = mkstemp (chndl->fname);
3251 
3252   if (fd == -1)
3253     {
3254       return SANE_STATUS_IO_ERROR;
3255     }
3256 
3257   close (fd);
3258 
3259   /* check if calibration needed */
3260   result = init (chndl);
3261 
3262   if (result < 0)
3263     {
3264       DBG (1, "Can't talk on USB.\n");
3265       return SANE_STATUS_IO_ERROR;
3266     }
3267 
3268   go_home (chndl);
3269 
3270   /* scan */
3271   if ((status = scan (chndl)) != SANE_STATUS_GOOD)
3272     {
3273       CANON_finish_scan (chndl);
3274       return status;
3275     }
3276 
3277   /* prepare for reading the temp file back out */
3278   chndl->fp = fopen (chndl->fname, "r");
3279   DBG (4, "reading %s\n", chndl->fname);
3280 
3281   if (!chndl->fp)
3282     {
3283       DBG (1, "open %s", chndl->fname);
3284       return SANE_STATUS_IO_ERROR;
3285     }
3286 
3287   return SANE_STATUS_GOOD;
3288 }
3289 
3290 
3291 static SANE_Status
CANON_read(CANON_Handle * chndl, SANE_Byte * data, SANE_Int max_length, SANE_Int * length)3292 CANON_read (CANON_Handle * chndl, SANE_Byte * data,
3293 	    SANE_Int max_length, SANE_Int * length)
3294 {
3295   SANE_Status status;
3296   int read_len;
3297 
3298   DBG (5, "CANON_read called\n");
3299 
3300   if (!chndl->fp)
3301     {
3302       return SANE_STATUS_INVAL;
3303     }
3304 
3305   read_len = fread (data, 1, max_length, chndl->fp);
3306   /* return some data */
3307   if (read_len > 0)
3308     {
3309       *length = read_len;
3310       DBG (5, "CANON_read returned (%d/%d)\n", *length, max_length);
3311       return SANE_STATUS_GOOD;
3312     }
3313 
3314   /* EOF or file err */
3315   *length = 0;
3316 
3317   if (feof (chndl->fp))
3318     {
3319       DBG (4, "EOF\n");
3320       status = SANE_STATUS_EOF;
3321     }
3322   else
3323     {
3324       DBG (4, "IO ERR\n");
3325       status = SANE_STATUS_IO_ERROR;
3326     }
3327 
3328   CANON_finish_scan (chndl);
3329   DBG (5, "CANON_read returned (%d/%d)\n", *length, max_length);
3330   return status;
3331 }
3332