-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMyCobotSaver.cpp
176 lines (146 loc) · 4.12 KB
/
MyCobotSaver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include "MyCobotSaver.h"
#if defined MyCobot_M5
MyCobotSaver::MyCobotSaver()
{
}
void MyCobotSaver::listDir(fs::FS &fs, const char *dirname, uint8_t levels)
{
Serial.printf("Listing directory: %s\r\n", dirname);
File root = fs.open(dirname);
if (!root) {
Serial.println("- failed to open directory");
return;
}
if (!root.isDirectory()) {
Serial.println(" - not a directory");
return;
}
File file = root.openNextFile(); //less 8 coloumns
while (file) {
if (file.isDirectory()) {
Serial.print(" DIR : ");
Serial.println(file.name());
if (levels) {
listDir(fs, file.name(), levels - 1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print("\tSIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
void MyCobotSaver::writeFile(fs::FS &fs, const char *path, const char *message)
{
Serial.printf("Writing file: %s\r\n", path);
File file = fs.open(path, FILE_WRITE);
if (!file) {
Serial.println("- failed to open file for writing");
return;
}
if (file.print(message)) {
Serial.println("- file written");
} else {
Serial.println("- frite failed");
}
}
void MyCobotSaver::appendFile(fs::FS &fs, const char *path, const char *message)
{
File file = fs.open(path, FILE_APPEND);
if (!file) {
return;
}
file.print(message);
}
void MyCobotSaver::deleteFile(fs::FS &fs, const char *path)
{
Serial.printf("Deleting file: %s\r\n", path);
if (fs.remove(path)) {
Serial.println("- file deleted");
} else {
Serial.println("- delete failed");
}
}
void MyCobotSaver::readFile(fs::FS &fs, const char *path)
{
File file = fs.open(path);
if (!file || file.isDirectory()) {
Serial.println("- failed to open file for reading");
return;
}
String this_line = "";
while (file.available()) {
char this_char = char(file.read());
this_line += this_char;
if (this_char == '\n') {
saver_angles_enc jae_this;
jae_this = processStringIntoInts(this_line);
this_line = "";
}
}
}
void MyCobotSaver::MyPalletizerreadFile(fs::FS &fs, const char *path)
{
File file = fs.open(path);
if (!file || file.isDirectory()) {
Serial.println("- failed to open file for reading");
return;
}
String this_line = "";
while (file.available()) {
char this_char = char(file.read());
this_line += this_char;
if (this_char == '\n') {
saver_MyPalletizer_angles_enc jae_this;
jae_this = MyPalletizerprocessStringIntoInts(this_line);
this_line = "";
}
}
}
MyCobotSaver::saver_angles_enc MyCobotSaver::processStringIntoInts(
String string_input)
{
saver_angles_enc sae;
int data_index = 0;
String data_angle_string = "";
for (int i = 0; string_input[i] != '\n'; i++) {
if (string_input[i] == ',') {
if ((data_index < 6) && (i > 1)) {
sae.joint_angle[data_index] = data_angle_string.toInt();
} else {
break;
}
data_angle_string = "";
data_index ++;
continue;
} else {
data_angle_string += string_input[i];
}
}
return sae;
}
MyCobotSaver::saver_MyPalletizer_angles_enc
MyCobotSaver::MyPalletizerprocessStringIntoInts(String string_input)
{
saver_MyPalletizer_angles_enc sae;
int data_index = 0;
String data_angle_string = "";
for (int i = 0; string_input[i] != '\n'; i++) {
if (string_input[i] == ',') {
if ((data_index < 4) && (i > 1)) {
sae.joint_angle[data_index] = data_angle_string.toInt();
} else {
break;
}
data_angle_string = "";
data_index ++;
continue;
} else {
data_angle_string += string_input[i];
}
}
return sae;
}
#endif