update for new inkscape --actions
[Printer-EVOLIS.git] / scripts / evolis-command.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Data::Dump qw(dump);
7 use Time::HiRes;
8 use Getopt::Long;
9 use Term::ReadLine;
10 use lib 'lib';
11 use Printer::EVOLIS::Parallel;
12
13 my $port = '/dev/usb/lp0';
14 my $debug = 0;
15
16 GetOptions(
17         'debug+' => \$debug,
18         'port=s' => \$port,
19 ) || die $!;
20
21 warn "# port $port debug $debug\n";
22
23 my $parallel = Printer::EVOLIS::Parallel->new( $port );
24 $Printer::EVOLIS::Parallel::debug = $debug;
25 sub cmd { $parallel->command( "\e$_[0]\r" ) . "\n"; }
26
27 my $term = Term::ReadLine->new('EVOLIS');
28 my $OUT = $term->OUT || \*STDOUT;
29
30 #select($OUT); $|=1;
31
32
33
34 my @help;
35 {
36         open(my $fh, '<', 'docs/commands.txt');
37         @help = <$fh>;
38         warn "# help for ", $#help + 1, " comands, grep with /search_string\n";
39 }
40
41 print $OUT "Printer model ", cmd('Rtp');
42 print $OUT "Printer s/no  ", cmd('Rsn');
43 print $OUT "Kit head no   ", cmd('Rkn');
44 print $OUT "Firmware      ", cmd('Rfv');
45 print $OUT "Mac address   ", cmd('Rmac');
46 print $OUT "IP address    ", cmd('Rip');
47
48 print $OUT "\nCounters:\n";
49 print $OUT "- printed panels: ",cmd('Rco;p');
50 print $OUT "- inserted cards: ",cmd('Rco;c');
51 print $OUT "- avg.clean freq: ",cmd('Rco;a');
52 print $OUT "- max.clean freq: ",cmd('Rco;m');
53 print $OUT "- clean number:   ",cmd('Rco;n');
54 print $OUT "- this ribbon:    ",cmd('Rco;l');
55 print $OUT "- $_ FIXME ",cmd("Rco;$_") foreach (qw/b e f i k r s/);
56
57 while ( defined ( $_ = $term->readline('command> ')) ) {
58         chomp;
59
60         if ( m{^/(.*)} ) {
61                 print $OUT $_ foreach grep { m{$1}i } @help;
62                 next;
63         }
64
65         my $send = "\e$_\r";
66
67         my $response = $parallel->command( $send );
68
69         $term->addhistory($_) if $response;
70
71         print $OUT "<answer ",dump($response),"\n";
72
73 }
74