Skip to content

Commit fde186d

Browse files
committed
add adxl345
1 parent ac9937a commit fde186d

8 files changed

Lines changed: 144 additions & 31 deletions

File tree

blocks/msg/en.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,4 +380,4 @@ Blockly.Msg.WEBDUINO_IRRECV_OFF = "stop receiving";
380380
Blockly.Msg.WEBDUINO_IRRECV_DO = "do:";
381381

382382
Blockly.Msg.WEBDUINO_IRLED = "IR launch, pin:";
383-
Blockly.Msg.WEBDUINO_IRLED_LAUNCHCODE = "Launch codes (m-16, eight):";
383+
Blockly.Msg.WEBDUINO_IRLED_LAUNCHCODE = "Launch codes (m-16):";

blocks/msg/zh-hant.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,5 +380,5 @@ Blockly.Msg.WEBDUINO_IRRECV_OFF = "停止接收";
380380
Blockly.Msg.WEBDUINO_IRRECV_DO = "執行:";
381381

382382
Blockly.Msg.WEBDUINO_IRLED = "紅外線發射,腳位:";
383-
Blockly.Msg.WEBDUINO_IRLED_LAUNCHCODE = "發射代碼 ( 十六進位,八碼 ):";
383+
Blockly.Msg.WEBDUINO_IRLED_LAUNCHCODE = "發射代碼 ( 十六進位 ):";
384384

blocks/webduino.js

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,9 +1841,9 @@ Blockly.Blocks['irrecv_on'] = {
18411841
init: function () {
18421842
this.appendDummyInput()
18431843
.appendField(new Blockly.FieldVariable("irrecv"), "name_")
1844-
.appendField(Blockly.Msg.WEBDUINO_IRRECV_ON,"開始接收");
1844+
.appendField(Blockly.Msg.WEBDUINO_IRRECV_ON, "開始接收");
18451845
this.appendStatementInput("on_")
1846-
.appendField(Blockly.Msg.WEBDUINO_IRRECV_DO,"執行:");
1846+
.appendField(Blockly.Msg.WEBDUINO_IRRECV_DO, "執行:");
18471847
this.setPreviousStatement(true);
18481848
this.setNextStatement(true);
18491849
this.setColour(65);
@@ -1856,7 +1856,7 @@ Blockly.Blocks['irrecv_val'] = {
18561856
init: function () {
18571857
this.appendDummyInput()
18581858
.appendField(new Blockly.FieldVariable("irrecv"), "name_")
1859-
.appendField(Blockly.Msg.WEBDUINO_IRRECV_CODE,"接收的代碼");
1859+
.appendField(Blockly.Msg.WEBDUINO_IRRECV_CODE, "接收的代碼");
18601860
this.setOutput(true);
18611861
this.setColour(65);
18621862
this.setTooltip('');
@@ -1868,7 +1868,7 @@ Blockly.Blocks['irrecv_off'] = {
18681868
init: function () {
18691869
this.appendDummyInput()
18701870
.appendField(new Blockly.FieldVariable("irrecv"), "name_")
1871-
.appendField(Blockly.Msg.WEBDUINO_IRRECV_OFF,"停止接收");
1871+
.appendField(Blockly.Msg.WEBDUINO_IRRECV_OFF, "停止接收");
18721872
this.setPreviousStatement(true);
18731873
this.setNextStatement(true);
18741874
this.setColour(65);
@@ -1881,20 +1881,9 @@ Blockly.Blocks['irrecv_off'] = {
18811881
Blockly.Blocks['irled_new'] = {
18821882
init: function () {
18831883
this.appendDummyInput()
1884-
.appendField(Blockly.Msg.WEBDUINO_IRLED,"紅外線發射,腳位:")
1884+
.appendField(Blockly.Msg.WEBDUINO_IRLED, "紅外線發射,腳位:")
18851885
.appendField(new Blockly.FieldDropdown([
1886-
["2", "2"],
1887-
["3", "3"],
1888-
["4", "4"],
1889-
["5", "5"],
1890-
["6", "6"],
1891-
["7", "7"],
1892-
["8", "8"],
1893-
["9", "9"],
1894-
["10", "10"],
1895-
["11", "11"],
1896-
["12", "12"],
1897-
["13", "13"]
1886+
["9", "9"]
18981887
]), "pin_");
18991888
this.setOutput(true);
19001889
this.setColour(230);
@@ -1908,11 +1897,72 @@ Blockly.Blocks['irled_launch'] = {
19081897
this.appendValueInput("code_")
19091898
.setCheck("String")
19101899
.appendField(new Blockly.FieldVariable("irled"), "name_")
1911-
.appendField(Blockly.Msg.WEBDUINO_IRLED_LAUNCHCODE,"發射代碼 ( 十六進位,八碼 ):");
1900+
.appendField(Blockly.Msg.WEBDUINO_IRLED_LAUNCHCODE, "發射代碼 ( 十六進位 ):");
19121901
this.setPreviousStatement(true);
19131902
this.setNextStatement(true);
19141903
this.setTooltip('');
19151904
this.setColour(65);
19161905
this.setHelpUrl('http://www.example.com/');
19171906
}
1918-
};
1907+
};
1908+
1909+
1910+
Blockly.Blocks['adxl345_new'] = {
1911+
init: function () {
1912+
this.appendDummyInput()
1913+
.appendField("三軸加速度計,SDA")
1914+
.appendField(new Blockly.FieldDropdown([
1915+
["A4", "4"]
1916+
]), "sda_")
1917+
.appendField(" SCL")
1918+
.appendField(new Blockly.FieldDropdown([
1919+
["A5", "5"]
1920+
]), "scl_");
1921+
this.setOutput(true);
1922+
this.setColour(230);
1923+
this.setTooltip('');
1924+
this.setHelpUrl('http://www.example.com/');
1925+
}
1926+
};
1927+
1928+
Blockly.Blocks['adxl345_on'] = {
1929+
init: function () {
1930+
this.appendDummyInput()
1931+
.appendField(new Blockly.FieldVariable("adxl"), "name_")
1932+
.appendField("開始偵測");
1933+
this.appendStatementInput("on_")
1934+
.appendField("執行:");
1935+
this.setPreviousStatement(true);
1936+
this.setNextStatement(true);
1937+
this.setColour(65);
1938+
this.setTooltip('');
1939+
this.setHelpUrl('http://www.example.com/');
1940+
}
1941+
};
1942+
1943+
Blockly.Blocks['adxl345_val'] = {
1944+
init: function() {
1945+
this.appendDummyInput()
1946+
.appendField(new Blockly.FieldVariable("adxl"), "name_")
1947+
.appendField("的")
1948+
.appendField(new Blockly.FieldDropdown([["x", "_x"], ["y", "_y"], ["z", "_z"], ["roll", "_r"], ["pitch", "_p"]]), "val_")
1949+
.appendField("數值");
1950+
this.setOutput(true);
1951+
this.setTooltip('');
1952+
this.setColour(65);
1953+
this.setHelpUrl('http://www.example.com/');
1954+
}
1955+
};
1956+
1957+
Blockly.Blocks['adxl345_off'] = {
1958+
init: function () {
1959+
this.appendDummyInput()
1960+
.appendField(new Blockly.FieldVariable("adxl"), "name_")
1961+
.appendField("停止偵測");
1962+
this.setPreviousStatement(true);
1963+
this.setNextStatement(true);
1964+
this.setColour(65);
1965+
this.setTooltip('');
1966+
this.setHelpUrl('http://www.example.com/');
1967+
}
1968+
};

generators/webduino.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,13 +1110,55 @@ Blockly.JavaScript['irrecv_off'] = function(block) {
11101110

11111111
Blockly.JavaScript['irled_new'] = function (block) {
11121112
var dropdown_pin_ = block.getFieldValue('pin_');
1113-
var code = 'getIRLed(board, ' + dropdown_pin_ + ')';
1113+
var code = 'getIRLed(board, "ffffffff")';
11141114
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
11151115
};
11161116

11171117
Blockly.JavaScript['irled_launch'] = function(block) {
11181118
var variable_name_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('name_'), Blockly.Variables.NAME_TYPE);
11191119
var value_code_ = Blockly.JavaScript.valueToCode(block, 'code_', Blockly.JavaScript.ORDER_ATOMIC);
1120-
var code = variable_name_+'.send('+value_code_+');\n';
1120+
var code;
1121+
if(value_code_.length>2){
1122+
code = variable_name_+'.send('+value_code_+');\n';
1123+
}else{
1124+
code = variable_name_+'.send("ffffffff");\n';
1125+
}
1126+
return code;
1127+
};
1128+
1129+
1130+
Blockly.JavaScript['adxl345_new'] = function (block) {
1131+
var dropdown_sda_ = block.getFieldValue('sda_');
1132+
var dropdown_scl_ = block.getFieldValue('scl_');
1133+
var code = 'getADXL345(board)';
1134+
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
1135+
};
1136+
1137+
Blockly.JavaScript['adxl345_on'] = function(block) {
1138+
var variable_name_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('name_'), Blockly.Variables.NAME_TYPE);
1139+
var statements_on_ = Blockly.JavaScript.statementToCode(block, 'on_');
1140+
var code = variable_name_+'.setSensitivity = 0;\n'+
1141+
variable_name_+'.setBaseAxis = "x";\n'+
1142+
variable_name_+'.on(function(_x,_y,_z,_r,_p){\n'+
1143+
' '+variable_name_+'._x = _x;\n'+
1144+
' '+variable_name_+'._y = _y;\n'+
1145+
' '+variable_name_+'._z = _z;\n'+
1146+
' '+variable_name_+'._r = _r;\n'+
1147+
' '+variable_name_+'._p = _p;\n'+
1148+
statements_on_+
1149+
'});\n';
1150+
return code;
1151+
};
1152+
1153+
Blockly.JavaScript['adxl345_val'] = function(block) {
1154+
var variable_name_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('name_'), Blockly.Variables.NAME_TYPE);
1155+
var dropdown_val_ = block.getFieldValue('val_');
1156+
var code = variable_name_+'.'+dropdown_val_;
1157+
return [code, Blockly.JavaScript.ORDER_ATOMIC];
1158+
};
1159+
1160+
Blockly.JavaScript['adxl345_off'] = function(block) {
1161+
var variable_name_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('name_'), Blockly.Variables.NAME_TYPE);
1162+
var code = variable_name_+'.off();\n';
11211163
return code;
11221164
};

msg/en.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ var MSG = {
5757
catMax7219: "LED Matrix",
5858
catPhotocell: "Photocell",
5959
catIRRecv: "IR Recv",
60-
catIRLed: "IR Launch"
60+
catIRLed: "IR Launch",
61+
catADXL345: "ADXL345"
6162
};

msg/zh-hant.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var MSG = {
4444
linkToBin: "程式編輯",
4545
catDatabase: "資料庫",
4646
catFirebase: "Firebase",
47-
update: "update 2015.9.1",
47+
update: "update 2015.10.12",
4848
catCarTest: "自走車 (2)",
4949
catCar: "自走車 (1)",
5050
catFish: "飛天魚",
@@ -59,5 +59,6 @@ var MSG = {
5959
catMax7219: "LED 點矩陣",
6060
catPhotocell: "光敏電阻",
6161
catIRRecv: "紅外線接收",
62-
catIRLed: "紅外線發射"
62+
catIRLed: "紅外線發射",
63+
catADXL345: "三軸加速度計"
6364
};

views/index.handlebars

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,14 +490,14 @@
490490
<field name="VAR">irled</field>
491491
<value name="VALUE">
492492
<block type="irled_new">
493-
<field name="pin_">10</field>
493+
<field name="pin_">9</field>
494494
</block>
495495
</value>
496496
</block>
497497
<block type="irled_launch">
498498
<value name="code_">
499499
<block type="text">
500-
<field name="TEXT">AABBCCDD</field>
500+
<field name="TEXT"></field>
501501
</block>
502502
</value>
503503
</block>
@@ -507,7 +507,7 @@
507507
<field name="VAR">irrecv</field>
508508
<value name="VALUE">
509509
<block type="irrecv_new">
510-
<field name="pin_">11</field>
510+
<field name="pin_">10</field>
511511
</block>
512512
</value>
513513
</block>
@@ -613,6 +613,20 @@
613613
<block type="photocell_val"></block>
614614
<block type="photocell_stop"></block>
615615
</category>
616+
<category id="catADXL345">
617+
<block type="variables_set">
618+
<field name="VAR">adxl</field>
619+
<value name="VALUE">
620+
<block type="adxl345_new">
621+
<field name="sda_">A4</field>
622+
<field name="scl_">A5</field>
623+
</block>
624+
</value>
625+
</block>
626+
<block type="adxl345_on"></block>
627+
<block type="adxl345_val"></block>
628+
<block type="adxl345_off"></block>
629+
</category>
616630
<sep></sep>
617631
</category>
618632
<category id="catMenu3">

webduino-blockly.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ function getIRRecv(board, pin) {
7373
return new webduino.module.IRRecv(board, board.getDigitalPin(pin));
7474
}
7575

76-
function getIRLed(board, pin) {
77-
return new webduino.module.IRLed(board, board.getDigitalPin(pin));
76+
function getIRLed(board, encode) {
77+
return new webduino.module.IRLed(board, encode);
78+
}
79+
80+
function getADXL345(board) {
81+
return new webduino.module.ADXL345(board);
7882
}
7983

8084
function getCar(board, F, B, L, R) {
@@ -214,5 +218,6 @@ scope.getMax7219 = getMax7219;
214218
scope.getPhotocell = getPhotocell;
215219
scope.getIRRecv = getIRRecv;
216220
scope.getIRLed = getIRLed;
221+
scope.getADXL345 = getADXL345;
217222

218223
}));

0 commit comments

Comments
 (0)