From 6eac36c66f71fe76856b7acbdc456e2547a31f71 Mon Sep 17 00:00:00 2001 From: Stefan de Bruijn Date: Tue, 25 May 2021 11:07:31 +0200 Subject: [PATCH] Changed ISR registration in ControlPin to class member registration. --- Grbl_Esp32/src/ControlPin.cpp | 7 ++----- Grbl_Esp32/src/ControlPin.h | 17 +++++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Grbl_Esp32/src/ControlPin.cpp b/Grbl_Esp32/src/ControlPin.cpp index 7b1fca2f..4665cc35 100644 --- a/Grbl_Esp32/src/ControlPin.cpp +++ b/Grbl_Esp32/src/ControlPin.cpp @@ -8,15 +8,12 @@ void IRAM_ATTR ControlPin::handleISR() { bool pinState = _pin.read(); _value = pinState; + if (_rtVariable) { *_rtVariable = pinState; } } -void /* IRAM_ATTR */ ControlPin::handle_control_pin(void* arg) { - ((ControlPin*)arg)->handleISR(); -} - void ControlPin::init() { if (_pin.defined()) { grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "%s switch on pin %s", _legend, _pin.name()); @@ -25,6 +22,6 @@ void ControlPin::init() { attr = attr | Pin::Attr::PullUp; } _pin.setAttr(attr); - _pin.attachInterrupt(ControlPin::handle_control_pin, CHANGE, (void*)this); + _pin.attachInterrupt(this, CHANGE); } } diff --git a/Grbl_Esp32/src/ControlPin.h b/Grbl_Esp32/src/ControlPin.h index bd18443b..d4f3534d 100644 --- a/Grbl_Esp32/src/ControlPin.h +++ b/Grbl_Esp32/src/ControlPin.h @@ -6,19 +6,20 @@ class ControlPin { private: // invertBitNum refers to a bit in INVERT_CONTROL_PIN_MASK. It is a // short-term hack to reduce the extent of the patch. - bool _invertBitNum; - bool _value; - const char _letter; - volatile bool* _rtVariable; - const char* _legend; - void IRAM_ATTR handleISR(); - static void /* IRAM_ATTR */ handle_control_pin(void* arg); + bool _invertBitNum; + bool _value; + const char _letter; + volatile bool* _rtVariable; + const char* _legend; + + void IRAM_ATTR handleISR(); public: ControlPin(uint8_t bitNum, volatile bool* rtVariable, const char* legend, char letter) : _invertBitNum(bitNum), _value(false), _letter(letter), _rtVariable(rtVariable), _legend(legend) {} - Pin _pin; + Pin _pin; + bool get() { return _value; } const char* legend() { return _legend; } // char invertBitNum() { return _invertBitNum; }