Nicolas Georges > Win32-Lglcd-0.03-dist > Win32::Lglcd

Download:
Win32-Lglcd-0.03-dist.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.03   Source  

NAME ^

Win32::Lglcd - Perl extension for writting perl's app for logitech devices.

SYNOPSIS ^

  use Win32::Lglcd;
   
  my $g15 = Win32::Lglcd->new;
  
  $g15->init();
  
  $g15->connect('App Name');

  sub onSoftButtonChanged{
    my ($connection, $button, $params) = @_;
    ...
    return 0;
  }
  
  $g15->open(callback=>\&onSoftButtonChanged);
  
  $g15->foreground();
  
  while( ... ){ #App main loop
  
    ...  #prepare $pict
        
    $g15->sendbmp($pict);
  
    Win32::Lglcd::g15_do_event();
  }
  
  $g15->close();
  
  $g15->disconnect();
  
  $g15->deinit();  

DESCRIPTION ^

This module provide an interface to Lglcd library from Perl. It's allow to write application that can communicate with the Logitech LCD manager.

Actually, configuration and notification callbacks are not supported. The softbuttons callback work but it need a regular call to Win32::Lglcd::g15_do_event sub.

FUNCTIONS ^

new

Object creator.

  my $lcd = new Win32::Lglcd;

init

To be called before any other subs.

  $lcd->init;

deinit

To be called at the end of use of this module, it will free all resources allocated by the library.

  $lcd->deinit;

get_last_error

Return the last error code my $errcode = $lcd->get_last_error;

get_error_message ERROR_CODE

Return the error message matching with ERROR_CODE.

  print "Error: " . $lcd->get_error_message( $errcode );

get_last_error_message

Return the last error message.

  print "Last error: " . $lcd->get_last_error_message;

use_families FAMILY_TYPE

Set the type of family devices to use, FAMILY_TYPE could one of the following constants:

  LGLCD_DEVICE_FAMILY_JACKBOX
  LGLCD_DEVICE_FAMILY_KEYBOARD_G15
  LGLCD_DEVICE_FAMILY_LCDEMULATOR_G15
  LGLCD_DEVICE_FAMILY_OTHER
  LGLCD_DEVICE_FAMILY_RAINBOW
  LGLCD_DEVICE_FAMILY_SPEAKERS_Z10

  $lcd->use_families( LGLCD_DEVICE_FAMILY_LCDEMULATOR_G15 );

foreground

Ask LCD manager to put application in foreground.

  $lcd->foreground;

background

Ask LCD manager to put application in background.

  $lcd->background;

sendbmp PICTURE

Send the PICTURE image to the LCD device, it must have the right format.

  $lcd->sendbmp( $pict );

Tips: you can use the sub GD::Image::Lglcd just provided with this package.

  $lcd->sendbmp( $gdimage->Lglcd );

open index=>value, callback=>{...}, paramcallback=>...

It starts the communication with an attached device.

  index: specifies the index of the device to open.

  callback: a sub onSoftbuttonsChanged take in args (device,dwButtons,context)

  paramcallback: a reference to what you want to retrieve in you callback.

  $lcd->open( callback => &\onSoftbuttons );

close

Close a connection with LCD manager.

  $lcd->close;

disconnect

Disconnect current openned connection with a device.

  $lcd->disconnect;

setfamilies

Used to inform the LCD Manager of what device types the app is interested in using. This will filter the result of enumerate and enumerateEx subs.

connect APPNAME

Establish a connection to the LCD manager, APPNAME is the application name.

  $lcd->connect('Perl Applet');

enumerate

Retrieve information about all the currently attached and supported LCD devices.

  foreach $dev( $lcd->enumerate ){
    print 
      $dev{width} . "x" . 
      $dev{height} . "x" . 
      $dev{bpp} . ":" . 
      $dev{softbuttons}. "\n";
  }

enumerateEx

Same as enumerate but with more informations.

  foreach $dev( $lcd->enumerateEx ){
    print 
      $dev{displayname} . "(" . 
      $dev{family} . "," . 
      $dev{reserved1} . "," . 
      $dev{reserved2} . "), " . 
      $dev{width} . "x" . 
      $dev{height} . "x" . 
      $dev{bpp} . ":" . 
      $dev{softbuttons}. "\n";
  }  

softbuttons_state

Use to retrieve the state of each soft buttons. It return a hash which keys are BUTTON0_PRESSED to BUTTON32_PRESSED.

  my %keys_state = $lcd->softbuttons_state;

GD::Image::Lglcd

GD::Image::Lglcd provide an helper sub to convert GD picture into a LGLCD compatible bitmap.

  use GD;
  use Benchmark;
  use Win32::Lglcd;             #here you include GD::Image::Lglcd sub
  my $start = new Benchmark;
  my $im = new GD::Image(160,43,0);
  my $white = $im->colorAllocate(255,255,255);
  my $black = $im->colorAllocate(0,0,0);       
  $im->rectangle(0,0,159,42,$black);
  $im->filledEllipse(80,21,140,24,$black);
  $im->string(gdSmallFont,20,15,"LCD Logo",$white);
  #ConvertData to Lglcd format !
  $|=1;
  my $pict = $im->Lglcd( 0=>'_', 1=>'0', eol=>"\n", x=>12, y=>13, width=>80, height=>25, white=>$black );
  print $pict;
  my $end = new Benchmark;
  warn ("Bench = " . timestr( timediff($end, $start) ) . "\n");

EXPORT

All by default.

Exportable constants

  LGLCDBUTTON_BUTTON0
  LGLCDBUTTON_BUTTON1
  LGLCDBUTTON_BUTTON2
  LGLCDBUTTON_BUTTON3
  LGLCD_APPLET_CAP_BASIC
  LGLCD_APPLET_CAP_CAN_CLOSE_AND_REOPEN_DEVICE
  LGLCD_APPLET_CAP_CAN_CLOSE_CONNECTION
  LGLCD_APPLET_CAP_CAN_CLOSE_DEVICE
  LGLCD_APPLET_CAP_CAN_RUN_ON_MULTIPLE_DEVICES
  LGLCD_BMP_FORMAT_160x43x1
  LGLCD_BMP_HEIGHT
  LGLCD_BMP_WIDTH
  LGLCD_DEVICE_FAMILY_JACKBOX
  LGLCD_DEVICE_FAMILY_KEYBOARD_G15
  LGLCD_DEVICE_FAMILY_LCDEMULATOR_G15
  LGLCD_DEVICE_FAMILY_OTHER
  LGLCD_DEVICE_FAMILY_RAINBOW
  LGLCD_DEVICE_FAMILY_SPEAKERS_Z10
  LGLCD_INVALID_CONNECTION
  LGLCD_INVALID_DEVICE
  LGLCD_LCD_FOREGROUND_APP_NO
  LGLCD_LCD_FOREGROUND_APP_YES
  LGLCD_NOTIFICATION_CLOSE_AND_REOPEN_DEVICE
  LGLCD_NOTIFICATION_CLOSE_CONNECTION
  LGLCD_NOTIFICATION_CLOSE_DEVICE
  LGLCD_NOTIFICATION_DEVICE_ARRIVAL
  LGLCD_NOTIFICATION_DEVICE_REMOVAL
  LGLCD_NOTIFICATION_RUN_NEW_INSTANCE_ON_DEVICE
  LGLCD_PRIORITY_ALERT
  LGLCD_PRIORITY_BACKGROUND
  LGLCD_PRIORITY_IDLE_NO_SHOW
  LGLCD_PRIORITY_NORMAL
  lgLcdConnect
  lgLcdConnectEx
  lgLcdEnumerateEx

Know bugs ^

While the applet is running, it crash when softbutton are clicked before the callback of previous as leaved. May be a re-entrance matter.

TODO List ^

  - write applet's skeleton / base object
  - add a parameter to choose the way to avoid the callback 're-entrance' 
crash.
  - implement configuration and notification callbacks.

SAMPLE ^

  use GD;
  use Win32::Lglcd;
  use Time::HiRes qw(usleep);
  
  $|=1;
  my $continue_loop = 1;                #Allow to close applet with CTRL+C
  sub sig_handler {                     #1st argument is signal name
      my($sig) = @_;
      print "Caught a SIG$sig--shutting down\n";
      $continue_loop=0;
  }
  $SIG{'INT'}  = \&sig_handler;
  $SIG{'BREAK'} = \&sig_handler;
  
  my $delay = 150;
  sub onSoftButtonChanged{
        my ($connection, $button, $params) = @_;
        $xinc +=1 if $button==1;
        $xinc -=1 if $button==2;
        $xinc +=10 if $button==3;
        $xinc -=10 if $button==4;
        $xinc = 1 if $xinc < 1;
        return 0;
  }
  
  my $g15 = Win32::Lglcd->new;
  $g15->init() or die "can't initialize Win32::Lglcd library!";
  $g15->connect('ScrollingText') or die "can't connect to Win32::Lglcd!";
  #~ $g15->use_families(LGLCD_DEVICE_FAMILY_LCDEMULATOR_G15);
  #~ my @devices = $g15->enumerateEx;
  #~ use Data::Dumper; print Dumper( @devices );
  $g15->open(callback=>\&onSoftButtonChanged) or die "can't open specified device!";
  $g15->foreground();
  my $im = new GD::Image(320,43,0);
  my $white = $im->colorAllocate(255,255,255);
  my $black = $im->colorAllocate(0,0,0);
  #$im->rectangle(0,0,159,42,$black);
  $im->string(gdGiantFont,10,5, "Scrolling text - test app - blah -" ,$black);
  $im->string(gdGiantFont,0,25, "- blah - Scrolling text - test app" ,$black);
  my $x = 0;
  our $xinc = 1;
  while($continue_loop){
        $x+=$xinc;
        $xinc=-$xinc,$x+=$xinc if $x>=160 or $x<=0;
        my $pict = $im->Lglcd( 'x'=> $x );
        $g15->sendbmp($pict);
        foreach(1..10){
                Win32::Lglcd::g15_do_event();   #a internal process message for callbacks (avoid crash)
                usleep(50);
        }
  }
  $g15->close() or die "can't close devices!"; 
  $g15->disconnect() or die "can't disconnect library Win32::Lglcd!";
  $g15->deinit() or die "can't free library Win32::Lglcd!";
  exit;

SEE ALSO ^

Mention other useful documentation such as the documentation of related modules or operating system documentation (such as man pages in UNIX), or any relevant external documentation such as RFCs or standards.

AUTHOR ^

N. Georges, <xlat.@cpan.org>

COPYRIGHT AND LICENSE ^

Copyright (C) 2008 by N. Georges

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: