From ffc9accb6ca0a901eee480403492813dbab5180e Mon Sep 17 00:00:00 2001 From: Yannik Enss Date: Sat, 13 Jul 2019 21:33:43 +0200 Subject: [PATCH] prepare for tracking volume and play/pause locally --- mpdclient.ino | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/mpdclient.ino b/mpdclient.ino index df73296..30f3576 100644 --- a/mpdclient.ino +++ b/mpdclient.ino @@ -29,6 +29,11 @@ struct song_info { String artist; }; +struct player_info { + int volume; + bool is_playing; +}; + enum btn_flag { BTN_NONE, BTN_VOLUP, BTN_VOLDN, BTN_PAUSE, BTN_NEXT }; btn_flag flag = BTN_NONE; @@ -219,9 +224,10 @@ void volume_down() { send_command("volume -1"); } -int get_volume() { +int get_player_info(player_info* player_info) { WiFiClient client; String vol_str; + String state_str; if (client.connect(MPDHOST, MPDPORT)) { Serial.println("connected"); @@ -235,6 +241,9 @@ int get_volume() { if (line.startsWith("volume: ")) { vol_str = line.substring(8); } + else if (line.startsWith("state: ")) { + state_str = line.substring(7); + } else if (line.equals("OK")) { client.stop(); } @@ -247,10 +256,13 @@ int get_volume() { else { display_error("mpd connect failed"); client.stop(); - return -1; + return 1; } - return vol_str.toInt(); + player_info->volume = vol_str.toInt(); + player_info->is_playing = state_str.equals("play"); + + return 0; } int get_song_info(song_info* song_info) { @@ -290,7 +302,11 @@ int get_song_info(song_info* song_info) { } void display_volume() { - int volume = get_volume(); + player_info pi; + if (get_player_info(&pi)) + return; + + int volume = pi.volume; display.clearDisplay(); display.drawBitmap(0, 0, volume_icon, 32, 32, WHITE);