-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.c
131 lines (124 loc) · 3.41 KB
/
cli.c
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
//#include<stdio.h>
#include "cli.h"
#define ABROAD
#include "driver.h"
#undef ABROAD
char cli_buffer[256];
int buffer_pos;
void cli_init() {
buffer_pos = 0;
puts("\r\n> ");
}
static void cli_process() {
char str[1024];
if(strncasecmp(cli_buffer, "home", 4) == 0) {puts("homing\n"); homing();}
else if(strncasecmp(cli_buffer, "bal", 3) == 0) balance();
else
if(strncasecmp(cli_buffer, "lean ", 5) == 0) {
int i;
sscanf(cli_buffer + 5, "%d", &i);
lean = i;
snprintf(str, sizeof(str), "lean = %d\n", lean);
puts(str);
} else
if(strncasecmp(cli_buffer, "a2s ", 4) == 0) {
int i;
sscanf(cli_buffer + 4, "%d", &i);
a2_scale = i;
snprintf(str, sizeof(str), "a2_scale = %d\n", a2_scale);
puts(str);
}
else
if(strncasecmp(cli_buffer, "cb ", 3) == 0) {
int i;
sscanf(cli_buffer + 3, "%d", &i);
center_bias = i;
snprintf(str, sizeof(str), "center_bias = %d\n", center_bias);
puts(str);
}
else
if(strncasecmp(cli_buffer, "a2o ", 4) == 0) {
int i;
sscanf(cli_buffer + 4, "%d", &i);
a2_offset = i;
snprintf(str, sizeof(str), "a2_offset = %d\n", a2_offset);
puts(str);
} else
if(strncasecmp(cli_buffer, "ah ", 3) == 0) {
int i;
sscanf(cli_buffer + 3, "%d", &i);
ah = i;
snprintf(str, sizeof(str), "ah = %d\n", ah);
puts(str);
}
else
if(strncasecmp(cli_buffer, "conf", 4) == 0) {
snprintf(str, sizeof(str), "lean = %d\n\ra2s = %d\n\ra2o = %d\n\rcb = %d\n\rah = %d\n\r", lean, a2_scale, a2_offset, center_bias, ah);
puts(str);
}
else
if(strncasecmp(cli_buffer, "ang", 3) == 0) {
int i = 0;
for(i=0; i<1000; i++) {
snprintf(str, sizeof(str), "%u\r\n", read_angle());
puts(str);
usleep(10);
}
}
else
if(strncasecmp(cli_buffer, "res", 3) == 0) {
encoder_head = 0;
}
else
if(strncasecmp(cli_buffer, "enc", 3) == 0) {
int i = 0;
for(i=0; i<C_BUFFER_SIZE; i++) {
snprintf(str, sizeof(str), "%d %d\r\n", encoder[i]&1, encoder[i]&2);
puts(str);
}
}
else
if(strncasecmp(cli_buffer, "tck", 3) == 0) {
snprintf(str, sizeof(str), "%d x= %d\r\n", tick_error_count, x);
puts(str);
}
else
puts("home -- home the carriage\r\n"
"bal -- balance\r\n"
"lean <int> -- added to CENTER constant to bias carriage to the center of the track\r\n"
"a2s <int> -- used to scale the square of the angle in the motor voltage computation\r\n"
"a2o <int> -- used to offset the square of the angle in the motor voltage computation\r\n"
"cb <int> -- center bias\r\n"
"ah <int> -- angle hysteresis\r\n"
"ang -- print current angel\r\n"
"conf -- print current values of config variables\r\n"
"res -- reset head pointer of the encoder tick buffer, i.e., restart recording\r\n"
"enc -- dump contents of the encoder tick buffer\r\n"
"tck -- display tick error count\r\n"
);
}
void cli(int c) {
switch(c) {
case 127:
case '\b':
if(buffer_pos>0) {
buffer_pos--;
puts("\b \b");
}
break;
case '\r':
case '\n':
cli_buffer[buffer_pos] = 0;
puts("\r\n");
cli_process();
puts("\r\n> ");
buffer_pos = 0;
break;
default:
uart_putc(c);
if(buffer_pos<sizeof(cli_buffer)) {
cli_buffer[buffer_pos] = c;
buffer_pos++;
}
}
}