Arduino-Makefile/bin/ard-reset-arduino
Sudar 60ca7d2852 Move reseting Leonardo logic to ard-reset-arduino
ard-reset-leonardo which was used for reseting Leonardo was written in
Python. Now the logic is added inside the ard-reset-arduino perl script
itself.

Fix #62

Squashed commit of the following:

commit a63366980f
Author: Simon John <git@the-jedi.co.uk>
Date:   Fri Jun 14 11:36:00 2013 +0200

    who put a space in the shebangs?!

commit c798eb26ea
Author: Simon John <git@the-jedi.co.uk>
Date:   Fri Jun 14 11:10:12 2013 +0200

    replaced ard-reset-leonardo with an update to ard-reset-arduino
    which is now called from Arduino.mk with the --leonardo flag

    removed some trailing whitespace

    upped version string in Arduino.mk
2013-06-14 16:09:38 +05:30

136 lines
2.5 KiB
Perl
Executable file

#!/usr/bin/env perl
use strict;
use warnings;
use Device::SerialPort;
use Getopt::Long;
use Pod::Usage;
my %Opt =
(
period => 0.1,
);
GetOptions(\%Opt,
"period=f", # width of reset pulse in seconds
"verbose!",
"help!",
"info!",
"leonardo!",
);
if ($Opt{help} || $Opt{info})
{
usage();
}
die "No Arduinos found!\n"
unless @ARGV;
foreach my $dev (@ARGV)
{
my $p = Device::SerialPort->new($dev)
or die "Unable to open $dev: $!\n";
if ($Opt{leonardo})
{
$p->baudrate(1200);
$p->write_settings;
$p->close;
print STDERR "Switching to 1200 baud on $dev\n"
if $Opt{verbose};
}
else
{
my $dt = $Opt{period};
print STDERR "Setting DTR high for ${dt}s on $dev\n"
if $Opt{verbose};
die "Invalid pulse width ($dt), "
unless $dt > 0.0;
$p->pulse_dtr_on($dt * 1000.0);
}
}
## here endeth the main
sub usage
{
pod2usage(-verbose => 2);
}
__END__
=head1 NAME
ard-reset-arduino - Reset an Arduino
=head1 USAGE
$ ard-reset-arduino /dev/cu.usb*
$ ard-reset-arduino --verbose --period=0.1 /dev/cu.usb*
$ ard-reset-arduino --verbose --leonardo /dev/ttyUSB0
=head1 DESCRIPTION
To reset (most) Arduinos, it's enough to just pulse the DTR line.
You can do that from the shell with stty, but there's an interesting
diversity of command flags. This little program gives a uniform interface
at the cost of requiring C<Device::SerialPort>.
=head1 OPTIONS
=over
=item --verbose
Watch what's going on on STDERR.
=item --period=0.25
Specify the DTR pulse width in seconds.
=item --leonardo
Reset a Leonardo.
=back
=head1 BUGS AND LIMITATIONS
There are no known bugs in this application.
Please report problems to the author.
Patches are welcome.
=head1 AUTHOR
Martin Oldfield, ex-atelier@mjo.tc
Support for Leonardo added by sej7278, https://github.com/sej7278
Thanks to Daniele Vergini who suggested this to me, and supplied
a command line version.
=head1 LICENCE AND COPYRIGHT
Copyright (c) 2012, Martin Oldfield. All rights reserved.
This file is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.