Skip to content

Commit

Permalink
Refactor attach and detach to remove 'Interrupt'
Browse files Browse the repository at this point in the history
Having the class functions share the name of the global function was good for intuitiveness, but causes issues on platforms that implement the global 'attachInterrupt' as something other than a function (see #27).

Removing 'Interrupt' from the name also makes these functions match their counterparts in the Servo library.
  • Loading branch information
dmadison committed Jan 25, 2024
1 parent 61e6c7f commit 7577f09
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/ServoInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ class ServoInputPin : public ServoInputSignal {
ServoInputPin<Pin>::PortRegister = SERVOINPUT_PIN_TO_BASEREG(Pin);
#endif
pinMode(Pin, INPUT_PULLUP);
attachInterrupt();
attach();
}

ServoInputPin(uint16_t pMin, uint16_t pMax) : ServoInputPin() {
ServoInputSignal::setRange(pMin, pMax);
}

void attachInterrupt() {
void attach() {
#if !defined(SERVOINPUT_NO_INTERRUPTS)

// Compile-time check that the selected pin supports interrupts
Expand All @@ -116,7 +116,7 @@ class ServoInputPin : public ServoInputSignal {

// Interrupt attachment, platform support
if (digitalPinToInterrupt(Pin) != NOT_AN_INTERRUPT) { // if pin supports external interrupts
::attachInterrupt(digitalPinToInterrupt(Pin), reinterpret_cast<void(*)()>(isr), CHANGE);
attachInterrupt(digitalPinToInterrupt(Pin), reinterpret_cast<void(*)()>(isr), CHANGE);
}

// Interrupt attachment, PinChangeInterrupt
Expand All @@ -131,21 +131,21 @@ class ServoInputPin : public ServoInputSignal {
// because we have no way of checking whether the pin is supported
// in hardware vs in the library
#else
::attachInterrupt(digitalPinToInterrupt(Pin), reinterpret_cast<void(*)()>(isr), CHANGE);
attachInterrupt(digitalPinToInterrupt(Pin), reinterpret_cast<void(*)()>(isr), CHANGE);
#endif

#endif
}

void detachInterrupt() {
void detach() {
#if !defined(SERVOINPUT_NO_INTERRUPTS)

// Interrupt detachment, with pin checks
#if !defined(SERVOINPUT_DISABLE_PIN_CHECK)

// Interrupt detachment, platform support
if (digitalPinToInterrupt(Pin) != NOT_AN_INTERRUPT) { // detach external interrupt
::detachInterrupt(digitalPinToInterrupt(Pin));
detachInterrupt(digitalPinToInterrupt(Pin));
}

// Interrupt detachment, PinChangeInterrupt
Expand All @@ -157,7 +157,7 @@ class ServoInputPin : public ServoInputSignal {

// Interrupt detachment, no pin checks
#else
::detachInterrupt(digitalPinToInterrupt(Pin));
detachInterrupt(digitalPinToInterrupt(Pin));
#endif
#endif
}
Expand Down

0 comments on commit 7577f09

Please sign in to comment.