From eacb325b3440ceb7a2e447c8df7921521d02920a Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Sat, 4 Jul 2015 12:51:58 +0200 Subject: [PATCH] [ES] Added handleCommand method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-óff-by: Jim Martens --- es/blatt6/uebung6-1/uebung6-1.ino | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/es/blatt6/uebung6-1/uebung6-1.ino b/es/blatt6/uebung6-1/uebung6-1.ino index 923e8c7..4f3b2a0 100644 --- a/es/blatt6/uebung6-1/uebung6-1.ino +++ b/es/blatt6/uebung6-1/uebung6-1.ino @@ -337,3 +337,38 @@ const char* readString(File file) return ""; } } + +/** + * Handles the command. + * + * @param String command + */ +void handleCommand(String command) +{ + String existCommand = "doesFileExist"; + String showCommand = "showFile"; + + // determine command and parameter + int indexP1 = command.indexOf('('); + int indexP2 = command.indexOf(')'); + String command2 = command; + command2.remove(indexP1); + + if (command2 != existCommand && command2 != showCommand) { + Serial.println("Use doesFileExist() or showFile()"); + return; + } + + command.remove(indexP2); + String parameter = command.substring(indexP1 + 1); + + if (command2 == existCommand) { + bool fileExists = SD.exists(parameter); + Serial.print("Does file exist? "); + Serial.println(fileExists ? "Yes" : "No"); + } + + if (command2 == showCommand) { + showFile(parameter); + } +}