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:

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: 320

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:

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:
 
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:
 
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:

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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…