diff --git a/src/components/Blockly/blocks/index.js b/src/components/Blockly/blocks/index.js index c466260..d1ce014 100644 --- a/src/components/Blockly/blocks/index.js +++ b/src/components/Blockly/blocks/index.js @@ -4,9 +4,12 @@ import './logic'; import './sensebox-sensors'; import './sensebox-telegram'; import './sensebox-osem'; +import './sensebox-web'; +import './sensebox-display'; import './io'; import './math'; import './procedures'; import './time'; + import '../helpers/types' \ No newline at end of file diff --git a/src/components/Blockly/blocks/sensebox-display.js b/src/components/Blockly/blocks/sensebox-display.js index e69de29..2f163b5 100644 --- a/src/components/Blockly/blocks/sensebox-display.js +++ b/src/components/Blockly/blocks/sensebox-display.js @@ -0,0 +1,248 @@ +import * as Blockly from 'blockly/core'; +import { getColour } from '../helpers/colour'; +import * as Types from '../helpers/types' + + +Blockly.Blocks['sensebox_display_beginDisplay'] = { + init: function () { + this.appendDummyInput() + .appendField(Blockly.Msg.senseBox_display_beginDisplay) + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setColour(getColour().sensebox); + this.setTooltip(Blockly.Msg.senseBox_display_beginDisplay_tip); + this.setHelpUrl('https://sensebox.de/books'); + } +}; + +Blockly.Blocks['sensebox_display_clearDisplay'] = { + init: function () { + this.appendDummyInput() + .appendField(Blockly.Msg.senseBox_display_clearDisplay) + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setColour(getColour().sensebox); + this.setTooltip(Blockly.Msg.senseBox_display_clearDisplay_tip); + this.setHelpUrl('https://sensebox.de/books'); + } +}; + +Blockly.Blocks['sensebox_display_printDisplay'] = { + init: function (block) { + this.setColour(getColour().sensebox); + this.appendDummyInput() + .appendField(Blockly.Msg.senseBox_display_printDisplay); + this.appendDummyInput() + .appendField(Blockly.Msg.senseBox_display_color) + .appendField(new Blockly.FieldDropdown([[Blockly.Msg.senseBox_display_white, "WHITE,BLACK"], [Blockly.Msg.senseBox_display_black, "BLACK,WHITE"]]), "COLOR"); + this.appendValueInput("SIZE", 'Number') + .appendField(Blockly.Msg.senseBox_display_setSize); + this.appendValueInput("X", 'Number') + .appendField(Blockly.Msg.senseBox_display_printDisplay_x); + this.appendValueInput("Y", 'Number') + .appendField(Blockly.Msg.senseBox_display_printDisplay_y); + this.appendValueInput('printDisplay') + .appendField(Blockly.Msg.senseBox_display_printDisplay_value) + .setCheck(null); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setTooltip(Blockly.Msg.senseBox_display_printDisplay_tip); + this.setHelpUrl('https://sensebox.de/books'); + }, + /** + * Called whenever anything on the workspace changes. + * Add warning if block is not nested inside a the correct loop. + * @param {!Blockly.Events.Abstract} e Change event. + * @this Blockly.Block + */ + onchange: function (e) { + var legal = false; + // Is the block nested in a loop? + var block = this; + do { + if (this.LOOP_TYPES.indexOf(block.type) !== -1) { + legal = true; + break; + } + block = block.getSurroundParent(); + } while (block); + if (legal) { + this.setWarningText(null); + } else { + this.setWarningText(Blockly.Msg.CONTROLS_FLOW_STATEMENTS_WARNING); + } + }, + LOOP_TYPES: ['sensebox_display_show'], +}; + + +Blockly.Blocks['sensebox_display_plotDisplay'] = { + init: function () { + this.setColour(getColour().sensebox); + this.appendDummyInput() + .appendField(Blockly.Msg.senseBox_display_plotDisplay) + this.appendValueInput("Title", 'Text') + .appendField(Blockly.Msg.senseBox_display_plotTitle); + this.appendValueInput("YLabel", 'Text') + .appendField(Blockly.Msg.senseBox_display_plotYLabel); + this.appendValueInput("XLabel", 'Text') + .appendField(Blockly.Msg.senseBox_display_plotXLabel); + this.appendValueInput("XRange1", 'Number') + .appendField(Blockly.Msg.senseBox_display_plotXRange1); + this.appendValueInput("XRange2", 'Number') + .appendField(Blockly.Msg.senseBox_display_plotXRange2) + this.appendValueInput("YRange1", 'Number') + .appendField(Blockly.Msg.senseBox_display_plotYRange1); + this.appendValueInput("YRange2", 'Number') + .appendField(Blockly.Msg.senseBox_display_plotYRange2); + this.setInputsInline(false); + this.appendValueInput("XTick", 'Number') + .appendField(Blockly.Msg.senseBox_display_plotXTick); + this.appendValueInput("YTick", 'Number') + .appendField(Blockly.Msg.senseBox_display_plotYTick); + this.appendValueInput("TimeFrame", 'Number') + .appendField(Blockly.Msg.senseBox_display_plotTimeFrame); + this.appendValueInput('plotDisplay') + .appendField(Blockly.Msg.senseBox_display_printDisplay_value) + .setCheck(null); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setTooltip(Blockly.Msg.senseBox_display_printDisplay_tip); + this.setHelpUrl('https://sensebox.de/books'); + }, + /** + * Called whenever anything on the workspace changes. + * Add warning if block is not nested inside a the correct loop. + * @param {!Blockly.Events.Abstract} e Change event. + * @this Blockly.Block + */ + onchange: function (e) { + var legal = false; + // Is the block nested in a loop? + var block = this; + do { + if (this.LOOP_TYPES.indexOf(block.type) !== -1) { + legal = true; + break; + } + block = block.getSurroundParent(); + } while (block); + if (legal) { + this.setWarningText(null); + } else { + this.setWarningText(Blockly.Msg.CONTROLS_FLOW_STATEMENTS_WARNING); + } + }, + LOOP_TYPES: ['sensebox_display_show'], +}; + +Blockly.Blocks['sensebox_display_show'] = { + init: function () { + + this.setColour(getColour().sensebox); + this.appendDummyInput() + .appendField(Blockly.Msg.sensebox_display_show); + this.appendStatementInput('SHOW'); + this.setTooltip(Blockly.Msg.sensebox_display_show_tip); + this.setHelpUrl(''); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + } +}; + +Blockly.Blocks['sensebox_display_fillCircle'] = { + init: function () { + this.setColour(getColour().sensebox); + this.appendDummyInput() + .appendField(Blockly.Msg.sensebox_display_fillCircle); + this.appendValueInput('X') + .appendField(Blockly.Msg.senseBox_display_printDisplay_x) + .setCheck(Types.NUMBER.compatibleTypes); + this.appendValueInput('Y') + .appendField(Blockly.Msg.senseBox_display_printDisplay_y) + .setCheck(Types.NUMBER.compatibleTypes); + this.appendValueInput('Radius') + .appendField(Blockly.Msg.sensebox_display_fillCircle_radius) + .setCheck(Types.NUMBER.compatibleTypes); + this.appendDummyInput('fill') + .appendField(Blockly.Msg.senseBox_display_filled) + .appendField(new Blockly.FieldCheckbox("TRUE"), "FILL"); + this.setInputsInline(false); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + }, + /** + * Called whenever anything on the workspace changes. + * Add warning if block is not nested inside a the correct loop. + * @param {!Blockly.Events.Abstract} e Change event. + * @this Blockly.Block + */ + onchange: function (e) { + var legal = false; + // Is the block nested in a loop? + var block = this; + do { + if (this.LOOP_TYPES.indexOf(block.type) !== -1) { + legal = true; + break; + } + block = block.getSurroundParent(); + } while (block); + if (legal) { + this.setWarningText(null); + } else { + this.setWarningText(Blockly.Msg.CONTROLS_FLOW_STATEMENTS_WARNING); + } + }, + LOOP_TYPES: ['sensebox_display_show'], +}; + +Blockly.Blocks['sensebox_display_drawRectangle'] = { + init: function () { + this.setColour(getColour().sensebox); + this.appendDummyInput() + .appendField(Blockly.Msg.sensebox_display_drawRectangle); + this.appendValueInput('X') + .appendField(Blockly.Msg.senseBox_display_printDisplay_x) + .setCheck(Types.NUMBER.compatibleTypes); + this.appendValueInput('Y') + .appendField(Blockly.Msg.senseBox_display_printDisplay_y) + .setCheck(Types.NUMBER.compatibleTypes); + this.appendValueInput('width') + .appendField(Blockly.Msg.sensebox_display_drawRectangle_width) + .setCheck(Types.NUMBER.compatibleTypes); + this.appendValueInput('height') + .appendField(Blockly.Msg.sensebox_display_drawRectangle_height) + .setCheck(Types.NUMBER.compatibleTypes); + this.appendDummyInput('fill') + .appendField(Blockly.Msg.senseBox_display_filled) + .appendField(new Blockly.FieldCheckbox("TRUE"), "FILL"); + this.setInputsInline(false); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + }, + /** + * Called whenever anything on the workspace changes. + * Add warning if block is not nested inside a the correct loop. + * @param {!Blockly.Events.Abstract} e Change event. + * @this Blockly.Block + */ + onchange: function (e) { + var legal = false; + // Is the block nested in a loop? + var block = this; + do { + if (this.LOOP_TYPES.indexOf(block.type) !== -1) { + legal = true; + break; + } + block = block.getSurroundParent(); + } while (block); + if (legal) { + this.setWarningText(null); + } else { + this.setWarningText(Blockly.Msg.CONTROLS_FLOW_STATEMENTS_WARNING); + } + }, + LOOP_TYPES: ['sensebox_display_show'], +}; \ No newline at end of file diff --git a/src/components/Blockly/blocks/sensebox-web.js b/src/components/Blockly/blocks/sensebox-web.js new file mode 100644 index 0000000..f82c490 --- /dev/null +++ b/src/components/Blockly/blocks/sensebox-web.js @@ -0,0 +1,58 @@ +import Blockly from 'blockly'; +import { getColour } from '../helpers/colour' + +Blockly.Blocks['sensebox_wifi'] = { + init: function () { + this.setTooltip(Blockly.Msg.senseBox_wifi_tip); + this.setHelpUrl(''); + this.setColour(getColour().sensebox); + this.appendDummyInput() + .appendField(Blockly.Msg.senseBox_wifi_connect); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_LEFT) + .appendField(Blockly.Msg.senseBox_wifi_ssid) + .appendField(new Blockly.FieldTextInput("SSID"), "SSID"); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_LEFT) + .appendField(Blockly.Msg.senseBox_output_password) + .appendField(new Blockly.FieldTextInput("Password"), "Password"); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + }, + onchange: function (e) { + var legal = false; + // Is the block nested in a loop? + var block = this; + do { + if (this.LOOP_TYPES.indexOf(block.type) !== -1) { + legal = true; + break; + } + block = block.getSurroundParent(); + } while (block); + if (legal) { + this.setWarningText(null); + + } else { + this.setWarningText(Blockly.Msg.CONTROLS_FLOW_STATEMENTS_WARNING); + + } + }, + LOOP_TYPES: ['arduino_functions'], +}; + +Blockly.Blocks['sensebox_startap'] = { + init: function () { + this.setTooltip(Blockly.Msg.senseBox_wifi_tip); + this.setHelpUrl(''); + this.setColour(getColour().sensebox); + this.appendDummyInput() + .appendField(Blockly.Msg.senseBox_wifi_startap); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_LEFT) + .appendField(Blockly.Msg.senseBox_wifi_ssid) + .appendField(new Blockly.FieldTextInput("SSID"), "SSID"); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + } +}; \ No newline at end of file diff --git a/src/components/Blockly/generator/index.js b/src/components/Blockly/generator/index.js index 263f970..d645206 100644 --- a/src/components/Blockly/generator/index.js +++ b/src/components/Blockly/generator/index.js @@ -3,6 +3,7 @@ import './loops'; import './sensebox-sensors'; import './sensebox-telegram'; import './sensebox-osem'; +import './sensebox-web'; import './logic'; import './math'; import './io'; diff --git a/src/components/Blockly/generator/sensebox-display.js b/src/components/Blockly/generator/sensebox-display.js new file mode 100644 index 0000000..5a83d8d --- /dev/null +++ b/src/components/Blockly/generator/sensebox-display.js @@ -0,0 +1,90 @@ +import * as Blockly from 'blockly/core'; + +/*Display Blocks*/ +Blockly.Arduino.sensebox_display_beginDisplay = function () { + Blockly.Arduino.libraries_['library_spi'] = '#include '; + Blockly.Arduino.libraries_['library_wire'] = '#include '; + Blockly.Arduino.libraries_['library_AdafruitGFX'] = '#include '; + Blockly.Arduino.libraries_['library_AdafruitSSD1306'] = '#include '; + Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; + Blockly.Arduino.definitions_['define_display'] = '#define OLED_RESET 4\nAdafruit_SSD1306 display(OLED_RESET);'; + Blockly.Arduino.setupCode_['sensebox_display_begin'] = 'senseBoxIO.powerI2C(true);\ndelay(2000);\ndisplay.begin(SSD1306_SWITCHCAPVCC, 0x3D);\ndisplay.display();\ndelay(100);\ndisplay.clearDisplay();'; + var code = ''; + return code; +}; + +Blockly.Arduino.sensebox_display_clearDisplay = function () { + var code = 'display.clearDisplay();\n'; + return code; +}; + +Blockly.Arduino.sensebox_display_printDisplay = function () { + var x = Blockly.Arduino.valueToCode(this, 'X', Blockly.Arduino.ORDER_ATOMIC) || '0' + var y = Blockly.Arduino.valueToCode(this, 'Y', Blockly.Arduino.ORDER_ATOMIC) || '0' + var printDisplay = Blockly.Arduino.valueToCode(this, 'printDisplay', Blockly.Arduino.ORDER_ATOMIC) || '"Keine Eingabe"'; + var size = Blockly.Arduino.valueToCode(this, 'SIZE', Blockly.Arduino.ORDER_ATOMIC) || '1' + var color = this.getFieldValue('COLOR'); + var code = 'display.setCursor(' + x + ',' + y + ');\n'; + code += 'display.setTextSize(' + size + ');\n'; + code += 'display.setTextColor(' + color + ');\n'; + code += 'display.println(' + printDisplay + ');\n'; + return code; +}; + +Blockly.Arduino.sensebox_display_show = function (block) { + var show = Blockly.Arduino.statementToCode(block, 'SHOW'); + var code = ''; + code += show; + code += 'display.display();\n'; + return code; +}; +Blockly.Arduino.sensebox_display_plotDisplay = function () { + var YLabel = Blockly.Arduino.valueToCode(this, 'YLabel', Blockly.Arduino.ORDER_ATOMIC) || 'Y' + var XLabel = Blockly.Arduino.valueToCode(this, 'XLabel', Blockly.Arduino.ORDER_ATOMIC) || 'X' + var Title = Blockly.Arduino.valueToCode(this, 'Title', Blockly.Arduino.ORDER_ATOMIC) || 'Title' + var XRange1 = Blockly.Arduino.valueToCode(this, 'XRange1', Blockly.Arduino.ORDER_ATOMIC) || '0' + var XRange2 = Blockly.Arduino.valueToCode(this, 'XRange2', Blockly.Arduino.ORDER_ATOMIC) || '0' + var YRange1 = Blockly.Arduino.valueToCode(this, 'YRange1', Blockly.Arduino.ORDER_ATOMIC) || '0' + var YRange2 = Blockly.Arduino.valueToCode(this, 'YRange2', Blockly.Arduino.ORDER_ATOMIC) || '0' + var XTick = Blockly.Arduino.valueToCode(this, 'XTick', Blockly.Arduino.ORDER_ATOMIC) || '0' + var YTick = Blockly.Arduino.valueToCode(this, 'YTick', Blockly.Arduino.ORDER_ATOMIC) || '0' + var TimeFrame = Blockly.Arduino.valueToCode(this, 'TimeFrame', Blockly.Arduino.ORDER_ATOMIC) || '0' + var plotDisplay = Blockly.Arduino.valueToCode(this, 'plotDisplay', Blockly.Arduino.ORDER_ATOMIC) || '"Keine Eingabe"'; + Blockly.Arduino.libraries_['library_plot'] = '#include '; + Blockly.Arduino.definitions_['define_plot_class'] = 'Plot DataPlot(&display);\n'; + Blockly.Arduino.variables_['define_plot_class'] = 'const double TIMEFRAME = ' + TimeFrame + ';\n'; + Blockly.Arduino.setupCode_['sensebox_plot_setup'] = 'DataPlot.setTitle(' + Title + ');\nDataPlot.setXLabel(' + XLabel + ');\nDataPlot.setYLabel(' + YLabel + ');\nDataPlot.setXRange(' + XRange1 + ',' + XRange2 + ');\nDataPlot.setYRange(' + YRange1 + ',' + YRange2 + ');\nDataPlot.setXTick(' + XTick + ');\nDataPlot.setYTick(' + YTick + ');\nDataPlot.setXPrecision(0);\nDataPlot.setYPrecision(0);\n'; + var code = 'DataPlot.clear();' + code += 'double starttime = millis();\ndouble t = 0;\nwhile (t <= TIMEFRAME) {\nt = (millis() - starttime) / 1000.0;\nfloat value = ' + plotDisplay + ';\n'; + code += 'DataPlot.addDataPoint(t,value);\n}\n'; + return code; +}; + +Blockly.Arduino.sensebox_display_fillCircle = function () { + var x = Blockly.Arduino.valueToCode(this, 'X', Blockly.Arduino.ORDER_ATOMIC) || '0' + var y = Blockly.Arduino.valueToCode(this, 'Y', Blockly.Arduino.ORDER_ATOMIC) || '0' + var radius = Blockly.Arduino.valueToCode(this, 'Radius', Blockly.Arduino.ORDER_ATOMIC) || '0' + var fill = this.getFieldValue('FILL'); + if (fill == 'TRUE') { + var code = 'display.fillCircle(' + x + ',' + y + ',' + radius + ',1);\n'; + } + else { + var code = 'display.drawCircle(' + x + ',' + y + ',' + radius + ',1);\n'; + } + return code; +} + +Blockly.Arduino.sensebox_display_drawRectangle = function () { + var x = Blockly.Arduino.valueToCode(this, 'X', Blockly.Arduino.ORDER_ATOMIC) || '0' + var y = Blockly.Arduino.valueToCode(this, 'Y', Blockly.Arduino.ORDER_ATOMIC) || '0' + var width = Blockly.Arduino.valueToCode(this, 'width', Blockly.Arduino.ORDER_ATOMIC) || '0' + var height = Blockly.Arduino.valueToCode(this, 'height', Blockly.Arduino.ORDER_ATOMIC) || '0' + var fill = this.getFieldValue('FILL'); + if (fill == 'TRUE') { + var code = 'display.fillRect(' + x + ',' + y + ',' + width + ',' + height + ',1);\n'; + } + else { + var code = 'display.drawRect(' + x + ',' + y + ',' + width + ',' + height + ',1);\n'; + } + return code; +} \ No newline at end of file diff --git a/src/components/Blockly/generator/sensebox-web.js b/src/components/Blockly/generator/sensebox-web.js new file mode 100644 index 0000000..8727328 --- /dev/null +++ b/src/components/Blockly/generator/sensebox-web.js @@ -0,0 +1,25 @@ +import Blockly from 'blockly'; + + +/* Wifi connection and openSenseMap Blocks*/ +Blockly.Arduino.sensebox_wifi = function (block) { + var pw = this.getFieldValue('Password'); + var ssid = this.getFieldValue('SSID'); + Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; + Blockly.Arduino.definitions_['define_network'] = 'Bee* b = new Bee();'; + if (pw === "") { + Blockly.Arduino.setupCode_['sensebox_network'] = 'b->connectToWifi("' + ssid + '");\ndelay(1000);'; + } else + Blockly.Arduino.setupCode_['sensebox_network'] = 'b->connectToWifi("' + ssid + '","' + pw + '");\ndelay(1000);'; + var code = ''; + return code; +}; + +Blockly.Arduino.sensebox_startap = function (block) { + var ssid = this.getFieldValue('SSID'); + Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; + Blockly.Arduino.definitions_['define_network'] = 'Bee* b = new Bee();'; + Blockly.Arduino.setupCode_['sensebox_network'] = 'b->startAP("' + ssid + '");' + var code = ''; + return code; +}; \ No newline at end of file diff --git a/src/components/Blockly/toolbox/Toolbox.js b/src/components/Blockly/toolbox/Toolbox.js index 18ec1db..c7ec1a1 100644 --- a/src/components/Blockly/toolbox/Toolbox.js +++ b/src/components/Blockly/toolbox/Toolbox.js @@ -19,6 +19,120 @@ class Toolbox extends React.Component { + + + + + + + + + + + + 1 + + + + + 0 + + + + + 0 + + + + + + + + + + + + + + + + + + + 0 + + + + + 15 + + + + + 0 + + + + + 50 + + + + + 5 + + + + + 0 + + + + + 15 + + + + + + + 0 + + + + + 0 + + + + + 0 + + + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + + + +