Firmata firmware for Arduino
Firmata is a protocol for communicating with microcontrollers from software on a host computer
Public Member Functions | Friends | List of all members
firmata::FirmataMarshaller Class Reference

Public Member Functions

 FirmataMarshaller ()
 
void begin (Stream &s)
 
void end ()
 
void queryFirmwareVersion (void) const
 
void queryVersion (void) const
 
void reportAnalogDisable (uint8_t pin) const
 
void reportAnalogEnable (uint8_t pin) const
 
void reportDigitalPortDisable (uint8_t portNumber) const
 
void reportDigitalPortEnable (uint8_t portNumber) const
 
void sendAnalog (uint8_t pin, uint16_t value) const
 
void sendAnalogMappingQuery (void) const
 
void sendCapabilityQuery (void) const
 
void sendDigital (uint8_t pin, uint8_t value) const
 
void sendDigitalPort (uint8_t portNumber, uint16_t portData) const
 
void sendFirmwareVersion (uint8_t major, uint8_t minor, size_t bytec, uint8_t *bytev) const
 
void sendVersion (uint8_t major, uint8_t minor) const
 
void sendPinMode (uint8_t pin, uint8_t config) const
 
void sendPinStateQuery (uint8_t pin) const
 
void sendString (const char *string) const
 
void sendSysex (uint8_t command, size_t bytec, uint8_t *bytev) const
 
void setSamplingInterval (uint16_t interval_ms) const
 
void systemReset (void) const
 

Friends

class FirmataClass
 

Constructor & Destructor Documentation

◆ FirmataMarshaller()

FirmataMarshaller::FirmataMarshaller ( )

The FirmataMarshaller class.

Member Function Documentation

◆ begin()

void FirmataMarshaller::begin ( Stream &  s)

Reassign the Firmata stream transport.

Parameters
sA reference to the Stream transport object. This can be any type of transport that implements the Stream interface. Some examples include Ethernet, WiFi and other UARTs on the board (Serial1, Serial2, etc).

◆ end()

void FirmataMarshaller::end ( void  )

Closes the FirmataMarshaller stream by setting its stream reference to (Stream *)NULL

◆ queryFirmwareVersion()

void FirmataMarshaller::queryFirmwareVersion ( void  ) const

Query the target's firmware name and version

◆ queryVersion()

void FirmataMarshaller::queryVersion ( void  ) const

Query the target's Firmata protocol version

◆ reportAnalogDisable()

void FirmataMarshaller::reportAnalogDisable ( uint8_t  pin) const

Halt the stream of analog readings from the Firmata host application. The range of pins is limited to [0..15] when using the REPORT_ANALOG. The maximum result of the REPORT_ANALOG is limited to 14 bits (16384). To increase the pin range or value, see the documentation for the EXTENDED_ANALOG message.

Parameters
pinThe analog pin for which to request the value (limited to pins 0 - 15).

◆ reportAnalogEnable()

void FirmataMarshaller::reportAnalogEnable ( uint8_t  pin) const

Request a stream of analog readings from the Firmata host application. The range of pins is limited to [0..15] when using the REPORT_ANALOG. The maximum result of the REPORT_ANALOG is limited to 14 bits (16384). To increase the pin range or value, see the documentation for the EXTENDED_ANALOG message.

Parameters
pinThe analog pin for which to request the value (limited to pins 0 - 15).

◆ reportDigitalPortDisable()

void FirmataMarshaller::reportDigitalPortDisable ( uint8_t  portNumber) const

Halt an 8-bit port stream from the Firmata host application (protocol v2 and later). Send 14-bits in a single digital message (protocol v1).

Parameters
portNumberThe port number for which to request the value. Note that this is not the same as a "port" on the physical microcontroller. Ports are defined in order per every 8 pins in ascending order of the Arduino digital pin numbering scheme. Port 0 = pins D0 - D7, port 1 = pins D8 - D15, etc.

◆ reportDigitalPortEnable()

void FirmataMarshaller::reportDigitalPortEnable ( uint8_t  portNumber) const

Request an 8-bit port stream from the Firmata host application (protocol v2 and later). Send 14-bits in a single digital message (protocol v1).

Parameters
portNumberThe port number for which to request the value. Note that this is not the same as a "port" on the physical microcontroller. Ports are defined in order per every 8 pins in ascending order of the Arduino digital pin numbering scheme. Port 0 = pins D0 - D7, port 1 = pins D8 - D15, etc.

◆ sendAnalog()

void FirmataMarshaller::sendAnalog ( uint8_t  pin,
uint16_t  value 
) const

Send an analog message to the Firmata host application. The range of pins is limited to [0..15] when using the ANALOG_MESSAGE. The maximum value of the ANALOG_MESSAGE is limited to 14 bits (16384). To increase the pin range or value, see the documentation for the EXTENDED_ANALOG message.

Parameters
pinThe analog pin to which the value is sent.
valueThe value of the analog pin (0 - 1024 for 10-bit analog, 0 - 4096 for 12-bit, etc).
Note
The maximum value is 14-bits (16384).

◆ sendAnalogMappingQuery()

void FirmataMarshaller::sendAnalogMappingQuery ( void  ) const

Send an analog mapping query to the Firmata host application. The resulting sysex message will have an ANALOG_MAPPING_RESPONSE command byte, followed by a list of pins [0-n]; where each pin will specify its corresponding analog pin number or 0x7F (127) if not applicable.

◆ sendCapabilityQuery()

void FirmataMarshaller::sendCapabilityQuery ( void  ) const

Send a capability query to the Firmata host application. The resulting sysex message will have a CAPABILITY_RESPONSE command byte, followed by a list of byte tuples (mode and mode resolution) for each pin; where each pin list is terminated by 0x7F (127).

◆ sendDigital()

void FirmataMarshaller::sendDigital ( uint8_t  pin,
uint8_t  value 
) const

Send a single digital pin value to the Firmata host application.

Parameters
pinThe digital pin to send the value of.
valueThe value of the pin.

◆ sendDigitalPort()

void FirmataMarshaller::sendDigitalPort ( uint8_t  portNumber,
uint16_t  portData 
) const

Send an 8-bit port in a single digital message (protocol v2 and later). Send 14-bits in a single digital message (protocol v1).

Parameters
portNumberThe port number to send. Note that this is not the same as a "port" on the physical microcontroller. Ports are defined in order per every 8 pins in ascending order of the Arduino digital pin numbering scheme. Port 0 = pins D0 - D7, port 1 = pins D8 - D15, etc.
portDataThe value of the port. The value of each pin in the port is represented by a bit.

◆ sendFirmwareVersion()

void FirmataMarshaller::sendFirmwareVersion ( uint8_t  major,
uint8_t  minor,
size_t  bytec,
uint8_t *  bytev 
) const

Sends the firmware name and version to the Firmata host application.

Parameters
majorThe major verison number
minorThe minor version number
bytecThe length of the firmware name
bytevThe firmware name array

◆ sendPinMode()

void FirmataMarshaller::sendPinMode ( uint8_t  pin,
uint8_t  config 
) const

Send the pin mode/configuration. The pin configuration (or mode) in Firmata represents the current function of the pin. Examples are digital input or output, analog input, pwm, i2c, serial (uart), etc.

Parameters
pinThe pin to configure.
configThe configuration value for the specified pin.

◆ sendPinStateQuery()

void FirmataMarshaller::sendPinStateQuery ( uint8_t  pin) const

Send a pin state query to the Firmata host application. The resulting sysex message will have a PIN_STATE_RESPONSE command byte, followed by the pin number, the pin mode and a stream of bits to indicate any data written to the pin (pin state).

Parameters
pinThe pin to query
Note
The pin state is any data written to the pin (i.e. pin state != pin value)

◆ sendString()

void FirmataMarshaller::sendString ( const char *  string) const

Send a string to the Firmata host application.

Parameters
stringA pointer to the char string

◆ sendSysex()

void FirmataMarshaller::sendSysex ( uint8_t  command,
size_t  bytec,
uint8_t *  bytev 
) const

Send a sysex message where all values after the command byte are packet as 2 7-bit bytes (this is not always the case so this function is not always used to send sysex messages).

Parameters
commandThe sysex command byte.
bytecThe number of data bytes in the message (excludes start, command and end bytes).
bytevA pointer to the array of data bytes to send in the message.

◆ sendVersion()

void FirmataMarshaller::sendVersion ( uint8_t  major,
uint8_t  minor 
) const

Send the Firmata protocol version to the Firmata host application.

Parameters
majorThe major verison number
minorThe minor version number

◆ setSamplingInterval()

void FirmataMarshaller::setSamplingInterval ( uint16_t  interval_ms) const

The sampling interval sets how often analog data and i2c data is reported to the client.

Parameters
interval_msThe interval (in milliseconds) at which to sample
Note
The default sampling interval is 19ms

◆ systemReset()

void FirmataMarshaller::systemReset ( void  ) const

Perform a software reset on the target. For example, StandardFirmata.ino will initialize everything to a known state and reset the parsing buffer.


The documentation for this class was generated from the following files: