From 2a44c1e853af837c7d56a56d47f40375b9fdee30 Mon Sep 17 00:00:00 2001 From: Phil Schatzmann Date: Thu, 29 Feb 2024 16:28:48 +0100 Subject: [PATCH] Pass pins by reference --- src/AudioBoard.h | 16 ++++++++-------- src/DriverPins.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/AudioBoard.h b/src/AudioBoard.h index e6d769b..65fbe86 100644 --- a/src/AudioBoard.h +++ b/src/AudioBoard.h @@ -12,22 +12,22 @@ namespace audio_driver { */ class AudioBoard { public: - AudioBoard(AudioDriver *driver, DriverPins pins=NoPins) { + AudioBoard(AudioDriver *driver, DriverPins* pins=&NoPins) { this->pins = pins; this->driver = driver; } - AudioBoard(AudioDriver &driver, DriverPins pins=NoPins) { - this->pins = pins; + AudioBoard(AudioDriver &driver, DriverPins& pins=NoPins) { + this->pins = &pins; this->driver = &driver; } bool begin(){ AD_LOGD("AudioBoard::pins::begin"); - bool result_pins = pins.begin(); + bool result_pins = pins->begin(); AD_LOGD("AudioBoard::pins::begin::returned:%s", result_pins ? "true" : "false"); AD_LOGD("AudioBoard::driver::begin"); - bool result_driver = driver->begin(codec_cfg, pins); + bool result_driver = driver->begin(codec_cfg, *pins); AD_LOGD("AudioBoard::driver::begin::returned:%s", result_driver ? "true" : "false"); setVolume(DRIVER_DEFAULT_VOLUME); AD_LOGD("AudioBoard::volume::set"); @@ -47,13 +47,13 @@ class AudioBoard { } bool end(void) { - pins.end(); + pins->end(); return driver->end(); } bool setMute(bool enable) { return driver->setMute(enable); } bool setVolume(int volume) { return driver->setVolume(volume); } int getVolume() { return driver->getVolume(); } - DriverPins& getPins() { return pins; } + DriverPins& getPins() { return *pins; } bool setPAPower(bool enable) { return driver->setPAPower(enable); } /// set volume for adc: this is only supported on some defined codecs bool setInputVolume(int volume) {return driver->setInputVolume(volume);} @@ -63,7 +63,7 @@ class AudioBoard { } protected: - DriverPins pins; + DriverPins* pins; CodecConfig codec_cfg; AudioDriver* driver = nullptr; }; diff --git a/src/DriverPins.h b/src/DriverPins.h index c690831..678ebfc 100644 --- a/src/DriverPins.h +++ b/src/DriverPins.h @@ -331,7 +331,7 @@ class DriverPins { // setup i2c AD_LOGD("DriverPins::begin::I2C"); for (auto &tmp : i2c) { - AD_LOGD("DriverPins::begin::I2C::begin"); + AD_LOGD("DriverPins::begin::I2C port:%d", tmp.port); result &= tmp.begin(); } return result;