From 48cf4d85d175fd1256bac049baedabf46395d43f Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Thu, 11 Jan 2018 14:08:09 -0600 Subject: [PATCH] Remove use of deprecated attach in USB Attach callbacks with the assignment operator rather than with the deprecated attach function. This fixes deprecation warnings. This patch also adds the ability to attach a Callback directly. --- .../unsupported/USBDevice/USBAudio/USBAudio.h | 49 ++++++++++++++++--- .../USBDevice/USBSerial/USBSerial.h | 13 ++++- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/features/unsupported/USBDevice/USBAudio/USBAudio.h b/features/unsupported/USBDevice/USBAudio/USBAudio.h index f1bdbe6d48..e72f42e559 100644 --- a/features/unsupported/USBDevice/USBAudio/USBAudio.h +++ b/features/unsupported/USBDevice/USBAudio/USBAudio.h @@ -152,7 +152,7 @@ public: * */ void attach(void(*fptr)(void)) { - updateVol.attach(fptr); + updateVol = Callback(fptr); } /** attach a handler to Tx Done * @@ -160,7 +160,7 @@ public: * */ void attachTx(void(*fptr)(void)) { - txDone.attach(fptr); + txDone = Callback(fptr); } /** attach a handler to Rx Done * @@ -168,7 +168,7 @@ public: * */ void attachRx(void(*fptr)(void)) { - rxDone.attach(fptr); + rxDone = Callback(fptr); } /** Attach a nonstatic void/void member function to update the volume @@ -179,15 +179,52 @@ public: */ template void attach(T *tptr, void(T::*mptr)(void)) { - updateVol.attach(tptr, mptr); + updateVol = Callback(tptr, mptr); } + /** Attach a nonstatic void/void member function to Tx Done + * + * @param tptr Object pointer + * @param mptr Member function pointer + * + */ template void attachTx(T *tptr, void(T::*mptr)(void)) { - txDone.attach(tptr, mptr); + txDone = Callback(tptr, mptr); } + /** Attach a nonstatic void/void member function to Rx Done + * + * @param tptr Object pointer + * @param mptr Member function pointer + * + */ template void attachRx(T *tptr, void(T::*mptr)(void)) { - rxDone.attach(tptr, mptr); + rxDone = Callback(tptr, mptr); + } + + /** Attach a Callback to update the volume + * + * @param cb Callback to attach + * + */ + void attach(Callback &cb) { + updateVol = cb; + } + /** attach a Callback to Tx Done + * + * @param cb Callback to attach + * + */ + void attachTx(Callback &cb) { + txDone = cb; + } + /** attach a Callback to Rx Done + * + * @param cb Callback to attach + * + */ + void attachRx(Callback &cb) { + rxDone = cb; } diff --git a/features/unsupported/USBDevice/USBSerial/USBSerial.h b/features/unsupported/USBDevice/USBSerial/USBSerial.h index 825b03caf6..69ed61abf5 100644 --- a/features/unsupported/USBDevice/USBSerial/USBSerial.h +++ b/features/unsupported/USBDevice/USBSerial/USBSerial.h @@ -127,7 +127,7 @@ public: template void attach(T* tptr, void (T::*mptr)(void)) { if((mptr != NULL) && (tptr != NULL)) { - rx.attach(tptr, mptr); + rx = Callback(mptr, tptr); } } @@ -138,10 +138,19 @@ public: */ void attach(void (*fptr)(void)) { if(fptr != NULL) { - rx.attach(fptr); + rx = Callback(fptr); } } + /** + * Attach a Callback called when a packet is received + * + * @param cb Callback to attach + */ + void attach(Callback &cb) { + rx = cb; + } + /** * Attach a callback to call when serial's settings are changed. *