Funciona todo sin modulo_imu
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
// Simulating Arduino String
|
||||
class String {
|
||||
std::string str;
|
||||
public:
|
||||
String(const char* s) : str(s) {}
|
||||
int length() const { return str.length(); }
|
||||
char charAt(int i) const { return str[i]; }
|
||||
int indexOf(char c, int start) const {
|
||||
size_t pos = str.find(c, start);
|
||||
return pos == std::string::npos ? -1 : pos;
|
||||
}
|
||||
String substring(int start, int end) const {
|
||||
return String(str.substr(start, end - start).c_str());
|
||||
}
|
||||
String substring(int start) const {
|
||||
return String(str.substr(start).c_str());
|
||||
}
|
||||
float toFloat() const {
|
||||
return std::stof(str);
|
||||
}
|
||||
const char* c_str() const { return str.c_str(); }
|
||||
};
|
||||
|
||||
int main() {
|
||||
String t = "A:0.265,0.265,0.265,0.265";
|
||||
float v[4] = {0, 0, 0, 0};
|
||||
|
||||
int c1 = t.indexOf(',', 2);
|
||||
int c2 = t.indexOf(',', c1 + 1);
|
||||
int c3 = t.indexOf(',', c2 + 1);
|
||||
|
||||
if (c1 == -1 || c2 == -1 || c3 == -1) {
|
||||
std::cout << "Parse failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
v[0] = t.substring(2, c1).toFloat();
|
||||
v[1] = t.substring(c1 + 1, c2).toFloat();
|
||||
v[2] = t.substring(c2 + 1, c3).toFloat();
|
||||
v[3] = t.substring(c3 + 1).toFloat();
|
||||
|
||||
std::cout << "v0: " << v[0] << ", v1: " << v[1] << ", v2: " << v[2] << ", v3: " << v[3] << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user