Skip to content

Commit 0508b29

Browse files
marty5499Ke, Mingze
authored andcommitted
add websocket support
1 parent 0d7ca18 commit 0508b29

8 files changed

Lines changed: 23 additions & 13 deletions

File tree

blocks/msg/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ Blockly.Msg.WEBDUINO_BOARD_SERVER = "Private Server";
227227
Blockly.Msg.WEBDUINO_BOARD_WIFI = "Wi-Fi";
228228
Blockly.Msg.WEBDUINO_BOARD_SERIAL = "Serial Port";
229229
Blockly.Msg.WEBDUINO_BOARD_BLUETOOTH = "Bluetooth";
230+
Blockly.Msg.WEBDUINO_BOARD_WEBSOCKET = "WebSocket";
230231
Blockly.Msg.WEBDUINO_BOARD_MULTI = " multi";
231232
Blockly.Msg.WEBDUINO_BOARD_CHAIN = "chain";
232233
Blockly.Msg.WEBDUINO_BOARD_CHAIN_OK = "When all boards chain ready";

blocks/msg/zh-hant.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ Blockly.Msg.WEBDUINO_BOARD_SERVER = "私有雲 Server,IP";
245245
Blockly.Msg.WEBDUINO_BOARD_WIFI = "Wi-Fi";
246246
Blockly.Msg.WEBDUINO_BOARD_SERIAL = "序列埠";
247247
Blockly.Msg.WEBDUINO_BOARD_BLUETOOTH = "藍芽";
248+
Blockly.Msg.WEBDUINO_BOARD_WEBSOCKET = "WebSocket";
248249
Blockly.Msg.WEBDUINO_BOARD_MULTI = " 協同控制";
249250
Blockly.Msg.WEBDUINO_BOARD_CHAIN = " 串聯";
250251
Blockly.Msg.WEBDUINO_BOARD_CHAIN_OK = "當開發板串連完成";

blocks/webduino.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,8 @@ Blockly.Blocks['board_ready'] = {
872872
.appendField(new Blockly.FieldDropdown([
873873
[Blockly.Msg.WEBDUINO_BOARD_WIFI, "1"],
874874
[Blockly.Msg.WEBDUINO_BOARD_SERIAL, "2"],
875-
[Blockly.Msg.WEBDUINO_BOARD_BLUETOOTH, "3"]
875+
[Blockly.Msg.WEBDUINO_BOARD_BLUETOOTH, "3"],
876+
[Blockly.Msg.WEBDUINO_BOARD_WEBSOCKET, "4"]
876877
]), "type_")
877878
.appendField(":");
878879
this.appendDummyInput()
@@ -1011,7 +1012,8 @@ Blockly.Blocks['pin_board'] = {
10111012
var nameMap = {
10121013
'1': Blockly.Msg.WEBDUINO_BOARD_WIFI,
10131014
'2': Blockly.Msg.WEBDUINO_BOARD_SERIAL,
1014-
'3': Blockly.Msg.WEBDUINO_BOARD_BLUETOOTH
1015+
'3': Blockly.Msg.WEBDUINO_BOARD_BLUETOOTH,
1016+
'4': Blockly.Msg.WEBDUINO_BOARD_WEBSOCKET
10151017
},
10161018
xml = Blockly.Xml.workspaceToDom(Code.workspace),
10171019
boards = xml.querySelectorAll("block[type=board_ready]"),
@@ -1030,15 +1032,19 @@ Blockly.Blocks['pin_board'] = {
10301032

10311033
switch (type) {
10321034
case '1':
1033-
menus.push(['(' + nameMap['1'] + ') ' + param, "{ transport: 'mqtt', device: '" + param + "' }"]);
1035+
menus.push(['(' + nameMap['1'] + ') ' + param, "{transport: 'mqtt', device: '" + param + "'}"]);
10341036
break;
10351037

10361038
case '2':
1037-
menus.push(['(' + nameMap['2'] + ') ' + param, "{ transport: 'serial', path: '" + param + "' }"]);
1039+
menus.push(['(' + nameMap['2'] + ') ' + param, "{transport: 'serial', path: '" + param + "'}"]);
10381040
break;
10391041

10401042
case '3':
1041-
menus.push(['(' + nameMap['3'] + ') ' + param, "{ transport: 'bluetooth', address: '" + param + "' }"]);
1043+
menus.push(['(' + nameMap['3'] + ') ' + param, "{transport: 'bluetooth', address: '" + param + "'}"]);
1044+
break;
1045+
1046+
case '4':
1047+
menus.push(['(' + nameMap['4'] + ') ' + param, "{transport: 'websocket', url: '" + param + "'}"]);
10421048
break;
10431049
}
10441050
}

generators/webduino.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,14 +714,16 @@ Blockly.JavaScript['board_ready'] = function (block) {
714714
var type;
715715
if (checkbox_type_ == '1') {
716716
if (checkbox_multi_ == 'TRUE') {
717-
type = 'boardReady({device:' + value_device_ + ' , multi:true}, async function (board) {\n';
717+
type = 'boardReady({device:' + value_device_ + ', multi: true}, async function (board) {\n';
718718
} else {
719719
type = 'boardReady(' + value_device_ + ', async function (board) {\n';
720720
}
721721
} else if (checkbox_type_ == '2') {
722-
type = 'boardReady({ transport: \'serial\', path:' + value_device_ + '}, async function (board) {\n';
722+
type = 'boardReady({transport: \'serial\', path: ' + value_device_ + '}, async function (board) {\n';
723723
} else if (checkbox_type_ == '3') {
724-
type = 'boardReady({ transport: \'bluetooth\', address:' + value_device_ + '}, async function (board) {\n';
724+
type = 'boardReady({transport: \'bluetooth\', address: ' + value_device_ + '}, async function (board) {\n';
725+
} else if (checkbox_type_ == '4') {
726+
type = 'boardReady({transport: \'websocket\', url: ' + value_device_ + '}, async function (board) {\n';
725727
}
726728

727729
var code;

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<script src="lib/tracking-min.js"></script>
4141
<script src="lib/face-min.js"></script>
4242
<script src="lib/saveSvgAsPng.js"></script>
43-
<script src="lib/webduino-all-0.3.9.min.js"></script>
43+
<script src="lib/webduino-all-0.4.0.min.js"></script>
4444
</head>
4545

4646
<body>

lib/webduino-all-0.3.9.min.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

lib/webduino-all-0.4.0.min.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webduino-blockly.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
device: options
2727
};
2828
}
29-
if (options.device) {
29+
if (options.device || options.url) {
3030
board = new webduino.WebArduino(options);
3131
} else {
3232
board = new webduino.Arduino(options);

0 commit comments

Comments
 (0)