Skip to content

Commit b70a77a

Browse files
committed
first commit
1 parent d3ae1e8 commit b70a77a

File tree

15 files changed

+376
-0
lines changed

15 files changed

+376
-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: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
startQueue(board);
55+
}
56+
57+
LORA.prototype = proto = Object.create(Module.prototype, {
58+
constructor: {
59+
value: LORA
60+
}
61+
});
62+
63+
proto.send = function (strData) {
64+
var cmd = [0xF0, 0x04, 0x22, 0x01, 0x04 /*Address*/ ];
65+
cmd = cmd.concat(toASCII(strData));
66+
cmd.push(0xF7);
67+
this._board.send(cmd);
68+
}
69+
70+
proto.sendAck = function (strData, ackOK, ackErr) {
71+
if (arguments.length == 2) {
72+
self._callbackAckOK = ackOK;
73+
}
74+
if (arguments.length == 3) {
75+
self._callbackAckOK = ackOK;
76+
self._callbackAckErr = ackErr;
77+
}
78+
var cmd = [0xF0, 0x04, 0x22, 0x02, 0x04 /*Address*/ ];
79+
cmd = cmd.concat(toASCII(strData));
80+
cmd.push(0xF7);
81+
this._board.send(cmd);
82+
}
83+
84+
proto.recvAck = function (ackOK) {
85+
if (arguments.length == 1) {
86+
self._callbackRecvAckOK = ackOK;
87+
}
88+
var cmd = [0xF0, 0x04, 0x22, 0x04, 0x04 /*Address*/ , 0xF7];
89+
this._board.send(cmd);
90+
}
91+
92+
function toASCII(str) {
93+
var data = [];
94+
for (var i = 0; i < str.length; i++) {
95+
data.push(str.charCodeAt(i));
96+
}
97+
return data;
98+
}
99+
100+
function startQueue(board) {
101+
setInterval(function () {
102+
if (sending || sendArray.length == 0) {
103+
return;
104+
}
105+
sending = true;
106+
var sendObj = sendArray.shift();
107+
sendAck = sendObj.ack;
108+
if (sendAck > 0) {
109+
board.send(sendObj.obj);
110+
} else {
111+
sending = false;
112+
sendCallback();
113+
}
114+
}, 0);
115+
}
116+
117+
scope.module.LORA = LORA;
118+
}));

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": "catMenu1",
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: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//https://blockly-demo.appspot.com/static/demos/blockfactory_old/index.html#5ag74x
2+
Blockly.Blocks['lora_new'] = {
3+
init: function() {
4+
this.appendDummyInput()
5+
.appendField("LORA , Reset Pin")
6+
.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")
7+
.appendField(" , Address:")
8+
.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");
9+
this.setOutput(true, null);
10+
this.setColour(230);
11+
this.setTooltip('');
12+
this.setHelpUrl('http://webduino.io/');
13+
}
14+
};
15+
16+
Blockly.Blocks['lora_send'] = {
17+
init: function() {
18+
this.appendValueInput("data")
19+
.setCheck(null)
20+
.appendField(new Blockly.FieldVariable("lora"), "lora")
21+
.appendField("傳送字串");
22+
this.setPreviousStatement(true, null);
23+
this.setNextStatement(true, null);
24+
this.setColour(65);
25+
this.setTooltip('');
26+
this.setHelpUrl('http://webduino.io/');
27+
}
28+
};
29+
30+
//https://blockly-demo.appspot.com/static/demos/blockfactory_old/index.html#hv345s
31+
Blockly.Blocks['lora_send_ack'] = {
32+
init: function() {
33+
this.appendValueInput("data")
34+
.setCheck(null)
35+
.appendField(new Blockly.FieldVariable("lora"), "lora")
36+
.appendField("傳送字串");
37+
this.appendStatementInput("send_ok")
38+
.setCheck(null)
39+
.appendField("成功後執行");
40+
this.appendStatementInput("send_failure")
41+
.setCheck(null)
42+
.appendField("失敗後執行");
43+
this.setPreviousStatement(true, null);
44+
this.setNextStatement(true, null);
45+
this.setColour(65);
46+
this.setTooltip('');
47+
this.setHelpUrl('http://webduino.io/');
48+
}
49+
};
50+
51+
//https://blockly-demo.appspot.com/static/demos/blockfactory_old/index.html#t673pk
52+
Blockly.Blocks['lora_recv_ack'] = {
53+
init: function() {
54+
this.appendStatementInput("recv_ok")
55+
.setCheck(null)
56+
.appendField(new Blockly.FieldVariable("lora"), "lora")
57+
.appendField("接收字串後執行");
58+
this.setPreviousStatement(true, null);
59+
this.setNextStatement(true, null);
60+
this.setColour(65);
61+
this.setTooltip('');
62+
this.setHelpUrl('http://webduino.io/');
63+
}
64+
};
65+
66+
//https://blockly-demo.appspot.com/static/demos/blockfactory_old/index.html#csh9m9
67+
Blockly.Blocks['lora_recv_data'] = {
68+
init: function() {
69+
this.appendDummyInput()
70+
.appendField(new Blockly.FieldVariable("lora"), "lora")
71+
.appendField("接收的字串");
72+
this.setOutput(true, null);
73+
this.setColour(65);
74+
this.setTooltip('');
75+
this.setHelpUrl('http://webduino.io/');
76+
}
77+
};

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// LCD1602
2+
Blockly.Msg.WEBDUINO_LCD1602 = "LCD (1602),SDA ";
3+
Blockly.Msg.WEBDUINO_LCD1602_SCL = " SCL";
4+
Blockly.Msg.WEBDUINO_LCD1602_PRINT = "LCD Print:";
5+
Blockly.Msg.WEBDUINO_LCD1602_CLEAR = "Clear LCD Screen";
6+
Blockly.Msg.WEBDUINO_LCD1602_LOCATE_X = "LCD Col:";
7+
Blockly.Msg.WEBDUINO_LCD1602_LOCATE_Y = "LCD Row:";

blockly/msg/blocks/zh-hans.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// LCD1602
2+
Blockly.Msg.WEBDUINO_LCD1602 = "LCD (1602),SDA ";
3+
Blockly.Msg.WEBDUINO_LCD1602_SCL = " SCL";
4+
Blockly.Msg.WEBDUINO_LCD1602_PRINT = "LCD 显示:";
5+
Blockly.Msg.WEBDUINO_LCD1602_CLEAR = "清除 LCD 萤幕";
6+
Blockly.Msg.WEBDUINO_LCD1602_LOCATE_X = "LCD 设定列:";
7+
Blockly.Msg.WEBDUINO_LCD1602_LOCATE_Y = "LCD 设定栏:";

blockly/msg/blocks/zh-hant.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// LCD1602
2+
Blockly.Msg.WEBDUINO_LCD1602 = "LCD (1602),SDA ";
3+
Blockly.Msg.WEBDUINO_LCD1602_SCL = " SCL";
4+
Blockly.Msg.WEBDUINO_LCD1602_PRINT = "LCD 顯示:";
5+
Blockly.Msg.WEBDUINO_LCD1602_CLEAR = "清除 LCD 螢幕";
6+
Blockly.Msg.WEBDUINO_LCD1602_LOCATE_X = "LCD 設定列:";
7+
Blockly.Msg.WEBDUINO_LCD1602_LOCATE_Y = "LCD 設定欄:";

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_1276";

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_1276";

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_1276";

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-ws2812",
3+
"description": "WS2812 Module for Webduino",
4+
"main": "ws2812.js",
5+
"authors": "",
6+
"license": "ISC",
7+
"keywords": [
8+
"arduino",
9+
"webduino",
10+
"ws2812"
11+
],
12+
"ignore": [
13+
"**/.*",
14+
"node_modules",
15+
"bower_components",
16+
"test",
17+
"tests"
18+
]
19+
}

0 commit comments

Comments
 (0)