add display and web blocks
This commit is contained in:
		
							parent
							
								
									0d70f66935
								
							
						
					
					
						commit
						ef80f15782
					
				| @ -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' | ||||
| @ -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'], | ||||
| }; | ||||
							
								
								
									
										58
									
								
								src/components/Blockly/blocks/sensebox-web.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								src/components/Blockly/blocks/sensebox-web.js
									
									
									
									
									
										Normal file
									
								
							| @ -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); | ||||
|     } | ||||
| }; | ||||
| @ -3,6 +3,7 @@ import './loops'; | ||||
| import './sensebox-sensors'; | ||||
| import './sensebox-telegram'; | ||||
| import './sensebox-osem'; | ||||
| import './sensebox-web'; | ||||
| import './logic'; | ||||
| import './math'; | ||||
| import './io'; | ||||
|  | ||||
							
								
								
									
										90
									
								
								src/components/Blockly/generator/sensebox-display.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								src/components/Blockly/generator/sensebox-display.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,90 @@ | ||||
| import * as Blockly from 'blockly/core'; | ||||
| 
 | ||||
| /*Display Blocks*/ | ||||
| Blockly.Arduino.sensebox_display_beginDisplay = function () { | ||||
|     Blockly.Arduino.libraries_['library_spi'] = '#include <SPI.h>'; | ||||
|     Blockly.Arduino.libraries_['library_wire'] = '#include <Wire.h>'; | ||||
|     Blockly.Arduino.libraries_['library_AdafruitGFX'] = '#include <Adafruit_GFX.h>'; | ||||
|     Blockly.Arduino.libraries_['library_AdafruitSSD1306'] = '#include <Adafruit_SSD1306.h>'; | ||||
|     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 <Plot.h>'; | ||||
|     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; | ||||
| } | ||||
							
								
								
									
										25
									
								
								src/components/Blockly/generator/sensebox-web.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/components/Blockly/generator/sensebox-web.js
									
									
									
									
									
										Normal file
									
								
							| @ -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; | ||||
| }; | ||||
| @ -19,6 +19,120 @@ class Toolbox extends React.Component { | ||||
|                         <Block type="sensebox_sensor_ultrasonic_ranger" /> | ||||
|                         <Block type="sensebox_sensor_sound" /> | ||||
|                     </Category > | ||||
|                     <Category name="WIFI" colour={getColour().sensebox}> | ||||
|                         <Block type="sensebox_wifi" /> | ||||
|                         <Block type="sensebox_startap" /> | ||||
|                     </Category> | ||||
|                     <Category name="Display" colour={getColour().sensebox}> | ||||
|                         <Block type="sensebox_display_beginDisplay" /> | ||||
|                         <Block type="sensebox_display_show" /> | ||||
|                         <Block type="sensebox_display_clearDisplay" /> | ||||
|                         <Block type="sensebox_display_printDisplay"> | ||||
|                             <Value name="SIZE"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">1</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="X"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">0</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="Y"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">0</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                         </Block> | ||||
|                         <Block type="sensebox_display_plotDisplay"> | ||||
|                             <Value name="Title"> | ||||
|                                 <Block type="text"> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="YLabel"> | ||||
|                                 <Block type="text"> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="XLabel"> | ||||
|                                 <Block type="text"> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="XRange1"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">0</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="XRange2"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">15</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="YRange1"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">0</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="YRange2"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">50</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="XTick"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">5</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="YTick"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">0</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="TimeFrame"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">15</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                         </Block> | ||||
|                         <Block type="sensebox_display_fillCircle"> | ||||
|                             <Value name="X"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">0</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="Y"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">0</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="Radius"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">0</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                         </Block> | ||||
|                         <Block type="sensebox_display_drawRectangle"> | ||||
|                             <Value name="X"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">0</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="Y"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">0</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="height"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">0</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                             <Value name="width"> | ||||
|                                 <Block type="math_number"> | ||||
|                                     <Field name="NUM">0</Field> | ||||
|                                 </Block> | ||||
|                             </Value> | ||||
|                         </Block> | ||||
|                     </Category> | ||||
|                     <Category name="Telegram" colour={getColour().sensebox}> | ||||
|                         <Block type="sensebox_telegram" /> | ||||
|                         <Block type="sensebox_telegram_do" /> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user