#!/usr/bin/perl

#
# $Id: test.pl,v 1.5 2011-10-20 18:04:37 scg Exp $
#

use strict;

use GD;
use USBLCD;



# create GD image
my $im = new GD::Image(16, 8);
my $black = $im->colorAllocate(0,0,0);
my $white = $im->colorAllocate(255, 255, 255);
$im->rectangle(0, 0, 15, 7, $white);



# claim device
my $usblcd = new USBLCD;
die "Can't claim the USB LCD device.\n" unless defined $usblcd;

# get device info
my $info_ref = $usblcd->getinfo;
print "info: type=$info_ref->{'type'}, num_modes=$info_ref->{'num_modes'}\n";

# get device modes
my $modes_ref = $usblcd->getmodes;
print "Supported modes:\n";
foreach my $mode_ref (@{$modes_ref}) {
    print "    $mode_ref->{'mode'}: $mode_ref->{'width'}x$mode_ref->{'height'}\@$mode_ref->{'bpp'}\n";
}

# get current mode
my $mode_ref = $usblcd->getmode;
print "Current mode: $mode_ref->{'mode'}: $mode_ref->{'width'}x$mode_ref->{'height'}\@$mode_ref->{'bpp'}\n";

# get device LEDs
my $leds_ref = $usblcd->getleds;
print "Existing LEDs:\n";
foreach my $led_ref (@{$leds_ref}) {
    print "    $led_ref->{'led'}: type = $led_ref->{'type'}, color = $led_ref->{'color'}, max. value = $led_ref->{'max'}\n";
    $usblcd->setled($led_ref->{'led'}, USBLCD_LED_ON);
    sleep(1);
    $usblcd->setled($led_ref->{'led'}, USBLCD_LED_OFF);
}

# set default mode
my $retval = $usblcd->setmode;
print "set_mode(): $retval\n";

$usblcd->setrotate(USBLCD_ROTATE90);
print "set_rotate(): $retval\n";

# set power on
$retval = $usblcd->setpower(USBLCD_POWER_ON);
print "set_power(): $retval\n";

# clear screen
$retval = $usblcd->fillrect(0, 0, 32, 122, 0);
print "set_fillrect(): $retval\n";

# draw image
$retval = $usblcd->bitbltgd(24, 8, $im);
print "bitbltgd(): $retval\n";

printf "Press <Enter> for continue...";
<>;

# set power off
$retval = $usblcd->setpower(USBLCD_POWER_OFF);
print "set_power(): $retval\n";
