yei

Dependencies:   interface mbed enc_1multi calPID motorout KondoServoLibrary

Fork of cat18_operate by Catch the GIANT Caplico!

Committer:
yuto17320508
Date:
Sun Sep 09 00:18:39 2018 +0000
Revision:
45:51ab3ca47228
Parent:
23:f45eb02433a5
a;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimizuta 22:4f1f8dc1705a 1 #include "filesystem.h"
shimizuta 22:4f1f8dc1705a 2 #include "mbed.h"
shimizuta 22:4f1f8dc1705a 3 #include "workinfo.h"
shimizuta 22:4f1f8dc1705a 4 #include "debug.h"
shimizuta 22:4f1f8dc1705a 5
shimizuta 22:4f1f8dc1705a 6 LocalFileSystem local("local");
shimizuta 22:4f1f8dc1705a 7 const char kFileName[100] = "/local/workdata.txt";
shimizuta 22:4f1f8dc1705a 8 const char kComment[][100] = {"pattern", "work_not_exist","box_exist_and_color"};
shimizuta 22:4f1f8dc1705a 9 void FileSave()
shimizuta 22:4f1f8dc1705a 10 {
shimizuta 22:4f1f8dc1705a 11 FILE *fp;
shimizuta 22:4f1f8dc1705a 12 DEBUG("FileSave() start\r\n");
shimizuta 22:4f1f8dc1705a 13 if((fp = fopen(kFileName, "w")) == NULL) {
shimizuta 23:f45eb02433a5 14 DEBUG("error : FileSave()\r\n");
shimizuta 22:4f1f8dc1705a 15 return;
shimizuta 22:4f1f8dc1705a 16 }
shimizuta 22:4f1f8dc1705a 17 fprintf(fp, "%s\r\n", kComment[0]);
shimizuta 22:4f1f8dc1705a 18 fprintf(fp, "%d\r\n", now_pattern);
shimizuta 22:4f1f8dc1705a 19 fprintf(fp, "%s\r\n", kComment[1]);
shimizuta 22:4f1f8dc1705a 20 for(int i = 0; i < kWorkAreaNum + kCommonAreaNum; i++) {
shimizuta 22:4f1f8dc1705a 21 if(work[i].is_exist == 0) fprintf(fp, "%d\r\n", i);
shimizuta 22:4f1f8dc1705a 22 }
shimizuta 22:4f1f8dc1705a 23 fprintf(fp, "%s\r\n", kComment[2]);
shimizuta 22:4f1f8dc1705a 24 for(int i = 0; i < kBoxNum; i++) {
shimizuta 22:4f1f8dc1705a 25 if(shootingbox[i].is_exist == 1) fprintf(fp, "%d\r\n%d\r\n", i, shootingbox[i].color);
shimizuta 22:4f1f8dc1705a 26 }
shimizuta 22:4f1f8dc1705a 27 fclose(fp);
shimizuta 22:4f1f8dc1705a 28 DEBUG("FileSave() finish\r\n");
shimizuta 22:4f1f8dc1705a 29
shimizuta 22:4f1f8dc1705a 30 }
shimizuta 22:4f1f8dc1705a 31 void FileLoad()
shimizuta 22:4f1f8dc1705a 32 {
shimizuta 22:4f1f8dc1705a 33 DEBUG("FileLoad() start\r\n");
shimizuta 22:4f1f8dc1705a 34 FILE *fp;
shimizuta 22:4f1f8dc1705a 35 if((fp = fopen(kFileName, "r")) == NULL) {
shimizuta 23:f45eb02433a5 36 DEBUG("There is no file\r\n");
shimizuta 22:4f1f8dc1705a 37 return;
shimizuta 22:4f1f8dc1705a 38 }
shimizuta 22:4f1f8dc1705a 39 int old_num = 0;
shimizuta 22:4f1f8dc1705a 40 int comment_num = 0;
shimizuta 22:4f1f8dc1705a 41 while(1) {
shimizuta 22:4f1f8dc1705a 42 char comment[100] = {};
shimizuta 22:4f1f8dc1705a 43 char *error;
shimizuta 22:4f1f8dc1705a 44 if(fscanf(fp,"%s",comment) == -1) {
shimizuta 22:4f1f8dc1705a 45 DEBUG("FileLoad() finish\r\n");
shimizuta 23:f45eb02433a5 46 fclose(fp);
shimizuta 22:4f1f8dc1705a 47 return;
shimizuta 22:4f1f8dc1705a 48 }
shimizuta 22:4f1f8dc1705a 49 int num = strtod(comment, &error);
shimizuta 22:4f1f8dc1705a 50 if (*error != '\0') {
shimizuta 22:4f1f8dc1705a 51 DEBUG("%s\r\n",error);
shimizuta 22:4f1f8dc1705a 52 for(int i = 0; i < sizeof(kComment)/sizeof(kComment[0]); i++) {
shimizuta 22:4f1f8dc1705a 53 if(strcmp(comment, kComment[i]) == 0) comment_num = i;
shimizuta 22:4f1f8dc1705a 54 }
shimizuta 22:4f1f8dc1705a 55 } else {
shimizuta 22:4f1f8dc1705a 56 switch(comment_num) {
shimizuta 22:4f1f8dc1705a 57 case 0:
shimizuta 22:4f1f8dc1705a 58 DEBUG("pattern is %d\r\n",num);
shimizuta 22:4f1f8dc1705a 59 now_pattern = (Pattern)num;
shimizuta 22:4f1f8dc1705a 60 break;
shimizuta 22:4f1f8dc1705a 61 case 1:
shimizuta 22:4f1f8dc1705a 62 DEBUG("work %d is not exist\r\n",num);
shimizuta 22:4f1f8dc1705a 63 work[num].is_exist = 0;
shimizuta 22:4f1f8dc1705a 64 break;
shimizuta 22:4f1f8dc1705a 65 case 2:
shimizuta 22:4f1f8dc1705a 66 static int is_boxnum = 0;
shimizuta 22:4f1f8dc1705a 67 is_boxnum = !is_boxnum;
shimizuta 23:f45eb02433a5 68 if(is_boxnum == 1) shootingbox[num].is_exist = 1;
shimizuta 22:4f1f8dc1705a 69 else shootingbox[old_num].color = (Color)num;
shimizuta 22:4f1f8dc1705a 70 }
shimizuta 22:4f1f8dc1705a 71 }
shimizuta 22:4f1f8dc1705a 72 old_num = num;
shimizuta 22:4f1f8dc1705a 73 }
shimizuta 22:4f1f8dc1705a 74 }