replace perl reset script with python one
This commit is contained in:
parent
5599d2ab1e
commit
07b0ad8371
5 changed files with 52 additions and 157 deletions
22
README.md
22
README.md
|
@ -34,30 +34,36 @@ package and can be installed using `apt-get` or `aptitude`.
|
||||||
You need to have the Arduino IDE. You can either install it through the
|
You need to have the Arduino IDE. You can either install it through the
|
||||||
installer or download the distribution zip file and extract it.
|
installer or download the distribution zip file and extract it.
|
||||||
|
|
||||||
The Makefile also delegates resetting the board to a short Perl program.
|
The Makefile also delegates resetting the board to a short Python program.
|
||||||
You'll need to install `Device::SerialPort` to use it though.
|
You'll need to install `pySerial` to use it though.
|
||||||
|
|
||||||
On Debian or Ubuntu:
|
On Debian or Ubuntu:
|
||||||
|
|
||||||
apt-get install libdevice-serialport-perl
|
apt-get install python-serial
|
||||||
|
|
||||||
On Fedora:
|
On Fedora:
|
||||||
|
|
||||||
yum install perl-Device-SerialPort
|
yum install pyserial
|
||||||
|
|
||||||
On openSUSE:
|
On openSUSE:
|
||||||
|
|
||||||
zypper install perl-Device-SerialPort
|
zypper install python-serial
|
||||||
|
|
||||||
On Mac using MacPorts:
|
On Mac using MacPorts:
|
||||||
|
|
||||||
sudo port install p5-device-serialport
|
sudo port install py27-serial
|
||||||
|
|
||||||
and use /opt/local/bin/perl5 instead of /usr/bin/perl
|
On Windows:
|
||||||
|
|
||||||
|
pySerial can be downloaded from PyPi
|
||||||
|
|
||||||
On other systems:
|
On other systems:
|
||||||
|
|
||||||
cpan Device::SerialPort
|
pip install pyserial
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
easy_install -U pyserial
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
|
@ -1,147 +1,37 @@
|
||||||
#!/usr/bin/env perl
|
#!/usr/bin/python
|
||||||
|
|
||||||
use strict;
|
import serial
|
||||||
use warnings;
|
import os.path
|
||||||
|
import argparse
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
use Device::SerialPort;
|
parser = argparse.ArgumentParser(description='Reset an Arduino')
|
||||||
use Getopt::Long;
|
parser.add_argument('--caterina', action='store_true', help='Reset a Leonardo, Micro, Robot or LilyPadUSB.')
|
||||||
use Pod::Usage;
|
parser.add_argument('--verbose', action='store_true', help="Watch what's going on on STDERR.")
|
||||||
|
parser.add_argument('--period', default=0.1, help='Specify the DTR pulse width in seconds.')
|
||||||
|
parser.add_argument('port', nargs=1, help='Serial device e.g. /dev/ttyACM0')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
my %Opt =
|
if args.caterina:
|
||||||
(
|
if args.verbose: print 'Forcing reset using 1200bps open/close on port %s' % args.port[0]
|
||||||
period => 0.1,
|
ser = serial.Serial(args.port[0], 57600)
|
||||||
);
|
ser.close()
|
||||||
|
ser.open()
|
||||||
GetOptions(\%Opt,
|
ser.close()
|
||||||
"period=f", # width of reset pulse in seconds
|
ser.setBaudrate(1200)
|
||||||
"verbose!",
|
ser.open()
|
||||||
"help!",
|
ser.close()
|
||||||
"info!",
|
sleep(1)
|
||||||
"caterina!",
|
|
||||||
);
|
|
||||||
|
|
||||||
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{caterina})
|
|
||||||
{
|
|
||||||
$p->baudrate(1200);
|
|
||||||
$p->write_settings;
|
|
||||||
$p->close;
|
|
||||||
|
|
||||||
print STDERR "Forcing reset using 1200bps open/close on port $dev\n"
|
|
||||||
if $Opt{verbose};
|
|
||||||
|
|
||||||
# wait for it to come back
|
|
||||||
sleep 1;
|
|
||||||
while( ! -e $dev ) {
|
|
||||||
print STDERR "Waiting for $dev to come back\n"
|
|
||||||
if $Opt{verbose};
|
|
||||||
sleep 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
print STDERR "$dev has come back after reset\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 --caterina /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 --caterina
|
|
||||||
|
|
||||||
Reset a Leonardo, Micro, Robot or LilyPadUSB.
|
|
||||||
|
|
||||||
=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/Micro 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.
|
|
||||||
|
|
||||||
|
while not os.path.exists(args.port[0]):
|
||||||
|
if args.verbose: print 'Waiting for %s to come back' % args.port[0]
|
||||||
|
sleep(1)
|
||||||
|
|
||||||
|
if args.verbose: print '%s has come back after reset' % args.port[0]
|
||||||
|
else:
|
||||||
|
if args.verbose: print 'Setting DTR high on %s for %ss' % (args.port[0],args.period)
|
||||||
|
ser = serial.Serial(args.port[0], 115200)
|
||||||
|
ser.setDTR(False)
|
||||||
|
sleep(args.period)
|
||||||
|
ser.setDTR(True)
|
||||||
|
ser.close()
|
||||||
|
|
|
@ -7,7 +7,7 @@ or [Ubuntu](https://launchpad.net/ubuntu/+source/arduino-mk) or use apt.
|
||||||
First install the dependencies for building/running the package, as root:
|
First install the dependencies for building/running the package, as root:
|
||||||
|
|
||||||
apt-get build-dep arduino-mk
|
apt-get build-dep arduino-mk
|
||||||
apt-get install arduino-core libdevice-serialport-perl help2man build-essential dpkg-dev fakeroot perl-doc devscripts
|
apt-get install arduino-core build-essential dpkg-dev fakeroot devscripts python-serial
|
||||||
|
|
||||||
Fetch the Debian source:
|
Fetch the Debian source:
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
First install the dependencies as root:
|
First install the dependencies as root:
|
||||||
|
|
||||||
yum install arduino-core perl-Device-SerialPort help2man rpm-build
|
yum install arduino-core rpm-build pyserial
|
||||||
|
|
||||||
From the top-level Arduino-Makefile directory you've checked out of github, run the following (as unprivileged user) to create a compressed tarball using the naming conventions required by rpmbuild:
|
From the top-level Arduino-Makefile directory you've checked out of github, run the following (as unprivileged user) to create a compressed tarball using the naming conventions required by rpmbuild:
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ Group: Development/Tools
|
||||||
License: LGPLv2+
|
License: LGPLv2+
|
||||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
Requires: arduino-core, perl-Device-SerialPort
|
Requires: arduino-core pyserial
|
||||||
BuildRequires: arduino-core, perl-Device-SerialPort, help2man
|
BuildRequires: arduino-core pyserial
|
||||||
|
|
||||||
%description
|
%description
|
||||||
Arduino is an open-source electronics prototyping platform based on
|
Arduino is an open-source electronics prototyping platform based on
|
||||||
|
@ -27,7 +27,6 @@ Arduino platform.
|
||||||
%install
|
%install
|
||||||
mkdir -p %{buildroot}/%{_datadir}/arduino
|
mkdir -p %{buildroot}/%{_datadir}/arduino
|
||||||
mkdir -p %{buildroot}/%{_bindir}
|
mkdir -p %{buildroot}/%{_bindir}
|
||||||
mkdir -p %{buildroot}/%{_mandir}/man1
|
|
||||||
mkdir -p %{buildroot}/%{_docdir}/%{name}/examples
|
mkdir -p %{buildroot}/%{_docdir}/%{name}/examples
|
||||||
install -m 755 -d %{buildroot}/%{_docdir}/%{name}
|
install -m 755 -d %{buildroot}/%{_docdir}/%{name}
|
||||||
install -m 755 -d %{buildroot}/%{_docdir}/%{name}/examples
|
install -m 755 -d %{buildroot}/%{_docdir}/%{name}/examples
|
||||||
|
@ -36,7 +35,6 @@ for file in `find examples -type f ! -name .gitignore` ; do install -m 644 $file
|
||||||
install -m 644 *.mk arduino-mk-vars.md %{buildroot}/%{_datadir}/arduino
|
install -m 644 *.mk arduino-mk-vars.md %{buildroot}/%{_datadir}/arduino
|
||||||
install -m 644 licence.txt %{buildroot}/%{_docdir}/%{name}
|
install -m 644 licence.txt %{buildroot}/%{_docdir}/%{name}
|
||||||
install -m 755 bin/ard-reset-arduino %{buildroot}/%{_bindir}/ard-reset-arduino
|
install -m 755 bin/ard-reset-arduino %{buildroot}/%{_bindir}/ard-reset-arduino
|
||||||
help2man %{buildroot}/%{_bindir}/ard-reset-arduino -n "Reset Arduino board" -s 1 -m "Arduino CLI Reset" --version-string=%{version} -N -o %{buildroot}/%{_mandir}/man1/ard-reset-arduino.1
|
|
||||||
|
|
||||||
%clean
|
%clean
|
||||||
rm -rf %{buildroot}
|
rm -rf %{buildroot}
|
||||||
|
@ -44,7 +42,6 @@ rm -rf %{buildroot}
|
||||||
%files
|
%files
|
||||||
%defattr(-,root,root,-)
|
%defattr(-,root,root,-)
|
||||||
%{_bindir}/ard-reset-arduino
|
%{_bindir}/ard-reset-arduino
|
||||||
%{_mandir}/man1/ard-reset-arduino.1*
|
|
||||||
%{_datadir}/arduino/*.mk
|
%{_datadir}/arduino/*.mk
|
||||||
%{_datadir}/arduino/arduino-mk-vars.md
|
%{_datadir}/arduino/arduino-mk-vars.md
|
||||||
%doc %{_docdir}/%{name}/licence.txt
|
%doc %{_docdir}/%{name}/licence.txt
|
||||||
|
@ -52,6 +49,8 @@ rm -rf %{buildroot}
|
||||||
%{_docdir}/%{name}/examples
|
%{_docdir}/%{name}/examples
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon Mar 24 2014 Simon John <git@the-jedi.co.uk>
|
||||||
|
- Replaced perl/help2man with pyserial for reset script.
|
||||||
* Tue Feb 04 2014 Simon John <git@the-jedi.co.uk>
|
* Tue Feb 04 2014 Simon John <git@the-jedi.co.uk>
|
||||||
- Added arduino-mk-vars.md to the files to be installed/packaged.
|
- Added arduino-mk-vars.md to the files to be installed/packaged.
|
||||||
* Sat Feb 01 2014 Simon John <git@the-jedi.co.uk>
|
* Sat Feb 01 2014 Simon John <git@the-jedi.co.uk>
|
||||||
|
|
Loading…
Reference in a new issue