update gps code
make gps blocks to osem block compatible
This commit is contained in:
		
							parent
							
								
									9ed49f2972
								
							
						
					
					
						commit
						0e0dbed77a
					
				| @ -1,110 +1,153 @@ | ||||
| import Blockly from 'blockly'; | ||||
| import { getColour } from '../helpers/colour' | ||||
| import * as Types from '../helpers/types' | ||||
| import { selectedBoard } from '../helpers/board' | ||||
| import Blockly from "blockly"; | ||||
| import { getColour } from "../helpers/colour"; | ||||
| import * as Types from "../helpers/types"; | ||||
| import { selectedBoard } from "../helpers/board"; | ||||
| 
 | ||||
| /** | ||||
|  * HDC1080 Temperature and Humidity Sensor | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_sensor_temp_hum'] = { | ||||
| Blockly.Blocks["sensebox_sensor_temp_hum"] = { | ||||
|   init: function () { | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_temp_hum); | ||||
|     this.appendDummyInput().appendField(Blockly.Msg.senseBox_temp_hum); | ||||
|     this.appendDummyInput() | ||||
|       .setAlign(Blockly.ALIGN_RIGHT) | ||||
|       .appendField(Blockly.Msg.senseBox_value) | ||||
|       .appendField(new Blockly.FieldDropdown([[Blockly.Msg.senseBox_temp, "Temperature"], [Blockly.Msg.senseBox_hum, "Humidity"]]), "NAME"); | ||||
|       .appendField( | ||||
|         new Blockly.FieldDropdown([ | ||||
|           [Blockly.Msg.senseBox_temp, "Temperature"], | ||||
|           [Blockly.Msg.senseBox_hum, "Humidity"], | ||||
|         ]), | ||||
|         "NAME" | ||||
|       ); | ||||
|     this.setOutput(true, Types.DECIMAL.typeName); | ||||
|     this.setColour(getColour().sensebox); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_temp_hum_tooltip); | ||||
|     this.setHelpUrl(Blockly.Msg.senseBox_temp_hum_helpurl); | ||||
|   } | ||||
|   }, | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
|  * VEML6070 and TSL4513  | ||||
|  *  | ||||
|  * VEML6070 and TSL4513 | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_sensor_uv_light'] = { | ||||
| Blockly.Blocks["sensebox_sensor_uv_light"] = { | ||||
|   init: function () { | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_uv_light); | ||||
|     this.appendDummyInput().appendField(Blockly.Msg.senseBox_uv_light); | ||||
|     this.appendDummyInput() | ||||
|       .setAlign(Blockly.ALIGN_RIGHT) | ||||
|       .appendField(Blockly.Msg.senseBox_value) | ||||
|       .appendField(new Blockly.FieldDropdown([[Blockly.Msg.senseBox_light, "Illuminance"], [Blockly.Msg.senseBox_uv, "UvIntensity"]]), "NAME"); | ||||
|       .appendField( | ||||
|         new Blockly.FieldDropdown([ | ||||
|           [Blockly.Msg.senseBox_light, "Illuminance"], | ||||
|           [Blockly.Msg.senseBox_uv, "UvIntensity"], | ||||
|         ]), | ||||
|         "NAME" | ||||
|       ); | ||||
|     this.setOutput(true, Types.DECIMAL.typeName); | ||||
|     this.setColour(getColour().sensebox); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_uv_light_tooltip); | ||||
|     this.setHelpUrl(Blockly.Msg.senseBox_uv_light_helpurl); | ||||
|   } | ||||
|   }, | ||||
| }; | ||||
| 
 | ||||
| /* | ||||
| BMX055 Three differen Blocks for Accelerometer, Gyroscope, Compass | ||||
| */ | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_sensor_bmx055_accelerometer'] = { | ||||
| Blockly.Blocks["sensebox_sensor_bmx055_accelerometer"] = { | ||||
|   init: function () { | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_bmx055_accelerometer); | ||||
|     this.appendDummyInput().appendField( | ||||
|       Blockly.Msg.senseBox_bmx055_accelerometer | ||||
|     ); | ||||
|     this.appendDummyInput() | ||||
|       .setAlign(Blockly.ALIGN_LEFT) | ||||
|       .appendField(Blockly.Msg.senseBox_bmx055_accelerometer_direction) | ||||
|       .appendField(new Blockly.FieldDropdown([[Blockly.Msg.senseBox_bmx055_accelerometer_direction_x, "X"], [Blockly.Msg.senseBox_bmx055_accelerometer_direction_y, "Y"], [Blockly.Msg.senseBox_bmx055_accelerometer_direction_z, "Z"], [Blockly.Msg.senseBox_bmx055_accelerometer_direction_total, "Total"]]), "VALUE"); | ||||
|       .appendField( | ||||
|         new Blockly.FieldDropdown([ | ||||
|           [Blockly.Msg.senseBox_bmx055_accelerometer_direction_x, "X"], | ||||
|           [Blockly.Msg.senseBox_bmx055_accelerometer_direction_y, "Y"], | ||||
|           [Blockly.Msg.senseBox_bmx055_accelerometer_direction_z, "Z"], | ||||
|           [Blockly.Msg.senseBox_bmx055_accelerometer_direction_total, "Total"], | ||||
|         ]), | ||||
|         "VALUE" | ||||
|       ); | ||||
|     this.appendDummyInput() | ||||
|       .setAlign(Blockly.ALIGN_LEFT) | ||||
|       .appendField(Blockly.Msg.senseBox_bmx055_accelerometer_range) | ||||
|       .appendField(new Blockly.FieldDropdown([[Blockly.Msg.senseBox_bmx055_accelerometer_range_2g, "0x3"], [Blockly.Msg.senseBox_bmx055_accelerometer_range_4g, "0x5"], [Blockly.Msg.senseBox_bmx055_accelerometer_range_8g, "0x8"], [Blockly.Msg.senseBox_bmx055_accelerometer_range_16g, "0x0C"]]), "RANGE"); | ||||
|       .appendField( | ||||
|         new Blockly.FieldDropdown([ | ||||
|           [Blockly.Msg.senseBox_bmx055_accelerometer_range_2g, "0x3"], | ||||
|           [Blockly.Msg.senseBox_bmx055_accelerometer_range_4g, "0x5"], | ||||
|           [Blockly.Msg.senseBox_bmx055_accelerometer_range_8g, "0x8"], | ||||
|           [Blockly.Msg.senseBox_bmx055_accelerometer_range_16g, "0x0C"], | ||||
|         ]), | ||||
|         "RANGE" | ||||
|       ); | ||||
|     this.setOutput(true, Types.DECIMAL.typeName); | ||||
|     this.setColour(getColour().sensebox); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_bmx055_accelerometer_tooltip); | ||||
|     this.setHelpUrl(Blockly.Msg.senseBox_bmx055_helpurl); | ||||
|   } | ||||
|   }, | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
|  * SDS011 Fine Particular Matter Sensor | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_sensor_sds011'] = { | ||||
| Blockly.Blocks["sensebox_sensor_sds011"] = { | ||||
|   init: function () { | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_sds011); | ||||
|     this.appendDummyInput().appendField(Blockly.Msg.senseBox_sds011); | ||||
|     this.appendDummyInput() | ||||
|       .setAlign(Blockly.ALIGN_RIGHT) | ||||
|       .appendField(Blockly.Msg.senseBox_value) | ||||
|       .appendField(new Blockly.FieldDropdown([[Blockly.Msg.senseBox_sds011_pm25, "Pm25"], [Blockly.Msg.senseBox_sds011_pm10, "Pm10"]]), "NAME") | ||||
|       .appendField( | ||||
|         new Blockly.FieldDropdown([ | ||||
|           [Blockly.Msg.senseBox_sds011_pm25, "Pm25"], | ||||
|           [Blockly.Msg.senseBox_sds011_pm10, "Pm10"], | ||||
|         ]), | ||||
|         "NAME" | ||||
|       ) | ||||
|       .appendField(Blockly.Msg.senseBox_sds011_dimension) | ||||
|       .appendField(new Blockly.FieldDropdown([[Blockly.Msg.senseBox_sds011_serial1, "Serial1"], [Blockly.Msg.senseBox_sds011_serial2, "Serial2"]]), "SERIAL"); | ||||
|       .appendField( | ||||
|         new Blockly.FieldDropdown([ | ||||
|           [Blockly.Msg.senseBox_sds011_serial1, "Serial1"], | ||||
|           [Blockly.Msg.senseBox_sds011_serial2, "Serial2"], | ||||
|         ]), | ||||
|         "SERIAL" | ||||
|       ); | ||||
|     this.setOutput(true, Types.DECIMAL.typeName); | ||||
|     this.setColour(getColour().sensebox); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_sds011_tooltip); | ||||
|     this.setHelpUrl(Blockly.Msg.senseBox_sds011_helpurl); | ||||
|   } | ||||
|   }, | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * BMP280 Pressure Sensor | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_sensor_pressure'] = { | ||||
| Blockly.Blocks["sensebox_sensor_pressure"] = { | ||||
|   init: function () { | ||||
|     var dropdownOptions = [[Blockly.Msg.senseBox_pressure, "Pressure"], [Blockly.Msg.senseBox_temp, "Temperature"], [Blockly.Msg.senseBox_gps_alt, "Altitude"]]; | ||||
|     var dropdown = new Blockly.FieldDropdown(dropdownOptions, function (option) { | ||||
|       var input = (option === 'Pressure') || (option === 'Temperature') || (option === 'Altitude'); | ||||
|     var dropdownOptions = [ | ||||
|       [Blockly.Msg.senseBox_pressure, "Pressure"], | ||||
|       [Blockly.Msg.senseBox_temp, "Temperature"], | ||||
|       [Blockly.Msg.senseBox_gps_alt, "Altitude"], | ||||
|     ]; | ||||
|     var dropdown = new Blockly.FieldDropdown(dropdownOptions, function ( | ||||
|       option | ||||
|     ) { | ||||
|       var input = | ||||
|         option === "Pressure" || | ||||
|         option === "Temperature" || | ||||
|         option === "Altitude"; | ||||
|       this.sourceBlock_.updateShape_(input); | ||||
|     }); | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_pressure_sensor); | ||||
|     this.appendDummyInput().appendField(Blockly.Msg.senseBox_pressure_sensor); | ||||
|     this.appendDummyInput() | ||||
|       .setAlign(Blockly.ALIGN_RIGHT) | ||||
|       .appendField(Blockly.Msg.senseBox_value) | ||||
| @ -121,8 +164,7 @@ Blockly.Blocks['sensebox_sensor_pressure'] = { | ||||
|    */ | ||||
| 
 | ||||
|   domToMutation: function (xmlElement) { | ||||
|     (xmlElement.getAttribute('port')); | ||||
| 
 | ||||
|     xmlElement.getAttribute("port"); | ||||
|   }, | ||||
|   /** | ||||
|    * Create XML to represent number of pins selection. | ||||
| @ -130,10 +172,10 @@ Blockly.Blocks['sensebox_sensor_pressure'] = { | ||||
|    * @this Blockly.Block | ||||
|    */ | ||||
|   mutationToDom: function () { | ||||
|     var container = document.createElement('mutation'); | ||||
|     var input = this.getFieldValue('NAME'); | ||||
|     var container = document.createElement("mutation"); | ||||
|     var input = this.getFieldValue("NAME"); | ||||
|     this.updateShape_(input); | ||||
|     container.setAttribute('NAME', input); | ||||
|     container.setAttribute("NAME", input); | ||||
|     return container; | ||||
|   }, | ||||
|   /** | ||||
| @ -143,58 +185,70 @@ Blockly.Blocks['sensebox_sensor_pressure'] = { | ||||
|    * @this Blockly.Block | ||||
|    */ | ||||
|   updateShape_: function () { | ||||
|     var extraFieldExist = this.getFieldValue('referencePressure'); | ||||
|     var input = this.getFieldValue('NAME'); | ||||
|     if (input === 'Altitude' && extraFieldExist === null) { | ||||
|       this.appendDummyInput('extraField') | ||||
|     var extraFieldExist = this.getFieldValue("referencePressure"); | ||||
|     var input = this.getFieldValue("NAME"); | ||||
|     if (input === "Altitude" && extraFieldExist === null) { | ||||
|       this.appendDummyInput("extraField") | ||||
|         .setAlign(Blockly.ALIGN_RIGHT) | ||||
|         .appendField(Blockly.Msg.senseBox_pressure_referencePressure) | ||||
|         .appendField(new Blockly.FieldTextInput("1013"), "referencePressure") | ||||
|         .appendField(Blockly.Msg.senseBox_pressure_referencePressure_dim); | ||||
|     } | ||||
| 
 | ||||
|     if ((input === 'Pressure' || input === 'Temperature') && extraFieldExist !== null) { | ||||
|       this.removeInput('extraField'); | ||||
|     if ( | ||||
|       (input === "Pressure" || input === "Temperature") && | ||||
|       extraFieldExist !== null | ||||
|     ) { | ||||
|       this.removeInput("extraField"); | ||||
|     } | ||||
|   } | ||||
|   }, | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * BME680 Environmental Sensor | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_sensor_bme680_bsec'] = { | ||||
| Blockly.Blocks["sensebox_sensor_bme680_bsec"] = { | ||||
|   init: function () { | ||||
|     var dropdownOptions = [[Blockly.Msg.senseBox_temp, "temperature"], [Blockly.Msg.senseBox_hum, "humidity"], [Blockly.Msg.senseBox_pressure, "pressure"], [Blockly.Msg.senseBox_bme_iaq, "IAQ"], [Blockly.Msg.senseBox_bme_iaq_accuracy, "IAQAccuracy"], [Blockly.Msg.senseBox_bme_co2, "CO2"], [Blockly.Msg.senseBox_bme_breatheVocEquivalent, "breathVocEquivalent"]]; | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_bme680); | ||||
|     var dropdownOptions = [ | ||||
|       [Blockly.Msg.senseBox_temp, "temperature"], | ||||
|       [Blockly.Msg.senseBox_hum, "humidity"], | ||||
|       [Blockly.Msg.senseBox_pressure, "pressure"], | ||||
|       [Blockly.Msg.senseBox_bme_iaq, "IAQ"], | ||||
|       [Blockly.Msg.senseBox_bme_iaq_accuracy, "IAQAccuracy"], | ||||
|       [Blockly.Msg.senseBox_bme_co2, "CO2"], | ||||
|       [Blockly.Msg.senseBox_bme_breatheVocEquivalent, "breathVocEquivalent"], | ||||
|     ]; | ||||
|     this.appendDummyInput().appendField(Blockly.Msg.senseBox_bme680); | ||||
|     this.appendDummyInput() | ||||
|       .setAlign(Blockly.ALIGN_RIGHT) | ||||
|       .appendField(Blockly.Msg.senseBox_value) | ||||
|       .appendField(new Blockly.FieldDropdown(dropdownOptions), "dropdown") | ||||
|       .appendField(new Blockly.FieldDropdown(dropdownOptions), "dropdown"); | ||||
|     this.setOutput(true, Types.DECIMAL.typeName); | ||||
|     this.setColour(getColour().sensebox); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_bme_tooltip); | ||||
|     this.setHelpUrl(Blockly.Msg.senseBox_bme680_helpurl) | ||||
|   } | ||||
|     this.setHelpUrl(Blockly.Msg.senseBox_bme680_helpurl); | ||||
|   }, | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
|  * Ultrasonic Sensor | ||||
|  *  | ||||
|  *  | ||||
|  * | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_sensor_ultrasonic_ranger'] = { | ||||
| Blockly.Blocks["sensebox_sensor_ultrasonic_ranger"] = { | ||||
|   init: function () { | ||||
| 
 | ||||
|     var dropdownOptions = [[Blockly.Msg.senseBox_ultrasonic_port_A, 'A'], | ||||
|     [Blockly.Msg.senseBox_ultrasonic_port_B, 'B'], [Blockly.Msg.senseBox_ultrasonic_port_C, 'C']]; | ||||
|     var dropdown = new Blockly.FieldDropdown(dropdownOptions, function (option) { | ||||
|       var input = (option === 'A') || (option === 'B') || (option === 'C'); | ||||
|     var dropdownOptions = [ | ||||
|       [Blockly.Msg.senseBox_ultrasonic_port_A, "A"], | ||||
|       [Blockly.Msg.senseBox_ultrasonic_port_B, "B"], | ||||
|       [Blockly.Msg.senseBox_ultrasonic_port_C, "C"], | ||||
|     ]; | ||||
|     var dropdown = new Blockly.FieldDropdown(dropdownOptions, function ( | ||||
|       option | ||||
|     ) { | ||||
|       var input = option === "A" || option === "B" || option === "C"; | ||||
|       this.sourceBlock_.updateShape_(input); | ||||
|     }); | ||||
| 
 | ||||
| @ -202,14 +256,18 @@ Blockly.Blocks['sensebox_sensor_ultrasonic_ranger'] = { | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_ultrasonic) | ||||
|       .appendField(dropdown, "port"); | ||||
|     this.appendDummyInput('TrigEcho') | ||||
|     this.appendDummyInput("TrigEcho") | ||||
|       .setAlign(Blockly.ALIGN_RIGHT) | ||||
|       .appendField(Blockly.Msg.senseBox_ultrasonic_trigger) | ||||
|       .appendField(new Blockly.FieldDropdown( | ||||
|         selectedBoard().digitalPins), 'ultrasonic_trigger') | ||||
|       .appendField( | ||||
|         new Blockly.FieldDropdown(selectedBoard().digitalPins), | ||||
|         "ultrasonic_trigger" | ||||
|       ) | ||||
|       .appendField(Blockly.Msg.senseBox_ultrasonic_echo) | ||||
|       .appendField(new Blockly.FieldDropdown( | ||||
|         selectedBoard().digitalPins), 'ultrasonic_echo'); | ||||
|       .appendField( | ||||
|         new Blockly.FieldDropdown(selectedBoard().digitalPins), | ||||
|         "ultrasonic_echo" | ||||
|       ); | ||||
|     this.setOutput(true, Types.NUMBER.typeName); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_ultrasonic_tooltip); | ||||
|     this.setHelpUrl(Blockly.Msg.senseBox_ultrasonic_helpurl); | ||||
| @ -220,8 +278,7 @@ Blockly.Blocks['sensebox_sensor_ultrasonic_ranger'] = { | ||||
|    * @this Blockly.Block | ||||
|    */ | ||||
|   domToMutation: function (xmlElement) { | ||||
|     (xmlElement.getAttribute('port')); | ||||
| 
 | ||||
|     xmlElement.getAttribute("port"); | ||||
|   }, | ||||
|   /** | ||||
|    * Create XML to represent number of pins selection. | ||||
| @ -229,8 +286,8 @@ Blockly.Blocks['sensebox_sensor_ultrasonic_ranger'] = { | ||||
|    * @this Blockly.Block | ||||
|    */ | ||||
|   mutationToDom: function () { | ||||
|     var container = document.createElement('mutation'); | ||||
|     var input = this.getFieldValue('port'); | ||||
|     var container = document.createElement("mutation"); | ||||
|     var input = this.getFieldValue("port"); | ||||
|     this.updateShape_(input); | ||||
|     container.setAttribute("port", input); | ||||
|     return container; | ||||
| @ -242,159 +299,185 @@ Blockly.Blocks['sensebox_sensor_ultrasonic_ranger'] = { | ||||
|    * @this Blockly.Block | ||||
|    */ | ||||
|   updateShape_: function () { | ||||
|     var input = this.getFieldValue('port'); | ||||
|     var input = this.getFieldValue("port"); | ||||
|     switch (input) { | ||||
|       case 'A': | ||||
|         this.setFieldValue('1', 'ultrasonic_trigger'); | ||||
|         this.setFieldValue('2', 'ultrasonic_echo'); | ||||
|       case "A": | ||||
|         this.setFieldValue("1", "ultrasonic_trigger"); | ||||
|         this.setFieldValue("2", "ultrasonic_echo"); | ||||
|         break; | ||||
|       case 'B': | ||||
|         this.setFieldValue('3', 'ultrasonic_trigger'); | ||||
|         this.setFieldValue('4', 'ultrasonic_echo'); | ||||
|       case "B": | ||||
|         this.setFieldValue("3", "ultrasonic_trigger"); | ||||
|         this.setFieldValue("4", "ultrasonic_echo"); | ||||
|         break; | ||||
|       case 'C': | ||||
|         this.setFieldValue('5', 'ultrasonic_trigger'); | ||||
|         this.setFieldValue('6', 'ultrasonic_echo'); | ||||
|       case "C": | ||||
|         this.setFieldValue("5", "ultrasonic_trigger"); | ||||
|         this.setFieldValue("6", "ultrasonic_echo"); | ||||
|         break; | ||||
|       default: | ||||
|         break; | ||||
|     } | ||||
|   } | ||||
|   }, | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * Microphone | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_sensor_sound'] = { | ||||
| Blockly.Blocks["sensebox_sensor_sound"] = { | ||||
|   init: function () { | ||||
|     this.setColour(getColour().sensebox); | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_sound) | ||||
|       .appendField("Pin:") | ||||
|       .appendField(new Blockly.FieldDropdown(selectedBoard().analogPins), "PIN") | ||||
|       .appendField( | ||||
|         new Blockly.FieldDropdown(selectedBoard().analogPins), | ||||
|         "PIN" | ||||
|       ); | ||||
|     this.setOutput(true, Types.NUMBER.typeName); | ||||
|     this.setHelpUrl(Blockly.Msg.senseBox_sound_helpurl); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_sound_tooltip); | ||||
|   } | ||||
|   }, | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * Button | ||||
|  *  | ||||
|  *  | ||||
|  * | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_button'] = { | ||||
| Blockly.Blocks["sensebox_button"] = { | ||||
|   init: function () { | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_button) | ||||
|       .appendField(new Blockly.FieldDropdown([[Blockly.Msg.senseBox_button_isPressed, "isPressed"], [Blockly.Msg.senseBox_button_wasPressed, "wasPressed"], [Blockly.Msg.senseBox_button_switch, "Switch"]]), "FUNCTION") | ||||
|       .appendField( | ||||
|         new Blockly.FieldDropdown([ | ||||
|           [Blockly.Msg.senseBox_button_isPressed, "isPressed"], | ||||
|           [Blockly.Msg.senseBox_button_wasPressed, "wasPressed"], | ||||
|           [Blockly.Msg.senseBox_button_switch, "Switch"], | ||||
|         ]), | ||||
|         "FUNCTION" | ||||
|       ) | ||||
|       .appendField("Pin:") | ||||
|       .appendField(new Blockly.FieldDropdown(selectedBoard().digitalPinsButton), "PIN"); | ||||
|       .appendField( | ||||
|         new Blockly.FieldDropdown(selectedBoard().digitalPinsButton), | ||||
|         "PIN" | ||||
|       ); | ||||
|     this.setOutput(true, Types.BOOLEAN.typeName); | ||||
|     this.setColour(getColour().sensebox); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_button_tooltip); | ||||
|   } | ||||
|   }, | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * SCD30 CO2 Sensor | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_scd30'] = { | ||||
| Blockly.Blocks["sensebox_scd30"] = { | ||||
|   init: function () { | ||||
|     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); | ||||
|     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() | ||||
|       .setAlign(Blockly.ALIGN_RIGHT) | ||||
|       .appendField(Blockly.Msg.senseBox_value) | ||||
|       .appendField(new Blockly.FieldDropdown(dropdownOptions), "dropdown") | ||||
|       .appendField(new Blockly.FieldDropdown(dropdownOptions), "dropdown"); | ||||
|     this.setOutput(true, Types.NUMBER.typeName); | ||||
|     this.setColour(getColour().sensebox); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_scd_tooltip); | ||||
|     this.setHelpUrl(Blockly.Msg.senseBox_scd_helpurl); | ||||
|   }, | ||||
|   onchange: function (e) { | ||||
|     var dropdown = this.getFieldValue('dropdown'); | ||||
|     if (dropdown === 'temperature' || dropdown === 'humidity') { | ||||
|     var dropdown = this.getFieldValue("dropdown"); | ||||
|     if (dropdown === "temperature" || dropdown === "humidity") { | ||||
|       this.setOutput(true, Types.DECIMAL.typeName); | ||||
|     } else if (dropdown === 'CO2') { | ||||
|     } else if (dropdown === "CO2") { | ||||
|       this.setOutput(true, Types.NUMBER.typeName); | ||||
|     } | ||||
|   } | ||||
|   }, | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * GPS Module | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_gps'] = { | ||||
| Blockly.Blocks["sensebox_gps"] = { | ||||
|   init: function () { | ||||
|     var dropdownOptions = [[Blockly.Msg.senseBox_gps_lat, "latitude"], [Blockly.Msg.senseBox_gps_lng, "longitude"], [Blockly.Msg.senseBox_gps_alt, "altitude"], ["pDOP", "pDOP"], ["Fix Type", "fixType"]]; | ||||
|     this.appendDummyInput() | ||||
|       .appendField("GPS Modul"); | ||||
|     var dropdownOptions = [ | ||||
|       [Blockly.Msg.senseBox_gps_lat, "latitude"], | ||||
|       [Blockly.Msg.senseBox_gps_lng, "longitude"], | ||||
|       [Blockly.Msg.senseBox_gps_alt, "altitude"], | ||||
|       ["pDOP", "pDOP"], | ||||
|       ["Timestamp", "timestamp"], | ||||
|       ["Fix Type", "fixType"], | ||||
|     ]; | ||||
|     this.appendDummyInput().appendField("GPS Modul"); | ||||
|     this.appendDummyInput() | ||||
|       .setAlign(Blockly.ALIGN_RIGHT) | ||||
|       .appendField(Blockly.Msg.senseBox_value) | ||||
|       .appendField(new Blockly.FieldDropdown(dropdownOptions), "dropdown") | ||||
|       .appendField(new Blockly.FieldDropdown(dropdownOptions), "dropdown"); | ||||
|     this.setOutput(true, Types.NUMBER.typeName); | ||||
|     this.setColour(getColour().sensebox); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_gps_tooltip); | ||||
|   } | ||||
|   }, | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
|  * Block for Truebner STM50 | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_sensor_truebner_smt50'] = { | ||||
| Blockly.Blocks["sensebox_sensor_truebner_smt50"] = { | ||||
|   init: function () { | ||||
|     var dropdownOptions = [[Blockly.Msg.senseBox_ultrasonic_port_A, 'A'], | ||||
|     [Blockly.Msg.senseBox_ultrasonic_port_B, 'B'], [Blockly.Msg.senseBox_ultrasonic_port_C, 'C']]; | ||||
|     var dropdownOptions = [ | ||||
|       [Blockly.Msg.senseBox_ultrasonic_port_A, "A"], | ||||
|       [Blockly.Msg.senseBox_ultrasonic_port_B, "B"], | ||||
|       [Blockly.Msg.senseBox_ultrasonic_port_C, "C"], | ||||
|     ]; | ||||
|     this.setColour(getColour().sensebox); | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_smt50); | ||||
|     this.appendDummyInput().appendField(Blockly.Msg.senseBox_smt50); | ||||
|     this.appendDummyInput() | ||||
|       .appendField("Port:") | ||||
|       .appendField(new Blockly.FieldDropdown(dropdownOptions), "Port") | ||||
|       .appendField(new Blockly.FieldDropdown(dropdownOptions), "Port"); | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_value) | ||||
|       .appendField(new Blockly.FieldDropdown([[Blockly.Msg.senseBox_temp, "temp"], [Blockly.Msg.senseBox_soil, "soil"]]), 'value') | ||||
|       .appendField( | ||||
|         new Blockly.FieldDropdown([ | ||||
|           [Blockly.Msg.senseBox_temp, "temp"], | ||||
|           [Blockly.Msg.senseBox_soil, "soil"], | ||||
|         ]), | ||||
|         "value" | ||||
|       ); | ||||
|     this.setOutput(true, Types.NUMBER.typeName); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_smt50_tooltip); | ||||
|     this.setHelpUrl(Blockly.Msg.senseBox_smt50_helpurl); | ||||
|   } | ||||
|   }, | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * DS18B20 Watertemperature | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_sensor_watertemperature'] = { | ||||
| Blockly.Blocks["sensebox_sensor_watertemperature"] = { | ||||
|   init: function () { | ||||
|     var dropdownOptions = [[Blockly.Msg.senseBox_ultrasonic_port_A, 'A'], | ||||
|     [Blockly.Msg.senseBox_ultrasonic_port_B, 'B'], [Blockly.Msg.senseBox_ultrasonic_port_C, 'C']]; | ||||
|     var dropdownOptions = [ | ||||
|       [Blockly.Msg.senseBox_ultrasonic_port_A, "A"], | ||||
|       [Blockly.Msg.senseBox_ultrasonic_port_B, "B"], | ||||
|       [Blockly.Msg.senseBox_ultrasonic_port_C, "C"], | ||||
|     ]; | ||||
|     this.setColour(getColour().sensebox); | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_watertemperature) | ||||
|       .appendField("Port:") | ||||
|       .appendField(new Blockly.FieldDropdown(dropdownOptions), "Port") | ||||
|       .appendField(new Blockly.FieldDropdown(dropdownOptions), "Port"); | ||||
|     this.setOutput(true, Types.NUMBER.typeName); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_watertemperature_tip); | ||||
|   } | ||||
|   }, | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
| @ -418,18 +501,20 @@ Blockly.Blocks['sensebox_windspeed'] = { | ||||
|  * DF Robot Soundsensor | ||||
|  */ | ||||
| 
 | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_soundsensor_dfrobot'] = { | ||||
| Blockly.Blocks["sensebox_soundsensor_dfrobot"] = { | ||||
|   init: function () { | ||||
|     var dropdownOptions = [[Blockly.Msg.senseBox_ultrasonic_port_A, 'A'], | ||||
|     [Blockly.Msg.senseBox_ultrasonic_port_B, 'B'], [Blockly.Msg.senseBox_ultrasonic_port_C, 'C']]; | ||||
|     var dropdownOptions = [ | ||||
|       [Blockly.Msg.senseBox_ultrasonic_port_A, "A"], | ||||
|       [Blockly.Msg.senseBox_ultrasonic_port_B, "B"], | ||||
|       [Blockly.Msg.senseBox_ultrasonic_port_C, "C"], | ||||
|     ]; | ||||
|     this.setColour(getColour().sensebox); | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_soundsensor_dfrobot) | ||||
|       .appendField("Port:") | ||||
|       .appendField(new Blockly.FieldDropdown(dropdownOptions), "Port") | ||||
|       .appendField(new Blockly.FieldDropdown(dropdownOptions), "Port"); | ||||
|     this.setOutput(true, Types.DECIMAL.typeName); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_soundsensor_dfrobot_tooltip); | ||||
|     this.setHelpUrl(Blockly.Msg.senseBox_soundsensor_dfrobot_helpurl) | ||||
|   } | ||||
| }; | ||||
|     this.setHelpUrl(Blockly.Msg.senseBox_soundsensor_dfrobot_helpurl); | ||||
|   }, | ||||
| }; | ||||
|  | ||||
| @ -1,66 +1,74 @@ | ||||
| import Blockly from 'blockly'; | ||||
| 
 | ||||
| import Blockly from "blockly"; | ||||
| 
 | ||||
| /** | ||||
| * Block send Data to the openSenseMap | ||||
| */ | ||||
|  * Block send Data to the openSenseMap | ||||
|  */ | ||||
| Blockly.Arduino.sensebox_send_to_osem = function (block) { | ||||
|   var code = ''; | ||||
|   var sensor_id = this.getFieldValue('SensorID'); | ||||
|   var code = ""; | ||||
|   var sensor_id = this.getFieldValue("SensorID"); | ||||
|   var id = sensor_id.slice(-3).toUpperCase(); | ||||
|   var sensor_value = Blockly.Arduino.valueToCode(this, 'Value', Blockly.Arduino.ORDER_ATOMIC) || '"Keine Eingabe"'; | ||||
|   Blockly.Arduino.definitions_['SENSOR_ID' + id + ''] = 'const char SENSOR_ID' + id + '[] PROGMEM = "' + sensor_id + '";'; | ||||
|   code += 'addMeasurement(SENSOR_ID' + id + ',' + sensor_value + ');\n'; | ||||
|   var sensor_value = | ||||
|     Blockly.Arduino.valueToCode(this, "Value", Blockly.Arduino.ORDER_ATOMIC) || | ||||
|     '"Keine Eingabe"'; | ||||
|   Blockly.Arduino.definitions_["SENSOR_ID" + id + ""] = | ||||
|     "const char SENSOR_ID" + id + '[] PROGMEM = "' + sensor_id + '";'; | ||||
|   code += "addMeasurement(SENSOR_ID" + id + "," + sensor_value + ");\n"; | ||||
|   return code; | ||||
| }; | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_osem_connection = function (Block) { | ||||
|   var box_id = this.getFieldValue('BoxID'); | ||||
|   var host = this.getFieldValue('host'); | ||||
|   var branch = Blockly.Arduino.statementToCode(Block, 'DO'); | ||||
|   var access_token = this.getFieldValue('access_token'); | ||||
|   var box_id = this.getFieldValue("BoxID"); | ||||
|   var host = this.getFieldValue("host"); | ||||
|   var branch = Blockly.Arduino.statementToCode(Block, "DO"); | ||||
|   var access_token = this.getFieldValue("access_token"); | ||||
|   var blocks = this.getDescendants(); | ||||
|   var type = this.getFieldValue('type'); | ||||
|   var ssl = this.getFieldValue('SSL'); | ||||
|   var type = this.getFieldValue("type"); | ||||
|   var ssl = this.getFieldValue("SSL"); | ||||
|   var port = 0; | ||||
|   var count = 0; | ||||
|   if (blocks !== undefined) { | ||||
|     for (var i = 0; i < blocks.length; i++) { | ||||
|       if (blocks[i].type === 'sensebox_send_to_osem') { | ||||
|       if (blocks[i].type === "sensebox_send_to_osem") { | ||||
|         count++; | ||||
| 
 | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|   var num_sensors = count; | ||||
|   Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_['num_sensors'] = 'static const uint8_t NUM_SENSORS = ' + num_sensors + ';' | ||||
|   Blockly.Arduino.definitions_['SenseBoxID'] = 'const char SENSEBOX_ID [] PROGMEM = "' + box_id + '";'; | ||||
|   Blockly.Arduino.definitions_['host'] = 'const char server [] PROGMEM =' + host + ';'; | ||||
|   if (ssl === 'TRUE') { | ||||
|     Blockly.Arduino.definitions_['WiFiSSLClient'] = 'WiFiSSLClient client;'; | ||||
|   Blockly.Arduino.libraries_["library_senseBoxMCU"] = | ||||
|     '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_["num_sensors"] = | ||||
|     "static const uint8_t NUM_SENSORS = " + num_sensors + ";"; | ||||
|   Blockly.Arduino.definitions_["SenseBoxID"] = | ||||
|     'const char SENSEBOX_ID [] PROGMEM = "' + box_id + '";'; | ||||
|   Blockly.Arduino.definitions_["host"] = | ||||
|     "const char server [] PROGMEM =" + host + ";"; | ||||
|   if (ssl === "TRUE") { | ||||
|     Blockly.Arduino.definitions_["WiFiSSLClient"] = "WiFiSSLClient client;"; | ||||
|     port = 443; | ||||
|   } else if (ssl === 'FALSE') { | ||||
|     Blockly.Arduino.definitions_['WiFiClient'] = 'WiFiClient client;'; | ||||
|   } else if (ssl === "FALSE") { | ||||
|     Blockly.Arduino.definitions_["WiFiClient"] = "WiFiClient client;"; | ||||
|     port = 80; | ||||
|   } | ||||
| 
 | ||||
|   Blockly.Arduino.definitions_['measurement'] = `typedef struct measurement {
 | ||||
|   Blockly.Arduino.definitions_["measurement"] = `typedef struct measurement {
 | ||||
|       const char *sensorId; | ||||
|       float value; | ||||
|     } measurement;`;
 | ||||
|   Blockly.Arduino.definitions_['buffer'] = 'char buffer[750];'; | ||||
|   Blockly.Arduino.definitions_['num_measurement'] = `measurement measurements[NUM_SENSORS];
 | ||||
|   Blockly.Arduino.definitions_["buffer"] = "char buffer[750];"; | ||||
|   Blockly.Arduino.definitions_[ | ||||
|     "num_measurement" | ||||
|   ] = `measurement measurements[NUM_SENSORS];
 | ||||
|     uint8_t num_measurements = 0;`;
 | ||||
|   Blockly.Arduino.definitions_['lengthMultiplikator'] = 'const int lengthMultiplikator = 35;'; | ||||
|   Blockly.Arduino.functionNames_['addMeasurement'] = ` | ||||
|   Blockly.Arduino.definitions_["lengthMultiplikator"] = | ||||
|     "const int lengthMultiplikator = 35;"; | ||||
|   Blockly.Arduino.functionNames_["addMeasurement"] = ` | ||||
|     void addMeasurement(const char *sensorId, float value) { | ||||
|     measurements[num_measurements].sensorId = sensorId; | ||||
|     measurements[num_measurements].value = value; | ||||
|     num_measurements++; | ||||
|     }`;
 | ||||
|   if (type === 'Stationary') { | ||||
|     Blockly.Arduino.functionNames_['writeMeasurementsToClient'] = ` | ||||
|   if (type === "Stationary") { | ||||
|     Blockly.Arduino.functionNames_["writeMeasurementsToClient"] = ` | ||||
|     void writeMeasurementsToClient() { | ||||
|     // iterate throug the measurements array
 | ||||
|     for (uint8_t i = 0; i < num_measurements; i++) { | ||||
| @ -72,7 +80,8 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) { | ||||
|     // reset num_measurements
 | ||||
|     num_measurements = 0; | ||||
|   }`;
 | ||||
|     Blockly.Arduino.functionNames_['submitValues'] = ` | ||||
|     Blockly.Arduino.functionNames_["submitValues"] = | ||||
|       ` | ||||
|     void submitValues() { | ||||
|   if (client.connected()) { | ||||
|     client.stop(); | ||||
| @ -83,7 +92,9 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) { | ||||
|   strcpy_P(_server, server); | ||||
|   for (uint8_t timeout = 2; timeout != 0; timeout--) { | ||||
|     Serial.println(F("connecting...")); | ||||
|     connected = client.connect(_server, `+ port + `); | ||||
|     connected = client.connect(_server, ` +
 | ||||
|       port + | ||||
|       `);
 | ||||
|     if (connected == true) { | ||||
|       // construct the HTTP POST request:
 | ||||
|       sprintf_P(buffer, | ||||
| @ -110,17 +121,33 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) { | ||||
|     } | ||||
|   } | ||||
|   }`;
 | ||||
|     var code = ''; | ||||
|     var code = ""; | ||||
|     code += branch; | ||||
|     code += "submitValues();\n"; | ||||
|   } | ||||
|   else if (type === 'Mobile') { | ||||
|     var lat = Blockly.Arduino.valueToCode(Block, 'lat', Blockly.Arduino.ORDER_ATOMIC); | ||||
|     var lng = Blockly.Arduino.valueToCode(Block, 'lng', Blockly.Arduino.ORDER_ATOMIC); | ||||
|     var timestamp = Blockly.Arduino.valueToCode(Block, 'timeStamp', Blockly.Arduino.ORDER_ATOMIC); | ||||
|     var altitude = Blockly.Arduino.valueToCode(Block, 'altitude', Blockly.Arduino.ORDER_ATOMIC); | ||||
|     Blockly.Arduino.definitions_['lengthMultiplikator'] = 'const int lengthMultiplikator = 77;'; | ||||
|     Blockly.Arduino.functionNames_['writeMeasurementsToClient'] = ` | ||||
|   } else if (type === "Mobile") { | ||||
|     var lat = Blockly.Arduino.valueToCode( | ||||
|       Block, | ||||
|       "lat", | ||||
|       Blockly.Arduino.ORDER_ATOMIC | ||||
|     ); | ||||
|     var lng = Blockly.Arduino.valueToCode( | ||||
|       Block, | ||||
|       "lng", | ||||
|       Blockly.Arduino.ORDER_ATOMIC | ||||
|     ); | ||||
|     var timestamp = Blockly.Arduino.valueToCode( | ||||
|       Block, | ||||
|       "timeStamp", | ||||
|       Blockly.Arduino.ORDER_ATOMIC | ||||
|     ); | ||||
|     var altitude = Blockly.Arduino.valueToCode( | ||||
|       Block, | ||||
|       "altitude", | ||||
|       Blockly.Arduino.ORDER_ATOMIC | ||||
|     ); | ||||
|     Blockly.Arduino.definitions_["lengthMultiplikator"] = | ||||
|       "const int lengthMultiplikator = 77;"; | ||||
|     Blockly.Arduino.functionNames_["writeMeasurementsToClient"] = ` | ||||
|       void writeMeasurementsToClient(float lat, float lng, float altitude, char* timeStamp) { | ||||
|       // iterate throug the measurements array
 | ||||
|       for (uint8_t i = 0; i < num_measurements; i++) { | ||||
| @ -132,7 +159,10 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) { | ||||
|       // reset num_measurements
 | ||||
|       num_measurements = 0; | ||||
|       }`;
 | ||||
|     Blockly.Arduino.functionNames_['submitValues'] = ` | ||||
|     Blockly.Arduino.variables_["latitude"] = "float latitude;"; | ||||
|     Blockly.Arduino.variables_["longitude"] = "float longitude;"; | ||||
|     Blockly.Arduino.functionNames_["submitValues"] = | ||||
|       ` | ||||
|       void submitValues(float lat, float lng, float altitude, char* timeStamp) { | ||||
|     if (client.connected()) { | ||||
|       client.stop(); | ||||
| @ -143,7 +173,9 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) { | ||||
|     strcpy_P(_server, server); | ||||
|     for (uint8_t timeout = 2; timeout != 0; timeout--) { | ||||
|       Serial.println(F("connecting...")); | ||||
|       connected = client.connect(_server, `+ port + `); | ||||
|       connected = client.connect(_server, ` +
 | ||||
|       port + | ||||
|       `);
 | ||||
|       if (connected == true) { | ||||
|         // construct the HTTP POST request:
 | ||||
|         sprintf_P(buffer, | ||||
| @ -170,10 +202,19 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) { | ||||
|         break; | ||||
|       } | ||||
|     } | ||||
|   }` | ||||
|     code = ''; | ||||
|   }`;
 | ||||
|     code = ""; | ||||
|     code += branch; | ||||
|     code += 'submitValues(' + lat + ',' + lng + ',' + altitude + ',' + timestamp + ');\n'; | ||||
|     code += | ||||
|       "submitValues((" + | ||||
|       lat + | ||||
|       "/float(10000000)),(" + | ||||
|       lng + | ||||
|       "/float(10000000),(" + | ||||
|       altitude + | ||||
|       "/float(100))," + | ||||
|       timestamp + | ||||
|       ");\n"; | ||||
|   } | ||||
|   return code; | ||||
| }; | ||||
|  | ||||
| @ -1,123 +1,128 @@ | ||||
| import Blockly from 'blockly'; | ||||
| import Blockly from "blockly"; | ||||
| 
 | ||||
| /** | ||||
|  * HDC1080 Temperature and Humidity Sensor | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_sensor_temp_hum = function () { | ||||
|   var dropdown_name = this.getFieldValue('NAME'); | ||||
|   Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_['define_hdc'] = 'HDC1080 hdc;'; | ||||
|   Blockly.Arduino.setupCode_['sensebox_sensor_temp_hum'] = 'hdc.begin();'; | ||||
|   var code = 'hdc.get' + dropdown_name + '()'; | ||||
|   var dropdown_name = this.getFieldValue("NAME"); | ||||
|   Blockly.Arduino.libraries_["library_senseBoxMCU"] = | ||||
|     '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_["define_hdc"] = "HDC1080 hdc;"; | ||||
|   Blockly.Arduino.setupCode_["sensebox_sensor_temp_hum"] = "hdc.begin();"; | ||||
|   var code = "hdc.get" + dropdown_name + "()"; | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
|  * VEML 6070 and TSL4513 UV-Light/Illuminance Sensor | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_sensor_uv_light = function () { | ||||
|   var dropdown_name = this.getFieldValue('NAME'); | ||||
|   let code = ''; | ||||
|   Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; | ||||
|   if (dropdown_name === 'UvIntensity') { | ||||
|     Blockly.Arduino.definitions_['define_veml'] = 'VEML6070 veml;' | ||||
|     Blockly.Arduino.setupCode_['sensebox_sensor_uv_light'] = 'veml.begin();' | ||||
|     code = 'veml.get' + dropdown_name + '()'; | ||||
|   var dropdown_name = this.getFieldValue("NAME"); | ||||
|   let code = ""; | ||||
|   Blockly.Arduino.libraries_["library_senseBoxMCU"] = | ||||
|     '#include "SenseBoxMCU.h"'; | ||||
|   if (dropdown_name === "UvIntensity") { | ||||
|     Blockly.Arduino.definitions_["define_veml"] = "VEML6070 veml;"; | ||||
|     Blockly.Arduino.setupCode_["sensebox_sensor_uv_light"] = "veml.begin();"; | ||||
|     code = "veml.get" + dropdown_name + "()"; | ||||
|   } | ||||
|   // if (dropdown_name === 'Illuminance') {
 | ||||
|   //   Blockly.Arduino.definitions_['define_tsl'] = 'TSL45315 tsl;'
 | ||||
|   //   Blockly.Arduino.setupCode_['sensebox_sensor_illuminance'] = 'tsl.begin();'
 | ||||
|   //   code = 'tsl.get' + dropdown_name + '()';
 | ||||
|   // }
 | ||||
|   if (dropdown_name === 'Illuminance') { | ||||
|     Blockly.Arduino.definitions_['define_lightsensor'] = 'Lightsensor lightsensor;' | ||||
|     Blockly.Arduino.setupCode_['sensebox_sensor_illuminance'] = 'lightsensor.begin();' | ||||
|     code = 'lightsensor.get' + dropdown_name + '()'; | ||||
|   if (dropdown_name === "Illuminance") { | ||||
|     Blockly.Arduino.definitions_["define_lightsensor"] = | ||||
|       "Lightsensor lightsensor;"; | ||||
|     Blockly.Arduino.setupCode_["sensebox_sensor_illuminance"] = | ||||
|       "lightsensor.begin();"; | ||||
|     code = "lightsensor.get" + dropdown_name + "()"; | ||||
|   } | ||||
| 
 | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * BMX055 Accelerometer | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_sensor_bmx055_accelerometer = function () { | ||||
|   var dropdown_value = this.getFieldValue('VALUE'); | ||||
|   var range = this.getFieldValue('RANGE'); | ||||
|   Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_['define_bmx'] = 'BMX055 bmx;'; | ||||
|   Blockly.Arduino.setupCode_['sensebox_sensor_bmx055'] = 'bmx.beginAcc(' + range + ');'; | ||||
|   var code = 'bmx.getAcceleration' + dropdown_value + '()'; | ||||
|   var dropdown_value = this.getFieldValue("VALUE"); | ||||
|   var range = this.getFieldValue("RANGE"); | ||||
|   Blockly.Arduino.libraries_["library_senseBoxMCU"] = | ||||
|     '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_["define_bmx"] = "BMX055 bmx;"; | ||||
|   Blockly.Arduino.setupCode_["sensebox_sensor_bmx055"] = | ||||
|     "bmx.beginAcc(" + range + ");"; | ||||
|   var code = "bmx.getAcceleration" + dropdown_value + "()"; | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
|  * SDS011 Fine Particlar Matter | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_sensor_sds011 = function () { | ||||
|   var dropdown_name = this.getFieldValue('NAME'); | ||||
|   var serial_name = this.getFieldValue('SERIAL'); | ||||
|   Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.codeFunctions_['define_sds011'] = 'SDS011 my_sds(' + serial_name + ');'; | ||||
|   Blockly.Arduino.variables_['variables_sds011'] = 'float p10,p25;\n'; | ||||
|   Blockly.Arduino.setupCode_['sensebox_sensor_sds011'] = serial_name + '.begin(9600);'; | ||||
|   var code = 'my_sds.get' + dropdown_name + '()'; | ||||
|   var dropdown_name = this.getFieldValue("NAME"); | ||||
|   var serial_name = this.getFieldValue("SERIAL"); | ||||
|   Blockly.Arduino.libraries_["library_senseBoxMCU"] = | ||||
|     '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.codeFunctions_["define_sds011"] = | ||||
|     "SDS011 my_sds(" + serial_name + ");"; | ||||
|   Blockly.Arduino.variables_["variables_sds011"] = "float p10,p25;\n"; | ||||
|   Blockly.Arduino.setupCode_["sensebox_sensor_sds011"] = | ||||
|     serial_name + ".begin(9600);"; | ||||
|   var code = "my_sds.get" + dropdown_name + "()"; | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
|  * BMP280 Pressure Sensor | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_sensor_pressure = function () { | ||||
|   var dropdown_name = this.getFieldValue('NAME'); | ||||
|   var code = ''; | ||||
|   var referencePressure = this.getFieldValue('referencePressure'); | ||||
|   Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_['define_pressure'] = 'BMP280 bmp_sensor;'; | ||||
|   Blockly.Arduino.setupCode_['sensebox_bmp_sensor'] = 'bmp_sensor.begin();'; | ||||
|   if (dropdown_name === 'Pressure' || dropdown_name === 'Temperature') { | ||||
|     code = 'bmp_sensor.get' + dropdown_name + '()'; | ||||
|   } | ||||
|   else if (dropdown_name === 'Altitude') { | ||||
|     code = 'bmp_sensor.getAltitude(' + referencePressure + ')'; | ||||
|   var dropdown_name = this.getFieldValue("NAME"); | ||||
|   var code = ""; | ||||
|   var referencePressure = this.getFieldValue("referencePressure"); | ||||
|   Blockly.Arduino.libraries_["library_senseBoxMCU"] = | ||||
|     '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_["define_pressure"] = "BMP280 bmp_sensor;"; | ||||
|   Blockly.Arduino.setupCode_["sensebox_bmp_sensor"] = "bmp_sensor.begin();"; | ||||
|   if (dropdown_name === "Pressure" || dropdown_name === "Temperature") { | ||||
|     code = "bmp_sensor.get" + dropdown_name + "()"; | ||||
|   } else if (dropdown_name === "Altitude") { | ||||
|     code = "bmp_sensor.getAltitude(" + referencePressure + ")"; | ||||
|   } | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * BME680 Environmental Sensor | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_sensor_bme680_bsec = function () { | ||||
|   var dropdown_name = this.getFieldValue('dropdown'); | ||||
|   let code = ''; | ||||
|   Blockly.Arduino.libraries_['library_bsec'] = '#include "bsec.h"'; | ||||
|   Blockly.Arduino.definitions_['bsec_iaqSensor'] = 'Bsec iaqSensor;' | ||||
|   Blockly.Arduino.variables_['bmeTemperatur'] = 'float bmeTemperatur;'; | ||||
|   Blockly.Arduino.variables_['bmeHumidity'] = 'float bmeHumidity;'; | ||||
|   Blockly.Arduino.variables_['bmePressure'] = 'double bmePressure;'; | ||||
|   Blockly.Arduino.variables_['bmeIAQ'] = 'float bmeIAQ;'; | ||||
|   Blockly.Arduino.variables_['bmeIAQAccuracy'] = 'float bmeIAQAccuracy;'; | ||||
|   Blockly.Arduino.variables_['bmeCO2'] = 'int bmeCO2;'; | ||||
|   Blockly.Arduino.variables_['bmeBreathVocEquivalent'] = 'float bmeBreathVocEquivalent;' | ||||
|   var dropdown_name = this.getFieldValue("dropdown"); | ||||
|   let code = ""; | ||||
|   Blockly.Arduino.libraries_["library_bsec"] = '#include "bsec.h"'; | ||||
|   Blockly.Arduino.definitions_["bsec_iaqSensor"] = "Bsec iaqSensor;"; | ||||
|   Blockly.Arduino.variables_["bmeTemperatur"] = "float bmeTemperatur;"; | ||||
|   Blockly.Arduino.variables_["bmeHumidity"] = "float bmeHumidity;"; | ||||
|   Blockly.Arduino.variables_["bmePressure"] = "double bmePressure;"; | ||||
|   Blockly.Arduino.variables_["bmeIAQ"] = "float bmeIAQ;"; | ||||
|   Blockly.Arduino.variables_["bmeIAQAccuracy"] = "float bmeIAQAccuracy;"; | ||||
|   Blockly.Arduino.variables_["bmeCO2"] = "int bmeCO2;"; | ||||
|   Blockly.Arduino.variables_["bmeBreathVocEquivalent"] = | ||||
|     "float bmeBreathVocEquivalent;"; | ||||
| 
 | ||||
|   Blockly.Arduino.functionNames_['checkIaqSensorStatus'] = ` | ||||
|   Blockly.Arduino.functionNames_["checkIaqSensorStatus"] = ` | ||||
|     void checkIaqSensorStatus(void) | ||||
|   { | ||||
|     if (iaqSensor.status != BSEC_OK) { | ||||
| @ -135,7 +140,7 @@ Blockly.Arduino.sensebox_sensor_bme680_bsec = function () { | ||||
|     } | ||||
|   } | ||||
|   `;
 | ||||
|   Blockly.Arduino.functionNames_['errLeds'] = ` | ||||
|   Blockly.Arduino.functionNames_["errLeds"] = ` | ||||
|   void errLeds(void) | ||||
|   { | ||||
|     pinMode(LED_BUILTIN, OUTPUT); | ||||
| @ -145,10 +150,12 @@ Blockly.Arduino.sensebox_sensor_bme680_bsec = function () { | ||||
|     delay(100); | ||||
|   }`;
 | ||||
|   //Setup Code
 | ||||
|   Blockly.Arduino.setupCode_['Wire.begin'] = 'Wire.begin();'; | ||||
|   Blockly.Arduino.setupCode_['iaqSensor.begin'] = 'iaqSensor.begin(BME680_I2C_ADDR_PRIMARY, Wire);'; | ||||
|   Blockly.Arduino.setupCode_['checkIaqSensorStatus'] = 'checkIaqSensorStatus();'; | ||||
|   Blockly.Arduino.setupCode_['bsec_sensorlist'] = ` | ||||
|   Blockly.Arduino.setupCode_["Wire.begin"] = "Wire.begin();"; | ||||
|   Blockly.Arduino.setupCode_["iaqSensor.begin"] = | ||||
|     "iaqSensor.begin(BME680_I2C_ADDR_PRIMARY, Wire);"; | ||||
|   Blockly.Arduino.setupCode_["checkIaqSensorStatus"] = | ||||
|     "checkIaqSensorStatus();"; | ||||
|   Blockly.Arduino.setupCode_["bsec_sensorlist"] = ` | ||||
|     bsec_virtual_sensor_t sensorList[10] = { | ||||
|       BSEC_OUTPUT_RAW_TEMPERATURE, | ||||
|       BSEC_OUTPUT_RAW_PRESSURE, | ||||
| @ -162,9 +169,10 @@ Blockly.Arduino.sensebox_sensor_bme680_bsec = function () { | ||||
|       BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY, | ||||
|     }; | ||||
|     `;
 | ||||
|   Blockly.Arduino.setupCode_['iaqSensorUpdateSubscription'] = 'iaqSensor.updateSubscription(sensorList, 10, BSEC_SAMPLE_RATE_LP);\ncheckIaqSensorStatus();'; | ||||
|   Blockly.Arduino.setupCode_["iaqSensorUpdateSubscription"] = | ||||
|     "iaqSensor.updateSubscription(sensorList, 10, BSEC_SAMPLE_RATE_LP);\ncheckIaqSensorStatus();"; | ||||
|   //Loop Code
 | ||||
|   Blockly.Arduino.loopCodeOnce_['iaqloop'] = ` | ||||
|   Blockly.Arduino.loopCodeOnce_["iaqloop"] = ` | ||||
|     if (iaqSensor.run()) { | ||||
|       bmeTemperatur = iaqSensor.temperature; | ||||
|       bmeHumidity = iaqSensor.humidity; | ||||
| @ -178,26 +186,26 @@ Blockly.Arduino.sensebox_sensor_bme680_bsec = function () { | ||||
|     } | ||||
|     `;
 | ||||
|   switch (dropdown_name) { | ||||
|     case 'temperature': | ||||
|       code = 'bmeTemperatur'; | ||||
|     case "temperature": | ||||
|       code = "bmeTemperatur"; | ||||
|       break; | ||||
|     case 'humidity': | ||||
|       code = 'bmeHumidity'; | ||||
|     case "humidity": | ||||
|       code = "bmeHumidity"; | ||||
|       break; | ||||
|     case 'pressure': | ||||
|       code = 'bmePressure' | ||||
|     case "pressure": | ||||
|       code = "bmePressure"; | ||||
|       break; | ||||
|     case 'IAQ': | ||||
|       code = 'bmeIAQ'; | ||||
|     case "IAQ": | ||||
|       code = "bmeIAQ"; | ||||
|       break; | ||||
|     case 'IAQAccuracy': | ||||
|       code = 'bmeIAQAccuracy'; | ||||
|     case "IAQAccuracy": | ||||
|       code = "bmeIAQAccuracy"; | ||||
|       break; | ||||
|     case 'CO2': | ||||
|       code = 'bmeCO2'; | ||||
|     case "CO2": | ||||
|       code = "bmeCO2"; | ||||
|       break; | ||||
|     case 'breathVocEquivalent': | ||||
|       code = 'bmeBreathVocEquivalent'; | ||||
|     case "breathVocEquivalent": | ||||
|       code = "bmeBreathVocEquivalent"; | ||||
|       break; | ||||
|     default: | ||||
|       break; | ||||
| @ -205,109 +213,119 @@ Blockly.Arduino.sensebox_sensor_bme680_bsec = function () { | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * Ultrasonic Distance Sensor | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_sensor_ultrasonic_ranger = function () { | ||||
|   var dropdown_pin_RX = this.getFieldValue('ultrasonic_trigger'); | ||||
|   var dropdown_pin_TX = this.getFieldValue('ultrasonic_echo'); | ||||
|   var port = this.getFieldValue('port'); | ||||
|   Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_['var_ultrasonic' + port] = 'Ultrasonic Ultrasonic' + port + '(' + dropdown_pin_RX + ',' + dropdown_pin_TX + ');'; | ||||
|   var dropdown_pin_RX = this.getFieldValue("ultrasonic_trigger"); | ||||
|   var dropdown_pin_TX = this.getFieldValue("ultrasonic_echo"); | ||||
|   var port = this.getFieldValue("port"); | ||||
|   Blockly.Arduino.libraries_["library_senseBoxMCU"] = | ||||
|     '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_["var_ultrasonic" + port] = | ||||
|     "Ultrasonic Ultrasonic" + | ||||
|     port + | ||||
|     "(" + | ||||
|     dropdown_pin_RX + | ||||
|     "," + | ||||
|     dropdown_pin_TX + | ||||
|     ");"; | ||||
|   var code; | ||||
|   code = 'Ultrasonic' + port + '.getDistance()'; | ||||
|   code = "Ultrasonic" + port + ".getDistance()"; | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
|  * Microphone | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_sensor_sound = function () { | ||||
|   var dropdown_pin = this.getFieldValue('PIN'); | ||||
|   Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_['define_microphone'] = 'Microphone microphone(' + dropdown_pin + ');' | ||||
|   var code = 'microphone.getValue()'; | ||||
|   var dropdown_pin = this.getFieldValue("PIN"); | ||||
|   Blockly.Arduino.libraries_["library_senseBoxMCU"] = | ||||
|     '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_["define_microphone"] = | ||||
|     "Microphone microphone(" + dropdown_pin + ");"; | ||||
|   var code = "microphone.getValue()"; | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * Button | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_button = function () { | ||||
|   var dropdown_pin = this.getFieldValue('PIN'); | ||||
|   var dropown_function = this.getFieldValue('FUNCTION'); | ||||
|   Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_['define_button' + dropdown_pin + ''] = 'Button button_' + dropdown_pin + '(' + dropdown_pin + ');'; | ||||
|   Blockly.Arduino.setupCode_['setup_button' + dropdown_pin + ''] = 'button_' + dropdown_pin + '.begin();'; | ||||
|   var code = ''; | ||||
|   if (dropown_function === 'isPressed') { | ||||
|     code = 'button_' + dropdown_pin + '.isPressed()'; | ||||
|   } | ||||
|   else if (dropown_function === 'Switch') { | ||||
|     code = 'button_' + dropdown_pin + '.getSwitch()'; | ||||
|   } | ||||
|   else if (dropown_function === 'wasPressed') { | ||||
|     code = 'button_' + dropdown_pin + '.wasPressed()'; | ||||
|   var dropdown_pin = this.getFieldValue("PIN"); | ||||
|   var dropown_function = this.getFieldValue("FUNCTION"); | ||||
|   Blockly.Arduino.libraries_["library_senseBoxMCU"] = | ||||
|     '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_["define_button" + dropdown_pin + ""] = | ||||
|     "Button button_" + dropdown_pin + "(" + dropdown_pin + ");"; | ||||
|   Blockly.Arduino.setupCode_["setup_button" + dropdown_pin + ""] = | ||||
|     "button_" + dropdown_pin + ".begin();"; | ||||
|   var code = ""; | ||||
|   if (dropown_function === "isPressed") { | ||||
|     code = "button_" + dropdown_pin + ".isPressed()"; | ||||
|   } else if (dropown_function === "Switch") { | ||||
|     code = "button_" + dropdown_pin + ".getSwitch()"; | ||||
|   } else if (dropown_function === "wasPressed") { | ||||
|     code = "button_" + dropdown_pin + ".wasPressed()"; | ||||
|   } | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
|  * SCD30 CO2 Sensor | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_scd30 = function () { | ||||
|   var dropdown = this.getFieldValue('dropdown'); | ||||
|   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.setupCode_['init_scd30'] = ` Wire.begin();
 | ||||
|   var dropdown = this.getFieldValue("dropdown"); | ||||
|   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.setupCode_["init_scd30"] = ` Wire.begin();
 | ||||
|   if (airSensor.begin() == false) | ||||
|   { | ||||
|     while (1) | ||||
|       ; | ||||
|   }`;
 | ||||
|   var code = ''; | ||||
|   var code = ""; | ||||
|   switch (dropdown) { | ||||
|     case 'temperature': | ||||
|       code = 'airSensor.getTemperature()'; | ||||
|     case "temperature": | ||||
|       code = "airSensor.getTemperature()"; | ||||
|       break; | ||||
|     case 'humidity': | ||||
|       code = 'airSensor.getHumiditiy()'; | ||||
|     case "humidity": | ||||
|       code = "airSensor.getHumiditiy()"; | ||||
|       break; | ||||
|     case 'CO2': | ||||
|       code = 'airSensor.getCO2()'; | ||||
|     case "CO2": | ||||
|       code = "airSensor.getCO2()"; | ||||
|       break; | ||||
|     default: | ||||
|       code = '' | ||||
|       code = ""; | ||||
|   } | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
|  * GPS Module | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_gps = function () { | ||||
|   var dropdown = this.getFieldValue('dropdown'); | ||||
|   Blockly.Arduino.libraries_['gps_library'] = '#include <SparkFun_u-blox_GNSS_Arduino_Library.h>' | ||||
|   Blockly.Arduino.libraries_['library_wire'] = '#include <Wire.h>'; | ||||
|   Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_['GPS'] = 'SFE_UBLOX_GNSS myGNSS;'; | ||||
|   Blockly.Arduino.setupCode_['init_gps'] = ` Wire.begin();
 | ||||
|   var dropdown = this.getFieldValue("dropdown"); | ||||
|   Blockly.Arduino.libraries_["gps_library"] = | ||||
|     "#include <SparkFun_u-blox_GNSS_Arduino_Library.h>"; | ||||
|   Blockly.Arduino.libraries_["library_wire"] = "#include <Wire.h>"; | ||||
|   Blockly.Arduino.libraries_["library_senseBoxMCU"] = | ||||
|     '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_["GPS"] = "SFE_UBLOX_GNSS myGNSS;"; | ||||
|   Blockly.Arduino.setupCode_["init_gps"] = ` Wire.begin();
 | ||||
| 
 | ||||
|   if (myGNSS.begin() == false) //Connect to the Ublox module using Wire port
 | ||||
|   { | ||||
| @ -317,95 +335,114 @@ Blockly.Arduino.sensebox_gps = function () { | ||||
| 
 | ||||
|   myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
 | ||||
|   myGNSS.saveConfiguration(); //Save the current settings to flash and BBR`;
 | ||||
|   var code = ''; | ||||
|   var code = ""; | ||||
|   switch (dropdown) { | ||||
|     case 'latitude': | ||||
|       code = 'myGNSS.getLatitude()'; | ||||
|     case "latitude": | ||||
|       code = "myGNSS.getLatitude()"; | ||||
|       break; | ||||
|     case 'longitude': | ||||
|       code = 'myGNSS.getLongitude()'; | ||||
|     case "longitude": | ||||
|       code = "myGNSS.getLongitude()"; | ||||
|       break; | ||||
|     case 'altitude': | ||||
|       code = 'myGNSS.getAltitudeMSL()'; | ||||
|     case "altitude": | ||||
|       code = "myGNSS.getAltitudeMSL()"; | ||||
|       break; | ||||
|     case 'pDOP': | ||||
|       code = 'myGNSS.getPDOP()'; | ||||
|     case "pDOP": | ||||
|       code = "myGNSS.getPDOP()"; | ||||
|       break; | ||||
|     case 'fixType': | ||||
|       code = 'myGNSS.getFixType()'; | ||||
|     case "fixType": | ||||
|       code = "myGNSS.getFixType()"; | ||||
|       break; | ||||
|     case "timestamp": | ||||
|       Blockly.Arduino.variables_["timestampVars"] = ` | ||||
| char tsBuffer[21]; | ||||
|       `;
 | ||||
|       Blockly.Arduino.codeFunctions_["getTimeStamp()"] = ` | ||||
| char* getTimeStamp() | ||||
| { | ||||
|   if (myGNSS.getTimeValid() == true) | ||||
|     { | ||||
|     sprintf(tsBuffer, "%04d-%02d-%02dT%02d:%02d:%02dZ", | ||||
|     myGNSS.getYear(), myGNSS.getMonth(), myGNSS.getDay(), myGNSS.getHour(), myGNSS.getMinute(), myGNSS.getSecond()); | ||||
|     } | ||||
| return tsBuffer; | ||||
| } | ||||
|       `;
 | ||||
|       code = "getTimeStamp()"; | ||||
|       break; | ||||
|     default: | ||||
|       code = '' | ||||
|       code = ""; | ||||
|   } | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| 
 | ||||
| } | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
|  * Block for Truebner STM50 | ||||
|  */ | ||||
| 
 | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_sensor_truebner_smt50 = function () { | ||||
|   var dropdown_port = this.getFieldValue('Port') | ||||
|   var dropdown_value = this.getFieldValue('value'); | ||||
|   var dropdown_port = this.getFieldValue("Port"); | ||||
|   var dropdown_value = this.getFieldValue("value"); | ||||
|   var dropdown_pin = 1; | ||||
|   var code = ''; | ||||
|   if (dropdown_value === 'temp') { | ||||
|     if (dropdown_port === 'A') { | ||||
|   var code = ""; | ||||
|   if (dropdown_value === "temp") { | ||||
|     if (dropdown_port === "A") { | ||||
|       dropdown_pin = 1; | ||||
|     } | ||||
|     if (dropdown_port === 'B') { | ||||
|     if (dropdown_port === "B") { | ||||
|       dropdown_pin = 3; | ||||
|     } | ||||
|     if (dropdown_port === 'C') { | ||||
|     if (dropdown_port === "C") { | ||||
|       dropdown_pin = 5; | ||||
|     } | ||||
|     Blockly.Arduino.codeFunctions_['sensebox_smt50_temp'] = 'float getSMT50Temperature(int analogPin){\n  int sensorValue = analogRead(analogPin);\n  float voltage = sensorValue * (3.3 / 1024.0);\n   return (voltage - 0.5) * 100;\n}'; | ||||
|     code = 'getSMT50Temperature(' + dropdown_pin + ')'; | ||||
|     Blockly.Arduino.codeFunctions_["sensebox_smt50_temp"] = | ||||
|       "float getSMT50Temperature(int analogPin){\n  int sensorValue = analogRead(analogPin);\n  float voltage = sensorValue * (3.3 / 1024.0);\n   return (voltage - 0.5) * 100;\n}"; | ||||
|     code = "getSMT50Temperature(" + dropdown_pin + ")"; | ||||
|     return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
|   } | ||||
|   else if (dropdown_value === 'soil') { | ||||
|     if (dropdown_port === 'A') { | ||||
|   } else if (dropdown_value === "soil") { | ||||
|     if (dropdown_port === "A") { | ||||
|       dropdown_pin = 2; | ||||
|     } | ||||
|     if (dropdown_port === 'B') { | ||||
|     if (dropdown_port === "B") { | ||||
|       dropdown_pin = 4; | ||||
|     } | ||||
|     if (dropdown_port === 'C') { | ||||
|     if (dropdown_port === "C") { | ||||
|       dropdown_pin = 6; | ||||
|     } | ||||
|     Blockly.Arduino.codeFunctions_['sensebox_smt50_soil'] = 'float getSMT50Moisture(int analogPin){\n   int sensorValue = analogRead(analogPin);\n    float voltage = sensorValue * (3.3 / 1024.0);\n   return (voltage * 50) / 3;\n}'; | ||||
|     code = 'getSMT50Moisture(' + dropdown_pin + ')'; | ||||
|     Blockly.Arduino.codeFunctions_["sensebox_smt50_soil"] = | ||||
|       "float getSMT50Moisture(int analogPin){\n   int sensorValue = analogRead(analogPin);\n    float voltage = sensorValue * (3.3 / 1024.0);\n   return (voltage * 50) / 3;\n}"; | ||||
|     code = "getSMT50Moisture(" + dropdown_pin + ")"; | ||||
|     return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
|   } | ||||
| 
 | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
|  * DS18B20 Watertemperature | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_sensor_watertemperature = function () { | ||||
| 
 | ||||
|   var dropdown_port = this.getFieldValue('Port'); | ||||
|   var dropdown_port = this.getFieldValue("Port"); | ||||
|   var dropdown_pin = 1; | ||||
|   if (dropdown_port === 'A') { | ||||
|   if (dropdown_port === "A") { | ||||
|     dropdown_pin = 1; | ||||
|   } | ||||
|   if (dropdown_port === 'B') { | ||||
|   if (dropdown_port === "B") { | ||||
|     dropdown_pin = 3; | ||||
|   } | ||||
|   if (dropdown_port === 'C') { | ||||
|   if (dropdown_port === "C") { | ||||
|     dropdown_pin = 5; | ||||
|   } | ||||
|   Blockly.Arduino.libraries_['library_oneWire'] = '#include "OneWire.h"'; | ||||
|   Blockly.Arduino.libraries_['library_oneDallasTemperature'] = '#include "DallasTemperature.h"'; | ||||
|   Blockly.Arduino.definitions_['define_OneWire'] = '#define ONE_WIRE_BUS ' + dropdown_pin + '\nOneWire oneWire(ONE_WIRE_BUS);\nDallasTemperature sensors(&oneWire);'; | ||||
|   Blockly.Arduino.setupCode_['sensebox_oneWireSetup'] = 'sensors.begin();'; | ||||
|   Blockly.Arduino.codeFunctions_['sensebox_requestTemp'] = 'float getWaterTemp(){\nsensors.requestTemperatures();\nsensors.getTempCByIndex(0);\n}'; | ||||
|   var code = 'getWaterTemp()'; | ||||
|   Blockly.Arduino.libraries_["library_oneWire"] = '#include "OneWire.h"'; | ||||
|   Blockly.Arduino.libraries_["library_oneDallasTemperature"] = | ||||
|     '#include "DallasTemperature.h"'; | ||||
|   Blockly.Arduino.definitions_["define_OneWire"] = | ||||
|     "#define ONE_WIRE_BUS " + | ||||
|     dropdown_pin + | ||||
|     "\nOneWire oneWire(ONE_WIRE_BUS);\nDallasTemperature sensors(&oneWire);"; | ||||
|   Blockly.Arduino.setupCode_["sensebox_oneWireSetup"] = "sensors.begin();"; | ||||
|   Blockly.Arduino.codeFunctions_["sensebox_requestTemp"] = | ||||
|     "float getWaterTemp(){\nsensors.requestTemperatures();\nsensors.getTempCByIndex(0);\n}"; | ||||
|   var code = "getWaterTemp()"; | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| }; | ||||
| 
 | ||||
| @ -443,28 +480,31 @@ float getWindspeed(){ | ||||
|  */ | ||||
| 
 | ||||
| /** | ||||
| *  | ||||
| *  | ||||
| */ | ||||
|  * | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_soundsensor_dfrobot = function () { | ||||
|   var dropdown_port = this.getFieldValue('Port'); | ||||
|   var dropdown_port = this.getFieldValue("Port"); | ||||
|   var dropdown_pin = 1; | ||||
|   if (dropdown_port === 'A') { | ||||
|   if (dropdown_port === "A") { | ||||
|     dropdown_pin = 1; | ||||
|   } | ||||
|   if (dropdown_port === 'B') { | ||||
|   if (dropdown_port === "B") { | ||||
|     dropdown_pin = 3; | ||||
|   } | ||||
|   if (dropdown_port === 'C') { | ||||
|   if (dropdown_port === "C") { | ||||
|     dropdown_pin = 5; | ||||
|   } | ||||
|   Blockly.Arduino.codeFunctions_['soundsensor'] = `    
 | ||||
|   Blockly.Arduino.codeFunctions_["soundsensor"] = | ||||
|     `    
 | ||||
| float getSoundValue(){ | ||||
|   float v = analogRead(`+ dropdown_pin + `) * (3.3 / 1024.0); | ||||
|   float v = analogRead(` +
 | ||||
|     dropdown_pin + | ||||
|     `) * (3.3 / 1024.0);
 | ||||
|   float decibel = v * 50; | ||||
|   return decibel; | ||||
| }` | ||||
|   var code = 'getSoundValue()'; | ||||
| }`;
 | ||||
|   var code = "getSoundValue()"; | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| }; | ||||
| }; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user