Skip to content

Commit

Permalink
Added When Wi-Fi is connected/disconnected blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jolivepetrus committed May 27, 2018
1 parent ba1f9fd commit 8b83b43
Show file tree
Hide file tree
Showing 78 changed files with 5,249 additions and 4,749 deletions.
Binary file modified closure-library/closure/bin/calcdeps.pyc
Binary file not shown.
3,050 changes: 1,525 additions & 1,525 deletions src/blockly_uncompressed.js

Large diffs are not rendered by default.

126 changes: 126 additions & 0 deletions src/blocks/wifi.js
Expand Up @@ -93,3 +93,129 @@ Blockly.Blocks['wifi_stop'] = {
domToMutation: Blockly.Blocks['wifi_start'].domToMutation,
updateShape_: Blockly.Blocks['wifi_start'].updateShape_,
};

Blockly.Blocks['when_wifi_is_conneted'] = {
module: "event",
init: function() {
this.appendDummyInput()
.appendField(Blockly.Msg.EVENT_WHEN_WIFI_IS_CONNECTED);

this.appendStatementInput('DO')
.appendField(Blockly.Msg.DO).setAlign(Blockly.ALIGN_RIGHT);

this.setPreviousStatement(false, null);
this.setNextStatement(false, null);
this.setColour(Blockly.Blocks.events.HUE);
this.setTooltip(Blockly.Msg.EVENT_WHEN_WIFI_IS_CONNECTED_TOOLTIP);
},
onchange: function(e) {
if (!this.workspace.isDragging || this.workspace.isDragging()) {
return;
}

if ((typeof e.element != "undefined") && (this.warning != null) && (e.element == "disabled")) {
if (e.blockId == this.id) {
this.setDisabled(true);
return;
}
}

if ((typeof e.element != "undefined") && (e.element == "disabled")) {
if ((e.newValue != e.oldValue) && (e.blockId == this.id)) {
this.disabledByUser = e.newValue;
}
}

var instances = 0;
var blocks = this.workspace.getTopBlocks(true);
for (var x = 0, block; block = blocks[x]; x++) {
if (blocks[x].type == this.type) {
instances++;
}
}

if (instances > 1) {
this.setWarningText(Blockly.Msg.WARNING_ONLY_ONE_INSTANCE_ALLOWED);
if (!this.isInFlyout) {
this.setDisabled(true);
}
} else {
var wasInWarning = (this.warning != null);

this.setWarningText(null);
if (!this.isInFlyout && wasInWarning & (typeof this.disabledByUser == "undefined"?true:(!this.disabledByUser))) {
this.setDisabled(false);
} else {
if (typeof this.disabledByUser != "undefined") {
this.setDisabled(this.disabledByUser);
}
}
}
},
section: function() {
return 'start';
}
};

Blockly.Blocks['when_wifi_is_disconneted'] = {
module: "event",
init: function() {
this.appendDummyInput()
.appendField(Blockly.Msg.EVENT_WHEN_WIFI_IS_DISCONNECTED);

this.appendStatementInput('DO')
.appendField(Blockly.Msg.DO).setAlign(Blockly.ALIGN_RIGHT);

this.setPreviousStatement(false, null);
this.setNextStatement(false, null);
this.setColour(Blockly.Blocks.events.HUE);
this.setTooltip(Blockly.Msg.EVENT_WHEN_WIFI_IS_DISCONNECTED_TOOLTIP);
},
onchange: function(e) {
if (!this.workspace.isDragging || this.workspace.isDragging()) {
return;
}

if ((typeof e.element != "undefined") && (this.warning != null) && (e.element == "disabled")) {
if (e.blockId == this.id) {
this.setDisabled(true);
return;
}
}

if ((typeof e.element != "undefined") && (e.element == "disabled")) {
if ((e.newValue != e.oldValue) && (e.blockId == this.id)) {
this.disabledByUser = e.newValue;
}
}

var instances = 0;
var blocks = this.workspace.getTopBlocks(true);
for (var x = 0, block; block = blocks[x]; x++) {
if (blocks[x].type == this.type) {
instances++;
}
}

if (instances > 1) {
this.setWarningText(Blockly.Msg.WARNING_ONLY_ONE_INSTANCE_ALLOWED);
if (!this.isInFlyout) {
this.setDisabled(true);
}
} else {
var wasInWarning = (this.warning != null);

this.setWarningText(null);
if (!this.isInFlyout && wasInWarning & (typeof this.disabledByUser == "undefined"?true:(!this.disabledByUser))) {
this.setDisabled(false);
} else {
if (typeof this.disabledByUser != "undefined") {
this.setDisabled(this.disabledByUser);
}
}
}
},
section: function() {
return 'start';
}
};
335 changes: 171 additions & 164 deletions src/blocks_compressed.js

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions src/generators/lua/wifi.js
Expand Up @@ -29,9 +29,38 @@
'use strict';

goog.provide('Blockly.Lua.Wifi');
goog.provide('Blockly.Lua.Wifi.helper');

goog.require('Blockly.Lua');

Blockly.Lua.Wifi.helper = {
networkCallback: function(block ){
var code = '';
var tryCode = '';

tryCode += Blockly.Lua.indent(0,'-- when_wifi_is_conneted') + "\n";
tryCode += Blockly.Lua.indent(0, 'if (_network_callback == nil) then') + "\n";
tryCode += Blockly.Lua.indent(1, '_network_callback = true') + "\n";
tryCode += Blockly.Lua.indent(1, 'net.callback(function(event)') + "\n";
tryCode += Blockly.Lua.indent(2, 'if ((event.interface == "wf") and (event.type == "up")) then') + "\n";
tryCode += Blockly.Lua.indent(3, 'if (not (_network_callback_wifi_connected == nil)) then') + "\n";
tryCode += Blockly.Lua.indent(4, '_network_callback_wifi_connected()') + "\n";
tryCode += Blockly.Lua.indent(3, 'end') + "\n";
tryCode += Blockly.Lua.indent(2, 'elseif ((event.interface == "wf") and (event.type == "down")) then') + "\n";
tryCode += Blockly.Lua.indent(3, 'if (not (_network_callback_wifi_disconnected == nil)) then') + "\n";
tryCode += Blockly.Lua.indent(4, '_network_callback_wifi_disconnected()') + "\n";
tryCode += Blockly.Lua.indent(3, 'end') + "\n";
tryCode += Blockly.Lua.indent(2, 'end') + "\n";
tryCode += Blockly.Lua.indent(1, 'end)') + "\n";
tryCode += Blockly.Lua.indent(0, 'end') + "\n";

code += Blockly.Lua.indent(0,'-- configure network callback') + "\n";
code += Blockly.Lua.indent(0,Blockly.Lua.tryBlock(0, block,tryCode)) + "\n";

return code;
}
};

Blockly.Lua['wifi_start'] = function(block) {
var code = '';

Expand Down Expand Up @@ -59,3 +88,39 @@ Blockly.Lua['wifi_stop'] = function(block) {

return code;
};

Blockly.Lua['when_wifi_is_conneted'] = function(block) {
var code = '';
var statement = Blockly.Lua.statementToCodeNoIndent(block, 'DO');

code += Blockly.Lua.indent(0,'-- when Wi-Fi is connected') + "\n";
code += Blockly.Lua.indent(0,'_network_callback_wifi_connected = function()') + "\n";

if (statement != "") {
code += Blockly.Lua.indent(1,statement);
}

code += Blockly.Lua.indent(0,'end') + "\n";

codeSection["declaration"].push(code);

return Blockly.Lua.Wifi.helper.networkCallback(block);
};

Blockly.Lua['when_wifi_is_disconneted'] = function(block) {
var code = '';
var statement = Blockly.Lua.statementToCodeNoIndent(block, 'DO');

code += Blockly.Lua.indent(0,'-- when Wi-Fi is disconnected') + "\n";
code += Blockly.Lua.indent(0,'_network_callback_wifi_disconnected = function()') + "\n";

if (statement != "") {
code += Blockly.Lua.indent(1,statement);
}

code += Blockly.Lua.indent(0,'end') + "\n";

codeSection["declaration"].push(code);

return Blockly.Lua.Wifi.helper.networkCallback(block);
};
Binary file modified src/i18n/common.pyc
Binary file not shown.

0 comments on commit 8b83b43

Please sign in to comment.