5
5
#include " AudioTools/CoreAudio/AudioActions.h"
6
6
7
7
namespace audio_tools {
8
- class AudioBoardStream ;
9
- AudioBoardStream *selfAudioBoard = nullptr ;
10
8
11
9
/* *
12
10
* @brief New functionality which replaces the AudioKitStream that is based on
@@ -28,7 +26,6 @@ class AudioBoardStream : public I2SCodecStream {
28
26
* https://github.com/pschatzmann/arduino-audio-driver/wiki
29
27
*/
30
28
AudioBoardStream (audio_driver::AudioBoard &board) : I2SCodecStream(board) {
31
- selfAudioBoard = this ;
32
29
// pin mode already set up by driver library
33
30
actions.setPinMode (false );
34
31
}
@@ -60,7 +57,7 @@ class AudioBoardStream : public I2SCodecStream {
60
57
TRACEI ();
61
58
// determine logic from config
62
59
AudioActions::ActiveLogic activeLogic = getActionLogic (pin);
63
- actions.add (pin, action, activeLogic, ref);
60
+ actions.add (pin, action, activeLogic, ref == nullptr ? this : ref );
64
61
}
65
62
66
63
/* *
@@ -75,11 +72,12 @@ class AudioBoardStream : public I2SCodecStream {
75
72
void addAction (int pin, void (*action)(bool , int , void *),
76
73
AudioActions::ActiveLogic activeLogic, void *ref = nullptr) {
77
74
TRACEI ();
78
- actions.add (pin, action, activeLogic, ref);
75
+ actions.add (pin, action, activeLogic, ref == nullptr ? this : ref);
79
76
}
80
77
81
78
// / Provides access to the AudioActions
82
79
AudioActions &audioActions () { return actions; }
80
+
83
81
AudioActions &getActions () { return actions; }
84
82
85
83
/* *
@@ -98,68 +96,74 @@ class AudioBoardStream : public I2SCodecStream {
98
96
* @brief Increase the volume
99
97
*
100
98
*/
101
- static void actionVolumeUp (bool , int , void *) {
99
+ static void actionVolumeUp (bool , int , void *ref ) {
102
100
TRACEI ();
103
- selfAudioBoard->incrementVolume (+selfAudioBoard->actionVolumeIncrementValue ());
101
+ AudioBoardStream *self = (AudioBoardStream*)ref;
102
+ self->incrementVolume (+self->actionVolumeIncrementValue ());
104
103
}
105
104
106
105
/* *
107
106
* @brief Decrease the volume
108
107
*
109
108
*/
110
- static void actionVolumeDown (bool , int , void *) {
109
+ static void actionVolumeDown (bool , int , void *ref ) {
111
110
TRACEI ();
112
- selfAudioBoard->incrementVolume (-selfAudioBoard->actionVolumeIncrementValue ());
111
+ AudioBoardStream *self = (AudioBoardStream*)ref;
112
+ self->incrementVolume (-self->actionVolumeIncrementValue ());
113
113
}
114
114
115
115
116
116
/* *
117
117
* @brief Toggle start stop
118
118
*
119
119
*/
120
- static void actionStartStop (bool , int , void *) {
120
+ static void actionStartStop (bool , int , void *ref ) {
121
121
TRACEI ();
122
- selfAudioBoard->active = !selfAudioBoard->active ;
123
- selfAudioBoard->setActive (selfAudioBoard->active );
122
+ AudioBoardStream *self = (AudioBoardStream*)ref;
123
+ self->active = !self->active ;
124
+ self->setActive (self->active );
124
125
}
125
126
126
127
/* *
127
128
* @brief Start
128
129
*
129
130
*/
130
- static void actionStart (bool , int , void *) {
131
+ static void actionStart (bool , int , void *ref ) {
131
132
TRACEI ();
132
- selfAudioBoard->active = true ;
133
- selfAudioBoard->setActive (selfAudioBoard->active );
133
+ AudioBoardStream *self = (AudioBoardStream*)ref;
134
+ self->active = true ;
135
+ self->setActive (self->active );
134
136
}
135
137
136
138
/* *
137
139
* @brief Stop
138
140
*/
139
- static void actionStop (bool , int , void *) {
141
+ static void actionStop (bool , int , void *ref ) {
140
142
TRACEI ();
141
- selfAudioBoard->active = false ;
142
- selfAudioBoard->setActive (selfAudioBoard->active );
143
+ AudioBoardStream *self = (AudioBoardStream*)ref;
144
+ self->active = false ;
145
+ self->setActive (self->active );
143
146
}
144
147
145
148
/* *
146
149
* @brief Switch off the PA if the headphone in plugged in
147
150
* and switch it on again if the headphone is unplugged.
148
151
* This method complies with the
149
152
*/
150
- static void actionHeadphoneDetection (bool , int , void *) {
151
- if (selfAudioBoard->pinHeadphoneDetect () >= 0 ) {
153
+ static void actionHeadphoneDetection (bool , int , void *ref) {
154
+ AudioBoardStream *self = (AudioBoardStream*)ref;
155
+ if (self->pinHeadphoneDetect () >= 0 ) {
152
156
153
157
// detect changes
154
- bool isConnected = selfAudioBoard ->headphoneStatus ();
155
- if (selfAudioBoard ->headphoneIsConnected != isConnected) {
156
- selfAudioBoard ->headphoneIsConnected = isConnected;
158
+ bool isConnected = self ->headphoneStatus ();
159
+ if (self ->headphoneIsConnected != isConnected) {
160
+ self ->headphoneIsConnected = isConnected;
157
161
158
162
// update if things have stabilized
159
163
bool powerActive = !isConnected;
160
164
LOGW (" Headphone jack has been %s" ,
161
165
isConnected ? " inserted" : " removed" );
162
- selfAudioBoard ->setSpeakerActive (powerActive);
166
+ self ->setSpeakerActive (powerActive);
163
167
}
164
168
}
165
169
yield ();
@@ -310,7 +314,7 @@ class AudioBoardStream : public I2SCodecStream {
310
314
int head_phone = pinHeadphoneDetect ();
311
315
if (head_phone != -1 && (getPinID (PinFunction::KEY, 6 ) != head_phone)) {
312
316
actions.add (head_phone, actionHeadphoneDetection,
313
- AudioActions::ActiveChange);
317
+ AudioActions::ActiveChange, this );
314
318
}
315
319
}
316
320
0 commit comments