]> git.donarmstrong.com Git - bin.git/blob - scan_stuff
add reset usb bus command
[bin.git] / scan_stuff
1 #!/usr/bin/perl
2 # scan_stuff scans papers
3 # and is released under the terms of the GNU GPL version 3, or any
4 # later version, at your option. See the file README and COPYING for
5 # more information.
6 # Copyright 2014 by Don Armstrong <don@donarmstrong.com>.
7
8
9 use warnings;
10 use strict;
11
12 use Getopt::Long;
13 use Pod::Usage;
14
15 =head1 NAME
16
17 scan_stuff - scans papers
18
19 =head1 SYNOPSIS
20
21 scan_stuff [options]
22
23  Options:
24    --simplex single sided
25    --duplex double sided (Default)
26    --mode Scanning mode (Color,Gray,Lineart)
27    --debug, -d debugging level (Default 0)
28    --help, -h display this help
29    --man, -m display manual
30
31 =head1 OPTIONS
32
33 =over
34
35 =item B<--simplex>
36
37 Single sided documents
38
39 =item B<--duplex>
40
41 Double sided documents (default)
42
43 =item B<--mode>
44
45 Scanning mode; passed directly to scanimage. Useful options are
46 C<Gray> (Default), C<Color>, and C<Lineart>.
47
48 =item B<--debug, -d>
49
50 Debug verbosity. (Default 0)
51
52 =item B<--help, -h>
53
54 Display brief usage information.
55
56 =item B<--man, -m>
57
58 Display this manual.
59
60 =back
61
62 =head1 EXAMPLES
63
64     scan_stuff; # repeat as necessary
65     scantailor-cli -l 1 --content-detection=cautious *.tif -o out;
66     make_djvu
67
68 =cut
69
70
71 use vars qw($DEBUG);
72
73 my %options = (device          => 'fujitsu',
74                debug           => 0,
75                help            => 0,
76                man             => 0,
77                mode            => 'Gray'
78               );
79
80 GetOptions(\%options,
81            'duplex!',
82            'simplex!',
83            'mode=s',
84            'debug|d+','help|h|?','man|m');
85
86 pod2usage() if $options{help};
87 pod2usage({verbose=>2}) if $options{man};
88
89 $DEBUG = $options{debug};
90
91 my @USAGE_ERRORS;
92 my $use_duplex = 1;
93 if (exists $options{duplex} and exists $options{simplex} and
94     not ($options{duplex} xor $options{simplex})) {
95     push @USAGE_ERRORS,"Conflicting --duplex and --simplex options given";
96 }
97
98 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
99
100
101 if ((exists $options{duplex} and not $options{duplex}) or
102     (exists $options{simplex} and $options{simplex})) {
103     $use_duplex = 0;
104 }
105
106
107 use File::Find;
108
109 if (@ARGV) {
110     chdir($ARGV[0]);
111 }
112
113 my $last_num = 0;
114 find(sub { return if /^\./;
115            $File::Find::prune = 1 if -d $_;
116            if (/out_(\d+)_/) {
117                $last_num = $1 if $1 > $last_num;
118            }
119        }
120      ,'.');
121
122 $last_num++;
123
124 exec('scanimage','-d',$options{device},
125      '--source',$use_duplex?'ADF Duplex':'ADF Front','--mode',$options{mode},'--format','tiff',
126      '--batch=out_'.sprintf('%03d',$last_num).'_%03d.tif');
127
128 __END__
129
130
131
132