-
Notifications
You must be signed in to change notification settings - Fork 0
/
spot-scratch.main.js
82 lines (76 loc) 路 2.42 KB
/
spot-scratch.main.js
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
class SpotScratch {
constructor() {
}
getInfo() {
return {
"id": "SpotScratch",
"name": "Spot! Scratch",
"blocks": [
{
"opcode": "bodyCommand",
"blockType": "command",
"text": "send a [cmdName] command to spot",
"arguments": {
"cmdName": {
"type": "string",
"defaultValue": "sit",
"menu": "cmdMenu"
},
},
},
{
"opcode": "rotateCommand",
"blockType": "command",
"text": "tell spot to rotate [pitch] deg [yaw] deg [roll] deg",
"arguments": {
"pitch": {
"type": "number",
"defaultValue": "0"
},
"yaw": {
"type": "number",
"defaultValue": "0"
},
"roll": {
"type": "number",
"defaultValue": "0"
},
}
}
],
"menus": {
"cmdMenu": [{text:"sit",value:"sit"}, {text:"stand",value:"stand"}]
}
};
}
bodyCommand({cmdName}) {
await fetch('http://192.168.80.101:8000/command', {
method: 'POST',
mode: 'no-cors',
headers: {},
body: JSON.stringify({
Command: cmdName // eg 'sit'
}),
});
return true;
}
rotateCommand(args) {
return new Promise((resolve, reject) => {
fetch('http://192.168.80.101:8000/command', {
method: 'POST',
mode: 'no-cors',
headers: {},
body: JSON.stringify({
Command: 'rotate', // eg 'sit'
Args: {
pitch: args.pitch,
yaw: args.yaw,
roll: args.roll
}
}),
}).then(() => resolve());
});
}
}
Scratch.extensions.register(new SpotScratch())
// data:text/javascript;base64,