-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_cli.c
76 lines (69 loc) · 1.51 KB
/
example_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
/* An interactive cli to serve as an example for the motor api */
#include "motor_api.h"
#include <stdio.h>
int main(int argc, char *argv[]) {
char c, r;
MOTOR motor;
if (argc < 2) {
fprintf(stderr, "Expected IP of node running motord as command line argument.\n");
return 1;
}
printf("motor api example\n"
"c : connect\n"
"d : disconnect\n"
"f : forward\n"
"b : back\n"
"r : right\n"
"l : left\n"
"s : state\n"
"q : quit\n");
printf("Enter cmd: ");
while(1) {
scanf("%c", &c);
switch(c) {
case 'c':
printf("Connecting...\n");
r = motor_connect(&motor, argv[1]);
printf("motord returned: %d\n", r);
break;
case 'd':
printf("Disconnecting...\n");
r = motor_disconnect(&motor);
printf("motord returned: %d\n", r);
motor = -1;
break;
case 'f':
printf("Forward...\n");
r = motor_forward(motor);
printf("motord returned: %d\n", r);
break;
case 'b':
printf("Back...\n");
r = motor_back(motor);
printf("motord returned: %d\n", r);
break;
case 'l':
printf("Left...\n");
r = motor_left(motor);
printf("motord returned: %d\n", r);
break;
case 'r':
printf("Right...\n");
r = motor_right(motor);
printf("motord returned: %d\n", r);
break;
case 's':
printf("State...\n");
r = motor_state(motor);
printf("motord returned: %d\n", r);
break;
case 'q':
if (motor != -1)
motor_disconnect(&motor);
return 0;
case '\n':
printf("Enter cmd: ");
}
}
return 0;
}