-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharmDemo.js
137 lines (118 loc) · 3.27 KB
/
armDemo.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
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
132
133
134
135
136
137
// https://zacsuo.github.io/ScratchSerial/armDemo.js
(function(ext) {
var currentBaud = 115200;
var currentStatus = 1;
// 当插件退出时要做的事情
ext._shutdown = function() {};
// 状态描述,用于提示插件的错误信息,比如不支持浏览器及版本等
ext._getStatus = function() {
var tmpResult = {status: 1, msg: '等待连接'};
if(currentStatus == 2)
{
tmpResult.status = 2;
tmpResult.msg = '连接成功';
}
return tmpResult;
};
ext.put_up = function(){
$.ajax({
url:'http://localhost:8800/p',
data:{
dt:1
}
});
};
ext.put_down = function(){
$.ajax({
url:'http://localhost:8800/p',
data:{
dt:2
}
});
};
ext.move_forward = function(){
$.ajax({
url:'http://localhost:8800/m',
data:{
dt:1
}
});
};
ext.move_backword = function(){
$.ajax({
url:'http://localhost:8800/m',
data:{
dt:2
}
});
};
ext.hand_catch = function(){
$.ajax({
url:'http://localhost:8800/h',
data:{
dt:1
}
});
};
ext.hand_free = function(){
$.ajax({
url:'http://localhost:8800/h',
data:{
dt:2
}
});
};
ext.send_message = function(msg){
$.ajax({
url:'http://localhost:8800/msg',
data:{
dt:msg
}
});
};
ext.check_connection = function(){
};
ext.get_last_message = function(callback){
$.ajax({
url:'http://localhost:8800/m',
type: "get",
async:false,
contentType:"text/plain",
data:{
dt:24
},
success:function(msg){
currentStatus = 2;
// info = msg;
// callback(info);
}
});
};
ext.set_baud_rate = function(baudRate){
return baudRate;
};
// 模块描述
var descriptor = {
blocks: [
// 模块类型, 模块名称, 对应方法名称,参数依次对应的默认值
[' ', '抬 起 ', 'put_up'],
[' ', '放 下 ', 'put_down'],
[' ', '向 前 ', 'move_forward'],
[' ', '向 后 ', 'move_backword'],
[' ', '抓 住 ', 'hand_catch'],
[' ', '放 开 ', 'hand_free'],
[' ', '发送数据 %s ', 'send_message','1'],
['b', '连接成功', 'check_connection'],
['r', '最新接受数据', 'get_last_message'],
['r', "波特率: %m.baudRates", 'set_baud_rate', currentBaud]
],
menus:{
my_first_menu:['one','two','three'],
baudRates: [2400, 9600, 19200, 38400, 57600, 115200]
},
url:'https://github.com/zacSuo/ScratchSerial',
displayName: '机械臂功能测试'
};
// 注册扩展插件
ScratchExtensions.register('机械臂小游戏', descriptor, ext);
})({});