Skip to content

Commit

Permalink
Clear command requires only 2 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrawehr committed Jul 11, 2021
1 parent d3cce00 commit 38151f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/DigitalInputFirmata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ void DigitalInputFirmata::reportDigital(byte port, int value)
{
if (port < TOTAL_PORTS) {
reportPINs[port] = (byte)value;
if (value) outputPort(port, readPort(port, portConfigInputs[port]), true);
if (value)
{
outputPort(port, readPort(port, portConfigInputs[port]), true);
}
}
// do not disable analog reporting on these 8 pins, to allow some
// pins used for digital, others analog. Instead, allow both types
Expand All @@ -108,6 +111,7 @@ boolean DigitalInputFirmata::handlePinMode(byte pin, int mode)
return true;
} else {
portConfigInputs[pin / 8] &= ~(1 << (pin & 7));
return true;
}
}
return false;
Expand Down
21 changes: 13 additions & 8 deletions src/Frequency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,30 @@ boolean Frequency::handleSysex(byte command, byte argc, byte* argv)
{
return false;
}
if (argc >= 5) // Expected: A command byte, a pin, the mode and a packed short
if (argc >= 2)
{
byte frequencyCommand = argv[0];
byte pin = argv[1];
int interrupt = digitalPinToInterrupt(pin);
byte mode = argv[2]; // see below
int32_t ms = (argv[4] << 7) | argv[3];
// Clear
if (frequencyCommand == FREQUENCY_SUBCOMMAND_CLEAR)
{
// This does not need a valid pin, so that it is possible to reset the interrupt even if the client doesn't know the state.
if (_activePin >= 0)
if (_activePin == pin || (_activePin >= 0 && pin == 0x7F))
{
// This cannot be -1 here
uint8_t interrupt = (uint8_t)digitalPinToInterrupt(_activePin);
detachInterrupt(interrupt);
_activePin = -1;
}
}
}
if (argc >= 5) // Expected: A command byte, a pin, the mode and a packed short
{
byte frequencyCommand = argv[0];
byte pin = argv[1];
int interrupt = digitalPinToInterrupt(pin);
byte mode = argv[2]; // see below
int32_t ms = (argv[4] << 7) | argv[3];
// Set or query
else if (frequencyCommand == FREQUENCY_SUBCOMMAND_QUERY)
if (frequencyCommand == FREQUENCY_SUBCOMMAND_QUERY)
{
if (pin >= TOTAL_PINS || interrupt < 0)
{
Expand Down

0 comments on commit 38151f0

Please sign in to comment.