Mobile::P2kMoto - interface with Motorola P2K phones


Mobile-P2kMoto documentation Contained in the Mobile-P2kMoto distribution.

Index


Code Index:

NAME

Top

Mobile::P2kMoto - interface with Motorola P2K phones

SYNOPSIS

Top

    use Mobile::P2kMoto;
    use constant TIMEOUT => 3000;

    Mobile::P2kMoto::easy_openPhone( device  => '/dev/ttyACM0',
                                     timeout => TIMEOUT,
                                     );

    Mobile::P2kMoto::FS::searchRequest( '/a/*.wav' );
    Mobile::P2kMoto::FS::fileList( sub { print $_[0]->name, "\n" } );

DESCRIPTION

Top

This module uses the p2kmoto library to interface with Motorola Mobile phones using an USB cable.

FUNCTIONS

Top

setACMdevice

  setACMdevice( "/dev/ttyACM1" );

The p2kmoto library uses /dev/ttyACM0 (for Unix) and COM3 (for Win32) as the default device, use this function to change it.

detectPhone

  my $rv = detectPhone();

Tries to auto-sense a phone connected to the current ACM device. If succesful, automatically calls setATconfig() and setP2kconfig().

findPhone

  my $rv = findPhone();

Detects current phone state. Returns one of P2K_PHONE_NONE, P2K_PHONE_AT, P2K_PHONE_P2K.

setP2Kmode

  my $rv = setP2Kmode( $timeout );

If the phone is in AT mode, switches it to P2K mode. Must be called before accessing the phone via openPhone().

openPhone

  my $rv = openPhone( $timeout );

Connects to the phone. The phone must be in P2K mode before performing this action.

easy_openPhone

  my $rv = easy_openPhone( device     => '/dev/ttyACM0',
                           timeout    => 3000,
                           p2k_config => [ 0x1, 0x2 ],
                           acm_config => [ 0x3, 0x4 ],
                           );

A simplified interface to configuring/detecting/opening the phone: device defaults to '/dev/ttyACM0' and timeout to 3000; p2k_config and acm_config are optional.

This function performa several actions: first it sets the ACM device; if p2k_config and acm_config are specified, calls setP2Kconfig and setACMconfig, otherwise calls detectPhone; switched the phone to P2K mode if it isn't already; calls openPhone.

closePhone

  my $rv = closePhone();

Closes the connection to the phone.

suspend

  my $rv = suspend();

Suspends the phone.

reboot

  my $rv = reboot();

Reboots the phone.

CONFIGURATION FUNCTIONS

Top

You should only need the functions below if autodetection fails and if the defaults values provided by p2kmoto do not work for you.

setATconfig

  setATconfig( 0x22b8, 0x4902 );

Sets the vendor/product ID used by p2kmoto for the AT interface.

setP2Kconfig

  setP2Kconfig( 0x22b8, 0x4901 );

Sets the vendor/product ID used by p2kmoto for the P2K interface.

getACMdevice

  my $device = getACMdevice();

Returns the device used to connect to the phone.

getATproduct

  my $id = getATproduct();

Sets the product ID used by p2kmoto for the AT interface.

getATvendor

  my $id = getATvendor();

Sets the vendor ID used by p2kmoto for the AT interface.

getP2Kproduct

  my $id = getP2Kproduct();

Sets the product ID used by p2kmoto for the P2K interface.

getP2Kvendor

  my $id = getP2Kvendor();

Sets the vendor ID used by p2kmoto for the P2K interface.

SEE ALSO

Top

Mobile::P2kMoto::FS, Mobile::P2kMoto::FS::FileInfo

AUTHOR

Top

Mattia Barbon, <mbarbon@cpan.org>

COPYRIGHT AND LICENSE

Top


Mobile-P2kMoto documentation Contained in the Mobile-P2kMoto distribution.

package Mobile::P2kMoto;

use 5.006;
use strict;
use warnings;

use Mobile::P2kMoto::FS;
use Mobile::P2kMoto::FS::FileInfo;

our $VERSION = '0.03';
our $AUTOLOAD;

sub AUTOLOAD {
    (my $constname = $AUTOLOAD) =~ s/.*:://;
    my ($error, $val) = constant($constname);
    if ($error)
    {
	require Carp;
	Carp::croak($error);
    }

    no strict 'refs';
    *$AUTOLOAD = sub { $val };
    goto &$AUTOLOAD;
}

require XSLoader;
XSLoader::load('Mobile::P2kMoto', $VERSION);

init();

sub easy_openPhone {
    my( %args ) = @_;

    $args{timeout} ||= 3000;
    $args{device}  ||= '/dev/ttyACM0';

    Mobile::P2kMoto::setACMdevice( $args{device} );
    if( $args{at_config} && $args{p2k_config} ) {
        Mobile::P2kMoto::setATconfig( @{$args{at_config}} );
        Mobile::P2kMoto::setP2Kconfig( @{$args{p2k_config}} );
    } else {
        Mobile::P2kMoto::detectPhone();
    }

    my $state = Mobile::P2kMoto::findPhone();

    if( $state == Mobile::P2kMoto::P2K_PHONE_NONE() ) {
        die "No phone found";
    } elsif( $state == Mobile::P2kMoto::P2K_PHONE_AT() ) {
        Mobile::P2kMoto::setP2Kmode( $args{timeout} )
            and die "Failed to set P2K mode";
    } elsif( $state == Mobile::P2kMoto::P2K_PHONE_P2K() ) {
        # do nothing, all is well
    }

    return Mobile::P2kMoto::openPhone( $args{timeout} );
}

1;

__END__