This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
103 lines (88 loc) · 2.82 KB
/
main.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
#include <cstdio>
#include <cassert>
#include <chrono>
#include <fstream>
#include "datacollector/win32utils.h"
#include "datacollector/sensor_device.h"
#include "datacollector/data_collector.h"
using namespace std::chrono_literals;
void testComDevice() {
SensorDevice sensor(6, 230400);
// sensor.setBaudRate(230400);
// auto &comDevice = sensor.comDevice();
// ComDevice comDevice(6, 19200);
// assert(comDevice.opened());
// while (true) {
// unsigned char c[64];
// DWORD errCode;
// long long read = comDevice.read(c, sizeof(c), &errCode);
// if (read > 0) {
// for (int i = 0; i < read; i++) {
// printf("%02x ", c[i]);
// }
// printf("\n");
// } else {
// printf("read = %lld, err = %s\n", read, getErrorCodeString(errCode).c_str());
// break;
// }
// }
// printf("starting thread\n");
// new std::thread([&](){
// std::this_thread::sleep_for(3s);
// sensor.requestRegisterValue(0x03);
// sensor.setReportRate(0x09);
// printf("written value\n");
// });
// printf("started thread\n");
while (true) {
using namespace std::chrono_literals;
std::this_thread::sleep_for(1000ms);
SensorState state = sensor.getCurrentSensorState();
auto &acc = state.Acceleration;
printf("%f %f %f\n", acc[0], acc[1], acc[2]);
// fflush(stdout);
}
sensor.mMonitorThread->join();
}
using namespace std::chrono_literals;
void drawGraph(const double *values,
int len,
double aRatioFull = 20,
int aColWidth = 21) {
assert((aColWidth & 1) && "aColWidth must be odd");
for (int i = 0; i < len; i++) {
printf("%s", &"|"[int(i == 0)]);
char buffer[128] = {};
memset(buffer, ' ', aColWidth);
const int halfWidth = aColWidth >> 1;
buffer[halfWidth] = '|';
int charsToFill = (int) std::trunc(values[i] / aRatioFull * halfWidth);
for (int offset = 1; offset <= std::min(std::abs(charsToFill), halfWidth); offset++) {
buffer[halfWidth + offset * (charsToFill < 0 ? -1 : 1)] = charsToFill < 0 ? '<' : '>';
}
printf("%s", buffer);
}
// printf("\n");
}
void testAngle() {
SensorDevice sensor(6, 230400);
assert(sensor.comDevice().opened());
assert(sensor.awaitDeviceFirstResponse(5));
while (true) {
std::this_thread::sleep_for(50ms);
SensorState state = sensor.getCurrentSensorState();
auto &acc = state.Acceleration;
drawGraph(acc, 3);
printf(" | %f %f %f\n", acc[0], acc[1], acc[2]);
}
}
namespace calibrator {
int main();
}
int main() {
// testComDevice();
collector_impl::runDataCollector();
// testAngle();
// calibrator::main();
return 0;
}