diff --git a/hal/api/CAN.h b/hal/api/CAN.h index 65221ccdec..241cd4c822 100644 --- a/hal/api/CAN.h +++ b/hal/api/CAN.h @@ -218,8 +218,20 @@ public: * @param method pointer to the member function to be called * @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error) */ - template - void attach(T* obj, void (T::*method)(void), IrqType type=RxIrq) { + template + void attach(T* obj, void (T::*method)(), IrqType type=RxIrq) { + attach(Callback(obj, method), type); + } + + /** Attach a member function to call whenever a CAN frame received interrupt + * is generated. + * + * @param obj pointer to the object to call the member function on + * @param method pointer to the member function to be called + * @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error) + */ + template + void attach(T* obj, void (*method)(T*), IrqType type=RxIrq) { attach(Callback(obj, method), type); } diff --git a/hal/api/Callback.h b/hal/api/Callback.h index d7b4d12ec8..b90baf91af 100644 --- a/hal/api/Callback.h +++ b/hal/api/Callback.h @@ -106,6 +106,9 @@ public: /** Call the attached function */ R call(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0, a1, a2, a3, a4); } @@ -244,6 +247,9 @@ public: /** Call the attached function */ R call(A0 a0, A1 a1, A2 a2, A3 a3) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0, a1, a2, a3); } @@ -382,6 +388,9 @@ public: /** Call the attached function */ R call(A0 a0, A1 a1, A2 a2) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0, a1, a2); } @@ -520,6 +529,9 @@ public: /** Call the attached function */ R call(A0 a0, A1 a1) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0, a1); } @@ -658,6 +670,9 @@ public: /** Call the attached function */ R call(A0 a0) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0); } @@ -796,7 +811,7 @@ public: /** Call the attached function */ R call() { - if (NULL == _thunk) { + if (!_thunk) { return (R)0; } return _thunk(_obj, &_func); diff --git a/hal/api/SerialBase.h b/hal/api/SerialBase.h index e9387f48ac..ed2e744790 100644 --- a/hal/api/SerialBase.h +++ b/hal/api/SerialBase.h @@ -100,8 +100,19 @@ public: * @param method pointer to the member function to be called * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) */ - template - void attach(T *obj, M method, IrqType type=RxIrq) { + template + void attach(T *obj, void (T::*method)(), IrqType type=RxIrq) { + attach(Callback(obj, method), type); + } + + /** Attach a member function to call whenever a serial interrupt is generated + * + * @param obj pointer to the object to call the member function on + * @param method pointer to the member function to be called + * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) + */ + template + void attach(T *obj, void (*method)(T*), IrqType type=RxIrq) { attach(Callback(obj, method), type); } diff --git a/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedSerial.h b/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedSerial.h index 5c58928e72..07bcb9b245 100644 --- a/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedSerial.h +++ b/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedSerial.h @@ -149,8 +149,18 @@ public: * @param method pointer to the member function to call * @param type Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty) */ - template - void attach(T *obj, M method, IrqType type=RxIrq) { + template + void attach(T *obj, void (T::*method)(), IrqType type=RxIrq) { + attach(Callback(obj, method), type); + } + + /** Attach a member function to call whenever a serial interrupt is generated + * @param obj pointer to the object to call the member function on + * @param method pointer to the member function to call + * @param type Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty) + */ + template + void attach(T *obj, void (*method)(T*), IrqType type=RxIrq) { attach(Callback(obj, method), type); } };