Arduino  1.8.9
FirmataClass クラス

#include <CP_Firmata.h>

公開メンバ関数

 FirmataClass ()
 
void begin ()
 
void begin (long)
 
void begin (Stream &s)
 
void printVersion (void)
 
void blinkVersion (void)
 
void printFirmwareVersion (void)
 
void setFirmwareNameAndVersion (const char *name, byte major, byte minor)
 
void disableBlinkVersion ()
 
int available (void)
 
void processInput (void)
 
void parse (unsigned char value)
 
boolean isParsingMessage (void)
 
void sendAnalog (byte pin, int value)
 
void sendDigital (byte pin, int value)
 
void sendDigitalPort (byte portNumber, int portData)
 
void sendString (const char *string)
 
void sendString (byte command, const char *string)
 
void sendSysex (byte command, byte bytec, byte *bytev)
 
void write (byte c)
 
void attach (byte command, callbackFunction newFunction)
 
void attach (byte command, systemResetCallbackFunction newFunction)
 
void attach (byte command, stringCallbackFunction newFunction)
 
void attach (byte command, sysexCallbackFunction newFunction)
 
void detach (byte command)
 
byte getPinMode (byte pin)
 
void setPinMode (byte pin, byte config)
 
int getPinState (byte pin)
 
void setPinState (byte pin, int state)
 
void sendValueAsTwo7bitBytes (int value)
 
void startSysex (void)
 
void endSysex (void)
 

詳解

CP_Firmata.h129 行目に定義があります。

構築子と解体子

◆ FirmataClass()

FirmataClass::FirmataClass ( )

The Firmata class. An instance named "Firmata" is created automatically for the user.

CP_Firmata.cpp64 行目に定義があります。

65 {
66  firmwareVersionCount = 0;
67  firmwareVersionVector = 0;
68  systemReset();
69 }

関数詳解

◆ attach() [1/4]

void FirmataClass::attach ( byte  command,
callbackFunction  newFunction 
)

Attach a generic sysex callback function to a command (options are: ANALOG_MESSAGE, DIGITAL_MESSAGE, REPORT_ANALOG, REPORT DIGITAL, SET_PIN_MODE and SET_DIGITAL_PIN_VALUE).

引数
commandThe ID of the command to attach a callback function to.
newFunctionA reference to the callback function to attach.

CP_Firmata.cpp497 行目に定義があります。

498 {
499  switch (command) {
500  case ANALOG_MESSAGE: currentAnalogCallback = newFunction; break;
501  case DIGITAL_MESSAGE: currentDigitalCallback = newFunction; break;
502  case REPORT_ANALOG: currentReportAnalogCallback = newFunction; break;
503  case REPORT_DIGITAL: currentReportDigitalCallback = newFunction; break;
504  case SET_PIN_MODE: currentPinModeCallback = newFunction; break;
505  case SET_DIGITAL_PIN_VALUE: currentPinValueCallback = newFunction; break;
506  }
507 }
#define DIGITAL_MESSAGE
Definition: CP_Firmata.h:50
#define REPORT_DIGITAL
Definition: CP_Firmata.h:53
#define SET_DIGITAL_PIN_VALUE
Definition: CP_Firmata.h:56
#define REPORT_ANALOG
Definition: CP_Firmata.h:52
#define SET_PIN_MODE
Definition: CP_Firmata.h:55
#define ANALOG_MESSAGE
Definition: CP_Firmata.h:51

◆ attach() [2/4]

void FirmataClass::attach ( byte  command,
systemResetCallbackFunction  newFunction 
)

Attach a callback function for the SYSTEM_RESET command.

引数
commandMust be set to SYSTEM_RESET or it will be ignored.
newFunctionA reference to the system reset callback function to attach.

CP_Firmata.cpp514 行目に定義があります。

515 {
516  switch (command) {
517  case SYSTEM_RESET: currentSystemResetCallback = newFunction; break;
518  }
519 }
#define SYSTEM_RESET
Definition: CP_Firmata.h:59

◆ attach() [3/4]

void FirmataClass::attach ( byte  command,
stringCallbackFunction  newFunction 
)

Attach a callback function for the STRING_DATA command.

引数
commandMust be set to STRING_DATA or it will be ignored.
newFunctionA reference to the string callback function to attach.

CP_Firmata.cpp526 行目に定義があります。

527 {
528  switch (command) {
529  case STRING_DATA: currentStringCallback = newFunction; break;
530  }
531 }
#define STRING_DATA
Definition: CP_Firmata.h:69

◆ attach() [4/4]

void FirmataClass::attach ( byte  command,
sysexCallbackFunction  newFunction 
)

Attach a generic sysex callback function to sysex command.

引数
commandThe ID of the command to attach a callback function to.
newFunctionA reference to the sysex callback function to attach.

CP_Firmata.cpp538 行目に定義があります。

539 {
540  currentSysexCallback = newFunction;
541 }

◆ available()

int FirmataClass::available ( void  )

A wrapper for Stream::available()

戻り値
The number of bytes remaining in the input stream buffer.

CP_Firmata.cpp225 行目に定義があります。

226 {
227  return FirmataStream->available();
228 }
virtual int available()=0

◆ begin() [1/3]

void FirmataClass::begin ( void  )

Initialize the default Serial transport at the default baud of 57600.

CP_Firmata.cpp78 行目に定義があります。

79 {
80  begin(57600);
81 }
void begin()
Definition: CP_Firmata.cpp:78

◆ begin() [2/3]

void FirmataClass::begin ( long  speed)

Initialize the default Serial transport and override the default baud. Sends the protocol version to the host application followed by the firmware version and name. blinkVersion is also called. To skip the call to blinkVersion, call Firmata.disableBlinkVersion() before calling Firmata.begin(baud).

引数
speedThe baud to use. 57600 baud is the default value.

CP_Firmata.cpp90 行目に定義があります。

91 {
92  Serial.begin(speed);
93  FirmataStream = &Serial;
94  blinkVersion();
95  printVersion(); // send the protocol version
96  printFirmwareVersion(); // send the firmware name and version
97 }
void printVersion(void)
Definition: CP_Firmata.cpp:117
void printFirmwareVersion(void)
Definition: CP_Firmata.cpp:159
void blinkVersion(void)
Definition: CP_Firmata.cpp:131

◆ begin() [3/3]

void FirmataClass::begin ( Stream s)

Reassign the Firmata stream transport.

引数
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).

CP_Firmata.cpp105 行目に定義があります。

106 {
107  FirmataStream = &s;
108  // do not call blinkVersion() here because some hardware such as the
109  // Ethernet shield use pin 13
110  printVersion();
112 }
void printVersion(void)
Definition: CP_Firmata.cpp:117
void printFirmwareVersion(void)
Definition: CP_Firmata.cpp:159

◆ blinkVersion()

void FirmataClass::blinkVersion ( void  )

Blink the Firmata protocol version to the onboard LEDs (if the board has an onboard LED). If VERSION_BLINK_PIN is not defined in Boards.h for a particular board, then this method does nothing. The first series of flashes indicates the firmware major version (2 flashes = 2). The second series of flashes indicates the firmware minor version (5 flashes = 5).

CP_Firmata.cpp131 行目に定義があります。

132 {
133 #if defined(VERSION_BLINK_PIN)
134  if (blinkVersionDisabled) return;
135  // flash the pin with the protocol version
136  pinMode(VERSION_BLINK_PIN, OUTPUT);
137  strobeBlinkPin(VERSION_BLINK_PIN, FIRMATA_FIRMWARE_MAJOR_VERSION, 40, 210);
138  delay(250);
139  strobeBlinkPin(VERSION_BLINK_PIN, FIRMATA_FIRMWARE_MINOR_VERSION, 40, 210);
140  delay(125);
141 #endif
142 }
void pinMode(uint8_t, uint8_t)
void delay(unsigned long)
Definition: wiring.c:106
#define FIRMATA_FIRMWARE_MINOR_VERSION
Definition: CP_Firmata.h:32
#define FIRMATA_FIRMWARE_MAJOR_VERSION
Definition: CP_Firmata.h:31
#define OUTPUT
Definition: Arduino.h:44

◆ detach()

void FirmataClass::detach ( byte  command)

Detach a callback function for a specified command (such as SYSTEM_RESET, STRING_DATA, ANALOG_MESSAGE, DIGITAL_MESSAGE, etc).

引数
commandThe ID of the command to detatch the callback function from.

CP_Firmata.cpp548 行目に定義があります。

549 {
550  switch (command) {
551  case SYSTEM_RESET: currentSystemResetCallback = NULL; break;
552  case STRING_DATA: currentStringCallback = NULL; break;
553  case START_SYSEX: currentSysexCallback = NULL; break;
554  default:
555  attach(command, (callbackFunction)NULL);
556  }
557 }
#define SYSTEM_RESET
Definition: CP_Firmata.h:59
#define START_SYSEX
Definition: CP_Firmata.h:61
firmata::FirmataClass::callbackFunction callbackFunction
Definition: Firmata.h:162
void attach(byte command, callbackFunction newFunction)
Definition: CP_Firmata.cpp:497
#define STRING_DATA
Definition: CP_Firmata.h:69
#define NULL
Definition: def.h:44

◆ disableBlinkVersion()

void FirmataClass::disableBlinkVersion ( )

Provides a means to disable the version blink sequence on the onboard LED, trimming startup time by a couple of seconds. Call this before Firmata.begin(). It only applies when using the default Serial transport.

CP_Firmata.cpp149 行目に定義があります。

150 {
151  blinkVersionDisabled = true;
152 }

◆ endSysex()

void FirmataClass::endSysex ( void  )

A helper method to write the end of a Sysex message transmission.

CP_Firmata.cpp51 行目に定義があります。

52 {
53  FirmataStream->write(END_SYSEX);
54 }
virtual size_t write(uint8_t)=0
#define END_SYSEX
Definition: CP_Firmata.h:62

◆ getPinMode()

byte FirmataClass::getPinMode ( byte  pin)
引数
pinThe pin to get the configuration of.
戻り値
The configuration of the specified pin.

CP_Firmata.cpp563 行目に定義があります。

564 {
565  return pinConfig[pin];
566 }

◆ getPinState()

int FirmataClass::getPinState ( byte  pin)
引数
pinThe pin to get the state of.
戻り値
The state of the specified pin.

CP_Firmata.cpp587 行目に定義があります。

588 {
589  return pinState[pin];
590 }

◆ isParsingMessage()

boolean FirmataClass::isParsingMessage ( void  )
戻り値
Returns true if the parser is actively parsing data.

CP_Firmata.cpp377 行目に定義があります。

378 {
379  return (waitForData > 0 || parsingSysex);
380 }

◆ parse()

void FirmataClass::parse ( unsigned char  value)

◆ printFirmwareVersion()

void FirmataClass::printFirmwareVersion ( void  )

Sends the firmware name and version to the Firmata host application. The major and minor version numbers are the first 2 bytes in the message. The following bytes are the characters of the firmware name.

CP_Firmata.cpp159 行目に定義があります。

160 {
161  byte i;
162 
163  if (firmwareVersionCount) { // make sure that the name has been set before reporting
164  startSysex();
165  FirmataStream->write(REPORT_FIRMWARE);
166  FirmataStream->write(firmwareVersionVector[0]); // major version number
167  FirmataStream->write(firmwareVersionVector[1]); // minor version number
168  for (i = 2; i < firmwareVersionCount; ++i) {
169  sendValueAsTwo7bitBytes(firmwareVersionVector[i]);
170  }
171  endSysex();
172  }
173 }
void sendValueAsTwo7bitBytes(int value)
Definition: CP_Firmata.cpp:34
virtual size_t write(uint8_t)=0
uint8_t i
#define REPORT_FIRMWARE
Definition: CP_Firmata.h:83
void endSysex(void)
Definition: CP_Firmata.cpp:51
void startSysex(void)
Definition: CP_Firmata.cpp:43

◆ printVersion()

void FirmataClass::printVersion ( void  )

Send the Firmata protocol version to the Firmata host application.

CP_Firmata.cpp117 行目に定義があります。

118 {
119  FirmataStream->write(REPORT_VERSION);
120  FirmataStream->write(FIRMATA_PROTOCOL_MAJOR_VERSION);
121  FirmataStream->write(FIRMATA_PROTOCOL_MINOR_VERSION);
122 }
#define FIRMATA_PROTOCOL_MAJOR_VERSION
Definition: CP_Firmata.h:23
#define REPORT_VERSION
Definition: CP_Firmata.h:58
virtual size_t write(uint8_t)=0
#define FIRMATA_PROTOCOL_MINOR_VERSION
Definition: CP_Firmata.h:24

◆ processInput()

void FirmataClass::processInput ( void  )

Read a single int from the input stream. If the value is not = -1, pass it on to parse(byte)

CP_Firmata.cpp273 行目に定義があります。

274 {
275  int inputData = FirmataStream->read(); // this is 'int' to handle -1 when no data
276  if (inputData != -1) {
277  parse(inputData);
278  }
279 }
virtual int read()=0
void parse(unsigned char value)

◆ sendAnalog()

void FirmataClass::sendAnalog ( byte  pin,
int  value 
)

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.

引数
pinThe analog pin to send the value of (limited to pins 0 - 15).
valueThe value of the analog pin (0 - 1024 for 10-bit analog, 0 - 4096 for 12-bit, etc). The maximum value is 14-bits (16384).

CP_Firmata.cpp394 行目に定義があります。

395 {
396  // pin can only be 0-15, so chop higher bits
397  FirmataStream->write(ANALOG_MESSAGE | (pin & 0xF));
399 }
void sendValueAsTwo7bitBytes(int value)
Definition: CP_Firmata.cpp:34
virtual size_t write(uint8_t)=0
#define ANALOG_MESSAGE
Definition: CP_Firmata.h:51

◆ sendDigital()

void FirmataClass::sendDigital ( byte  pin,
int  value 
)

CP_Firmata.cpp407 行目に定義があります。

408 {
409  /* TODO add single pin digital messages to the protocol, this needs to
410  * track the last digital data sent so that it can be sure to change just
411  * one bit in the packet. This is complicated by the fact that the
412  * numbering of the pins will probably differ on Arduino, Wiring, and
413  * other boards.
414  */
415 
416  // TODO: the digital message should not be sent on the serial port every
417  // time sendDigital() is called. Instead, it should add it to an int
418  // which will be sent on a schedule. If a pin changes more than once
419  // before the digital message is sent on the serial port, it should send a
420  // digital message for each change.
421 
422  // if(value == 0)
423  // sendDigitalPortPair();
424 }

◆ sendDigitalPort()

void FirmataClass::sendDigitalPort ( byte  portNumber,
int  portData 
)

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

引数
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.

CP_Firmata.cpp435 行目に定義があります。

436 {
437  FirmataStream->write(DIGITAL_MESSAGE | (portNumber & 0xF));
438  FirmataStream->write((byte)portData % 128); // Tx bits 0-6 (protocol v1 and higher)
439  FirmataStream->write(portData >> 7); // Tx bits 7-13 (bit 7 only for protocol v2 and higher)
440 }
#define DIGITAL_MESSAGE
Definition: CP_Firmata.h:50
virtual size_t write(uint8_t)=0

◆ sendString() [1/2]

void FirmataClass::sendString ( const char *  string)

Send a string to the Firmata host application.

引数
stringA pointer to the char string

CP_Firmata.cpp476 行目に定義があります。

477 {
478  sendString(STRING_DATA, string);
479 }
void sendString(const char *string)
Definition: CP_Firmata.cpp:476
#define STRING_DATA
Definition: CP_Firmata.h:69

◆ sendString() [2/2]

void FirmataClass::sendString ( byte  command,
const char *  string 
)

Send a string to the Firmata host application.

引数
commandMust be STRING_DATA
stringA pointer to the char string

CP_Firmata.cpp465 行目に定義があります。

466 {
467  if (command == STRING_DATA) {
468  sendSysex(command, strlen(string), (byte *)string);
469  }
470 }
size_t strlen(const char *) __ATTR_PURE__
Calculate the length of a string.
void sendSysex(byte command, byte bytec, byte *bytev)
Definition: CP_Firmata.cpp:449
#define STRING_DATA
Definition: CP_Firmata.h:69

◆ sendSysex()

void FirmataClass::sendSysex ( byte  command,
byte  bytec,
byte bytev 
)

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).

引数
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.

CP_Firmata.cpp449 行目に定義があります。

450 {
451  byte i;
452  startSysex();
453  FirmataStream->write(command);
454  for (i = 0; i < bytec; i++) {
455  sendValueAsTwo7bitBytes(bytev[i]);
456  }
457  endSysex();
458 }
void sendValueAsTwo7bitBytes(int value)
Definition: CP_Firmata.cpp:34
virtual size_t write(uint8_t)=0
uint8_t i
void endSysex(void)
Definition: CP_Firmata.cpp:51
void startSysex(void)
Definition: CP_Firmata.cpp:43

◆ sendValueAsTwo7bitBytes()

void FirmataClass::sendValueAsTwo7bitBytes ( int  value)

Split a 16-bit byte into two 7-bit values and write each value.

引数
valueThe 16-bit value to be split and written separately.

CP_Firmata.cpp34 行目に定義があります。

35 {
36  FirmataStream->write(value & 0x7F); // LSB
37  FirmataStream->write(value >> 7 & 0x7F); // MSB
38 }
virtual size_t write(uint8_t)=0

◆ setFirmwareNameAndVersion()

void FirmataClass::setFirmwareNameAndVersion ( const char *  name,
byte  major,
byte  minor 
)

Sets the name and version of the firmware. This is not the same version as the Firmata protocol (although at times the firmware version and protocol version may be the same number).

引数
nameA pointer to the name char array
majorThe major version number
minorThe minor version number

CP_Firmata.cpp182 行目に定義があります。

183 {
184  const char *firmwareName;
185  const char *extension;
186 
187  // parse out ".cpp" and "applet/" that comes from using __FILE__
188  extension = strstr(name, ".cpp");
189  firmwareName = strrchr(name, '/');
190 
191  if (!firmwareName) {
192  // windows
193  firmwareName = strrchr(name, '\\');
194  }
195  if (!firmwareName) {
196  // user passed firmware name
197  firmwareName = name;
198  } else {
199  firmwareName ++;
200  }
201 
202  if (!extension) {
203  firmwareVersionCount = strlen(firmwareName) + 2;
204  } else {
205  firmwareVersionCount = extension - firmwareName + 2;
206  }
207 
208  // in case anyone calls setFirmwareNameAndVersion more than once
209  free(firmwareVersionVector);
210 
211  firmwareVersionVector = (byte *) malloc(firmwareVersionCount + 1);
212  firmwareVersionVector[firmwareVersionCount] = 0;
213  firmwareVersionVector[0] = major;
214  firmwareVersionVector[1] = minor;
215  strncpy((char *)firmwareVersionVector + 2, firmwareName, firmwareVersionCount - 2);
216 }
char * strstr(const char *, const char *) __ATTR_PURE__
Locate a substring.
uint8_t name[11]
Definition: FatStructs.h:292
void free(void *__ptr)
void * malloc(size_t __size) __ATTR_MALLOC__
size_t strlen(const char *) __ATTR_PURE__
Calculate the length of a string.
char * strrchr(const char *, int) __ATTR_PURE__
Locate character in string.
char * strncpy(char *, const char *, size_t)
Copy a string.

◆ setPinMode()

void FirmataClass::setPinMode ( byte  pin,
byte  config 
)

Set 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.

引数
pinThe pin to configure.
configThe configuration value for the specified pin.

CP_Firmata.cpp575 行目に定義があります。

576 {
577  if (pinConfig[pin] == PIN_MODE_IGNORE)
578  return;
579 
580  pinConfig[pin] = config;
581 }
#define PIN_MODE_IGNORE
Definition: CP_Firmata.h:107

◆ setPinState()

void FirmataClass::setPinState ( byte  pin,
int  state 
)

Set the pin state. The pin state of an output pin is the pin value. The state of an input pin is 0, unless the pin has it's internal pull up resistor enabled, then the value is 1.

引数
pinThe pin to set the state of
stateSet the state of the specified pin

CP_Firmata.cpp598 行目に定義があります。

599 {
600  pinState[pin] = state;
601 }

◆ startSysex()

void FirmataClass::startSysex ( void  )

A helper method to write the beginning of a Sysex message transmission.

CP_Firmata.cpp43 行目に定義があります。

44 {
45  FirmataStream->write(START_SYSEX);
46 }
virtual size_t write(uint8_t)=0
#define START_SYSEX
Definition: CP_Firmata.h:61

◆ write()

void FirmataClass::write ( byte  c)

A wrapper for Stream::available(). Write a single byte to the output stream.

引数
cThe byte to be written.

CP_Firmata.cpp486 行目に定義があります。

487 {
488  FirmataStream->write(c);
489 }
virtual size_t write(uint8_t)=0

このクラス詳解は次のファイルから抽出されました: