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.
pull/5874/head
Russ Butler 2018-01-11 14:08:09 -06:00
parent 6decbedbb8
commit 48cf4d85d1
2 changed files with 54 additions and 8 deletions

View File

@ -152,7 +152,7 @@ public:
*
*/
void attach(void(*fptr)(void)) {
updateVol.attach(fptr);
updateVol = Callback<void()>(fptr);
}
/** attach a handler to Tx Done
*
@ -160,7 +160,7 @@ public:
*
*/
void attachTx(void(*fptr)(void)) {
txDone.attach(fptr);
txDone = Callback<void()>(fptr);
}
/** attach a handler to Rx Done
*
@ -168,7 +168,7 @@ public:
*
*/
void attachRx(void(*fptr)(void)) {
rxDone.attach(fptr);
rxDone = Callback<void()>(fptr);
}
/** Attach a nonstatic void/void member function to update the volume
@ -179,15 +179,52 @@ public:
*/
template<typename T>
void attach(T *tptr, void(T::*mptr)(void)) {
updateVol.attach(tptr, mptr);
updateVol = Callback<void()>(tptr, mptr);
}
/** Attach a nonstatic void/void member function to Tx Done
*
* @param tptr Object pointer
* @param mptr Member function pointer
*
*/
template<typename T>
void attachTx(T *tptr, void(T::*mptr)(void)) {
txDone.attach(tptr, mptr);
txDone = Callback<void()>(tptr, mptr);
}
/** Attach a nonstatic void/void member function to Rx Done
*
* @param tptr Object pointer
* @param mptr Member function pointer
*
*/
template<typename T>
void attachRx(T *tptr, void(T::*mptr)(void)) {
rxDone.attach(tptr, mptr);
rxDone = Callback<void()>(tptr, mptr);
}
/** Attach a Callback to update the volume
*
* @param cb Callback to attach
*
*/
void attach(Callback<void()> &cb) {
updateVol = cb;
}
/** attach a Callback to Tx Done
*
* @param cb Callback to attach
*
*/
void attachTx(Callback<void()> &cb) {
txDone = cb;
}
/** attach a Callback to Rx Done
*
* @param cb Callback to attach
*
*/
void attachRx(Callback<void()> &cb) {
rxDone = cb;
}

View File

@ -127,7 +127,7 @@ public:
template<typename T>
void attach(T* tptr, void (T::*mptr)(void)) {
if((mptr != NULL) && (tptr != NULL)) {
rx.attach(tptr, mptr);
rx = Callback<void()>(mptr, tptr);
}
}
@ -138,10 +138,19 @@ public:
*/
void attach(void (*fptr)(void)) {
if(fptr != NULL) {
rx.attach(fptr);
rx = Callback<void()>(fptr);
}
}
/**
* Attach a Callback called when a packet is received
*
* @param cb Callback to attach
*/
void attach(Callback<void()> &cb) {
rx = cb;
}
/**
* Attach a callback to call when serial's settings are changed.
*