| 1 | package Device::ParallelPort::drv::script; | ||
| 2 | use strict; | ||
| 3 | use Carp; | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | Device::ParallelPort::drv::script - Call a script to do your hardware actions | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | This basic drive allows you to write a completely seperate piece of code to | ||
| 12 | control the bits, and still allow the usual interface. This is fairly pointeless | ||
| 13 | interface by itself but does allow for testing and unusal circumstances. | ||
| 14 | |||
| 15 | Really there is not much point in this module, however it was useful at one | ||
| 16 | time to me, and therefore may be to others. | ||
| 17 | |||
| 18 | =head1 CAPABILITIES | ||
| 19 | |||
| 20 | =head2 Operating System | ||
| 21 | |||
| 22 | Totally depends on the scripts available... but this code is independent. | ||
| 23 | |||
| 24 | =head2 Special Requirements | ||
| 25 | |||
| 26 | Anything special about the scripts, eg: root/not etc. If the script requires | ||
| 27 | root access then so does this system (unless you are using unix setuid) | ||
| 28 | |||
| 29 | Script parameters | ||
| 30 | |||
| 31 | The script has the following substituted before execution automatically. | ||
| 32 | Things like port should be included in the parameter automatically. | ||
| 33 | |||
| 34 | {offset} Which byte to set, from 0 | ||
| 35 | {byte} What is the byte to set | ||
| 36 | |||
| 37 | =head1 HOW IT WORKS | ||
| 38 | |||
| 39 | =head1 LIMITATIONS | ||
| 40 | |||
| 41 | This system can only write a byte to the output script, it uses the previouslly | ||
| 42 | set values to return the current state of the output. | ||
| 43 | |||
| 44 | If you want to set the base port address, that is up to you in the script. | ||
| 45 | For example your script could be along the lines of | ||
| 46 | |||
| 47 | myscript 0x378 {offset} {byte} | ||
| 48 | |||
| 49 | =head1 COPYRIGHT | ||
| 50 | |||
| 51 | Copyright (c) 2002,2004 Scott Penrose. All rights reserved. | ||
| 52 | This program is free software; you can redistribute it and/or modify | ||
| 53 | it under the same terms as Perl itself. | ||
| 54 | |||
| 55 | =head1 AUTHOR | ||
| 56 | |||
| 57 | Scott Penrose L<scottp@dd.com.au>, L<http://linux.dd.com.au/> | ||
| 58 | |||
| 59 | =head1 SEE ALSO | ||
| 60 | |||
| 61 | L<Device::ParallelPort> | ||
| 62 | |||
| 63 | =cut | ||
| 64 | |||
| 65 | use base qw/Device::ParallelPort::drv/; | ||
| 66 | |||
| 67 | sub init { | ||
| 68 | my ($this, $str, @params) = @_; | ||
| 69 | $this->{DATA}{SCRIPT} = $str; | ||
| 70 | my ($script, $rest) = split(/ /, $str, 2); | ||
| 71 | unless (-x $script) { | ||
| 72 | croak "Must provide a script as the parameter, $script not executable"; | ||
| 73 | } | ||
| 74 | $this->{BYTES} = []; | ||
| 75 | } | ||
| 76 | |||
| 77 | sub INFO { | ||
| 78 | return { | ||
| 79 | 'os' => 'any', | ||
| 80 | 'type' => 'byte', | ||
| 81 | }; | ||
| 82 | } | ||
| 83 | |||
| 84 | sub set_byte { | ||
| 85 | my ($this, $byte, $val) = @_; | ||
| 86 | |||
| 87 | # Get the script and the byte | ||
| 88 | my $script = $this->{DATA}{SCRIPT}; | ||
| 89 | $this->{BYTES}[$byte] = $val; | ||
| 90 | |||
| 91 | # Set the values | ||
| 92 | $script =~ s/{offset}/$byte/g; | ||
| 93 | $script =~ s/{byte}/$val/g; | ||
| 94 | |||
| 95 | # Execute | ||
| 96 | print STDERR "Script exec - $script\n" if ($this->{DEBUG}); | ||
| 97 | system($script); | ||
| 98 | } | ||
| 99 | |||
| 100 | sub get_byte { | ||
| 101 | my ($this, $byte) = @_; | ||
| 102 | return $this->{BYTES}[$byte]; | ||
| 103 | } | ||
| 104 | |||
| 105 | 1; | ||
| 106 |