ConfigurableFirmata Module Functions

I am writing custom modules for ConfigurableFirmata, I see that libraries use callbacks such as:

void Class::handleCapability(byte pin);
boolean Class::handlePinMode(byte pin, int mode);
...
boolean Class::handleSysex(byte command, byte argc, byte *argv);

The question is, I don’t quite understand why some functions are logical and when to return TRUE or FALSE (and what happens when you return TRUE or FALSE?).

+4
source share
2 answers

The answer lies in the FirmataExt.cpp file. If the extension returns FALSE, it simply sends a string to firmata for debugging purposes.

+2
source
boolean FirmataExt::handleSysex(byte command, byte argc, byte* argv)
{
  switch (command) {

    case PIN_STATE_QUERY:
      if (argc > 0) {
        byte pin = argv[0];
        if (pin < TOTAL_PINS) {
          //...
          return true;
        }
      }
      break;
    case CAPABILITY_QUERY:
      //...
      return true;
    default:
      for (byte i = 0; i < numFeatures; i++) {
        if (features[i]->handleSysex(command, argc, argv)) {
          return true;
        }
      }
      break;
  }
  return false;
}

This function returns true if the command is valid.

0
source

Source: https://habr.com/ru/post/1651955/


All Articles