#!/usr/bin/perl
# nearly trivial script to mount /mnt/camera on /dev/ttyUSB1,
# create a new directory named with the current date/time,
# copy images from the camera to disk, and umount the camera.
#---------------------------------------------------------------------
$| = 1;
use strict;
use Tk;
use Tk::Pane;
use Tk::ProgressBar;
my $message = 'Ready';
my $main = MainWindow->new();
$main->configure(-title=>'Camera 2 Disk', -background =>'blue');
$main->geometry('370x200+100+00');
my $label = $main->Label(-text =>"Digital Camera Tool\nCopy Images from Fuji FinePix to Disk",
-relief => 'raised',
-background =>'#42b4b4')
->pack(-side=>'top', -fill =>'both');
my $button_frame = $main->Frame(-relief=>'raised')
->pack(-side => 'top', -fill => 'x');
my $dump = $button_frame->Button(-text => 'Dump',
-command => \&get_files)
->pack(-side =>'left', -anchor => 'w');
my $status_text = 'Ready';
my $status_label = $button_frame->Label(-textvariable =>\$status_text,
-relief => 'raised',
-background =>'grey77')
->pack(-side=>'left',-fill=>'both', -expand=>'1');
my $exit = $button_frame->Button(-text => 'Exit', -command => 'exit')
->pack(-side =>'right');
my $status = $main->Scrolled('Pane', -scrollbars => 'se', -relief => 'flat')
->pack(-side=>'top', -fill=>'both', -expand=>'y');
$status->Label(textvariable =>\$message,
-relief => 'flat')
->pack(-side=>'top', -fill =>'both');
my $percent_done;
my $position = '0';
my $progress = $main->ProgressBar(-troughcolor => 'grey70',
-width => 20,
-length => 370,
-anchor => 'w',
-from => 0,
-to => 100,
-blocks => 0.1,
-colors => [0, 'blue', 100],
)->pack(-side=>'left', -fill=>'both');
$progress->value($position);
MainLoop();
#---------------------------------------------------------------------
sub get_files {
my $date = localtime;
my @time = split /\s|:/, $date;
my $new_dir = '/home/julmer/images/'.$time[1].'_'.$time[2].'_'.$time[6].'_'.$time[3].$time[4].$time[5];
my $mount = '';
my $cmd = "mount /mnt/camera";
open(CAM," $cmd 2>&1 |") || die "Failed open: $!\n";
while (<CAM>) { $mount .= $_ ; }
close CAM;
if ($mount =~ /already mounted/i)
{
$message = '/mnt/camera is already mounted';
}
elsif ($mount =~ /no medium found|not a valid/i)
{
$message = "Mount Failed: $mount Be sure the camera is connected";
$message .= "\nand turned on in USB DSC mode.\n";
return;
}
$message = '';
my @files = `ls /mnt/camera/dcim/100_fuji/`;
chomp (@files);
my $num_files = $#files + 1;
$message = $num_files."$files[0]";
my $file_count = '1';
# if ($#files > 0 ) # stupid!!
if ($files[0] =~ /\w/ )
{
$dump->configure(-state=>'disable');
$exit->configure(-state=>'disable');
mkdir($new_dir);
foreach (@files)
{
my $from = '/mnt/camera/dcim/100_fuji/'.$_;
my $to = $new_dir."/$_";
my $cmd = qq(cp $from $to);
$message = "Copying $_ to disk.\n";
`$cmd`;
$percent_done = int(($file_count/$num_files) * 100);
$progress->value($percent_done);
$progress->update;
$file_count++;
$status_text = qq(Progress: $percent_done %);
}
$dump->configure(-state=>'normal');
$exit->configure(-state=>'normal');
}
$cmd = "umount /mnt/camera";
open(CAM," $cmd 2>&1 |") || die "Failed open: $!\n";
while (<CAM>) { $mount .= $_ ; }
close CAM;
$status_text = 'Done';
$message .= "\nDone!\n";
}