Device::Firmata::Platform - Firmata API
Provides the application programming interface for Device::Firmata implementing all major features of the Firmata 2.5 specification:
Analog Firmata
Digital Firmata
I2C Firmata
1-Wire Firmata
Serial Firmata
Servo Firmata
Stepper Firmata
Firmata Scheduler
This API documentation is currently incomplete and only covers a small subset of the implementation. Anyone willing to help improve the documentation is welcome.
Creates new Firmata Platform instance and attaches the provided I/O port.
param pkg: Perl package name or an instance of Device::Firmata::Platform
param ioPort: either an instance of Device::Firmata::IO::SerialIO or DDevice::Firmata::IO::NetIO or of any other class that provides compatible implementations for the methods data_read and data_write
return new Device::Firmata::Platform instance
After attaching the I/O port to the Firmata Platform the following sequence of operations is recommended:
1. Call "probe ( )" to request the capabilities of the Firmata device.
2. Call "pin_mode ( pin, mode )" to configure the pins of the Firmata device.
Periodically call "poll ( )" to processess messages from the Firmata device.
Detach IO port from Firmata Platform. Typically used only internally by "close ( )".
Close IO port and detach from Firmata Platform.
Try to reset Firmata device. Will only work if Firmata device is connected.
Receive identified message packets and convert them into their appropriate structures and parse them as required. Typically used only internally by "poll ( )".
Receive identified sysex packets and convert them into their appropriate structures and parse them as required. Typically used only internally by "messages_handle ( messages )".
On device boot time we wait 3 seconds for firmware name that the target device is using. If not received the starting message, then we wait for response another 2 seconds and fire requests for version. If the response received, then we store protocol version and analog mapping and capability.
return on success, undef on error
undef
Set mode of Firmata device pin.
parm pin: Firmata device pin
param mode: use a member of constant $BASE from Device::Firmata::Constants
param state: new state (0 or 1) for digial pin to set on Firmata device
Deprecation warning: Writing to pin with mode "PIN_INPUT" is only supported for backward compatibility to switch pullup on and off. Use sub "pin_mode ( pin, mode )" with $mode=PIN_PULLUP instead.
return last state (0 or 1) of digital pin received from Firmata device
return last value of analog pin received from Firmata device
param state: new value for PWM pin to set on Firmata device
pmw_write ( pin, value ) is an alias for "analog_write ( pin, value )"
Call this function every once in a while to check up on the status of the comm port, receive and process data from the Firmata device
Register callback sub that will be called by "messages_handle ( messages )" if a new value for a digital pin was received from the Firmata device.
parm observer: callback sub reference with the parameters pin, oldState, newState, context
parm context: context value passed as last parameter to callback sub
Register callback sub that will be called by "messages_handle ( messages )" if the value of the analog pin received from the Firmata device has changed.
parm observer: callback sub reference with the parameters pin, oldValue, newValue, context
return analog channel number if analog mapping is available (e.g. by calling "probe ( )"), undef if given pin is not mapped as an analog channel or given pin if analog mapping is not available
Verify if pin was configured with "pin_mode ( pin, mode )" for requested mode.
return 1 on success or undef on error
Device::Firmata::Constants
To install Device::Firmata, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::Firmata
CPAN shell
perl -MCPAN -e shell install Device::Firmata
For more information on module installation, please visit the detailed CPAN module installation guide.