55#include " AudioTools/CoreAudio/AudioActions.h"
66
77namespace audio_tools {
8- class AudioBoardStream ;
9- AudioBoardStream *selfAudioBoard = nullptr ;
108
119/* *
1210 * @brief New functionality which replaces the AudioKitStream that is based on
@@ -28,7 +26,6 @@ class AudioBoardStream : public I2SCodecStream {
2826 * https://github.com/pschatzmann/arduino-audio-driver/wiki
2927 */
3028 AudioBoardStream (audio_driver::AudioBoard &board) : I2SCodecStream(board) {
31- selfAudioBoard = this ;
3229 // pin mode already set up by driver library
3330 actions.setPinMode (false );
3431 }
@@ -60,7 +57,7 @@ class AudioBoardStream : public I2SCodecStream {
6057 TRACEI ();
6158 // determine logic from config
6259 AudioActions::ActiveLogic activeLogic = getActionLogic (pin);
63- actions.add (pin, action, activeLogic, ref);
60+ actions.add (pin, action, activeLogic, ref == nullptr ? this : ref );
6461 }
6562
6663 /* *
@@ -75,11 +72,12 @@ class AudioBoardStream : public I2SCodecStream {
7572 void addAction (int pin, void (*action)(bool , int , void *),
7673 AudioActions::ActiveLogic activeLogic, void *ref = nullptr) {
7774 TRACEI ();
78- actions.add (pin, action, activeLogic, ref);
75+ actions.add (pin, action, activeLogic, ref == nullptr ? this : ref);
7976 }
8077
8178 // / Provides access to the AudioActions
8279 AudioActions &audioActions () { return actions; }
80+
8381 AudioActions &getActions () { return actions; }
8482
8583 /* *
@@ -98,68 +96,74 @@ class AudioBoardStream : public I2SCodecStream {
9896 * @brief Increase the volume
9997 *
10098 */
101- static void actionVolumeUp (bool , int , void *) {
99+ static void actionVolumeUp (bool , int , void *ref ) {
102100 TRACEI ();
103- selfAudioBoard->incrementVolume (+selfAudioBoard->actionVolumeIncrementValue ());
101+ AudioBoardStream *self = (AudioBoardStream*)ref;
102+ self->incrementVolume (+self->actionVolumeIncrementValue ());
104103 }
105104
106105 /* *
107106 * @brief Decrease the volume
108107 *
109108 */
110- static void actionVolumeDown (bool , int , void *) {
109+ static void actionVolumeDown (bool , int , void *ref ) {
111110 TRACEI ();
112- selfAudioBoard->incrementVolume (-selfAudioBoard->actionVolumeIncrementValue ());
111+ AudioBoardStream *self = (AudioBoardStream*)ref;
112+ self->incrementVolume (-self->actionVolumeIncrementValue ());
113113 }
114114
115115
116116 /* *
117117 * @brief Toggle start stop
118118 *
119119 */
120- static void actionStartStop (bool , int , void *) {
120+ static void actionStartStop (bool , int , void *ref ) {
121121 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 );
124125 }
125126
126127 /* *
127128 * @brief Start
128129 *
129130 */
130- static void actionStart (bool , int , void *) {
131+ static void actionStart (bool , int , void *ref ) {
131132 TRACEI ();
132- selfAudioBoard->active = true ;
133- selfAudioBoard->setActive (selfAudioBoard->active );
133+ AudioBoardStream *self = (AudioBoardStream*)ref;
134+ self->active = true ;
135+ self->setActive (self->active );
134136 }
135137
136138 /* *
137139 * @brief Stop
138140 */
139- static void actionStop (bool , int , void *) {
141+ static void actionStop (bool , int , void *ref ) {
140142 TRACEI ();
141- selfAudioBoard->active = false ;
142- selfAudioBoard->setActive (selfAudioBoard->active );
143+ AudioBoardStream *self = (AudioBoardStream*)ref;
144+ self->active = false ;
145+ self->setActive (self->active );
143146 }
144147
145148 /* *
146149 * @brief Switch off the PA if the headphone in plugged in
147150 * and switch it on again if the headphone is unplugged.
148151 * This method complies with the
149152 */
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 ) {
152156
153157 // 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;
157161
158162 // update if things have stabilized
159163 bool powerActive = !isConnected;
160164 LOGW (" Headphone jack has been %s" ,
161165 isConnected ? " inserted" : " removed" );
162- selfAudioBoard ->setSpeakerActive (powerActive);
166+ self ->setSpeakerActive (powerActive);
163167 }
164168 }
165169 yield ();
@@ -310,7 +314,7 @@ class AudioBoardStream : public I2SCodecStream {
310314 int head_phone = pinHeadphoneDetect ();
311315 if (head_phone != -1 && (getPinID (PinFunction::KEY, 6 ) != head_phone)) {
312316 actions.add (head_phone, actionHeadphoneDetection,
313- AudioActions::ActiveChange);
317+ AudioActions::ActiveChange, this );
314318 }
315319 }
316320
0 commit comments