fhem-mirror/FHEM/lib/Device/Firmata.pm
ntruchsess e918d9bf66 incorporate perl-firmata (Device::Firmata)
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@2596 2b470e98-0d58-463d-a4d8-8e2adae1ed80
2013-01-29 21:03:38 +00:00

73 lines
1.4 KiB
Perl

package Device::Firmata;
use strict;
use warnings;
use Device::Firmata::Constants;
use Device::Firmata::Base
ISA => 'Device::Firmata::Base',
FIRMATA_ATTRIBS => {
};
=head1 NAME
Device::Firmata - A host interface to Firmata for the arduino platform.
=head1 VERSION
Version 0.50
=cut
our $VERSION = '0.50';
our $DEBUG = 0;
=head1 SYNOPSIS
use strict;
use warnings;
use Device::Firmata::Constants qw/ :all /;
use Device::Firmata;
$|++;
use Time::HiRes 'sleep';
my $led_pin = 13;
my $device = Device::Firmata->open('/dev/ttyUSB0') or die "Could not connect to Firmata Server";
$device->pin_mode($led_pin=>PIN_OUTPUT);
my $iteration = 0;
while (1) {
my $strobe_state = $iteration++%2;
$device->digital_write($led_pin=>$strobe_state);
sleep 0.5;
}
=head1 SUBROUTINES/METHODS
=head2 open
establish communication to the device. Single argument is the name of the device file mapped to the arduino. Typicaly '/dev/ttyUSB0'
=cut
sub open {
# --------------------------------------------------
# Establish a connection with the serial port
#
my ( $self, $serial_port, $opts ) = @_;
# We're going to try and create the device connection first...
my $package = "Device::Firmata::Platform";
eval "require $package";
my $device = $package->open($serial_port,$opts);
# Figure out what platform we're running on
$device->probe;
return $device;
}
1;