Repository navigation
Expand file tree
/
Copy pathcommand.js
More file actions
100 lines (78 loc) · 2.01 KB
/
Copy pathcommand.js
File metadata and controls
100 lines (78 loc) · 2.01 KB
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
var _ = require('lodash');
const DEFAULT_COMMANDS = [
{
code: 'takeoff',
command: ['takeoff()']
},
{
code: 'land',
command: ['land()']
},
{
code: 'calibrate',
command: ['calibrate(0)']
},
{
code: 'enable-bottom-camera',
command: ['config("video:video_channel", 3)']
},
{
code: 'enable-front-camera',
command: ['config("video:video_channel", 0)']
},
{
code: 'initiator',
command: ['front(0.035)']
},
{
code: 'stop',
command: ['stop()']
}
];
const CONFIGURABLE_COMMANDS = [
{
code: 'a',
command: ['right(0.035)', 'wait(2000)', 'stop()'],
final: true
},
{
code: 'b',
command: ['NOTYETASSIGNED'],
start: true
},
{
code: 'c',
command: ['NOTYETASSIGNED']
},
{
code: 'd',
command: ['NOTYETASSIGNED']
},
{
code: 'e',
command: ['NOTYETASSIGNED']
}
]
module.exports = {
getCommand: function(code) {
const command = _.find(_.union(DEFAULT_COMMANDS, CONFIGURABLE_COMMANDS), (command) => command.code === code);
return command.command;
},
isValidCode: function(code) {
return _.some(_.union(DEFAULT_COMMANDS, CONFIGURABLE_COMMANDS), (command) => command.code === code);
},
isConfigurableCode: function(code) {
return _.some(CONFIGURABLE_COMMANDS, (command) => command.code === code);
},
isDefaultCode: function(code) {
return _.some(DEFAULT_COMMANDS, (command) => command.code === code);
},
isFinalCode: function(code) {
const command = _.find(_.union(DEFAULT_COMMANDS, CONFIGURABLE_COMMANDS), (command) => command.code === code);
return !!command.final;
},
isStartCode: function(code) {
const command = _.find(_.union(DEFAULT_COMMANDS, CONFIGURABLE_COMMANDS), (command) => command.code === code);
return !!command.start;
}
};