update perl-firmata to upstream version

git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@4064 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
ntruchsess
2013-10-18 12:08:22 +00:00
parent 63fd8f1954
commit 33f9f141c4
8 changed files with 1445 additions and 1592 deletions

View File

@@ -11,7 +11,7 @@ use Device::Firmata::Base
=head1 NAME
Device::Firmata - A host interface to Firmata for the arduino platform.
Device::Firmata - Perl interface to Firmata for the arduino platform.
=head1 VERSION
@@ -19,7 +19,7 @@ Version 0.50
=cut
our $VERSION = '0.50';
our $VERSION = '0.51';
our $DEBUG = 0;
@@ -47,13 +47,13 @@ while (1) {
=head2 open
establish communication to the device. Single argument is the name of the device file mapped to the arduino. Typicaly '/dev/ttyUSB0'
establish serial connection with an Arduino micro-controller. Single argument is the name of the device file mapped to the arduino. Typically '/dev/ttyUSB0' or 'COM9'
=cut
sub open {
# --------------------------------------------------
# Establish a connection with the serial port
# Establish a connection to Arduino via the serial port
#
my ( $self, $serial_port, $opts ) = @_;

View File

@@ -1,19 +1,16 @@
package Device::Firmata::Base;
use strict 'vars', 'subs';
use vars qw/
$AUTOLOAD
use vars qw/
$AUTOLOAD
$FIRMATA_DEBUG_LEVEL
$FIRMATA_ERROR_CLASS
$FIRMATA_ERROR
$FIRMATA_ATTRIBS
$FIRMATA_DEBUGGING
$FIRMATA_LOCALE
$FIRMATA_ATTRIBS
$FIRMATA_DEBUGGING
$FIRMATA_LOCALE
$FIRMATA_LOCALE_PATH
$FIRMATA_LOCALE_MESSAGES
$FIRMATA_LOCALE_MESSAGES
/;
=head1 NAME
@@ -23,49 +20,42 @@ Device::Firmata::Base -- Abstract baseclass for Device::Firmata modules
=cut
$FIRMATA_DEBUGGING = 1;
$FIRMATA_ATTRIBS = {
};
$FIRMATA_ATTRIBS = {};
$FIRMATA_LOCALE = 'en';
$FIRMATA_LOCALE_PATH = '.';
$FIRMATA_DEBUG_LEVEL = 0;
$FIRMATA_DEBUG_LEVEL = 0;
$FIRMATA_ERROR_CLASS = 'Device::Firmata::Error';
=head1 METHODS
=head2 import
Ease the use of setting up configuration options
Ease setting of configuration options
=cut
=cut
sub import {
my $self = shift;
my $pkg = caller;
my $self = shift;
my $pkg = caller;
my $config_opts = {
debugging => $FIRMATA_DEBUGGING,
};
my $config_opts = {
debugging => $FIRMATA_DEBUGGING,
};
if ( @_ ) {
my $opts = $self->parameters( @_ );
if ( my $attrs = $opts->{FIRMATA_ATTRIBS} ) {
*{$pkg.'::FIRMATA_ATTRIBS'} = \$attrs;
}
unless ( ref *{$pkg.'::ISA'} eq 'ARRAY' and @${$pkg.'::ISA'}) {
my @ISA = ref $opts->{ISA} ? @{$opts->{ISA}} :
$opts->{ISA} ? $opts->{ISA} :
__PACKAGE__;
*{$pkg.'::ISA'} = \@ISA;
}
use strict;
$self->SUPER::import( @_ );
if ( @_ ) {
my $opts = $self->parameters( @_ );
if ( my $attrs = $opts->{FIRMATA_ATTRIBS} ) {
*{$pkg.'::FIRMATA_ATTRIBS'} = \$attrs;
}
unless ( ref *{$pkg.'::ISA'} eq 'ARRAY' and @${$pkg.'::ISA'}) {
my @ISA = ref $opts->{ISA} ? @{$opts->{ISA}} :
$opts->{ISA} ? $opts->{ISA} :
__PACKAGE__;
*{$pkg.'::ISA'} = \@ISA;
}
use strict;
$self->SUPER::import( @_ );
}
}
=head2 new
@@ -92,7 +82,7 @@ sub new {
=head2 create
A soft new as some objects will override new and
A soft new as some objects will override new and
we don't want to cause problems but still want
to invoice our creation code
@@ -137,7 +127,7 @@ sub init_instance_attribs {
=head2 init_class_attribs
=cut
=cut
sub init_class_attribs {
# --------------------------------------------------
@@ -196,7 +186,7 @@ sub parameters {
@_ % 2 or $_[0]->warn( "Even number of elements were not passed to call.", join( " ", caller() ) );
shift;
shift;
return {@_};
}
@@ -268,7 +258,6 @@ sub error {
# Handle any error messages
#
my $self = shift;
if ( @_ ) {
my $err_msg = $self->init_error->error(@_);
$self->{error} = $err_msg;
@@ -395,4 +384,3 @@ sub object_load {
1;

View File

@@ -2,7 +2,7 @@ package Device::Firmata::Constants;
=head1 NAME
Device::Firmata::Constants - constants used in the system
Device::Firmata::Constants - constants used in the Device::Firmata system
=cut
@@ -11,7 +11,6 @@ use Exporter;
use vars qw/
@ISA @EXPORT_OK %EXPORT_TAGS
$BASE
$DEVICES
$COMMANDS $COMMAND_NAMES
$COMMAND_LOOKUP
/;
@@ -19,325 +18,307 @@ use vars qw/
# Basic commands and constants
use constant (
$BASE = {
PIN_INPUT => 0,
PIN_OUTPUT => 1,
PIN_ANALOG => 2,
PIN_PWM => 3,
PIN_SERVO => 4,
PIN_SHIFT => 5,
PIN_I2C => 6,
PIN_ONEWIRE => 7,
PIN_STEPPER => 8,
PIN_LOW => 0,
PIN_HIGH => 1,
}
$BASE = {
PIN_INPUT => 0,
PIN_OUTPUT => 1,
PIN_ANALOG => 2,
PIN_PWM => 3,
PIN_SERVO => 4,
PIN_SHIFT => 5,
PIN_I2C => 6,
PIN_ONEWIRE => 7,
PIN_STEPPER => 8,
PIN_LOW => 0,
PIN_HIGH => 1,
}
);
$DEVICES = { 'arduino_dumilanove' => {}, };
# We need to apply all the available protocols
use constant (
$COMMANDS = {
$COMMANDS = {
V_2_01 => {
V_2_01 => {
MAX_DATA_BYTES =>
32, # max number of data bytes in non-Sysex messages
MAX_DATA_BYTES => 32, # max number of data bytes in non-Sysex messages
# message command bytes (128-255/0x80-0xFF)
DIGITAL_MESSAGE => 0x90, # send data for a digital pin
ANALOG_MESSAGE => 0xE0, # send data for an analog pin (or PWM)
REPORT_ANALOG => 0xC0, # enable analog input by pin #
REPORT_DIGITAL => 0xD0, # enable digital input by port pair
SET_PIN_MODE => 0xF4, # set a pin to INPUT/OUTPUT/PWM/etc
REPORT_VERSION => 0xF9, # report protocol version
SYSTEM_RESET => 0xFF, # reset from MIDI
START_SYSEX => 0xF0, # start a MIDI Sysex message
END_SYSEX => 0xF7, # end a MIDI Sysex message
# message command bytes (128-255/0x80-0xFF)
DIGITAL_MESSAGE => 0x90, # send data for a digital pin
ANALOG_MESSAGE => 0xE0, # send data for an analog pin (or PWM)
REPORT_ANALOG => 0xC0, # enable analog input by pin #
REPORT_DIGITAL => 0xD0, # enable digital input by port pair
SET_PIN_MODE => 0xF4, # set a pin to INPUT/OUTPUT/PWM/etc
REPORT_VERSION => 0xF9, # report protocol version
SYSTEM_RESET => 0xFF, # reset from MIDI
START_SYSEX => 0xF0, # start a MIDI Sysex message
END_SYSEX => 0xF7, # end a MIDI Sysex message
# extended command set using sysex (0-127/0x00-0x7F)
SERVO_CONFIG => 0x70, # set max angle, minPulse, maxPulse, freq
STRING_DATA => 0x71, # a string message with 14-bits per char
SHIFT_DATA => 0x75, # a bitstream to/from a shift register
I2C_REQUEST => 0x76, # send an I2C read/write request
I2C_REPLY => 0x77, # a reply to an I2C read request
I2C_CONFIG => 0x78, # config I2C settings such as delay times and power pins
REPORT_FIRMWARE => 0x79, # report name and version of the firmware
SAMPLING_INTERVAL => 0x7A, # set the poll rate of the main loop
SYSEX_NON_REALTIME => 0x7E, # MIDI Reserved for non-realtime messages
SYSEX_REALTIME => 0x7F, # MIDI Reserved for realtime messages
# extended command set using sysex (0-127/0x00-0x7F)
SERVO_CONFIG => 0x70, # set max angle, minPulse, maxPulse, freq
STRING_DATA => 0x71, # a string message with 14-bits per char
SHIFT_DATA => 0x75, # a bitstream to/from a shift register
I2C_REQUEST => 0x76, # send an I2C read/write request
I2C_REPLY => 0x77, # a reply to an I2C read request
I2C_CONFIG => 0x78, # config I2C settings such as delay times and power pins
REPORT_FIRMWARE => 0x79, # report name and version of the firmware
SAMPLING_INTERVAL => 0x7A, # set the poll rate of the main loop
SYSEX_NON_REALTIME => 0x7E, # MIDI Reserved for non-realtime messages
SYSEX_REALTIME => 0x7F, # MIDI Reserved for realtime messages
# these are DEPRECATED to make the naming more consistent
FIRMATA_STRING => 0x71, # same as STRING_DATA
SYSEX_I2C_REQUEST => 0x76, # same as I2C_REQUEST
SYSEX_I2C_REPLY => 0x77, # same as I2C_REPLY
SYSEX_SAMPLING_INTERVAL => 0x7A, # same as SAMPLING_INTERVAL
# these are DEPRECATED to make the naming more consistent
FIRMATA_STRING => 0x71, # same as STRING_DATA
SYSEX_I2C_REQUEST => 0x76, # same as I2C_REQUEST
SYSEX_I2C_REPLY => 0x77, # same as I2C_REPLY
SYSEX_SAMPLING_INTERVAL => 0x7A, # same as SAMPLING_INTERVAL
# pin modes
INPUT => 0x00, # digital pin in digitalOut mode
OUTPUT => 0x01, # digital pin in digitalInput mode
ANALOG => 0x02, # analog pin in analogInput mode
PWM => 0x03, # digital pin in PWM output mode
SERVO => 0x04, # digital pin in Servo output mode
SHIFT => 0x05, # shiftIn/shiftOut mode
I2C => 0x06, # pin included in I2C setup
# pin modes
INPUT => 0x00, # digital pin in digitalOut mode
OUTPUT => 0x01, # digital pin in digitalInput mode
ANALOG => 0x02, # analog pin in analogInput mode
PWM => 0x03, # digital pin in PWM output mode
SERVO => 0x04, # digital pin in Servo output mode
SHIFT => 0x05, # shiftIn/shiftOut mode
I2C => 0x06, # pin included in I2C setup
# Deprecated entries
deprecated => [
qw( FIRMATA_STRING SYSEX_I2C_REQUEST SYSEX_I2C_REPLY SYSEX_SAMPLING_INTERVAL )
],
# Deprecated entries
deprecated => [
qw( FIRMATA_STRING SYSEX_I2C_REQUEST SYSEX_I2C_REPLY SYSEX_SAMPLING_INTERVAL )
],
}, # /Constants for Version 2.1
}, # /Constants for Version 2.1
V_2_02 => {
V_2_02 => {
MAX_DATA_BYTES => 32, # max number of data bytes in non-Sysex messages
MAX_DATA_BYTES =>
32, # max number of data bytes in non-Sysex messages
# message command bytes (128-255/0x80-0xFF)
DIGITAL_MESSAGE => 0x90, # send data for a digital pin
ANALOG_MESSAGE => 0xE0, # send data for an analog pin (or PWM)
REPORT_ANALOG => 0xC0, # enable analog input by pin #
REPORT_DIGITAL => 0xD0, # enable digital input by port pair
SET_PIN_MODE => 0xF4, # set a pin to INPUT/OUTPUT/PWM/etc
REPORT_VERSION => 0xF9, # report protocol version
SYSTEM_RESET => 0xFF, # reset from MIDI
START_SYSEX => 0xF0, # start a MIDI Sysex message
END_SYSEX => 0xF7, # end a MIDI Sysex message
# message command bytes (128-255/0x80-0xFF)
DIGITAL_MESSAGE => 0x90, # send data for a digital pin
ANALOG_MESSAGE => 0xE0, # send data for an analog pin (or PWM)
REPORT_ANALOG => 0xC0, # enable analog input by pin #
REPORT_DIGITAL => 0xD0, # enable digital input by port pair
SET_PIN_MODE => 0xF4, # set a pin to INPUT/OUTPUT/PWM/etc
REPORT_VERSION => 0xF9, # report protocol version
SYSTEM_RESET => 0xFF, # reset from MIDI
START_SYSEX => 0xF0, # start a MIDI Sysex message
END_SYSEX => 0xF7, # end a MIDI Sysex message
# extended command set using sysex (0-127/0x00-0x7F)
RESERVED_COMMAND => 0x00, # 2nd SysEx data byte is a chip-specific command (AVR, PIC, TI, etc).
ANALOG_MAPPING_QUERY => 0x69, # ask for mapping of analog to pin numbers
ANALOG_MAPPING_RESPONSE => 0x6A, # reply with mapping info
CAPABILITY_QUERY => 0x6B, # ask for supported modes and resolution of all pins
CAPABILITY_RESPONSE => 0x6C, # reply with supported modes and resolution
PIN_STATE_QUERY => 0x6D, # ask for a pin's current mode and value
PIN_STATE_RESPONSE => 0x6E, # reply with a pin's current mode and value
EXTENDED_ANALOG => 0x6F, # analog write (PWM, Servo, etc) to any pin
SERVO_CONFIG => 0x70, # set max angle, minPulse, maxPulse, freq
STRING_DATA => 0x71, # a string message with 14-bits per char
SHIFT_DATA => 0x75, # shiftOut config/data message (34 bits)
I2C_REQUEST => 0x76, # send an I2C read/write request
I2C_REPLY => 0x77, # a reply to an I2C read request
I2C_CONFIG => 0x78, # config I2C settings such as delay times and power pins
REPORT_FIRMWARE => 0x79, # report name and version of the firmware
SAMPLING_INTERVAL => 0x7A, # set the poll rate of the main loop
SYSEX_NON_REALTIME => 0x7E, # MIDI Reserved for non-realtime messages
SYSEX_REALTIME => 0x7F, # MIDI Reserved for realtime messages
# extended command set using sysex (0-127/0x00-0x7F)
RESERVED_COMMAND => 0x00, # 2nd SysEx data byte is a chip-specific command (AVR, PIC, TI, etc).
ANALOG_MAPPING_QUERY => 0x69, # ask for mapping of analog to pin numbers
ANALOG_MAPPING_RESPONSE => 0x6A, # reply with mapping info
CAPABILITY_QUERY => 0x6B, # ask for supported modes and resolution of all pins
CAPABILITY_RESPONSE => 0x6C, # reply with supported modes and resolution
PIN_STATE_QUERY => 0x6D, # ask for a pin's current mode and value
PIN_STATE_RESPONSE => 0x6E, # reply with a pin's current mode and value
EXTENDED_ANALOG => 0x6F, # analog write (PWM, Servo, etc) to any pin
SERVO_CONFIG => 0x70, # set max angle, minPulse, maxPulse, freq
STRING_DATA => 0x71, # a string message with 14-bits per char
SHIFT_DATA => 0x75, # shiftOut config/data message (34 bits)
I2C_REQUEST => 0x76, # send an I2C read/write request
I2C_REPLY => 0x77, # a reply to an I2C read request
I2C_CONFIG => 0x78, # config I2C settings such as delay times and power pins
REPORT_FIRMWARE => 0x79, # report name and version of the firmware
SAMPLING_INTERVAL => 0x7A, # set the poll rate of the main loop
SYSEX_NON_REALTIME => 0x7E, # MIDI Reserved for non-realtime messages
SYSEX_REALTIME => 0x7F, # MIDI Reserved for realtime messages
# pin modes
INPUT => 0x00, # digital pin in digitalOut mode
OUTPUT => 0x01, # digital pin in digitalInput mode
ANALOG => 0x02, # analog pin in analogInput mode
PWM => 0x03, # digital pin in PWM output mode
SERVO => 0x04, # digital pin in Servo output mode
SHIFT => 0x05, # shiftIn/shiftOut mode
I2C => 0x06, # pin included in I2C setup
# pin modes
INPUT => 0x00, # digital pin in digitalOut mode
OUTPUT => 0x01, # digital pin in digitalInput mode
ANALOG => 0x02, # analog pin in analogInput mode
PWM => 0x03, # digital pin in PWM output mode
SERVO => 0x04, # digital pin in Servo output mode
SHIFT => 0x05, # shiftIn/shiftOut mode
I2C => 0x06, # pin included in I2C setup
# Deprecated entries
deprecated => [
qw( FIRMATA_STRING SYSEX_I2C_REQUEST SYSEX_I2C_REPLY SYSEX_SAMPLING_INTERVAL )
],
# Deprecated entries
deprecated => [
qw( FIRMATA_STRING SYSEX_I2C_REQUEST SYSEX_I2C_REPLY SYSEX_SAMPLING_INTERVAL )
],
}, # /Constants for Version 2.2
}, # /Constants for Version 2.2
V_2_03 => {
V_2_03 => {
MAX_DATA_BYTES => 32, # max number of data bytes in non-Sysex messages
MAX_DATA_BYTES =>
32, # max number of data bytes in non-Sysex messages
# message command bytes (128-255/0x80-0xFF)
DIGITAL_MESSAGE => 0x90, # send data for a digital pin
ANALOG_MESSAGE => 0xE0, # send data for an analog pin (or PWM)
REPORT_ANALOG => 0xC0, # enable analog input by pin #
REPORT_DIGITAL => 0xD0, # enable digital input by port pair
SET_PIN_MODE => 0xF4, # set a pin to INPUT/OUTPUT/PWM/etc
REPORT_VERSION => 0xF9, # report protocol version
SYSTEM_RESET => 0xFF, # reset from MIDI
START_SYSEX => 0xF0, # start a MIDI Sysex message
END_SYSEX => 0xF7, # end a MIDI Sysex message
# message command bytes (128-255/0x80-0xFF)
DIGITAL_MESSAGE => 0x90, # send data for a digital pin
ANALOG_MESSAGE => 0xE0, # send data for an analog pin (or PWM)
REPORT_ANALOG => 0xC0, # enable analog input by pin #
REPORT_DIGITAL => 0xD0, # enable digital input by port pair
SET_PIN_MODE => 0xF4, # set a pin to INPUT/OUTPUT/PWM/etc
REPORT_VERSION => 0xF9, # report protocol version
SYSTEM_RESET => 0xFF, # reset from MIDI
START_SYSEX => 0xF0, # start a MIDI Sysex message
END_SYSEX => 0xF7, # end a MIDI Sysex message
# extended command set using sysex (0-127/0x00-0x7F)
RESERVED_COMMAND => 0x00, # 2nd SysEx data byte is a chip-specific command (AVR, PIC, TI, etc).
ANALOG_MAPPING_QUERY => 0x69, # ask for mapping of analog to pin numbers
ANALOG_MAPPING_RESPONSE => 0x6A, # reply with mapping info
CAPABILITY_QUERY => 0x6B, # ask for supported modes and resolution of all pins
CAPABILITY_RESPONSE => 0x6C, # reply with supported modes and resolution
PIN_STATE_QUERY => 0x6D, # ask for a pin's current mode and value
PIN_STATE_RESPONSE => 0x6E, # reply with a pin's current mode and value
EXTENDED_ANALOG => 0x6F, # analog write (PWM, Servo, etc) to any pin
SERVO_CONFIG => 0x70, # set max angle, minPulse, maxPulse, freq
STRING_DATA => 0x71, # a string message with 14-bits per char
SHIFT_DATA => 0x75, # shiftOut config/data message (34 bits)
I2C_REQUEST => 0x76, # send an I2C read/write request
I2C_REPLY => 0x77, # a reply to an I2C read request
I2C_CONFIG => 0x78, # config I2C settings such as delay times and power pins
REPORT_FIRMWARE => 0x79, # report name and version of the firmware
SAMPLING_INTERVAL => 0x7A, # set the poll rate of the main loop
SYSEX_NON_REALTIME => 0x7E, # MIDI Reserved for non-realtime messages
SYSEX_REALTIME => 0x7F, # MIDI Reserved for realtime messages
# extended command set using sysex (0-127/0x00-0x7F)
RESERVED_COMMAND => 0x00, # 2nd SysEx data byte is a chip-specific command (AVR, PIC, TI, etc).
ANALOG_MAPPING_QUERY => 0x69, # ask for mapping of analog to pin numbers
ANALOG_MAPPING_RESPONSE => 0x6A, # reply with mapping info
CAPABILITY_QUERY => 0x6B, # ask for supported modes and resolution of all pins
CAPABILITY_RESPONSE => 0x6C, # reply with supported modes and resolution
PIN_STATE_QUERY => 0x6D, # ask for a pin's current mode and value
PIN_STATE_RESPONSE => 0x6E, # reply with a pin's current mode and value
EXTENDED_ANALOG => 0x6F, # analog write (PWM, Servo, etc) to any pin
SERVO_CONFIG => 0x70, # set max angle, minPulse, maxPulse, freq
STRING_DATA => 0x71, # a string message with 14-bits per char
SHIFT_DATA => 0x75, # shiftOut config/data message (34 bits)
I2C_REQUEST => 0x76, # send an I2C read/write request
I2C_REPLY => 0x77, # a reply to an I2C read request
I2C_CONFIG => 0x78, # config I2C settings such as delay times and power pins
REPORT_FIRMWARE => 0x79, # report name and version of the firmware
SAMPLING_INTERVAL => 0x7A, # set the poll rate of the main loop
SYSEX_NON_REALTIME => 0x7E, # MIDI Reserved for non-realtime messages
SYSEX_REALTIME => 0x7F, # MIDI Reserved for realtime messages
# pin modes
INPUT => 0x00, # digital pin in digitalOut mode
OUTPUT => 0x01, # digital pin in digitalInput mode
ANALOG => 0x02, # analog pin in analogInput mode
PWM => 0x03, # digital pin in PWM output mode
SERVO => 0x04, # digital pin in Servo output mode
SHIFT => 0x05, # shiftIn/shiftOut mode
I2C => 0x06, # pin included in I2C setup
# pin modes
INPUT => 0x00, # digital pin in digitalOut mode
OUTPUT => 0x01, # digital pin in digitalInput mode
ANALOG => 0x02, # analog pin in analogInput mode
PWM => 0x03, # digital pin in PWM output mode
SERVO => 0x04, # digital pin in Servo output mode
SHIFT => 0x05, # shiftIn/shiftOut mode
I2C => 0x06, # pin included in I2C setup
# Deprecated entries
deprecated => [
qw( FIRMATA_STRING SYSEX_I2C_REQUEST SYSEX_I2C_REPLY SYSEX_SAMPLING_INTERVAL )
],
# Deprecated entries
deprecated => [
qw( FIRMATA_STRING SYSEX_I2C_REQUEST SYSEX_I2C_REPLY SYSEX_SAMPLING_INTERVAL )
],
}, # /Constants for Version 2.3 (same as V_2_02)
}, # /Constants for Version 2.3 (same as V_2_02)
V_2_04 => {
V_2_04 => {
MAX_DATA_BYTES => 64, # max number of data bytes in non-Sysex messages
MAX_DATA_BYTES => 64, # max number of data bytes in non-Sysex messages
# message command bytes (128-255/0x80-0xFF)
DIGITAL_MESSAGE => 0x90, # send data for a digital pin
ANALOG_MESSAGE => 0xE0, # send data for an analog pin (or PWM)
REPORT_ANALOG => 0xC0, # enable analog input by pin #
REPORT_DIGITAL => 0xD0, # enable digital input by port pair
SET_PIN_MODE => 0xF4, # set a pin to INPUT/OUTPUT/PWM/etc
REPORT_VERSION => 0xF9, # report protocol version
SYSTEM_RESET => 0xFF, # reset from MIDI
START_SYSEX => 0xF0, # start a MIDI Sysex message
END_SYSEX => 0xF7, # end a MIDI Sysex message
# message command bytes (128-255/0x80-0xFF)
DIGITAL_MESSAGE => 0x90, # send data for a digital pin
ANALOG_MESSAGE => 0xE0, # send data for an analog pin (or PWM)
REPORT_ANALOG => 0xC0, # enable analog input by pin #
REPORT_DIGITAL => 0xD0, # enable digital input by port pair
SET_PIN_MODE => 0xF4, # set a pin to INPUT/OUTPUT/PWM/etc
REPORT_VERSION => 0xF9, # report protocol version
SYSTEM_RESET => 0xFF, # reset from MIDI
START_SYSEX => 0xF0, # start a MIDI Sysex message
END_SYSEX => 0xF7, # end a MIDI Sysex message
# extended command set using sysex (0-127/0x00-0x7F)
RESERVED_COMMAND => 0x00, # 2nd SysEx data byte is a chip-specific command (AVR, PIC, TI, etc).
ANALOG_MAPPING_QUERY => 0x69, # ask for mapping of analog to pin numbers
ANALOG_MAPPING_RESPONSE => 0x6A, # reply with mapping info
CAPABILITY_QUERY => 0x6B, # ask for supported modes and resolution of all pins
CAPABILITY_RESPONSE => 0x6C, # reply with supported modes and resolution
PIN_STATE_QUERY => 0x6D, # ask for a pin's current mode and value
PIN_STATE_RESPONSE => 0x6E, # reply with a pin's current mode and value
EXTENDED_ANALOG => 0x6F, # analog write (PWM, Servo, etc) to any pin
SERVO_CONFIG => 0x70, # set max angle, minPulse, maxPulse, freq
STRING_DATA => 0x71, # a string message with 14-bits per char
ONEWIRE_DATA => 0x73, # OneWire read/write/reset/select/skip/search request + read/search reply
SHIFT_DATA => 0x75, # shiftOut config/data message (34 bits)
I2C_REQUEST => 0x76, # send an I2C read/write request
I2C_REPLY => 0x77, # a reply to an I2C read request
I2C_CONFIG => 0x78, # config I2C settings such as delay times and power pins
REPORT_FIRMWARE => 0x79, # report name and version of the firmware
SAMPLING_INTERVAL => 0x7A, # set the poll rate of the main loop
SCHEDULER_DATA => 0x7B, # createtask/deletetask/addtotask/schedule/querytasks/querytask request and querytasks/querytask reply
SYSEX_NON_REALTIME => 0x7E, # MIDI Reserved for non-realtime messages
SYSEX_REALTIME => 0x7F, # MIDI Reserved for realtime messages
# extended command set using sysex (0-127/0x00-0x7F)
RESERVED_COMMAND => 0x00, # 2nd SysEx data byte is a chip-specific command (AVR, PIC, TI, etc).
ANALOG_MAPPING_QUERY => 0x69, # ask for mapping of analog to pin numbers
ANALOG_MAPPING_RESPONSE => 0x6A, # reply with mapping info
CAPABILITY_QUERY => 0x6B, # ask for supported modes and resolution of all pins
CAPABILITY_RESPONSE => 0x6C, # reply with supported modes and resolution
PIN_STATE_QUERY => 0x6D, # ask for a pin's current mode and value
PIN_STATE_RESPONSE => 0x6E, # reply with a pin's current mode and value
EXTENDED_ANALOG => 0x6F, # analog write (PWM, Servo, etc) to any pin
SERVO_CONFIG => 0x70, # set max angle, minPulse, maxPulse, freq
STRING_DATA => 0x71, # a string message with 14-bits per char
ONEWIRE_DATA => 0x73, # OneWire read/write/reset/select/skip/search request + read/search reply
SHIFT_DATA => 0x75, # shiftOut config/data message (34 bits)
I2C_REQUEST => 0x76, # send an I2C read/write request
I2C_REPLY => 0x77, # a reply to an I2C read request
I2C_CONFIG => 0x78, # config I2C settings such as delay times and power pins
REPORT_FIRMWARE => 0x79, # report name and version of the firmware
SAMPLING_INTERVAL => 0x7A, # set the poll rate of the main loop
SCHEDULER_DATA => 0x7B, # createtask/deletetask/addtotask/schedule/querytasks/querytask request and querytasks/querytask reply
SYSEX_NON_REALTIME => 0x7E, # MIDI Reserved for non-realtime messages
SYSEX_REALTIME => 0x7F, # MIDI Reserved for realtime messages
# pin modes
INPUT => 0x00, # digital pin in digitalOut mode
OUTPUT => 0x01, # digital pin in digitalInput mode
ANALOG => 0x02, # analog pin in analogInput mode
PWM => 0x03, # digital pin in PWM output mode
SERVO => 0x04, # digital pin in Servo output mode
SHIFT => 0x05, # shiftIn/shiftOut mode
I2C => 0x06, # pin included in I2C setup
ONEWIRE => 0x07,
# pin modes
INPUT => 0x00, # digital pin in digitalOut mode
OUTPUT => 0x01, # digital pin in digitalInput mode
ANALOG => 0x02, # analog pin in analogInput mode
PWM => 0x03, # digital pin in PWM output mode
SERVO => 0x04, # digital pin in Servo output mode
SHIFT => 0x05, # shiftIn/shiftOut mode
I2C => 0x06, # pin included in I2C setup
ONEWIRE => 0x07,
# Deprecated entries
deprecated => [
qw( FIRMATA_STRING SYSEX_I2C_REQUEST SYSEX_I2C_REPLY SYSEX_SAMPLING_INTERVAL )
],
}, # /Constants for Version 2.4
# Deprecated entries
deprecated => [
qw( FIRMATA_STRING SYSEX_I2C_REQUEST SYSEX_I2C_REPLY SYSEX_SAMPLING_INTERVAL )
],
V_2_05 => {
}, # /Constants for Version 2.4
MAX_DATA_BYTES => 64, # max number of data bytes in non-Sysex messages
V_2_05 => {
# message command bytes (128-255/0x80-0xFF)
DIGITAL_MESSAGE => 0x90, # send data for a digital pin
ANALOG_MESSAGE => 0xE0, # send data for an analog pin (or PWM)
REPORT_ANALOG => 0xC0, # enable analog input by pin #
REPORT_DIGITAL => 0xD0, # enable digital input by port pair
SET_PIN_MODE => 0xF4, # set a pin to INPUT/OUTPUT/PWM/etc
REPORT_VERSION => 0xF9, # report protocol version
SYSTEM_RESET => 0xFF, # reset from MIDI
START_SYSEX => 0xF0, # start a MIDI Sysex message
END_SYSEX => 0xF7, # end a MIDI Sysex message
MAX_DATA_BYTES => 64, # max number of data bytes in non-Sysex messages
# extended command set using sysex (0-127/0x00-0x7F)
RESERVED_COMMAND => 0x00, # 2nd SysEx data byte is a chip-specific command (AVR, PIC, TI, etc).
ANALOG_MAPPING_QUERY => 0x69, # ask for mapping of analog to pin numbers
ANALOG_MAPPING_RESPONSE => 0x6A, # reply with mapping info
CAPABILITY_QUERY => 0x6B, # ask for supported modes and resolution of all pins
CAPABILITY_RESPONSE => 0x6C, # reply with supported modes and resolution
PIN_STATE_QUERY => 0x6D, # ask for a pin's current mode and value
PIN_STATE_RESPONSE => 0x6E, # reply with a pin's current mode and value
EXTENDED_ANALOG => 0x6F, # analog write (PWM, Servo, etc) to any pin
SERVO_CONFIG => 0x70, # set max angle, minPulse, maxPulse, freq
STRING_DATA => 0x71, # a string message with 14-bits per char
ONEWIRE_DATA => 0x73, # OneWire read/write/reset/select/skip/search request + read/search reply
SHIFT_DATA => 0x75, # shiftOut config/data message (34 bits)
I2C_REQUEST => 0x76, # send an I2C read/write request
I2C_REPLY => 0x77, # a reply to an I2C read request
I2C_CONFIG => 0x78, # config I2C settings such as delay times and power pins
REPORT_FIRMWARE => 0x79, # report name and version of the firmware
SAMPLING_INTERVAL => 0x7A, # set the poll rate of the main loop
SCHEDULER_DATA => 0x7B, # createtask/deletetask/addtotask/schedule/querytasks/querytask request and querytasks/querytask reply
SYSEX_NON_REALTIME => 0x7E, # MIDI Reserved for non-realtime messages
SYSEX_REALTIME => 0x7F, # MIDI Reserved for realtime messages
# message command bytes (128-255/0x80-0xFF)
DIGITAL_MESSAGE => 0x90, # send data for a digital pin
ANALOG_MESSAGE => 0xE0, # send data for an analog pin (or PWM)
REPORT_ANALOG => 0xC0, # enable analog input by pin #
REPORT_DIGITAL => 0xD0, # enable digital input by port pair
SET_PIN_MODE => 0xF4, # set a pin to INPUT/OUTPUT/PWM/etc
REPORT_VERSION => 0xF9, # report protocol version
SYSTEM_RESET => 0xFF, # reset from MIDI
START_SYSEX => 0xF0, # start a MIDI Sysex message
END_SYSEX => 0xF7, # end a MIDI Sysex message
# pin modes
INPUT => 0x00, # digital pin in digitalOut mode
OUTPUT => 0x01, # digital pin in digitalInput mode
ANALOG => 0x02, # analog pin in analogInput mode
PWM => 0x03, # digital pin in PWM output mode
SERVO => 0x04, # digital pin in Servo output mode
SHIFT => 0x05, # shiftIn/shiftOut mode
I2C => 0x06, # pin included in I2C setup
ONEWIRE => 0x07,
# extended command set using sysex (0-127/0x00-0x7F)
RESERVED_COMMAND => 0x00, # 2nd SysEx data byte is a chip-specific command (AVR, PIC, TI, etc).
ANALOG_MAPPING_QUERY => 0x69, # ask for mapping of analog to pin numbers
ANALOG_MAPPING_RESPONSE => 0x6A, # reply with mapping info
CAPABILITY_QUERY => 0x6B, # ask for supported modes and resolution of all pins
CAPABILITY_RESPONSE => 0x6C, # reply with supported modes and resolution
PIN_STATE_QUERY => 0x6D, # ask for a pin's current mode and value
PIN_STATE_RESPONSE => 0x6E, # reply with a pin's current mode and value
EXTENDED_ANALOG => 0x6F, # analog write (PWM, Servo, etc) to any pin
SERVO_CONFIG => 0x70, # set max angle, minPulse, maxPulse, freq
STRING_DATA => 0x71, # a string message with 14-bits per char
ONEWIRE_DATA => 0x73, # OneWire read/write/reset/select/skip/search request + read/search reply
SHIFT_DATA => 0x75, # shiftOut config/data message (34 bits)
I2C_REQUEST => 0x76, # send an I2C read/write request
I2C_REPLY => 0x77, # a reply to an I2C read request
I2C_CONFIG => 0x78, # config I2C settings such as delay times and power pins
REPORT_FIRMWARE => 0x79, # report name and version of the firmware
SAMPLING_INTERVAL => 0x7A, # set the poll rate of the main loop
SCHEDULER_DATA => 0x7B, # createtask/deletetask/addtotask/schedule/querytasks/querytask request and querytasks/querytask reply
SYSEX_NON_REALTIME => 0x7E, # MIDI Reserved for non-realtime messages
SYSEX_REALTIME => 0x7F, # MIDI Reserved for realtime messages
# Deprecated entries
deprecated => [
qw( FIRMATA_STRING SYSEX_I2C_REQUEST SYSEX_I2C_REPLY SYSEX_SAMPLING_INTERVAL )
],
# pin modes
INPUT => 0x00, # digital pin in digitalOut mode
OUTPUT => 0x01, # digital pin in digitalInput mode
ANALOG => 0x02, # analog pin in analogInput mode
PWM => 0x03, # digital pin in PWM output mode
SERVO => 0x04, # digital pin in Servo output mode
SHIFT => 0x05, # shiftIn/shiftOut mode
I2C => 0x06, # pin included in I2C setup
ONEWIRE => 0x07,
# Deprecated entries
deprecated => [
qw( FIRMATA_STRING SYSEX_I2C_REQUEST SYSEX_I2C_REPLY SYSEX_SAMPLING_INTERVAL )
],
}, # /Constants for Version 2.5
}
}, # /Constants for Version 2.5
}
);
# Handle the reverse lookups of the protocol
$COMMAND_LOOKUP = {};
while ( my ( $protocol_version, $protocol_commands ) = each %$COMMANDS ) {
my $protocol_lookup = $COMMAND_LOOKUP->{$protocol_version} = {};
my $deprecated = $protocol_lookup->{deprecated} || [];
my $deprecated_lookup = { map { ( $_ => 1 ) } @$deprecated };
while ( my ( $protocol_command, $command_value ) =
each %$protocol_commands )
{
next if $protocol_command eq 'deprecated';
next if $deprecated_lookup->{$protocol_command};
$protocol_lookup->{$command_value} = $protocol_command;
}
my $protocol_lookup = $COMMAND_LOOKUP->{$protocol_version} = {};
my $deprecated = $protocol_lookup->{deprecated} || [];
my $deprecated_lookup = { map { ( $_ => 1 ) } @$deprecated };
while ( my ( $protocol_command, $command_value ) = each %$protocol_commands ) {
next if $protocol_command eq 'deprecated';
next if $deprecated_lookup->{$protocol_command};
$protocol_lookup->{$command_value} = $protocol_command;
}
}
# Now we consolidate all the string keynames into a single master list.
use constant (
$COMMAND_NAMES = {
map {
map { ( $_ => $_ ) }
keys %$_
} values %$COMMANDS
}
);
use constant ( $COMMAND_NAMES = { map { map { ( $_ => $_ ) } keys %$_ } values %$COMMANDS } );
use constant { COMMAND_NAMES => [ $COMMAND_NAMES = [ keys %$COMMAND_NAMES ] ] };
@EXPORT_OK = (
@$COMMAND_NAMES, keys %$BASE,
keys %$COMMANDS,
qw( $COMMANDS $COMMAND_NAMES $COMMAND_LOOKUP )
);
@$COMMAND_NAMES, keys %$BASE,
keys %$COMMANDS,
qw( $COMMANDS $COMMAND_NAMES $COMMAND_LOOKUP ),
);
%EXPORT_TAGS = ( all => \@EXPORT_OK );
1;
1;

View File

@@ -9,11 +9,11 @@ Device::Firmata::Error - Error handlers
use strict;
use Exporter;
use vars qw/
@ISA
%ERRORS
@EXPORT
$FIRMATA_ERROR_DEFAULT
use vars qw/
@ISA
%ERRORS
@EXPORT
$FIRMATA_ERROR_DEFAULT
@ERROR_STACK
/;
use Device::Firmata::Base;
@@ -28,7 +28,7 @@ $FIRMATA_ERROR_DEFAULT = -1;
=head2 error
The base error reporting system. All errors will be
stored in this object until the errors flush code is called.
stored in this object until the error flush code is called.
This will allow the system to collect all errors that occur
in various parts of the system in one place. Very useful
for error reporting since it's a simple call to find
@@ -37,10 +37,10 @@ out the last error.
Invocation of this function
$err->error( [numerical error level], ErrorMessage, ... parameters ... );
ErrorMessage can be in the format "KEY" that will be referenced by
ErrorMessage can be in the format "KEY" that will be referenced by
Device::Firmata::Base->language or "KEY:Message" where if ->language does
not map to anything, the error will default to Message
not map to anything, the error will default to Message
=cut
@@ -71,7 +71,7 @@ sub error {
: warn "\@$fn:$pkg:$line". ' : ' . $text . "\n";
};
# warn "Error called wih args: @_ from " . join( " ", caller() ) . "\n";
# warn "Error called with args: @_ from " . join( " ", caller() ) . "\n";
# require Carp;
# Carp::cluck();
@@ -90,5 +90,3 @@ sub errors_flush {
1;

View File

@@ -17,7 +17,7 @@ use Device::Firmata::Base
baudrate => 57600,
};
$SERIAL_CLASS = $^O eq 'MSWin32' ? 'Win32::Serialport'
$SERIAL_CLASS = $^O eq 'MSWin32' ? 'Win32::SerialPort'
: 'Device::SerialPort';
eval "require $SERIAL_CLASS";
@@ -28,27 +28,21 @@ eval "require $SERIAL_CLASS";
sub open {
# --------------------------------------------------
my ( $pkg, $serial_port, $opts ) = @_;
my $self = ref $pkg ? $pkg : $pkg->new($opts);
my $serial_obj = $SERIAL_CLASS->new( $serial_port, 1, 0 ) or return;
$self->attach($serial_obj,$opts);
$self->{handle}->baudrate($self->{baudrate});
$self->{handle}->databits(8);
$self->{handle}->stopbits(1);
return $self;
my ( $pkg, $serial_port, $opts ) = @_;
my $self = ref $pkg ? $pkg : $pkg->new($opts);
my $serial_obj = $SERIAL_CLASS->new( $serial_port, 1, 0 ) or return;
$self->attach($serial_obj,$opts);
$self->{handle}->baudrate($self->{baudrate});
$self->{handle}->databits(8);
$self->{handle}->stopbits(1);
return $self;
}
sub attach {
my ( $pkg, $serial_obj, $opts ) = @_;
my $self = ref $pkg ? $pkg : $pkg->new($opts);
$self->{handle} = $serial_obj;
return $self;
my ( $pkg, $serial_obj, $opts ) = @_;
my $self = ref $pkg ? $pkg : $pkg->new($opts);
$self->{handle} = $serial_obj;
return $self;
}
=head2 data_write
@@ -59,9 +53,9 @@ Dump a bunch of data into the comm port
sub data_write {
# --------------------------------------------------
my ( $self, $buf ) = @_;
$Device::Firmata::DEBUG and print ">".join(",",map{sprintf"%02x",ord$_}split//,$buf)."\n";
return $self->{handle}->write( $buf );
my ( $self, $buf ) = @_;
$Device::Firmata::DEBUG and print ">".join(",",map{sprintf"%02x",ord$_}split//,$buf)."\n";
return $self->{handle}->write( $buf );
}
@@ -74,12 +68,10 @@ This function is non-blocking
sub data_read {
# --------------------------------------------------
my ( $self, $bytes ) = @_;
my ( $count, $string ) = $self->{handle}->read($bytes);
if ( $Device::Firmata::DEBUG and $string ) {
print "<".join(",",map{sprintf"%02x",ord$_}split//,$string)."\n";
}
return $string;
my ( $self, $bytes ) = @_;
my ( $count, $string ) = $self->{handle}->read($bytes);
print "<".join(",",map{sprintf"%02x",ord$_}split//,$string)."\n" if ( $Device::Firmata::DEBUG and $string );
return $string;
}
1;

View File

@@ -9,9 +9,9 @@ Device::Firmata::Language - Localization
use strict;
use vars qw/
$FIRMATA_LOCALE
$FIRMATA_LOCALE
$FIRMATA_LOCALE_PATH
$FIRMATA_LOCALE_MESSAGES
$FIRMATA_LOCALE_MESSAGES
/;
use Device::Firmata::Base
ISA => 'Device::Firmata::Base',
@@ -71,7 +71,6 @@ sub language {
( $m ||= {} )->{$1} = $2;
}
close $fh;
$m;
};
@@ -88,13 +87,12 @@ sub language {
my $message_template;
# Get the message template in the following order:
# 1. The local object if available
# 1. The local object if available
# 2. The global message object
# 3. The provided default message
#
ref $self and $message_template = $self->{messages}{$key};
$message_template ||= $messages->{$key} || $message;
return sprintf( $message_template, @_ );
}
@@ -104,5 +102,5 @@ __DATA__
FIRMATA__unhandled Unhandled attribute '%s' called
FIRMATA__unknown Unknown/Unhandled error encountered: %s
FIRMATA__separator ,
FIRMATA__separator ,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff