diff --git a/main.c b/main.c index 34da80d..3a32a10 100644 --- a/main.c +++ b/main.c @@ -36,10 +36,10 @@ { struct mpd_connection *conn; unsigned int tries = 0; - conn = mpd_connection_new("/var/run/mpd/socket", 0, 0); + conn = mpd_connection_new("/run/mpd.socket", 0, 0); while ((mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) && (tries < 60)) { mpd_connection_free(conn); - conn = mpd_connection_new("/var/run/mpd/socket", 0, 0); + conn = mpd_connection_new("/run/mpd.socket", 0, 0); tries++; sleep(1); } @@ -77,59 +77,66 @@ while(!success) { switch(last_pin_pressed) { case PLAYPAUSE_PIN: - success = mpd_run_toggle_pause(conn); - break; + success = mpd_run_toggle_pause(conn); + printf("play/pause %d\n", success); + break; case ONOFF_PIN: - if (playing) { - success = mpd_run_stop(conn); - playing = false; - } else { - success = mpd_run_play(conn); - playing = true; - } - if (success) { - playing = !playing; - } - break; + if (playing) { + success = mpd_run_stop(conn); + playing = false; + } else { + success = mpd_run_play(conn); + playing = true; + } + printf("on/off %d\n", success); + if (success) { + playing = !playing; + } + break; case FASTFORWARD_PIN: - success = mpd_run_next(conn); - break; + success = mpd_run_next(conn); + printf("ff %d\n", success); + break; case REWIND_PIN: - success = mpd_run_previous(conn); - break; + success = mpd_run_previous(conn); + printf("rw %d\n", success); + break; case VOLUMEDOWN_PIN: - success = mpd_run_change_volume(conn, -10); - break; + success = mpd_run_change_volume(conn, -10); + printf("vol- %d\n", success); + break; case VOLUMEUP_PIN: - success = mpd_run_change_volume(conn, 10); - break; + success = mpd_run_change_volume(conn, 10); + printf("vol+ %d\n", success); + break; default: - success = true; - break; + success = true; + break; + } + if (!success) { + switch(mpd_connection_get_error(conn)) { + case MPD_ERROR_SERVER: + case MPD_ERROR_ARGUMENT: + case MPD_ERROR_STATE: + case MPD_ERROR_MALFORMED: + mpd_connection_clear_error(conn); + printf("Clear error, try again.\n"); + break; + case MPD_ERROR_TIMEOUT: + case MPD_ERROR_CLOSED: + mpd_connection_free(conn); + conn = mpd_connection_new("/run/mpd.socket", 0, 0); + if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) { + mpd_connection_free(conn); + return EXIT_FAILURE; + } + printf("Reconnected, try again.\n"); + break; + default: + return EXIT_FAILURE; + } } } - if (!success) { - switch(mpd_connection_get_error(conn)) { - case MPD_ERROR_SERVER: - case MPD_ERROR_ARGUMENT: - case MPD_ERROR_STATE: - case MPD_ERROR_MALFORMED: - mpd_connection_clear_error(conn); - break; - case MPD_ERROR_TIMEOUT: - case MPD_ERROR_CLOSED: - mpd_connection_free(conn); - conn = mpd_connection_new("/var/run/mpd/socket", 0, 0); - if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) { - mpd_connection_free(conn); - return EXIT_FAILURE; - } - break; - default: - return EXIT_FAILURE; - } - } - } mpd_connection_free(conn);