B4R Question Inline c for DFPlayer library

derez

Expert
Licensed User
Longtime User
I'm having problems with the code I put as inline c for this library (attached).
I get this error log:
sketch\b4r_main.cpp: In function 'void Mp3_set_serial(B4R::Object*)':
b4r_main.cpp:46: error: '__softserial' is not a member of 'b4r_main'
mp3_set_serial(b4r_main::__softserial);
^
sketch\b4r_main.cpp: In function 'void Mp3_set_volume(B4R::Object*)':
b4r_main.cpp:49: error: '__volume' is not a member of 'b4r_main'
mp3_set_volume(b4r_main::__volume);
^
exit status 1
'__softserial' is not a member of 'b4r_main'

The code I use:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private Softserial As SoftwareSerial
...
Private Volume As UInt
...
End sub

Sub AppStart
...
RunNative("Mp3_set_serial", Null)
    Delay(150)
    Volume = 15
    RunNative("Mp3_set_volume", Null)
    Delay(150)
...
End sub

#If C
#include <DFPlayer_Mini_Mp3.h>
void Mp3_set_serial(B4R::Object* o) {
mp3_set_serial(b4r_main::__softserial);
}
void Mp3_set_volume(B4R::Object* o) {
mp3_set_volume(b4r_main::__volume);
}
void Mp3_play(B4R::Object* o) {
mp3_play();
}
#End If

These methods code in the cpp file is:
B4X:
void mp3_set_serial (SoftwareSerial &theSerial) {
    _software_serial = &theSerial;
    send_func = s_send_func;
}

//0x06 set volume 0-30
void mp3_set_volume (uint16_t volume) {
    mp3_send_cmd (0x06, volume);
}

(The code without parameters does not create errors :))...
 

Attachments

  • DFPlayer_Mini_mp3.zip
    14.2 KB · Views: 319

derez

Expert
Licensed User
Longtime User
You need to add a single underscore to the global variables, not two.
:) I don't know where the additional underscore came from but for sure I copied it to the second method....
The volume is solved but the set serial not yet, now I get this:
sketch\b4r_main.cpp: In function 'void Mp3_set_serial(B4R::Object*)':
b4r_main.cpp:46: error: no matching function for call to 'mp3_set_serial(B4R::B4RSoftwareSerial*&)'
mp3_set_serial(b4r_main::_softserial);
^
sketch\b4r_main.cpp:46:38: note: candidates are:
In file included from sketch\b4r_main.cpp:34:0:
D:\Arduino\libraries\DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:78:6: note: void mp3_set_serial(HardwareSerial&)
void mp3_set_serial (HardwareSerial &theSerial);
^
D:\Arduino\libraries\DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:78:6: note: no known conversion for argument 1 from 'B4R::B4RSoftwareSerial*' to 'HardwareSerial&'
D:\Arduino\libraries\DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:81:6: note: void mp3_set_serial(SoftwareSerial&)
void mp3_set_serial (SoftwareSerial &theSerial);
^
D:\Arduino\libraries\DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:81:6: note: no known conversion for argument 1 from 'B4R::B4RSoftwareSerial*' to 'SoftwareSerial&'
exit status 1

In the library there are two functions with the same name, one uses Hardwareserial and the other Softwareserial. I think I need to use only the softwareserial.
B4X:
void mp3_set_serial (HardwareSerial &theSerial) {
    _hardware_serial = &theSerial;
    send_func = h_send_func;
}
 
Upvote 0

derez

Expert
Licensed User
Longtime User
I commented the HW method in the library, now I have "only" this:
sketch\b4r_main.cpp: In function 'void Mp3_set_serial(B4R::Object*)':
b4r_main.cpp:46: error: no matching function for call to 'mp3_set_serial(B4R::B4RSoftwareSerial*&)'
mp3_set_serial(b4r_main::_softserial);
^
sketch\b4r_main.cpp:46:38: note: candidates are:
In file included from sketch\b4r_main.cpp:34:0:
D:\Arduino\libraries\DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:78:6: note: void mp3_set_serial(HardwareSerial&)
void mp3_set_serial (HardwareSerial &theSerial);
^
D:\Arduino\libraries\DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:78:6: note: no known conversion for argument 1 from 'B4R::B4RSoftwareSerial*' to 'HardwareSerial&'
D:\Arduino\libraries\DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:81:6: note: void mp3_set_serial(SoftwareSerial&)
void mp3_set_serial (SoftwareSerial &theSerial);
^
D:\Arduino\libraries\DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:81:6: note: no known conversion for argument 1 from 'B4R::B4RSoftwareSerial*' to 'SoftwareSerial&'
exit status 1
no matching function for call to 'mp3_set_serial(B4R::B4RSoftwareSerial*&)'
 
Upvote 0

derez

Expert
Licensed User
Longtime User
Have you tried it with the code I've posted?
Sorry I didn't see it before.
After changing I get:
sketch\b4r_main.cpp: In function 'void Mp3_set_serial(B4R::Object*)':
b4r_main.cpp:46: error: no matching function for call to 'SoftwareSerial::SoftwareSerial(Stream*&)'
mp3_set_serial((SoftwareSerial)b4r_main::_softserial->getStream()->wrappedStream);
^
sketch\b4r_main.cpp:46:68: note: candidates are:
In file included from sketch\B4RDefines.h:21:0,
from sketch\b4r_main.cpp:1:
C:\Users\dudu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\SoftwareSerial/SoftwareSerial.h:38:4: note: SoftwareSerial::SoftwareSerial(int, int, bool, unsigned int)
SoftwareSerial(int receivePin, int transmitPin, bool inverse_logic = false, unsigned int buffSize = 64);
^
C:\Users\dudu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\SoftwareSerial/SoftwareSerial.h:38:4: note: candidate expects 4 arguments, 1 provided
C:\Users\dudu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\SoftwareSerial/SoftwareSerial.h:35:7: note: constexpr SoftwareSerial::SoftwareSerial(const SoftwareSerial&)
class SoftwareSerial : public Stream
^
C:\Users\dudu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\SoftwareSerial/SoftwareSerial.h:35:7: note: no known conversion for argument 1 from 'Stream*' to 'const SoftwareSerial&'
exit status 1
no matching function for call to 'SoftwareSerial::SoftwareSerial(Stream*&)'
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It should be:
B4X:
#If C
#include <DFPlayer_Mini_Mp3.h>
void Mp3_set_serial(B4R::Object* o) {
   SoftwareSerial* soft = (SoftwareSerial*)b4r_main::_softserial->getStream()->wrappedStream;
   mp3_set_serial(*soft);
}
void Mp3_set_volume(B4R::Object* o) {
   mp3_set_volume(b4r_main::_volume);
}
void Mp3_play(B4R::Object* o) {
   mp3_play();
}
#End If
 
Upvote 0

derez

Expert
Licensed User
Longtime User
I want to use the following method which has two arguments (from the two optional formats):
B4X:
void mp3_send_cmd (uint8_t cmd, uint16_t arg) {
    send_buf[3] = cmd;
    fill_uint16_bigend ((send_buf+5), arg);
    mp3_fill_checksum ();
    send_func ();
}

void mp3_send_cmd (uint8_t cmd) {
    send_buf[3] = cmd;
    fill_uint16_bigend ((send_buf+5), 0);
    mp3_fill_checksum ();
    send_func ();
}

I put this code:
B4X:
void Mp3_send_cmd(B4R::Object* o) {
mp3_send_cmd(b4r_main::_cmd, b4r_main::_arg);
}
Where Cmd as Byte and Arg as Uint are defined as globals, but get this error:
sketch\b4r_main.cpp: In function 'void Mp3_send_cmd(B4R::Object*)':
b4r_main.cpp:43: error: 'mp3_send_cmd' was not declared in this scope
mp3_send_cmd(b4r_main::_cmd, b4r_main::_arg);
^
exit status 1
'mp3_send_cmd' was not declared in this scope

What is wrong ?
 
Last edited:
Upvote 0

derez

Expert
Licensed User
Longtime User
I changed the commented line in the h file to uncommented: void mp3_send_cmd (uint8_t cmd, uint16_t arg);
Now it runs without errors and it works :)
 
Last edited:
Upvote 0
Top