Skip to content

Commit 48cf4d8

Browse files
committed
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.
1 parent 6decbed commit 48cf4d8

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

features/unsupported/USBDevice/USBAudio/USBAudio.h

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,23 @@ class USBAudio: public USBDevice {
152152
*
153153
*/
154154
void attach(void(*fptr)(void)) {
155-
updateVol.attach(fptr);
155+
updateVol = Callback<void()>(fptr);
156156
}
157157
/** attach a handler to Tx Done
158158
*
159159
* @param function Function to attach
160160
*
161161
*/
162162
void attachTx(void(*fptr)(void)) {
163-
txDone.attach(fptr);
163+
txDone = Callback<void()>(fptr);
164164
}
165165
/** attach a handler to Rx Done
166166
*
167167
* @param function Function to attach
168168
*
169169
*/
170170
void attachRx(void(*fptr)(void)) {
171-
rxDone.attach(fptr);
171+
rxDone = Callback<void()>(fptr);
172172
}
173173

174174
/** Attach a nonstatic void/void member function to update the volume
@@ -179,15 +179,52 @@ class USBAudio: public USBDevice {
179179
*/
180180
template<typename T>
181181
void attach(T *tptr, void(T::*mptr)(void)) {
182-
updateVol.attach(tptr, mptr);
182+
updateVol = Callback<void()>(tptr, mptr);
183183
}
184+
/** Attach a nonstatic void/void member function to Tx Done
185+
*
186+
* @param tptr Object pointer
187+
* @param mptr Member function pointer
188+
*
189+
*/
184190
template<typename T>
185191
void attachTx(T *tptr, void(T::*mptr)(void)) {
186-
txDone.attach(tptr, mptr);
192+
txDone = Callback<void()>(tptr, mptr);
187193
}
194+
/** Attach a nonstatic void/void member function to Rx Done
195+
*
196+
* @param tptr Object pointer
197+
* @param mptr Member function pointer
198+
*
199+
*/
188200
template<typename T>
189201
void attachRx(T *tptr, void(T::*mptr)(void)) {
190-
rxDone.attach(tptr, mptr);
202+
rxDone = Callback<void()>(tptr, mptr);
203+
}
204+
205+
/** Attach a Callback to update the volume
206+
*
207+
* @param cb Callback to attach
208+
*
209+
*/
210+
void attach(Callback<void()> &cb) {
211+
updateVol = cb;
212+
}
213+
/** attach a Callback to Tx Done
214+
*
215+
* @param cb Callback to attach
216+
*
217+
*/
218+
void attachTx(Callback<void()> &cb) {
219+
txDone = cb;
220+
}
221+
/** attach a Callback to Rx Done
222+
*
223+
* @param cb Callback to attach
224+
*
225+
*/
226+
void attachRx(Callback<void()> &cb) {
227+
rxDone = cb;
191228
}
192229

193230

features/unsupported/USBDevice/USBSerial/USBSerial.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class USBSerial: public USBCDC, public Stream {
127127
template<typename T>
128128
void attach(T* tptr, void (T::*mptr)(void)) {
129129
if((mptr != NULL) && (tptr != NULL)) {
130-
rx.attach(tptr, mptr);
130+
rx = Callback<void()>(mptr, tptr);
131131
}
132132
}
133133

@@ -138,10 +138,19 @@ class USBSerial: public USBCDC, public Stream {
138138
*/
139139
void attach(void (*fptr)(void)) {
140140
if(fptr != NULL) {
141-
rx.attach(fptr);
141+
rx = Callback<void()>(fptr);
142142
}
143143
}
144144

145+
/**
146+
* Attach a Callback called when a packet is received
147+
*
148+
* @param cb Callback to attach
149+
*/
150+
void attach(Callback<void()> &cb) {
151+
rx = cb;
152+
}
153+
145154
/**
146155
* Attach a callback to call when serial's settings are changed.
147156
*

0 commit comments

Comments
 (0)