commit
						5eb6a94a0b
					
				| @ -1,5 +1,4 @@ | |||||||
| import * as Blockly from 'blockly'; | import * as Blockly from 'blockly'; | ||||||
| import { FieldSlider } from '@blockly/field-slider'; |  | ||||||
| import { getColour } from '../helpers/colour' | import { getColour } from '../helpers/colour' | ||||||
| import { selectedBoard } from '../helpers/board' | import { selectedBoard } from '../helpers/board' | ||||||
| 
 | 
 | ||||||
| @ -27,15 +26,12 @@ Blockly.Blocks['sensebox_rgb_led'] = { | |||||||
|             .appendField(Blockly.Msg.senseBox_rgb_led) |             .appendField(Blockly.Msg.senseBox_rgb_led) | ||||||
|             .appendField("Pin:") |             .appendField("Pin:") | ||||||
|             .appendField(new Blockly.FieldDropdown(selectedBoard().digitalPins), "PIN"); |             .appendField(new Blockly.FieldDropdown(selectedBoard().digitalPins), "PIN"); | ||||||
|         this.appendDummyInput() |         this.appendValueInput("RED", 'Number') | ||||||
|             .appendField(Blockly.Msg.COLOUR_RGB_RED)//Blockly.Msg.senseBox_basic_red
 |             .appendField(Blockly.Msg.COLOUR_RGB_RED);//Blockly.Msg.senseBox_basic_red
 | ||||||
|             .appendField(new FieldSlider(255, 0, 255), "RED"); |         this.appendValueInput("GREEN", 'Number') | ||||||
|         this.appendDummyInput() |             .appendField(Blockly.Msg.COLOUR_RGB_GREEN);//Blockly.Msg.senseBox_basic_green
 | ||||||
|             .appendField(Blockly.Msg.COLOUR_RGB_GREEN)//Blockly.Msg.senseBox_basic_green
 |         this.appendValueInput("BLUE", 'Number') | ||||||
|             .appendField(new FieldSlider(255, 0, 255), "GREEN"); |             .appendField(Blockly.Msg.COLOUR_RGB_BLUE); | ||||||
|         this.appendDummyInput() |  | ||||||
|             .appendField(Blockly.Msg.COLOUR_RGB_BLUE)//Blockly.Msg.senseBox_basic_green
 |  | ||||||
|             .appendField(new FieldSlider(255, 0, 255), "BLUE"); |  | ||||||
|         this.setPreviousStatement(true, null); |         this.setPreviousStatement(true, null); | ||||||
|         this.setNextStatement(true, null); |         this.setNextStatement(true, null); | ||||||
|         this.setTooltip(Blockly.Msg.senseBox_rgb_led_tip); |         this.setTooltip(Blockly.Msg.senseBox_rgb_led_tip); | ||||||
| @ -53,7 +49,7 @@ Blockly.Blocks['sensebox_ws2818_led'] = { | |||||||
|         this.setColour(getColour().sensebox); |         this.setColour(getColour().sensebox); | ||||||
|         this.appendDummyInput() |         this.appendDummyInput() | ||||||
|             .appendField(Blockly.Msg.senseBox_ws2818_rgb_led) |             .appendField(Blockly.Msg.senseBox_ws2818_rgb_led) | ||||||
|             .appendField("Pin:") |             .appendField("Port:") | ||||||
|             .appendField(new Blockly.FieldDropdown(dropdownOptions), "Port") |             .appendField(new Blockly.FieldDropdown(dropdownOptions), "Port") | ||||||
|         this.appendValueInput("BRIGHTNESS", "brightness") |         this.appendValueInput("BRIGHTNESS", "brightness") | ||||||
|             .appendField((Blockly.Msg.senseBox_ws2818_rgb_led_brightness)); |             .appendField((Blockly.Msg.senseBox_ws2818_rgb_led_brightness)); | ||||||
|  | |||||||
| @ -351,3 +351,79 @@ Blockly.Blocks['sensebox_gps'] = { | |||||||
|     this.setTooltip(Blockly.Msg.senseBox_bme_tip); |     this.setTooltip(Blockly.Msg.senseBox_bme_tip); | ||||||
|   } |   } | ||||||
| }; | }; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Block for Truebner STM50 | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | 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']]; | ||||||
|  |     this.setColour(getColour().sensebox); | ||||||
|  |     this.appendDummyInput() | ||||||
|  |       .appendField(Blockly.Msg.sensebox_soil_smt50); | ||||||
|  |     this.appendDummyInput() | ||||||
|  |       .appendField("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') | ||||||
|  |     this.setOutput(true, Types.NUMBER.typeName); | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * DS18B20 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']]; | ||||||
|  |     this.setColour(getColour().sensebox); | ||||||
|  |     this.appendDummyInput() | ||||||
|  |       .appendField(Blockly.Msg.senseBox_watertemperature) | ||||||
|  |       .appendField("Port:") | ||||||
|  |       .appendField(new Blockly.FieldDropdown(dropdownOptions), "Port") | ||||||
|  |     this.setOutput(true, Types.NUMBER.typeName); | ||||||
|  |     this.setTooltip(Blockly.Msg.senseBox_watertemperature_tip); | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Windspeed | ||||||
|  |  * removed for now | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | Blockly.Blocks['sensebox_windspeed'] = { | ||||||
|  |   init: function () { | ||||||
|  |     this.setColour(getColour().sensebox); | ||||||
|  |     this.appendDummyInput() | ||||||
|  |       .appendField(Blockly.Msg.senseBox_windspeed) | ||||||
|  |       .appendField("Pin:") | ||||||
|  |       .appendField(new Blockly.FieldDropdown(selectedBoard().analogPins), "PIN") | ||||||
|  |     this.setOutput(true, Types.DECIMAL.typeName); | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * DF Robot Soundsensor | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 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']]; | ||||||
|  |     this.setColour(getColour().sensebox); | ||||||
|  |     this.appendDummyInput() | ||||||
|  |       .appendField(Blockly.Msg.senseBox_soundsensor_dfrobot) | ||||||
|  |       .appendField("Port:") | ||||||
|  |       .appendField(new Blockly.FieldDropdown(dropdownOptions), "Port") | ||||||
|  |     this.setOutput(true, Types.DECIMAL.typeName); | ||||||
|  |   } | ||||||
|  | }; | ||||||
| @ -10,9 +10,9 @@ Blockly.Arduino.sensebox_led = function () { | |||||||
| 
 | 
 | ||||||
| Blockly.Arduino.sensebox_rgb_led = function () { | Blockly.Arduino.sensebox_rgb_led = function () { | ||||||
|     var dropdown_pin = this.getFieldValue('PIN'); |     var dropdown_pin = this.getFieldValue('PIN'); | ||||||
|     var red = this.getFieldValue('RED') || '0' |     var red = Blockly.Arduino.valueToCode(this, 'RED', Blockly.Arduino.ORDER_ATOMIC) || '0' | ||||||
|     var green = this.getFieldValue('GREEN') || '0' |     var green = Blockly.Arduino.valueToCode(this, 'GREEN', Blockly.Arduino.ORDER_ATOMIC) || '0' | ||||||
|     var blue = this.getFieldValue('BLUE') || '0' |     var blue = Blockly.Arduino.valueToCode(this, 'BLUE', Blockly.Arduino.ORDER_ATOMIC) || '0' | ||||||
|     Blockly.Arduino.libraries_['define_rgb_led' + dropdown_pin] = '#include <Adafruit_NeoPixel.h>\n Adafruit_NeoPixel rgb_led_' + dropdown_pin + ' = Adafruit_NeoPixel(1,' + dropdown_pin + ',NEO_RGB + NEO_KHZ800);\n'; |     Blockly.Arduino.libraries_['define_rgb_led' + dropdown_pin] = '#include <Adafruit_NeoPixel.h>\n Adafruit_NeoPixel rgb_led_' + dropdown_pin + ' = Adafruit_NeoPixel(1,' + dropdown_pin + ',NEO_RGB + NEO_KHZ800);\n'; | ||||||
|     Blockly.Arduino.setupCode_['setup_rgb_led' + dropdown_pin] = 'rgb_led_' + dropdown_pin + '.begin();'; |     Blockly.Arduino.setupCode_['setup_rgb_led' + dropdown_pin] = 'rgb_led_' + dropdown_pin + '.begin();'; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -332,3 +332,130 @@ Blockly.Arduino.sensebox_gps = function () { | |||||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; |   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_pin = 1; | ||||||
|  |   if (dropdown_value === 'temp') { | ||||||
|  |     if (dropdown_port === 'A') { | ||||||
|  |       dropdown_pin = 1; | ||||||
|  |     } | ||||||
|  |     if (dropdown_port === 'B') { | ||||||
|  |       dropdown_pin = 3; | ||||||
|  |     } | ||||||
|  |     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}'; | ||||||
|  |     var code = 'getSMT50Temperature(' + dropdown_pin + ')'; | ||||||
|  |     return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||||
|  |   } | ||||||
|  |   else if (dropdown_value === 'soil') { | ||||||
|  |     if (dropdown_port === 'A') { | ||||||
|  |       dropdown_pin = 2; | ||||||
|  |     } | ||||||
|  |     if (dropdown_port === 'B') { | ||||||
|  |       dropdown_pin = 4; | ||||||
|  |     } | ||||||
|  |     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}'; | ||||||
|  |     var 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_pin = 1; | ||||||
|  |   if (dropdown_port === 'A') { | ||||||
|  |     dropdown_pin = 1; | ||||||
|  |   } | ||||||
|  |   if (dropdown_port === 'B') { | ||||||
|  |     dropdown_pin = 3; | ||||||
|  |   } | ||||||
|  |   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()'; | ||||||
|  |   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Windspeed | ||||||
|  |  * remove for now | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | Blockly.Arduino.sensebox_windspeed = function () { | ||||||
|  |   var dropdown_pin = this.getFieldValue('PIN'); | ||||||
|  |   Blockly.Arduino.codeFunctions_['windspeed'] = `    
 | ||||||
|  | float getWindspeed(){ | ||||||
|  |   float voltageWind = analogRead(`+ dropdown_pin + `) * (3.3 / 1024.0); | ||||||
|  |   float windspeed = 0.0; | ||||||
|  |   if (voltageWind >= 0.018){ | ||||||
|  |     float poly1 = pow(voltageWind, 3); | ||||||
|  |     poly1 = 17.0359801998299 * poly1; | ||||||
|  |     float poly2 = pow(voltageWind, 2); | ||||||
|  |     poly2 = 47.9908168343362 * poly2; | ||||||
|  |     float poly3 = 122.899677524413 * voltageWind; | ||||||
|  |     float poly4 = 0.657504127272728; | ||||||
|  |     windspeed = poly1 - poly2 + poly3 - poly4; | ||||||
|  |     windspeed = windspeed * 0.2777777777777778; //conversion in m/s
 | ||||||
|  |   } | ||||||
|  |     return windspeed; | ||||||
|  | }` | ||||||
|  |   var code = 'getWindspeed()'; | ||||||
|  |   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||||
|  | }; | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * DF Robot Soundsensor | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  | *  | ||||||
|  | *  | ||||||
|  | */ | ||||||
|  | 
 | ||||||
|  | Blockly.Arduino.sensebox_soundsensor_dfrobot = function () { | ||||||
|  |   var dropdown_port = this.getFieldValue('Port'); | ||||||
|  |   var dropdown_pin = 1; | ||||||
|  |   if (dropdown_port === 'A') { | ||||||
|  |     dropdown_pin = 1; | ||||||
|  |   } | ||||||
|  |   if (dropdown_port === 'B') { | ||||||
|  |     dropdown_pin = 3; | ||||||
|  |   } | ||||||
|  |   if (dropdown_port === 'C') { | ||||||
|  |     dropdown_pin = 5; | ||||||
|  |   } | ||||||
|  |   Blockly.Arduino.codeFunctions_['soundsensor'] = `    
 | ||||||
|  | float getSoundValue(){ | ||||||
|  |   float v = analogRead(`+ dropdown_pin + `) * (3.3 / 1024.0); | ||||||
|  |   float decibel = v * 50; | ||||||
|  |   return decibel; | ||||||
|  | }` | ||||||
|  |   var code = 'getSoundValue()'; | ||||||
|  |   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||||
|  | }; | ||||||
| @ -760,6 +760,12 @@ Blockly.Msg.senseBox_LoRa_sensor_tip = "Sende eine Sensorwert mit einer bestimmt | |||||||
| Blockly.Msg.senseBox_LoRa_init_abp_tip = "Initialisiere die LoRa übertragung. Kopiere die ID's im lsb Format"; | Blockly.Msg.senseBox_LoRa_init_abp_tip = "Initialisiere die LoRa übertragung. Kopiere die ID's im lsb Format"; | ||||||
| Blockly.Msg.senseBox_LoRa_init_otaa_tip = "Initialisiere die LoRa übertragung. Kopiere die ID's im lsb Format"; | Blockly.Msg.senseBox_LoRa_init_otaa_tip = "Initialisiere die LoRa übertragung. Kopiere die ID's im lsb Format"; | ||||||
| 
 | 
 | ||||||
|  | //Windspeed
 | ||||||
|  | Blockly.Msg.senseBox_windspeed = "Windgeschwindigkeitssensor"; | ||||||
|  | //Soundsensor
 | ||||||
|  | Blockly.Msg.senseBox_soundsensor_dfrobot = "Soundsensor (DF Robot)"; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| //BME680
 | //BME680
 | ||||||
| Blockly.Msg.senseBox_bme680 = "Umweltsensor (BME680)"; | Blockly.Msg.senseBox_bme680 = "Umweltsensor (BME680)"; | ||||||
| Blockly.Msg.senseBox_bme_iaq = "Innenraumluftqualität (IAQ)"; | Blockly.Msg.senseBox_bme_iaq = "Innenraumluftqualität (IAQ)"; | ||||||
|  | |||||||
| @ -782,6 +782,12 @@ Blockly.Msg.senseBox_mqtt_password = "Password"; | |||||||
| Blockly.Msg.sensebox_mqtt_subscribe = "Subscribe to Feed" | Blockly.Msg.sensebox_mqtt_subscribe = "Subscribe to Feed" | ||||||
| Blockly.Msg.senseBox_mqtt_publish = "Publish to Feed/Topic"; | Blockly.Msg.senseBox_mqtt_publish = "Publish to Feed/Topic"; | ||||||
| 
 | 
 | ||||||
|  | //Windspeed
 | ||||||
|  | Blockly.Msg.senseBox_windspeed = "Windspeedsensor" | ||||||
|  | 
 | ||||||
|  | //Soundsensor
 | ||||||
|  | Blockly.Msg.senseBox_soundsensor_dfrobot = "Soundsensor (DF Robot)"; | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * Add Translation for Blocks above |  * Add Translation for Blocks above | ||||||
|  * --------------------------------------------------------------- |  * --------------------------------------------------------------- | ||||||
|  | |||||||
| @ -50,6 +50,10 @@ class Toolbox extends React.Component { | |||||||
|                     <Block type="sensebox_sensor_ultrasonic_ranger" /> |                     <Block type="sensebox_sensor_ultrasonic_ranger" /> | ||||||
|                     <Block type="sensebox_sensor_sound" /> |                     <Block type="sensebox_sensor_sound" /> | ||||||
|                     <Block type="sensebox_button" /> |                     <Block type="sensebox_button" /> | ||||||
|  |                     <Block type="sensebox_sensor_truebner_smt50" /> | ||||||
|  |                     <Block type="sensebox_sensor_watertemperature" /> | ||||||
|  |                     {/* <Block type="sensebox_windspeed" /> */} | ||||||
|  |                     <Block type="sensebox_soundsensor_dfrobot" /> | ||||||
|                 </Category > |                 </Category > | ||||||
|                 <Category name="WIFI" colour={getColour().sensebox}> |                 <Category name="WIFI" colour={getColour().sensebox}> | ||||||
|                     <Block type="sensebox_wifi" /> |                     <Block type="sensebox_wifi" /> | ||||||
| @ -61,7 +65,23 @@ class Toolbox extends React.Component { | |||||||
|                     <Block type="sensebox_sd_write_file" /> |                     <Block type="sensebox_sd_write_file" /> | ||||||
|                 </Category> |                 </Category> | ||||||
|                 <Category name="LED" colour={getColour().sensebox}> |                 <Category name="LED" colour={getColour().sensebox}> | ||||||
|                     <Block type="sensebox_rgb_led" /> |                     <Block type="sensebox_rgb_led"> | ||||||
|  |                         <Value name="RED"> | ||||||
|  |                             <Block type="math_number"> | ||||||
|  |                                 <Field name="NUM">0</Field> | ||||||
|  |                             </Block> | ||||||
|  |                         </Value> | ||||||
|  |                         <Value name="GREEN"> | ||||||
|  |                             <Block type="math_number"> | ||||||
|  |                                 <Field name="NUM">0</Field> | ||||||
|  |                             </Block> | ||||||
|  |                         </Value> | ||||||
|  |                         <Value name="BLUE"> | ||||||
|  |                             <Block type="math_number"> | ||||||
|  |                                 <Field name="NUM">0</Field> | ||||||
|  |                             </Block> | ||||||
|  |                         </Value> | ||||||
|  |                     </Block> | ||||||
|                     <Block type="sensebox_led" /> |                     <Block type="sensebox_led" /> | ||||||
|                     <Block type="sensebox_ws2818_led"> |                     <Block type="sensebox_ws2818_led"> | ||||||
|                         <Value name="POSITION"> |                         <Value name="POSITION"> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user