1 # Copyright (c) 1999 Joseph E. Smith <jes@presto.med.upenn.edu>
3 # See the 'COPYRIGHT' section below for complete copyright information.
5 package Comedi::Trigger;
8 use vars qw($VERSION $AUTOLOAD @ISA @EXPORT @EXPORT_OK);
15 @ISA = qw(Exporter AutoLoader);
17 # Nothing exported by default; all access through Trigger object
24 # Preloaded methods go here.
31 my ($member, $value) = (shift, shift);
33 $self->$member($value);
41 my $struct = $self->_pack;
43 $self->{'struct'} = $struct;
45 return $struct ? $self : undef;
51 my $chl = $self->{'chanlist'} || return undef;
53 my $n_chan = (exists($self->{'n_chan'}) ?
54 $self->{'n_chan'} : @$chl) || return undef;
56 # keep these buffers in the object so they don't go away
58 $self->{'_chanlist'} = pack('L*', @{$self->{'chanlist'}});
64 if (exists($self->{'n'}) && exists($self->{'data'})) {
66 $buf = $self->{'data'};
68 elsif (exists($self->{'n'})) {
70 $self->{'_data'} = "\0" x ($n * $n_chan * 2);
71 $buf = $self->{'data'} = \$self->{'_data'};
73 elsif (exists($self->{'data'})) {
74 $buf = $self->{'data'};
75 $n = length($$buf)/(2*$n_chan);
81 # TODO: more error-checking (return undef)
83 # minimal sanity checks
85 croak("Data buffer is not a scalar reference")
86 unless ref($buf) eq 'SCALAR';
87 croak("Sample count (2*$n) too large for buffer (" .
89 unless ((2*$n) <= length $$buf);
91 return pack('L4 p2 L5 L3',
92 $self->{'subdev'} || 0,
94 $self->{'flags'} || 0,
99 $self->{'trigsrc'} || $self->{'source'},
100 $self->{'trigvar'} || $self->{'major'},
101 $self->{'trigvar1'} || $self->{'minor'},
109 ref($self) || croak "$self is not an object";
111 (my $name = $AUTOLOAD) =~ s/.*://; # strip leading class name(s)
113 return @_ ? $self->{$name} = shift : $self->{$name};
116 # Autoload methods go after =cut, and are processed by the autosplit program.
120 # Below is the stub of documentation for your module. You better edit it!
124 Comedi::Trigger - Object oriented interface to comedi trigger struct
130 $t = new Comedi::Trigger;
133 $t->chanlist([ CR_PACK(0,0,AREF_GROUND), CR_PACK(1,0,AREF_GROUND) ]);
138 $ret = comedi_trigger($dev, $t);
142 This module provides an object oriented interface to B<comedi> trigger
143 structures. It provides some convenience over C<pack>ing one by hand:
144 you need only specify a minimum of information, the rest will be
145 calculated if possible.
149 Each element of the B<comedi> trigger structure is available as a
150 method which either retrieves or sets the value of that element. In
151 addition, some of the elements have aliases which may be used to make
152 the programmer's intention clear.
154 The following methods function analogously to the C struct elements:
170 These elements function analogously, but have aliases:
174 =item trigsrc or source
176 =item trigvar or major
178 =item trigvar1 or minor
182 These elements function somewhat differently than the C implementation:
188 This should be a reference to a Perl list of channel descriptors
189 packed using B<Comedi::CR_PACK> (see the example above).
191 If the number of channels (B<n_chan>)is not specified, it will be set
192 to the number of elements in this list.
196 This should be a scalar, pre-allocated to a length large enough to
197 hold the requested data. If no value is set, a scalar will be created
198 of the appropriate size.
202 This element should be set to the size of the data buffer (in bytes).
203 If not specified, it will be set automatically.
207 This method is specific to the Perl module.
211 This method packs the current state of the trigger elements into a
212 binary form compatible with the C C<comedi_trig_struct>. This method
213 is normally called automatically by B<Comedi::Lib> functions that take
218 Version 0.01 09-Nov-1999
222 Joe Smith <F<jes@presto.med.upenn.edu>>.
226 Copyright (c) 1999 Joseph E. Smith. All rights reserved. This
227 program is free software. You may redistribute it and/or modify it
228 under the same terms as Perl itself.
232 Comedi(1), Comedi::Lib(1).