Skip to content

Commit

Permalink
Pass pins by reference
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Feb 29, 2024
1 parent b3d2477 commit 2a44c1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/AudioBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);}
Expand All @@ -63,7 +63,7 @@ class AudioBoard {
}

protected:
DriverPins pins;
DriverPins* pins;
CodecConfig codec_cfg;
AudioDriver* driver = nullptr;
};
Expand Down
2 changes: 1 addition & 1 deletion src/DriverPins.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2a44c1e

Please sign in to comment.