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