init implementation of procedures
This commit is contained in:
		
							parent
							
								
									4601439ae3
								
							
						
					
					
						commit
						8e2deed1d5
					
				| @ -1,5 +1,4 @@ | ||||
| import Blockly, { FieldDropdown } from 'blockly/core'; | ||||
| import { selectedBoard } from '../helpers/board' | ||||
| import Blockly, { FieldDropdown } from 'blockly/core' | ||||
| import * as Types from '../helpers/types' | ||||
| import { getColour } from '../helpers/colour'; | ||||
| 
 | ||||
|  | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -50,8 +50,6 @@ Blockly.Blocks['sensebox_display_printDisplay'] = { | ||||
|             .setCheck(null); | ||||
|         this.setPreviousStatement(true, null); | ||||
|         this.setNextStatement(true, null); | ||||
|         let variableName = this.getField('COLOR'); | ||||
|         console.log(variableName.getValue()); | ||||
|         this.setTooltip(Blockly.Msg.senseBox_display_printDisplay_tip); | ||||
|         this.setHelpUrl('https://sensebox.de/books'); | ||||
|     }, | ||||
|  | ||||
| @ -103,13 +103,10 @@ Blockly.Blocks['sensebox_send_to_osem'] = { | ||||
|             for (var i = 0; i < apiData.sensors.length; i++) { | ||||
|                 options.push([apiData.sensors[i].title, apiData.sensors[i]._id]); | ||||
|             } | ||||
|             console.log(options); | ||||
| 
 | ||||
|         } | ||||
|         if (options.length > 1) { | ||||
| 
 | ||||
|             var dropdown = options.slice(1) | ||||
|             console.log(dropdown); | ||||
|             return dropdown; | ||||
|         } else | ||||
|             return options; | ||||
|  | ||||
| @ -309,7 +309,7 @@ Blockly.Blocks['sensebox_button'] = { | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_scd30'] = { | ||||
|   init: function () { | ||||
|     var dropdownOptions = [[Blockly.Msg.senseBox_temp, "temperature"], [Blockly.Msg.senseBox_hum, "humidity"], [Blockly.Msg.senseBox_bme_co2, "CO2"]]; | ||||
|     var dropdownOptions = [[Blockly.Msg.senseBox_scd_co2, "CO2"], [Blockly.Msg.senseBox_temp, "temperature"], [Blockly.Msg.senseBox_hum, "humidity"]]; | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_scd30); | ||||
|     this.appendDummyInput() | ||||
| @ -318,6 +318,14 @@ Blockly.Blocks['sensebox_scd30'] = { | ||||
|       .appendField(new Blockly.FieldDropdown(dropdownOptions), "dropdown") | ||||
|     this.setOutput(true, Types.NUMBER.typeName); | ||||
|     this.setColour(getColour().sensebox); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_bme_tip); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_scd_tip); | ||||
|   }, | ||||
|   onchange: function (e) { | ||||
|     var dropdown = this.getFieldValue('dropdown'); | ||||
|     if (dropdown === 'temperature' || dropdown === 'humidity') { | ||||
|       this.setOutput(true, Types.DECIMAL.typeName); | ||||
|     } else if (dropdown === 'CO2') { | ||||
|       this.setOutput(true, Types.NUMBER.typeName); | ||||
|     } | ||||
|   } | ||||
| }; | ||||
|  | ||||
| @ -44,7 +44,7 @@ Blockly['Arduino'].addReservedWords( | ||||
|     'setup,loop,if,else,for,switch,case,while,' + | ||||
|     'do,break,continue,return,goto,define,include,' + | ||||
|     'HIGH,LOW,INPUT,OUTPUT,INPUT_PULLUP,true,false,' + | ||||
|     'interger, constants,floating,point,void,bookean,char,' + | ||||
|     'interger, constants,floating,point,void,boolean,char,' + | ||||
|     'unsigned,byte,int,word,long,float,double,string,String,array,' + | ||||
|     'static, volatile,const,sizeof,pinMode,digitalWrite,digitalRead,' + | ||||
|     'analogReference,analogRead,analogWrite,tone,noTone,shiftOut,shitIn,' + | ||||
|  | ||||
| @ -28,3 +28,97 @@ Blockly.Arduino['arduino_functions'] = function (block) { | ||||
|     //var loopcode = Blockly.Arduino.scrub_(block, loopBranch); No comment block
 | ||||
|     return loopBranch; | ||||
| }; | ||||
| 
 | ||||
| Blockly.Arduino['procedures_defreturn'] = function (block: Block | any) { | ||||
|     // Define a procedure with a return value.
 | ||||
|     const funcName = Blockly.Arduino.variableDB_.getName( | ||||
|         block.getFieldValue('NAME'), | ||||
|         Blockly.Procedures.NAME_TYPE | ||||
|     ); | ||||
|     const branch = Blockly.Arduino.statementToCode(block, 'STACK'); | ||||
|     const returnType = block.getFieldValue('RETURN TYPE') || 'void'; | ||||
| 
 | ||||
|     let returnValue = | ||||
|         Blockly.Arduino.valueToCode(block, 'RETURN', Blockly.Arduino.ORDER_NONE) || | ||||
|         ''; | ||||
|     if (returnValue) { | ||||
|         returnValue = Blockly.Arduino.INDENT + 'return ' + returnValue + ';\n'; | ||||
|     } | ||||
|     const args = []; | ||||
|     for (let i = 0; i < block.argumentVarModels_.length; i++) { | ||||
|         args[i] = | ||||
|             translateType(block.argumentVarModels_[i].type) + | ||||
|             ' ' + | ||||
|             block.argumentVarModels_[i].name; | ||||
|     } | ||||
|     let code = | ||||
|         translateType(returnType) + | ||||
|         ' ' + | ||||
|         funcName + | ||||
|         '(' + | ||||
|         args.join(', ') + | ||||
|         ') {\n' + | ||||
|         branch + | ||||
|         returnValue + | ||||
|         '}'; | ||||
|     code = Blockly.Arduino.scrub_(block, code); | ||||
|     // Add % so as not to collide with helper functions in definitions list.
 | ||||
|     Blockly.Arduino.functionNames_['%' + funcName] = code; | ||||
|     return null; | ||||
| }; | ||||
| 
 | ||||
| function translateType(type) { | ||||
|     switch (type) { | ||||
|         case 'Number': | ||||
|             return 'double'; | ||||
|         case 'String': | ||||
|             return 'String'; | ||||
|         case 'Boolean': | ||||
|             return 'boolean'; | ||||
|         case 'void': | ||||
|             return 'void'; | ||||
|         default: | ||||
|             throw new Error('Invalid Parameter Type'); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| Blockly.Arduino['procedures_defnoreturn'] = | ||||
|     Blockly.Arduino['procedures_defreturn']; | ||||
| 
 | ||||
| Blockly.Arduino['procedures_callreturn'] = function (block) { | ||||
|     // Call a procedure with a return value.
 | ||||
|     const funcName = Blockly.Arduino.variableDB_.getName( | ||||
|         block.getFieldValue('NAME'), | ||||
|         Blockly.Procedures.NAME_TYPE | ||||
|     ); | ||||
|     const args = []; | ||||
|     for (let i = 0; i < block.arguments_.length; i++) { | ||||
|         args[i] = | ||||
|             Blockly.Arduino.valueToCode( | ||||
|                 block, | ||||
|                 'ARG' + i, | ||||
|                 Blockly.Arduino.ORDER_COMMA | ||||
|             ) || 'null'; | ||||
|     } | ||||
|     const code = funcName + '(' + args.join(', ') + ')'; | ||||
|     return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| }; | ||||
| 
 | ||||
| Blockly.Arduino['procedures_callnoreturn'] = function (block) { | ||||
|     // Call a procedure with no return value.
 | ||||
|     const funcName = Blockly.Arduino.variableDB_.getName( | ||||
|         block.getFieldValue('NAME'), | ||||
|         Blockly.Procedures.NAME_TYPE | ||||
|     ); | ||||
|     const args = []; | ||||
|     for (let i = 0; i < block.arguments_.length; i++) { | ||||
|         args[i] = | ||||
|             Blockly.Arduino.valueToCode( | ||||
|                 block, | ||||
|                 'ARG' + i, | ||||
|                 Blockly.Arduino.ORDER_COMMA | ||||
|             ) || 'null'; | ||||
|     } | ||||
| 
 | ||||
|     return funcName + '(' + args.join(', ') + ');\n'; | ||||
| }; | ||||
| @ -263,32 +263,22 @@ Blockly.Arduino.sensebox_scd30 = function () { | ||||
|   Blockly.Arduino.libraries_['scd30_library'] = '#include "SparkFun_SCD30_Arduino_Library.h"' | ||||
|   Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_['SCD30'] = 'SCD30 airSensor;'; | ||||
|   Blockly.Arduino.variables_['scd30_temp'] = 'float scd30_temp;'; | ||||
|   Blockly.Arduino.variables_['scd30_humi'] = 'float scd30_humi;'; | ||||
|   Blockly.Arduino.variables_['scd30_co2'] = 'float scd30_co2;'; | ||||
|   Blockly.Arduino.setupCode_['init_scd30'] = ` Wire.begin();
 | ||||
|   if (airSensor.begin() == false) | ||||
|   { | ||||
|     Serial.println("Air sensor not detected. Please check wiring. Freezing..."); | ||||
|     while (1) | ||||
|       ; | ||||
|   }`;
 | ||||
|   Blockly.Arduino.loopCodeOnce_['scd30_getData'] = `if (airSensor.dataAvailable())
 | ||||
|   { | ||||
|    scd30_co2 = airSensor.getCO2(); | ||||
|    scd30_temp = airSensor.getTemperature(); | ||||
|    scd30_humi = airSensor.getHumidity(); | ||||
|   }` | ||||
|   var code = ''; | ||||
|   switch (dropdown) { | ||||
|     case 'temperature': | ||||
|       code = 'scd30_temp'; | ||||
|       code = 'aireSensor.getTemperature()'; | ||||
|       break; | ||||
|     case 'humidity': | ||||
|       code = 'scd30_humi'; | ||||
|       code = 'airSensor.getHumiditiy()'; | ||||
|       break; | ||||
|     case 'CO2': | ||||
|       code = 'scd30_co2'; | ||||
|       code = 'aireSensor.getCO2()'; | ||||
|       break; | ||||
|     default: | ||||
|       code = '' | ||||
|  | ||||
| @ -89,7 +89,7 @@ export const CHILD_BLOCK_MISSING = { | ||||
| const compatibleTypes = { | ||||
|     Array: ['Array'], | ||||
|     boolean: ['boolean'], | ||||
|     int: ['int'], | ||||
|     int: ['int', 'long', 'double', 'float'], | ||||
|     char: ['char'], | ||||
|     String: ['String'], | ||||
|     void: ['void'], | ||||
|  | ||||
| @ -774,6 +774,8 @@ Blockly.Msg.senseBox_telegram_message = "Nachricht" | ||||
| Blockly.Msg.senseBox_telegram_send = "Sende Nachricht" | ||||
| //SCD30 CO2 Sensor
 | ||||
| Blockly.Msg.senseBox_scd30 = "CO2 Sensor (Sensirion SCD30)"; | ||||
| Blockly.Msg.senseBox_scd_tip = "Gibt den Wert des CO2 Sensors"; | ||||
| Blockly.Msg.senseBox_scd_co2 = "CO2 in ppm"; | ||||
| //WS2818 RGB LED
 | ||||
| Blockly.Msg.senseBox_ws2818_rgb_led = "senseBox WS2812 - RGB LED"; | ||||
| Blockly.Msg.senseBox_ws2818_rgb_led_position = "Position"; | ||||
|  | ||||
| @ -757,6 +757,9 @@ Blockly.Msg.sensebox_soil_smt50 = "Soil Moisture and Temperature (SMT50)"; | ||||
| Blockly.Msg.sensebox_web_readHTML_filename = "File:"; | ||||
| //SCD30 CO2 Sensor
 | ||||
| Blockly.Msg.senseBox_scd30 = "CO2 Sensor (Sensirion SCD30)"; | ||||
| Blockly.Msg.senseBox_scd_co2 = "CO2 in ppm"; | ||||
| Blockly.Msg.senseBox_scd_tip = "Returns value of the CO2 Sensor"; | ||||
| 
 | ||||
| 
 | ||||
| //WS2818 RGB LED
 | ||||
| Blockly.Msg.senseBox_ws2818_rgb_led = "senseBox WS2812 - RGB LED"; | ||||
|  | ||||
| @ -379,6 +379,7 @@ class Toolbox extends React.Component { | ||||
|                     <Block type="array_getIndex" /> | ||||
|                     <Block type="lists_length" /> | ||||
|                 </Category> | ||||
|                 <Category name="Functions" custom="PROCEDURE"></Category> | ||||
|                 <sep></sep> | ||||
|                 <Category name="Eingang/Ausgang" colour={getColour().io}> | ||||
|                     <Block type="io_digitalwrite"></Block> | ||||
|  | ||||
| @ -58,7 +58,6 @@ class GalleryHome extends Component { | ||||
|     } | ||||
| 
 | ||||
|     componentDidMount() { | ||||
|         console.log(process.env.REACT_APP_BLOCKLY_API) | ||||
|         fetch(process.env.REACT_APP_BLOCKLY_API + this.props.location.pathname) | ||||
|             .then(res => res.json()) | ||||
|             .then((data) => { | ||||
|  | ||||
| @ -88,19 +88,12 @@ class Home extends Component { | ||||
|   } | ||||
| 
 | ||||
|   render() { | ||||
|     // console.log(this.props.match.params.galleryId);
 | ||||
|     // console.log(gallery);
 | ||||
|     // console.log(gallery.filter(project => project.id == this.props.match.params.galleryId));
 | ||||
|     if (this.state.projectToLoad) { | ||||
|       console.log(this.state.projectToLoad.xml) | ||||
|     } | ||||
|     console.log(this.props); | ||||
|     return ( | ||||
|       <div> | ||||
|         <div style={{ float: 'right', height: '40px', marginBottom: '20px' }}><WorkspaceFunc /></div> | ||||
|         <div style={{ float: 'left', height: '40px', position: 'relative' }}><WorkspaceStats /></div> | ||||
|         <Grid container spacing={2}> | ||||
|           <Grid item xs={12} md={this.state.codeOn ? 6 : 12} style={{ position: 'relative' }}> | ||||
|           <Grid item xs={12} md={this.state.codeOn ? 8 : 12} style={{ position: 'relative' }}> | ||||
|             <Tooltip title={this.state.codeOn ? 'Code ausblenden' : 'Code anzeigen'} > | ||||
|               <IconButton | ||||
|                 className={this.state.codeOn ? this.props.classes.codeOn : this.props.classes.codeOff} | ||||
| @ -117,7 +110,7 @@ class Home extends Component { | ||||
| 
 | ||||
|           </Grid> | ||||
|           {this.state.codeOn ? | ||||
|             <Grid item xs={12} md={6}> | ||||
|             <Grid item xs={12} md={4}> | ||||
|               <CodeViewer /> | ||||
|             </Grid> | ||||
|             : null} | ||||
|  | ||||
| @ -51,7 +51,6 @@ class Builder extends Component { | ||||
|   } | ||||
| 
 | ||||
|   submit = () => { | ||||
|     console.log(this.props.id) | ||||
|     if (this.props.id === null) { | ||||
|       var randomID = Date.now(); | ||||
|     } else { | ||||
| @ -115,7 +114,6 @@ class Builder extends Component { | ||||
|       this.props.readJSON(result); | ||||
|       this.setState({ snackbar: true, key: Date.now(), message: `${isFile ? 'Die übergebene JSON-Datei' : 'Der übergebene JSON-String'} wurde erfolgreich übernommen.`, type: 'success' }); | ||||
|     } catch (err) { | ||||
|       console.log(err); | ||||
|       this.props.progress(false); | ||||
|       this.props.jsonString(''); | ||||
|       this.setState({ open: true, string: false, title: 'Ungültiges JSON-Format', content: `${isFile ? 'Die übergebene Datei' : 'Der übergebene String'} enthält nicht valides JSON. Bitte überprüfe ${isFile ? 'die JSON-Datei' : 'den JSON-String'} und versuche es erneut.` }); | ||||
|  | ||||
| @ -30,7 +30,6 @@ class HintTutorialExists extends Component { | ||||
|   constructor(props) { | ||||
|     var previousPageWasAnotherDomain = props.pageVisits === 0; | ||||
|     var userDoNotWantToSeeNews = window.localStorage.getItem('news') ? true : false; | ||||
|     console.log(userDoNotWantToSeeNews); | ||||
|     super(props); | ||||
|     this.state = { | ||||
|       open: userDoNotWantToSeeNews ? !userDoNotWantToSeeNews : previousPageWasAnotherDomain | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user