ESP32-A2DP Problem understanding the use of 'const uint8_t*'
Posted: Fri Sep 09, 2022 6:53 pm
Hi,
I start by saying "Sorry" and that's for the lack of knowledge how you use forums to ask for help.
I know that I should precent my code in a certain way, but I'm an old fart, and don't get this advanced internet things..
New to this type of programming and should call my self a "Copy & Paste" programmer. I have only used Basic, VB and some Python before I got started with the ESP32.
Using Mr. Pschatzmann's ESP32-A2DP library, ( https://github.com/pschatzmann/ESP32-A2DP )
it's very easy to use the examples and I got a working "Bluetooth" streamer playing to my SPDIF input on the stereo direct from the ESP32.
Now to my problem...
I added a small LCD display (4x20) to show the Song, Artist and Album information.
And going trough the code and using the terminal for debug/check, I found that I could also access the time off the track.
My problem is that I can call the data and I can print it out in Serial as text with "Serial.printf("%s\n", data);" but I need to use the data in an calculation, how do I extract/convert it to an int, or char array?
The call to get the data is this:
void avrc_metadata_callback(uint8_t data1, const uint8_t *data2) {
...
//I can use the switch command and look at the "data1" and from that ID I can select what I like to send to the LCD.
//But to use this on the LCD (or in the serial terminal) i need to use this:
switch (data1) {
case 1: // Print the song name
//Serial.printf("Song: 0x%x, %s\n", data1, data2);
Serial.print("Song: ");
Serial.printf("%s\n", data2);
break;
case 2: // Print the Artist name
//Serial.printf("Artist: 0x%x, %s\n", data1, data2);
Serial.print("Artist: ");
Serial.printf("%s\n", data2);
break;
case 4: // Print the Album name
//Serial.printf("Album 0x%x, %s\n", data1, data2);
Serial.print("Album: ");
Serial.printf("%s\n", data2);
break;
case 0x40: // Print the song length.
//Serial.printf("Time: 0x%x, %s\n", data1, data2);
Serial.print("Time: ");
Serial.printf("%s\n", data2);
break;
default:
break;
}
}
So the thing I can't get around is how to use this ( Serial.printf("%s\n", data2); ) info in the data2 and get that into a variable that I can use in calculations...
I have spent several days trying the help files, checking webpages and so on...
Please... can anyone get me to understand this...
Best regards,
Niklas.
I start by saying "Sorry" and that's for the lack of knowledge how you use forums to ask for help.
I know that I should precent my code in a certain way, but I'm an old fart, and don't get this advanced internet things..
New to this type of programming and should call my self a "Copy & Paste" programmer. I have only used Basic, VB and some Python before I got started with the ESP32.
Using Mr. Pschatzmann's ESP32-A2DP library, ( https://github.com/pschatzmann/ESP32-A2DP )
it's very easy to use the examples and I got a working "Bluetooth" streamer playing to my SPDIF input on the stereo direct from the ESP32.
Now to my problem...
I added a small LCD display (4x20) to show the Song, Artist and Album information.
And going trough the code and using the terminal for debug/check, I found that I could also access the time off the track.
My problem is that I can call the data and I can print it out in Serial as text with "Serial.printf("%s\n", data);" but I need to use the data in an calculation, how do I extract/convert it to an int, or char array?
The call to get the data is this:
void avrc_metadata_callback(uint8_t data1, const uint8_t *data2) {
...
//I can use the switch command and look at the "data1" and from that ID I can select what I like to send to the LCD.
//But to use this on the LCD (or in the serial terminal) i need to use this:
switch (data1) {
case 1: // Print the song name
//Serial.printf("Song: 0x%x, %s\n", data1, data2);
Serial.print("Song: ");
Serial.printf("%s\n", data2);
break;
case 2: // Print the Artist name
//Serial.printf("Artist: 0x%x, %s\n", data1, data2);
Serial.print("Artist: ");
Serial.printf("%s\n", data2);
break;
case 4: // Print the Album name
//Serial.printf("Album 0x%x, %s\n", data1, data2);
Serial.print("Album: ");
Serial.printf("%s\n", data2);
break;
case 0x40: // Print the song length.
//Serial.printf("Time: 0x%x, %s\n", data1, data2);
Serial.print("Time: ");
Serial.printf("%s\n", data2);
break;
default:
break;
}
}
So the thing I can't get around is how to use this ( Serial.printf("%s\n", data2); ) info in the data2 and get that into a variable that I can use in calculations...
I have spent several days trying the help files, checking webpages and so on...
Please... can anyone get me to understand this...
Best regards,
Niklas.