Open lmore377 opened 3 years ago
Great Idea to get these commands built-in. I've been snowed under by work recently But I can see the light again and will add this to the to-do list.
I tested but only "play","stop" and "pause" functions worked.
here's my loop()
if(Serial.available()){
//read until a terminator. after this point there should only be numbers
command = Serial.readStringUntil('#');
if(command.equals("play")){
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_PLAY, ESP_AVRC_PT_CMD_STATE_PRESSED);
Serial.println("play");
}
if(command.equals("pause")){
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_PAUSE, ESP_AVRC_PT_CMD_STATE_PRESSED);
Serial.println("pause");
}
if(command.equals("FF")){
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_FAST_FORWARD, ESP_AVRC_PT_CMD_STATE_PRESSED);
Serial.println("fast_forward");
}
if(command.equals("RW")){
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_REWIND, ESP_AVRC_PT_CMD_STATE_PRESSED);
Serial.println("rewind");
}
if(command.equals("stop")){
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_STOP, ESP_AVRC_PT_CMD_STATE_PRESSED);
Serial.println("stop");
}
if(command.equals("forward")){
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_FORWARD, ESP_AVRC_PT_CMD_STATE_PRESSED);
Serial.println("forward");
}
if(command.equals("backward")){
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_BACKWARD, ESP_AVRC_PT_CMD_STATE_PRESSED);
Serial.println("backward");
}
}
@biglee991228 fast forward and rewind didn't work for me either but everything else does. Have you tried using a different app and/or device?
@lmore377
I got it!
if(Serial.available()){
//read until a terminator. after this point there should only be numbers
command = Serial.readStringUntil('#');
if(command.equals("play")){
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_PLAY, ESP_AVRC_PT_CMD_STATE_PRESSED);
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_PLAY, ESP_AVRC_PT_CMD_STATE_RELEASED);
Serial.println("play");
}
if(command.equals("pause")){
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_PAUSE, ESP_AVRC_PT_CMD_STATE_PRESSED);
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_PAUSE, ESP_AVRC_PT_CMD_STATE_RELEASED);
Serial.println("pause");
}
if(command.equals("stop")){
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_STOP, ESP_AVRC_PT_CMD_STATE_PRESSED);
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_STOP, ESP_AVRC_PT_CMD_STATE_RELEASED);
Serial.println("stop");
}
if(command.equals("forward")){
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_FORWARD, ESP_AVRC_PT_CMD_STATE_PRESSED);
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_FORWARD, ESP_AVRC_PT_CMD_STATE_RELEASED);
Serial.println("forward");
}
if(command.equals("backward")){
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_BACKWARD, ESP_AVRC_PT_CMD_STATE_PRESSED);
esp_avrc_ct_send_passthrough_cmd(0, ESP_AVRC_PT_CMD_BACKWARD, ESP_AVRC_PT_CMD_STATE_RELEASED);
Serial.println("backward");
}
}
don't forget "RELEASED“!
My device doesn't seem to need/respond to the released commands but I'll keep that in mind if something pops up
my phone can be controlled by my chevey car (linux OS),so it must can be controlled by the passthrough command from ESP32. because the AVRCP profile is the same thing.
Great idea. I have 3 buttons on my EPS32 board which seems like a perfect use case for that!
Is it somehow possible to detect, if the device is connected?
for checking connection events see here . I could add a variable to the class that monitors this connection.
That would be pretty cool, cause my programing skills are just on a basic level …
What about "receiving" volume control commands? Is that possible (assuming my streaming device sends them)?
I figured out how to send some AVRCP commands. Basically you just run this, replacing
<command>
with one of the commands below.esp_avrc_ct_send_passthrough_cmd(0, <command>, ESP_AVRC_PT_CMD_STATE_PRESSED);
You can see all the commands here but it seems like only the ones below work (I tried just the hex codes for other commands but my phone didn't respond to any except these. I don't know if they're not supported by the avrc library or my phone).
You can see more info about that specific method here.