Lines Matching refs:dev
170 do_cancel(struct device_s *dev);
190 update_img_size (struct device_s *dev)
196 if (dev->status == STATUS_SCANNING)
198 dev->height = -1;
202 dx = dev->optionw[X2_OFFSET] - dev->optionw[X1_OFFSET];
203 dy = dev->optionw[Y2_OFFSET] - dev->optionw[Y1_OFFSET];
205 switch (dev->optionw[RES_OFFSET])
208 dev->width = round2 ((dx / ((double) MAX_X_S)) * 640);
209 dev->height = round2 ((dy / ((double) MAX_Y_S)) * 880);
212 dev->width = round2 ((dx / ((double) MAX_X_S)) * 848);
213 dev->height = round2 ((dy / ((double) MAX_Y_S)) * 1180);
216 dev->width = round2 ((dx / ((double) MAX_X_S)) * 1264);
217 dev->height = round2 ((dy / ((double) MAX_Y_S)) * 1775);
220 dev->width = round2 ((dx / ((double) MAX_X_S)) * 1696);
221 dev->height = round2 ((dy / ((double) MAX_Y_S)) * 2351);
224 dev->width = round2 ((dx / ((double) MAX_X_S)) * 2528);
225 dev->height = round2 ((dy / ((double) MAX_Y_S)) * 3510);
228 dev->width = round2 ((dx / ((double) MAX_X_S)) * 5088);
229 dev->height = round2 ((dy / ((double) MAX_Y_S)) * 7020);
232 dev->width = round2 ((dx / ((double) MAX_X_S)) * 10208);
233 dev->height = round2 ((dy / ((double) MAX_Y_S)) * 14025);
237 DBG(2,"New image size: %dx%d\n",dev->width, dev->height);
261 struct device_s *dev;
263 dev = malloc (sizeof (struct device_s));
264 if (!dev)
266 memset (dev, 0, sizeof (struct device_s));
268 dev->devname = devname;
269 DBG(1,"New device found: %s\n",dev->devname);
273 dev->optiond[0].name = "";
274 dev->optiond[0].title = NULL;
275 dev->optiond[0].desc = NULL;
276 dev->optiond[0].type = SANE_TYPE_INT;
277 dev->optiond[0].unit = SANE_UNIT_NONE;
278 dev->optiond[0].size = sizeof (SANE_Word);
279 dev->optionw[0] = OPTION_MAX;
282 dev->optiond[RES_OFFSET].name = "resolution";
283 dev->optiond[RES_OFFSET].title = "resolution";
284 dev->optiond[RES_OFFSET].desc = "resolution";
285 dev->optiond[RES_OFFSET].type = SANE_TYPE_INT;
286 dev->optiond[RES_OFFSET].unit = SANE_UNIT_DPI;
287 dev->optiond[RES_OFFSET].type = SANE_TYPE_INT;
288 dev->optiond[RES_OFFSET].size = sizeof (SANE_Word);
289 dev->optiond[RES_OFFSET].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
290 dev->optiond[RES_OFFSET].constraint_type = SANE_CONSTRAINT_WORD_LIST;
291 dev->optiond[RES_OFFSET].constraint.word_list = resolution_list;
292 dev->optionw[RES_OFFSET] = 75;
295 dev->optiond[X1_OFFSET].name = "tl-x";
296 dev->optiond[X1_OFFSET].title = "tl-x";
297 dev->optiond[X1_OFFSET].desc = "tl-x";
298 dev->optiond[X1_OFFSET].type = SANE_TYPE_INT;
299 dev->optiond[X1_OFFSET].unit = SANE_UNIT_MM;
300 dev->optiond[X1_OFFSET].size = sizeof (SANE_Word);
301 dev->optiond[X1_OFFSET].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
302 dev->optiond[X1_OFFSET].constraint_type = SANE_CONSTRAINT_RANGE;
303 dev->optiond[X1_OFFSET].constraint.range = &range_x;
304 dev->optionw[X1_OFFSET] = 0;
306 dev->optiond[Y1_OFFSET].name = "tl-y";
307 dev->optiond[Y1_OFFSET].title = "tl-y";
308 dev->optiond[Y1_OFFSET].desc = "tl-y";
309 dev->optiond[Y1_OFFSET].type = SANE_TYPE_INT;
310 dev->optiond[Y1_OFFSET].unit = SANE_UNIT_MM;
311 dev->optiond[Y1_OFFSET].size = sizeof (SANE_Word);
312 dev->optiond[Y1_OFFSET].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
313 dev->optiond[Y1_OFFSET].constraint_type = SANE_CONSTRAINT_RANGE;
314 dev->optiond[Y1_OFFSET].constraint.range = &range_y;
315 dev->optionw[Y1_OFFSET] = 0;
317 dev->optiond[X2_OFFSET].name = "br-x";
318 dev->optiond[X2_OFFSET].title = "br-x";
319 dev->optiond[X2_OFFSET].desc = "br-x";
320 dev->optiond[X2_OFFSET].type = SANE_TYPE_INT;
321 dev->optiond[X2_OFFSET].unit = SANE_UNIT_MM;
322 dev->optiond[X2_OFFSET].size = sizeof (SANE_Word);
323 dev->optiond[X2_OFFSET].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
324 dev->optiond[X2_OFFSET].constraint_type = SANE_CONSTRAINT_RANGE;
325 dev->optiond[X2_OFFSET].constraint.range = &range_x;
326 dev->optionw[X2_OFFSET] = MAX_X_S;
328 dev->optiond[Y2_OFFSET].name = "br-y";
329 dev->optiond[Y2_OFFSET].title = "br-y";
330 dev->optiond[Y2_OFFSET].desc = "br-y";
331 dev->optiond[Y2_OFFSET].type = SANE_TYPE_INT;
332 dev->optiond[Y2_OFFSET].unit = SANE_UNIT_MM;
333 dev->optiond[Y2_OFFSET].size = sizeof (SANE_Word);
334 dev->optiond[Y2_OFFSET].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
335 dev->optiond[Y2_OFFSET].constraint_type = SANE_CONSTRAINT_RANGE;
336 dev->optiond[Y2_OFFSET].constraint.range = &range_y;
337 dev->optionw[Y2_OFFSET] = MAX_Y_S;
340 dev->optiond[BRIGH_OFFSET].name = "brightness";
341 dev->optiond[BRIGH_OFFSET].title = "Brightness";
342 dev->optiond[BRIGH_OFFSET].desc = "Set the brightness";
343 dev->optiond[BRIGH_OFFSET].type = SANE_TYPE_INT;
344 dev->optiond[BRIGH_OFFSET].unit = SANE_UNIT_NONE;
345 dev->optiond[BRIGH_OFFSET].size = sizeof (SANE_Word);
346 dev->optiond[BRIGH_OFFSET].cap =
348 dev->optiond[BRIGH_OFFSET].constraint_type = SANE_CONSTRAINT_RANGE;
349 dev->optiond[BRIGH_OFFSET].constraint.range = &range_br_cont;
350 dev->optionw[BRIGH_OFFSET] = 0x6;
353 dev->optiond[CONTR_OFFSET].name = "contrast";
354 dev->optiond[CONTR_OFFSET].title = "Contrast";
355 dev->optiond[CONTR_OFFSET].desc = "Set the contrast";
356 dev->optiond[CONTR_OFFSET].type = SANE_TYPE_INT;
357 dev->optiond[CONTR_OFFSET].unit = SANE_UNIT_NONE;
358 dev->optiond[CONTR_OFFSET].size = sizeof (SANE_Word);
359 dev->optiond[CONTR_OFFSET].cap =
361 dev->optiond[CONTR_OFFSET].constraint_type = SANE_CONSTRAINT_RANGE;
362 dev->optiond[CONTR_OFFSET].constraint.range = &range_br_cont;
363 dev->optionw[CONTR_OFFSET] = 0x6;
366 dev->optiond[COLOR_OFFSET].name = SANE_NAME_SCAN_MODE;
367 dev->optiond[COLOR_OFFSET].title = SANE_TITLE_SCAN_MODE;
368 dev->optiond[COLOR_OFFSET].desc = SANE_DESC_SCAN_MODE;
369 dev->optiond[COLOR_OFFSET].type = SANE_TYPE_STRING;
370 dev->optiond[COLOR_OFFSET].size = max_string_size (mode_list);
371 dev->optiond[COLOR_OFFSET].cap =
373 dev->optiond[COLOR_OFFSET].constraint_type = SANE_CONSTRAINT_STRING_LIST;
374 dev->optiond[COLOR_OFFSET].constraint.string_list = mode_list;
375 dev->optionw[COLOR_OFFSET] = RGB;
376 dev->dn = 0;
377 dev->idx = cur_idx;
378 dev->status = STATUS_IDLE;
380 dev->next = devlist_head;
381 devlist_head = dev;
499 struct device_s *dev;
505 dev = devlist_head;
508 for (; dev; dev = dev->next)
509 if (!strcmp (name, dev->devname))
512 if (!dev) {
520 ret = sanei_usb_open (name, &(dev->dn));
527 ret = sanei_usb_claim_interface (dev->dn, 0);
530 sanei_usb_close (dev->dn);
540 *h = dev;
548 struct device_s *dev = (struct device_s *) h;
553 if (dev->status == STATUS_CANCELING)
555 do_cancel(dev);
558 sanei_usb_release_interface (dev->dn, 0);
559 sanei_usb_close (dev->dn);
566 struct device_s *dev = (struct device_s *) h;
570 return &(dev->optiond[option]);
576 struct device_s *dev = (struct device_s *) h;
579 *((SANE_Word *) v) = dev->optionw[option];
583 dev->optiond[option].constraint.string_list[dev->
592 struct device_s *dev = (struct device_s *) h;
601 status = sanei_constrain_value (&(dev->optiond[option]), value, info);
613 dev->optionw[option] = *((SANE_Word *) value);
614 s_unit = (int) round2 ((dev->optionw[option] / ((double) MAX_X_S))
616 s_unit_2 = (int) round2 ((dev->optionw[X2_OFFSET] / ((double) MAX_X_S))
620 dev->optionw[option] = round2 ((s_unit / ((double) MAX_X_H)) * MAX_X_S);
628 dev->optionw[option] = *((SANE_Word *) value);
630 s_unit = (int) round2 ((dev->optionw[option] / ((double) MAX_X_S))
632 s_unit_2 = (int) round2 ((dev->optionw[X1_OFFSET] / ((double) MAX_X_S))
636 dev->optionw[option] = round2 ((s_unit / ((double) MAX_X_H)) * MAX_X_S);
642 dev->optionw[option] = *((SANE_Word *) value);
644 s_unit = (int) round2 ((dev->optionw[option] / ((double) MAX_Y_S))
647 s_unit_2 = (int) round2 ((dev->optionw[Y2_OFFSET] / ((double) MAX_Y_S))
652 dev->optionw[option] = round2 ((s_unit / ((double) MAX_Y_H)) * MAX_Y_S);
658 dev->optionw[option] = *((SANE_Word *) value);
660 s_unit = (int) round2 ((dev->optionw[option] / ((double) MAX_Y_S))
663 s_unit_2 = (int) round2 ((dev->optionw[Y1_OFFSET] / ((double) MAX_Y_S))
668 dev->optionw[option] = round2 ((s_unit / ((double) MAX_Y_H)) * MAX_Y_S);
674 dev->optionw[option] = GRAY; /* Gray */
676 dev->optionw[option] = RGB; /* RGB */
681 dev->optionw[option] = *((SANE_Word *) value);
714 struct device_s *dev = (struct device_s *) h;
720 dev->optionw[COLOR_OFFSET] == RGB ? SANE_FRAME_RGB : SANE_FRAME_GRAY;
724 update_img_size (dev);
725 p->pixels_per_line = dev->width;
726 p->lines = dev->height;
735 send_pkt (int command, int data_size, struct device_s *dev)
739 DBG(100,"Sending packet %d, next data size %d, device %s\n", command, data_size, dev->devname);
741 memset (dev->packet_data, 0, size);
742 dev->packet_data[0] = htonl (MAGIC_NUMBER);
743 dev->packet_data[1] = htonl (command);
744 dev->packet_data[5] = htonl (data_size);
745 sanei_usb_write_bulk (dev->dn, (unsigned char *) dev->packet_data, &size);
752 wait_ack (struct device_s *dev, int *s)
756 DBG(100, "Waiting scanner answer on device %s\n",dev->devname);
761 sanei_usb_read_bulk (dev->dn, (unsigned char *) dev->packet_data,
766 *s = ntohl (dev->packet_data[4]);
767 return ntohl (dev->packet_data[5]);
771 send_conf (struct device_s *dev)
775 DBG(100,"Sending configuration packet on device %s\n",dev->devname);
776 y1 = (int) round2 ((dev->optionw[Y1_OFFSET] / ((double) MAX_Y_S)) * MAX_Y_H);
777 y2 = (int) round2 ((dev->optionw[Y2_OFFSET] / ((double) MAX_Y_S)) * MAX_Y_H);
778 x1 = (int) round2 ((dev->optionw[X1_OFFSET] / ((double) MAX_X_S)) * MAX_X_H);
779 x2 = (int) round2 ((dev->optionw[X2_OFFSET] / ((double) MAX_X_S)) * MAX_X_H);
782 DBG(100,"\t brightness: %d, contrast: %d\n", dev->optionw[BRIGH_OFFSET], dev->optionw[CONTR_OFFSET]);
783 DBG(100,"\t resolution: %d\n",dev->optionw[RES_OFFSET]);
785 dev->conf_data[0] = htonl (0x15);
786 dev->conf_data[1] = htonl (dev->optionw[BRIGH_OFFSET]);
787 dev->conf_data[2] = htonl (dev->optionw[CONTR_OFFSET]);
788 dev->conf_data[3] = htonl (dev->optionw[RES_OFFSET]);
789 dev->conf_data[4] = htonl (0x1);
790 dev->conf_data[5] = htonl (0x1);
791 dev->conf_data[6] = htonl (0x1);
792 dev->conf_data[7] = htonl (0x1);
793 dev->conf_data[8] = 0;
794 dev->conf_data[9] = 0;
795 dev->conf_data[10] = htonl (0x8);
796 dev->conf_data[11] = 0;
797 dev->conf_data[12] = 0;
798 dev->conf_data[13] = 0;
799 dev->conf_data[14] = 0;
800 dev->conf_data[16] = htonl (y1);
801 dev->conf_data[17] = htonl (x1);
802 dev->conf_data[18] = htonl (y2);
803 dev->conf_data[19] = htonl (x2);
804 dev->conf_data[20] = 0;
805 dev->conf_data[21] = 0;
806 dev->conf_data[22] = htonl (0x491);
807 dev->conf_data[23] = htonl (0x352);
809 if (dev->optionw[COLOR_OFFSET] == RGB)
811 dev->conf_data[15] = htonl (0x2);
812 dev->conf_data[24] = htonl (0x1);
817 dev->conf_data[15] = htonl (0x6);
818 dev->conf_data[24] = htonl (0x0);
821 sanei_usb_write_bulk (dev->dn, (unsigned char *) dev->conf_data, &size);
825 get_data (struct device_s *dev)
830 unsigned char *buffer = (unsigned char *) dev->packet_data;
831 if (dev->status == STATUS_IDLE)
837 sanei_usb_read_bulk (dev->dn, buffer, &size);
840 if (ntohl (dev->packet_data[0]) == MAGIC_NUMBER)
842 if (ntohl (dev->packet_data[1]) == PKT_DATA)
844 if (ntohl (dev->packet_data[1]) == PKT_END_DATA)
846 dev->status = STATUS_IDLE;
847 DBG(100,"End of scan encountered on device %s\n",dev->devname);
848 send_pkt (PKT_GO_IDLE, 0, dev);
849 wait_ack (dev, NULL);
850 wait_ack (dev, NULL);
851 send_pkt (PKT_UNKNOW_1, 0, dev);
852 wait_ack (dev, NULL);
853 send_pkt (PKT_RESET, 0, dev);
861 packet_size = ntohl (dev->packet_data[5]);
862 if (!dev->buffer)
864 dev->bufs = packet_size - 24 /* size of header */ ;
865 if (dev->optionw[COLOR_OFFSET] == RGB)
866 dev->bufs *= 3;
867 dev->buffer = malloc (dev->bufs);
868 if (!dev->buffer)
870 dev->write_offset_r = 0;
871 dev->write_offset_g = 1;
872 dev->write_offset_b = 2;
879 sanei_usb_read_bulk (dev->dn, buffer, &size);
882 color = ntohl (dev->packet_data[0]);
884 dev->width = ntohl (dev->packet_data[5]);
885 DBG(100,"Got data size %d on device %s. Scan width: %d\n",packet_size, dev->devname, dev->width);
895 ret = sanei_usb_read_bulk (dev->dn, buffer, &size);
902 DBG(101,"Got red layer data on device %s\n",dev->devname);
903 i = dev->write_offset_r + 3 * size;
904 if (i > dev->bufs)
905 i = dev->bufs;
906 for (j = 0; dev->write_offset_r < i; dev->write_offset_r += 3)
907 dev->buffer[dev->write_offset_r] = buffer[j++];
910 DBG(101,"Got green layer data on device %s\n",dev->devname);
911 i = dev->write_offset_g + 3 * size;
912 if (i > dev->bufs)
913 i = dev->bufs;
914 for (j = 0; dev->write_offset_g < i; dev->write_offset_g += 3)
915 dev->buffer[dev->write_offset_g] = buffer[j++];
918 DBG(101,"Got blue layer data on device %s\n",dev->devname);
919 i = dev->write_offset_b + 3 * size;
920 if (i > dev->bufs)
921 i = dev->bufs;
922 for (j = 0; dev->write_offset_b < i; dev->write_offset_b += 3)
923 dev->buffer[dev->write_offset_b] = buffer[j++];
926 DBG(101,"Got gray layer data on device %s\n",dev->devname);
927 if (dev->write_offset_r + (int)size >= dev->bufs)
928 size = dev->bufs - dev->write_offset_r;
929 memcpy (dev->buffer + dev->write_offset_r, buffer, size);
930 dev->write_offset_r += size;
941 struct device_s *dev = (struct device_s *) h;
945 dev->read_offset = 0;
946 dev->write_offset_r = 0;
947 dev->write_offset_g = 1;
948 dev->write_offset_b = 2;
950 free (dev->buffer);
951 dev->buffer = NULL;
954 send_pkt (PKT_RESET, 0, dev);
955 send_pkt (PKT_READ_STATUS, 0, dev);
956 wait_ack (dev, &status);
960 send_pkt (PKT_READCONF, 0, dev);
962 if ((size = wait_ack (dev, NULL)))
964 sanei_usb_read_bulk (dev->dn, (unsigned char *) dev->conf_data, &size);
966 send_pkt (PKT_SETCONF, 100, dev);
967 send_conf (dev);
968 wait_ack (dev, NULL);
970 send_pkt (PKT_START_SCAN, 0, dev);
971 wait_ack (dev, NULL);
972 if ((size = wait_ack (dev, NULL)))
974 sanei_usb_read_bulk (dev->dn, (unsigned char *) dev->conf_data, &size);
976 if ((size = wait_ack (dev, NULL)))
978 sanei_usb_read_bulk (dev->dn, (unsigned char *) dev->conf_data, &size);
980 if ((size = wait_ack (dev, NULL)))
982 sanei_usb_read_bulk (dev->dn, (unsigned char *) dev->conf_data, &size);
985 dev->status = STATUS_SCANNING;
987 return get_data (dev);
992 do_cancel(struct device_s *dev)
994 while (get_data (dev) == SANE_STATUS_GOOD);
995 free (dev->buffer);
996 dev->buffer = NULL;
1015 struct device_s *dev = (struct device_s *) h;
1019 if (dev->status == STATUS_IDLE)
1021 if (dev->optionw[COLOR_OFFSET] == RGB)
1023 while (min3 (dev->write_offset_r, dev->write_offset_g,
1024 dev->write_offset_b) <= dev->read_offset)
1026 ret = get_data (dev);
1029 if (min3 (dev->write_offset_r,
1030 dev->write_offset_g,
1031 dev->write_offset_b) <= dev->read_offset)
1035 available = min3 (dev->write_offset_r, dev->write_offset_g,
1036 dev->write_offset_b);
1040 while (dev->write_offset_r <= dev->read_offset)
1042 ret = get_data (dev);
1044 if (dev->write_offset_r <= dev->read_offset)
1047 available = dev->write_offset_r;
1049 *len = available - dev->read_offset;
1052 memcpy (buf, dev->buffer + dev->read_offset, *len);
1053 dev->read_offset += *len;
1054 if (dev->read_offset == dev->bufs)
1056 free (dev->buffer);
1057 dev->buffer = NULL;
1058 dev->read_offset = 0;
1059 dev->write_offset_r = 0;
1060 dev->write_offset_g = 1;
1061 dev->write_offset_b = 2;
1065 if (dev->status == STATUS_CANCELING)
1067 do_cancel(dev);
1076 struct device_s *dev = (struct device_s *) h;
1079 if (dev->status == STATUS_SCANNING)
1081 dev->status = STATUS_CANCELING;
1085 free (dev->buffer);
1086 dev->buffer = NULL;