yei

Dependencies:   interface mbed enc_1multi calPID motorout KondoServoLibrary

Fork of cat18_operate by Catch the GIANT Caplico!

Revision:
20:13934809e117
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/filesystem/filesystem.cpp	Mon Aug 27 03:47:21 2018 +0000
@@ -0,0 +1,69 @@
+#include "filesystem.h"
+#include "mbed.h"
+#include "workinfo.h"
+#include "debug.h"
+
+LocalFileSystem local("local");
+const char kFileName[100] = "local/workdata.txt";
+const char kComment[][100] = {"pattern", "workexist","boxexist"};
+void FileSave()
+{
+    DEBUG("FileSave() start\r\n");
+    remove(kFileName);
+    FILE *fp;
+    if((fp = fopen(kFileName, "w")) == NULL) {
+        DEBUG("error : FileSave()");
+        return;
+    }
+    fprintf(fp, "%s\r\n", kComment[0]);
+    fprintf(fp, "%d\r\n", now_pattern);
+    fprintf(fp, "%s\r\n", kComment[1]);
+    for(int i = 0; i < kWorkAreaNum + kCommonAreaNum; i++) {
+        if(work[i].is_exist == 0) fprintf(fp, "%d\r\n", i);
+    }
+    fprintf(fp, "%s\r\n", kComment[2]);
+    for(int i = 0; i < kBoxNum; i++) {
+        if(shootingbox[i].is_exist == 1) fprintf(fp, "%d\r\n%d\r\n", i, shootingbox[i].color);
+    }
+    fclose(fp);
+    DEBUG("FileSave() finish\r\n");
+}
+void FileLoad()
+{
+    DEBUG("FileLoad() start\r\n");
+    FILE *fp;
+    if((fp = fopen(kFileName, "r")) == NULL) {
+        return;
+    }
+    int old_num = 0;
+    while(1) {
+        char comment[100] = {};
+        char *error;
+        int comment_num = 0;
+        if(fscanf(fp,"%s",comment) == -1) {
+            DEBUG("FileLoad() finish\r\n");
+            return;
+        }
+        int num = strtod(comment, &error);
+        if (*error != '\0') {
+            for(int i = 0; i < sizeof(kComment)/sizeof(kComment[0]); i++) {
+                if(strcmp(comment, kComment[i]) == 0) comment_num = i;
+            }
+        } else {
+            switch(comment_num) {
+                case 0:
+                    now_pattern = (Pattern)num;
+                    break;
+                case 1:
+                    work[num].is_exist = 0;
+                    break;
+                case 2:
+                    static int is_boxnum = 0;
+                    is_boxnum = !is_boxnum;
+                    if(is_boxnum == 1) shootingbox[num].is_exist = 0;
+                    else shootingbox[old_num].color = (Color)num;
+            }
+        }
+        old_num = num;
+    }
+}