Skip to content

Commit 2c31eb6

Browse files
committed
Merge branch 'gh-pages'
2 parents d3ae1e8 + 8ab4c3b commit 2c31eb6

File tree

15 files changed

+360
-0
lines changed

15 files changed

+360
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Webduino
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

LORA-blockly.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
+(function (window, webduino) {
2+
3+
'use strict';
4+
5+
window.getLORA = function (board, rstPin, address) {
6+
return new webduino.module.LORA(board, rstPin, address);
7+
};
8+
9+
}(window, window.webduino));

LORA.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
+(function (factory) {
2+
if (typeof exports === 'undefined') {
3+
factory(webduino || {});
4+
} else {
5+
module.exports = factory;
6+
}
7+
}(function (scope) {
8+
'use strict';
9+
10+
var self;
11+
var proto;
12+
var sendArray = [];
13+
var sending = false;
14+
var sendAck = '';
15+
var sendCallback;
16+
var Module = scope.Module;
17+
var _backlight;
18+
19+
function LORA(board, rstPin, address) {
20+
Module.call(this);
21+
this._board = board;
22+
self = this;
23+
self._rstPin = rstPin;
24+
self._address = address;
25+
self._callbackAckOK = function () {}
26+
self._callbackAckErr = function () {}
27+
self._callbackRecvAckOK = function () {}
28+
self.recvData = '';
29+
var cmd = [0xF0, 0x04, 0x22, 0x0 /*init*/ , rstPin, address, 0xF7];
30+
board.send(cmd);
31+
board.on(webduino.BoardEvent.SYSEX_MESSAGE,
32+
function (event) {
33+
var m = event.message;
34+
//send Ack response
35+
if (m.length == 4 && m[2] == 2) {
36+
var state = m[3] - 48; //ascii to int
37+
if (state == 0) {
38+
self._callbackAckOK();
39+
} else {
40+
self._callbackAckErr();
41+
}
42+
}
43+
//recv Ack response
44+
if (m[2] == 4) {
45+
var data = '';
46+
for (var i = 3; i < m.length; i++) {
47+
data += String.fromCharCode(m[i]);
48+
}
49+
self.recvData = data;
50+
self._callbackRecvAckOK();
51+
}
52+
sending = false;
53+
});
54+
}
55+
56+
LORA.prototype = proto = Object.create(Module.prototype, {
57+
constructor: {
58+
value: LORA
59+
}
60+
});
61+
62+
proto.send = function (strData) {
63+
var cmd = [0xF0, 0x04, 0x22, 0x01, this._address /*Address*/ ];
64+
cmd = cmd.concat(toASCII(strData));
65+
cmd.push(0xF7);
66+
this._board.send(cmd);
67+
}
68+
69+
proto.sendAck = function (strData, ackOK, ackErr) {
70+
if (arguments.length == 2) {
71+
self._callbackAckOK = ackOK;
72+
}
73+
if (arguments.length == 3) {
74+
self._callbackAckOK = ackOK;
75+
self._callbackAckErr = ackErr;
76+
}
77+
var cmd = [0xF0, 0x04, 0x22, 0x02, this._address /*Address*/ ];
78+
cmd = cmd.concat(toASCII(strData));
79+
cmd.push(0xF7);
80+
this._board.send(cmd);
81+
}
82+
83+
proto.recvAck = function (ackOK) {
84+
if (arguments.length == 1) {
85+
self._callbackRecvAckOK = ackOK;
86+
}
87+
var cmd = [0xF0, 0x04, 0x22, 0x04, this._address /*Address*/ , 0xF7];
88+
this._board.send(cmd);
89+
}
90+
91+
function toASCII(str) {
92+
var data = [];
93+
for (var i = 0; i < str.length; i++) {
94+
data.push(str.charCodeAt(i));
95+
}
96+
return data;
97+
}
98+
99+
scope.module.LORA = LORA;
100+
}));

blockly.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"types": ["lora_new","lora_send","lora_send_ack","lora_recv_ack","lora_recv_data"],
3+
"category": "catMenu4",
4+
"scripts": [
5+
"blockly/blocks.js",
6+
"blockly/javascript.js"
7+
],
8+
"dependencies": [
9+
"LORA.js",
10+
"LORA-blockly.js"
11+
],
12+
"msg": "blockly/msg",
13+
"blocksMsg": "blockly/msg/blocks",
14+
"toolbox": "blockly/toolbox.xml"
15+
}

blockly/blocks.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
//https://blockly-demo.appspot.com/static/demos/blockfactory_old/index.html#5ag74x
2+
var mainUrl = 'https://tutorials.webduino.io/zh-tw/docs/';
3+
var utmUrl = '?utm_source=cloud-blockly&utm_medium=contextMenu&utm_campaign=tutorials';
4+
5+
Blockly.Blocks['lora_new'] = {
6+
init: function() {
7+
this.appendDummyInput()
8+
.appendField("LORA , Reset")
9+
.appendField(new Blockly.FieldDropdown([["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["15", "15"]]), "resetPin")
10+
.appendField(" Address")
11+
.appendField(new Blockly.FieldDropdown([["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["15", "15"]]), "address");
12+
this.setOutput(true, null);
13+
this.setColour(230);
14+
this.setTooltip('');
15+
this.setHelpUrl(mainUrl + 'basic/index.html' + utmUrl);
16+
}
17+
};
18+
19+
Blockly.Blocks['lora_send'] = {
20+
init: function() {
21+
this.appendValueInput("data")
22+
.setCheck(null)
23+
.appendField(new Blockly.FieldVariable("lora"), "lora")
24+
.appendField(Blockly.Msg.WEBDUINO_LORA_SEND_STRING);
25+
this.setPreviousStatement(true, null);
26+
this.setNextStatement(true, null);
27+
this.setColour(65);
28+
this.setTooltip('');
29+
this.setHelpUrl(mainUrl + 'basic/index.html' + utmUrl);
30+
}
31+
};
32+
33+
//https://blockly-demo.appspot.com/static/demos/blockfactory_old/index.html#hv345s
34+
Blockly.Blocks['lora_send_ack'] = {
35+
init: function() {
36+
this.appendValueInput("data")
37+
.setCheck(null)
38+
.appendField(new Blockly.FieldVariable("lora"), "lora")
39+
.appendField(Blockly.Msg.WEBDUINO_LORA_SEND_STRING);
40+
this.appendStatementInput("send_ok")
41+
.setCheck(null)
42+
.appendField(Blockly.Msg.WEBDUINO_LORA_SUCCESS_CALLBACK)
43+
.setAlign(Blockly.ALIGN_RIGHT);
44+
this.appendStatementInput("send_failure")
45+
.setCheck(null)
46+
.appendField(Blockly.Msg.WEBDUINO_LORA_FAIL_CALLBACK)
47+
.setAlign(Blockly.ALIGN_RIGHT);
48+
this.setPreviousStatement(true, null);
49+
this.setNextStatement(true, null);
50+
this.setColour(65);
51+
this.setTooltip('');
52+
this.setHelpUrl(mainUrl + 'basic/index.html' + utmUrl);
53+
}
54+
};
55+
56+
//https://blockly-demo.appspot.com/static/demos/blockfactory_old/index.html#t673pk
57+
Blockly.Blocks['lora_recv_ack'] = {
58+
init: function() {
59+
this.appendStatementInput("recv_ok")
60+
.setCheck(null)
61+
.appendField(new Blockly.FieldVariable("lora"), "lora")
62+
.appendField(Blockly.Msg.WEBDUINO_LORA_RECEIVE_CALLBACK);
63+
this.setPreviousStatement(true, null);
64+
this.setNextStatement(true, null);
65+
this.setColour(65);
66+
this.setTooltip('');
67+
this.setHelpUrl(mainUrl + 'basic/index.html' + utmUrl);
68+
}
69+
};
70+
71+
//https://blockly-demo.appspot.com/static/demos/blockfactory_old/index.html#csh9m9
72+
Blockly.Blocks['lora_recv_data'] = {
73+
init: function() {
74+
this.appendDummyInput()
75+
.appendField(new Blockly.FieldVariable("lora"), "lora")
76+
.appendField(Blockly.Msg.WEBDUINO_LORA_RECEIVED_STRING);
77+
this.setOutput(true, null);
78+
this.setColour(35);
79+
this.setTooltip('');
80+
this.setHelpUrl(mainUrl + 'basic/index.html' + utmUrl);
81+
}
82+
};

blockly/javascript.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Blockly.JavaScript['lora_new'] = function (block) {
2+
var dropdown_resetpin = block.getFieldValue('resetPin');
3+
var dropdown_address = block.getFieldValue('address');
4+
var code = 'getLORA(board,' + dropdown_resetpin + ',' + dropdown_address + ')';
5+
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
6+
};
7+
8+
9+
Blockly.JavaScript['lora_send'] = function (block) {
10+
var variable_lora = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('lora'), Blockly.Variables.NAME_TYPE);
11+
var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
12+
var code = variable_lora + '.send(' + value_data + ');\n';
13+
return code;
14+
};
15+
16+
17+
Blockly.JavaScript['lora_send_ack'] = function (block) {
18+
var variable_lora = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('lora'), Blockly.Variables.NAME_TYPE);
19+
var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
20+
var statements_send_ok = Blockly.JavaScript.statementToCode(block, 'send_ok');
21+
var statements_send_failure = Blockly.JavaScript.statementToCode(block, 'send_failure');
22+
var code = variable_lora + '.sendAck(' + value_data + ',\n';
23+
code += "function(){\n " + statements_send_ok + "},\n";
24+
code += "function(){\n " + statements_send_failure + "});\n";
25+
return code;
26+
};
27+
28+
29+
Blockly.JavaScript['lora_recv_ack'] = function (block) {
30+
var variable_lora = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('lora'), Blockly.Variables.NAME_TYPE);
31+
var statements_recv_ok = Blockly.JavaScript.statementToCode(block, 'recv_ok');
32+
var code = variable_lora + '.recvAck(\n';
33+
code += "function(){\n " + statements_recv_ok + "});\n";
34+
return code;
35+
};
36+
37+
38+
Blockly.JavaScript['lora_recv_data'] = function (block) {
39+
var variable_lora = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('lora'), Blockly.Variables.NAME_TYPE);
40+
var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
41+
var code = variable_lora + '.recvData';
42+
return [code];
43+
};

blockly/msg/blocks/en.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// LoRa
2+
Blockly.Msg.WEBDUINO_LORA_SEND_STRING = "Send String";
3+
Blockly.Msg.WEBDUINO_LORA_SUCCESS_CALLBACK = "After Successed, Do";
4+
Blockly.Msg.WEBDUINO_LORA_FAIL_CALLBACK = "After Failed, Do";
5+
Blockly.Msg.WEBDUINO_LORA_RECEIVE_CALLBACK = "After Receiving String, Do";
6+
Blockly.Msg.WEBDUINO_LORA_RECEIVED_STRING = "Received String";

blockly/msg/blocks/zh-hans.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// LoRa
2+
Blockly.Msg.WEBDUINO_LORA_SEND_STRING = "传送字串";
3+
Blockly.Msg.WEBDUINO_LORA_SUCCESS_CALLBACK = "成功后执行";
4+
Blockly.Msg.WEBDUINO_LORA_FAIL_CALLBACK = "失败后执行";
5+
Blockly.Msg.WEBDUINO_LORA_RECEIVE_CALLBACK = "接收字串后执行";
6+
Blockly.Msg.WEBDUINO_LORA_RECEIVED_STRING = "接收的字串";

blockly/msg/blocks/zh-hant.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// LoRa
2+
Blockly.Msg.WEBDUINO_LORA_SEND_STRING = "傳送字串";
3+
Blockly.Msg.WEBDUINO_LORA_SUCCESS_CALLBACK = "成功後執行";
4+
Blockly.Msg.WEBDUINO_LORA_FAIL_CALLBACK = "失敗後執行";
5+
Blockly.Msg.WEBDUINO_LORA_RECEIVE_CALLBACK = "接收字串後執行";
6+
Blockly.Msg.WEBDUINO_LORA_RECEIVED_STRING = "接收的字串";

blockly/msg/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MSG.catLORA = "LORA";

blockly/msg/zh-hans.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MSG.catLORA = "LORA";

blockly/msg/zh-hant.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MSG.catLORA = "LORA";

blockly/toolbox.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<category id="catLORA" tags="fly,smart">
2+
<block type="variables_set">
3+
<field name="VAR">lora</field>
4+
<value name="VALUE">
5+
<block type="lora_new">
6+
<field name="resetPin">10</field>
7+
<field name="address">9</field>
8+
</block>
9+
</value>
10+
</block>
11+
<block type="lora_send">
12+
<value name="data">
13+
<block type="text">
14+
<field name="TEXT">test</field>
15+
</block>
16+
</value>
17+
</block>
18+
19+
<block type="lora_send_ack">
20+
<value name="data">
21+
<block type="text">
22+
<field name="TEXT">test</field>
23+
</block>
24+
</value>
25+
</block>
26+
27+
<block type="lora_recv_ack"></block>
28+
<block type="lora_recv_data"></block>
29+
30+
31+
</category>

bower.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "webduino-module-lora",
3+
"description": "Lora Module for Webduino",
4+
"main": "LORA.js",
5+
"authors": "",
6+
"license": "ISC",
7+
"keywords": [
8+
"arduino",
9+
"webduino",
10+
"lora"
11+
],
12+
"ignore": [
13+
"**/.*",
14+
"node_modules",
15+
"bower_components",
16+
"test",
17+
"tests"
18+
]
19+
}

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "webduino-module-lora",
3+
"version": "1.0.0",
4+
"description": "Lora Module for Webduino",
5+
"main": "LORA.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"keywords": [
12+
"arduino",
13+
"webduino",
14+
"lora"
15+
],
16+
"dependencies": {
17+
"webduino-js": "0.x"
18+
}
19+
}

0 commit comments

Comments
 (0)