AAC-Pvoice
view release on metacpan or search on metacpan
lib/AAC/Pvoice/Input.pm view on Meta::CPAN
sub Next
{
my $self = shift;
my $sub = shift;
$self->{next} = $sub;
}
sub Select
{
my $self = shift;
my $sub = shift;
$self->{select} = $sub;
}
sub _keycontrol
{
# BEWARE: $self is the window object this event belongs to
my ($self, $event) = @_;
return if $self->{pause};
$self->{input}->{select}->() if ($event->GetKeyCode == $self->{config}->ReadInt('SelectKey', WXK_RETURN)) || (uc(chr($event->GetKeyCode)) eq uc(chr($self->{config}->ReadInt('SelectKey'))));
$self->{input}->{next}->() if (( ($event->GetKeyCode == $self->{config}->ReadInt('NextKey', WXK_SPACE)) ||
(uc(chr($event->GetKeyCode)) eq uc(chr($self->{config}->ReadInt('NextKey'))))) and
(not $self->{config}->ReadInt('Buttons') == 1));
}
sub _iconcontrol
{
# BEWARE: $self is the window object this event belongs to
my ($self, $event) = @_;
return if $self->{pause};
$self->{input}->{select}->() if $event->LeftUp;
$self->{input}->{next}->() if $event->RightUp &&
not $self->{config}->ReadInt('Buttons') == 1;
}
#----------------------------------------------------------------------
# This sub is used to monitor the parallel port for the adremo device
sub _monitorport
{
# BEWARE: $self is the wxWindow subclass the timer
# belongs to!
my ($self, $event) = @_;
# do nothing if the device is not adremo or
# if we're already running
return if ($self->{monitorrun} ||
(not $self->{input}->{next}) ||
(not $self->{input}->{select}) ||
$self->{pause});
# set the flag that we're checking the port
$self->{monitorrun} = 1;
$self->{pp} = Device::ParallelPort->new() if not $self->{pp};
my $curvalue = $self->{pp}->get_status();
if (not defined $curvalue)
{
# clear the flag that we're checking the port and return
$self->{monitorrun} = 0;
return
}
$self->{lastvalue} = 0 if not exists $self->{lastvalue};
# if we detect a change...
if ($curvalue != $self->{lastvalue})
{
unless ($curvalue & 0x40)
{
# if bit 6 is off it's a headmove to the right
# which will indicate a Next() event unless we're in
# one button mode
$self->{input}->{next}->() unless $self->{config}->ReadInt('Buttons') == 1;
}
if ($curvalue & 0x80)
{
# if bit 7 is on (this bit is inverted), it's a headmove to the left
# which will indicate a Select() event.
$self->{input}->{select}->();
}
}
# the current value becomes the last value
$self->{lastvalue} = $curvalue if $curvalue;
# clear the flag that we're checking the port
$self->{monitorrun} = 0;
}
1;
__END__
=head1 NAME
AAC::Pvoice::Input - A class that handles the input that controls a pVoice-like application
=head1 SYNOPSIS
# this module will normally not be called directly. It's called from
# AAC::Pvoice::Panel by default
=head1 DESCRIPTION
AAC::Pvoice::Input allows one or two button operation of an AAC::Pvoice based
application.
The module uses Device::ParallelPort, so it should be able to run
on Win32 as well as Linux platforms.
=head1 USAGE
=head2 new($window)
This constructor takes the window (AAC::Pvoice::Panel typically) on which
the events and timer will be called as a parameter.
If the configuration (read using Wx::ConfigBase::Get) has a key called
'Device' (which can be set to 'icon', 'keys' , 'mouse' or 'adremo') is set to 'adremo', it
will start polling the parallel port every x milliseconds, where x is the
value of the configuration key 'Interval'. This setting is only useful if you connect
an "Adremo" electrical wheelchair to the parallel port of your PC (for more
information see http://www.adremo.nl).
If the key 'Device' is set to 'icon' it will respond to the left and right
mouse button, and if it's set to 'keys' it will respond to the configuration
keys 'SelectKey' and 'NextKey' (which are the keyboard codes for the 'select'
( run in 2.486 seconds using v1.01-cache-2.11-cpan-0b5f733616e )