[chronojump/michrolab] Michrolab. Added get file through the serial.



commit 1d3051c433239435d00e4b416892e589b33bd66b
Author: xpadulles <x padulles gmail com>
Date:   Thu Oct 13 12:44:09 2022 +0200

    Michrolab. Added get file through the serial.

 arduino/michrolab/michrolab.ino | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
---
diff --git a/arduino/michrolab/michrolab.ino b/arduino/michrolab/michrolab.ino
index 43aeaa01e..ca7871085 100644
--- a/arduino/michrolab/michrolab.ino
+++ b/arduino/michrolab/michrolab.ino
@@ -680,6 +680,8 @@ void serialEvent() {
     File dir = SD.open("/");
     printDirectory(dir, 2);
     dir.close();
+  } else if (commandString == "getFile") {
+    sendFile(parameters);
   } else if (commandString == "setGroup") {
     setGroup(parameters);
   } else if (commandString == "getGroup") {
@@ -2285,6 +2287,28 @@ void getRaceAnalyzerDynamics()
   }
 }
 
+void sendFile(String fullFileName)
+{
+  //Extracting the text before the ";"
+  fullFileName = fullFileName.substring(0, fullFileName.indexOf(";"));
+  Serial.println("Retrieving file \"" + fullFileName + "\"");
+  if (! SD.exists(fullFileName.c_str()) )
+  {
+    Serial.println("File not found");
+    return;
+  } 
+  File file = SD.open(fullFileName, FILE_READ);
+  //Serial.println(file.name());
+  unsigned long int fileSize = file.size();
+  unsigned long int pos = 0;
+  while (pos < fileSize)
+  {
+    Serial.print((char)file.read());
+    pos++;
+  }
+  file.close();
+}
+
 /*
 void encoderBChange()
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]