From e87fae308b4ca786047c8fd59d2df88c1108a3ff Mon Sep 17 00:00:00 2001
From: Stefan Gehr <stefan.kerman.gehr@fau.de>
Date: Thu, 13 Oct 2022 16:25:49 +0200
Subject: [PATCH] add option to respect busy pin in playFile

---
 solarpump/mp3.h   | 2 +-
 solarpump/mp3.ino | 8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/solarpump/mp3.h b/solarpump/mp3.h
index bcc64ed..038879b 100644
--- a/solarpump/mp3.h
+++ b/solarpump/mp3.h
@@ -2,7 +2,7 @@
 #define MP3_H
 
 void mp3Setup(void);
-void playFile(uint8_t fileNumber);
+void playFile(uint8_t fileNumber, bool respectBusyPin);
 void mp3Loop(void);
 void playFileQueue(uint8_t fileNumber);
 
diff --git a/solarpump/mp3.ino b/solarpump/mp3.ino
index a58ec6d..3436883 100644
--- a/solarpump/mp3.ino
+++ b/solarpump/mp3.ino
@@ -14,8 +14,12 @@ void mp3Setup(void) {
 	//mp3.sendCommand(CMD_SEL_DEV, 0, 2); //select sd-card
 }
 
-// immediately play a file, ignoring any queue or BUSY pin
-void playFile(uint8_t fileNumber) {
+// immediately play a file
+void playFile(uint8_t fileNumber, bool respectBusyPin) {
+	// do nothing if we want to wait for the BUSY pin
+	if (respectBusyPin && digitalRead(MP3BUSY)) {
+		return;
+	}
 	mp3.write(fileNumber);
 }
 
-- 
GitLab