SnijderC / dyplayer

Abstracton for DY-XXXX mp3 player modules over UART.
Other
107 stars 29 forks source link

Using the DYPlayer as an instance in another object instance #62

Open sbarabe opened 4 months ago

sbarabe commented 4 months ago

Hi, in an arduino sketch on Platformio, I'm trying to create an instance of the DYPlayer in an ohter instance.

I am using Nano Every and the DYPlayerArduino.h

Exemple:

> class AudioPlayer
> {
> private:
>     DY::Player _dyPlayer;
> public:
>     Player(Stream *serial):_dyPlayer(serial){}
> };

Then in the main sketch I'm using:

AudioPlayer(&Serial) ;

ou

AudioPlayer(&SoftSerial)

but I keep having those messages at compile:

no instance of constructor "DY::Player::Player" matches the argument list argument types are: (arduino::Stream ) conversion` from 'arduino::Stream' to 'const DY::Player' is ambiguous

Do you think it's possible to fix this ? Thank you !

sbarabe commented 4 months ago

Ok here is how I solve my problem. The only thig I'm not sure is if the constructor with no argument ( Player_DY::Player_DY() : _player(){};) really works and if it is initiating a DYPlayer with hardware serial ?

`

#include <Arduino.h>
#include <DYPlayerArduino.h>
#include <SoftwareSerial.h>

SoftwareSerial serial(4, 5);

class Player_DY
{
private:
  DY::Player _player;

public:
  Player_DY::Player_DY(SoftwareSerial &serial) : _player(&serial){};
  Player_DY::Player_DY(HardwareSerial &serial) : _player(&serial){};
  Player_DY::Player_DY() : _player(){};
  void begin()
  {
    _player.begin();
  }
};

Player_DY playerSW(serial);
Player_DY playerHW(Serial1);
Player_DY player;

void setup()
{
player.begin();
playerSW.begin();
playerHW.begin();
}

void loop()
{ }

`