diff --git a/src/components/Blockly/blocks/sensebox-sensors.js b/src/components/Blockly/blocks/sensebox-sensors.js index 2798249..2465b24 100644 --- a/src/components/Blockly/blocks/sensebox-sensors.js +++ b/src/components/Blockly/blocks/sensebox-sensors.js @@ -301,3 +301,23 @@ Blockly.Blocks['sensebox_button'] = { }; +/** + * SCD30 CO2 Sensor + * + */ + + +Blockly.Blocks['sensebox_scd30'] = { + init: function () { + var dropdownOptions = [[Blockly.Msg.senseBox_temp, "temperature"], [Blockly.Msg.senseBox_hum, "humidity"], [Blockly.Msg.senseBox_bme_co2, "CO2"]]; + this.appendDummyInput() + .appendField(Blockly.Msg.senseBox_scd30); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField(Blockly.Msg.senseBox_value) + .appendField(new Blockly.FieldDropdown(dropdownOptions), "dropdown") + this.setOutput(true, Types.NUMBER.typeName); + this.setColour(getColour().sensebox); + this.setTooltip(Blockly.Msg.senseBox_bme_tip); + } +}; diff --git a/src/components/Blockly/generator/sensebox-sensors.js b/src/components/Blockly/generator/sensebox-sensors.js index ed8bfe3..6599e4a 100644 --- a/src/components/Blockly/generator/sensebox-sensors.js +++ b/src/components/Blockly/generator/sensebox-sensors.js @@ -251,4 +251,48 @@ Blockly.Arduino.sensebox_button = function () { code = 'button_' + dropdown_pin + '.wasPressed()'; } return [code, Blockly.Arduino.ORDER_ATOMIC]; -}; \ No newline at end of file +}; + +/** + * SCD30 CO2 Sensor + * + */ + +Blockly.Arduino.sensebox_scd30 = function () { + var dropdown = this.getFieldValue('dropdown'); + Blockly.Arduino.libraries_['scd30_library'] = '#include "SparkFun_SCD30_Arduino_Library.h"' + Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; + Blockly.Arduino.definitions_['SCD30'] = 'SCD30 airSensor;'; + Blockly.Arduino.variables_['scd30_temp'] = 'float scd30_temp;'; + Blockly.Arduino.variables_['scd30_humi'] = 'float scd30_humi;'; + Blockly.Arduino.variables_['scd30_co2'] = 'float scd30_co2;'; + Blockly.Arduino.setupCode_['init_scd30'] = ` Wire.begin(); + if (airSensor.begin() == false) + { + Serial.println("Air sensor not detected. Please check wiring. Freezing..."); + while (1) + ; + }`; + Blockly.Arduino.loopCodeOnce_['scd30_getData'] = `if (airSensor.dataAvailable()) + { + scd30_co2 = airSensor.getCO2(); + scd30_temp = airSensor.getTemperature(); + scd30_humi = airSensor.getHumidity(); + }` + var code = ''; + switch (dropdown) { + case 'temperature': + code = 'scd30_temp'; + break; + case 'humidity': + code = 'scd30_humi'; + break; + case 'CO2': + code = 'scd30_co2'; + break; + default: + code = '' + } + return [code, Blockly.Arduino.ORDER_ATOMIC]; + +} \ No newline at end of file diff --git a/src/components/Blockly/msg/de.js b/src/components/Blockly/msg/de.js index 159693e..cf6db85 100644 --- a/src/components/Blockly/msg/de.js +++ b/src/components/Blockly/msg/de.js @@ -768,3 +768,5 @@ Blockly.Msg.senseBox_telegram_do_on_message = "bei Nachricht" Blockly.Msg.senseBox_telegram_message = "Nachricht" Blockly.Msg.senseBox_telegram_send = "Sende Nachricht" +Blockly.Msg.senseBox_scd30 = "CO2 Sensor (Sensirion SCD30)"; + diff --git a/src/components/Blockly/msg/en.js b/src/components/Blockly/msg/en.js index b4bc8c0..e32e321 100644 --- a/src/components/Blockly/msg/en.js +++ b/src/components/Blockly/msg/en.js @@ -750,3 +750,4 @@ Blockly.Msg.sensebox_sd_filename = "data"; Blockly.Msg.sensebox_soil_smt50 = "Soil Moisture and Temperature (SMT50)"; Blockly.Msg.sensebox_web_readHTML_filename = "File:"; +Blockly.Msg.senseBox_scd30 = "CO2 Sensor (Sensirion SCD30)"; \ No newline at end of file diff --git a/src/components/Blockly/toolbox/Toolbox.js b/src/components/Blockly/toolbox/Toolbox.js index 327c5de..3cfae6e 100644 --- a/src/components/Blockly/toolbox/Toolbox.js +++ b/src/components/Blockly/toolbox/Toolbox.js @@ -44,6 +44,7 @@ class Toolbox extends React.Component { + diff --git a/src/components/Compile.js b/src/components/Compile.js index c9ce34b..946466f 100644 --- a/src/components/Compile.js +++ b/src/components/Compile.js @@ -38,7 +38,7 @@ const styles = (theme) => ({ class Compile extends Component { - constructor(props){ + constructor(props) { super(props); this.state = { progress: false, @@ -50,9 +50,9 @@ class Compile extends Component { }; } - componentDidUpdate(props){ - if(props.name !== this.props.name){ - this.setState({name: this.props.name}); + componentDidUpdate(props) { + if (props.name !== this.props.name) { + this.setState({ name: this.props.name }); } } @@ -68,17 +68,17 @@ class Compile extends Component { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) - .then(response => response.json()) - .then(data => { - console.log(data); - this.setState({id: data.data.id}, () => { - this.createFileName(); + .then(response => response.json()) + .then(data => { + console.log(data); + this.setState({ id: data.data.id }, () => { + this.createFileName(); + }); + }) + .catch(err => { + console.log(err); + this.setState({ progress: false, file: false, open: true, title: 'Fehler', content: 'Etwas ist beim Kompilieren schief gelaufen. Versuche es nochmal.' }); }); - }) - .catch(err => { - console.log(err); - this.setState({ progress: false, file: false, open: true, title: 'Fehler', content: 'Etwas ist beim Kompilieren schief gelaufen. Versuche es nochmal.' }); - }); } download = () => { @@ -95,33 +95,33 @@ class Compile extends Component { } createFileName = () => { - if(this.state.name){ + if (this.state.name) { this.download(); } - else{ + else { this.setState({ file: true, open: true, title: 'Blöcke kompilieren', content: 'Bitte gib einen Namen für die Bennenung des zu kompilierenden Programms ein und bestätige diesen mit einem Klick auf \'Eingabe\'.' }); } } setFileName = (e) => { - this.setState({name: e.target.value}); + this.setState({ name: e.target.value }); } render() { return (
{this.props.iconButton ? - + this.compile()} > - + - : + : } @@ -132,15 +132,15 @@ class Compile extends Component { title={this.state.title} content={this.state.content} onClose={this.toggleDialog} - onClick={this.state.file ? () => {this.toggleDialog(); this.setState({name: this.props.name})} : this.toggleDialog} + onClick={this.state.file ? () => { this.toggleDialog(); this.setState({ name: this.props.name }) } : this.toggleDialog} button={this.state.file ? 'Abbrechen' : 'Schließen'} > {this.state.file ? -
- +
+
- : null} + : null}
); @@ -159,4 +159,4 @@ const mapStateToProps = state => ({ }); -export default connect(mapStateToProps, { workspaceName })(withStyles(styles, {withTheme: true})(Compile)); +export default connect(mapStateToProps, { workspaceName })(withStyles(styles, { withTheme: true })(Compile));