Merge pull request #14 from sensebox/block/co2-sensor

add co2 sensor
This commit is contained in:
Mario Pesch 2020-10-13 10:03:38 +02:00 committed by GitHub
commit b53a5b277c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 95 additions and 27 deletions

View File

@ -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);
}
};

View File

@ -252,3 +252,47 @@ Blockly.Arduino.sensebox_button = function () {
} }
return [code, Blockly.Arduino.ORDER_ATOMIC]; return [code, Blockly.Arduino.ORDER_ATOMIC];
}; };
/**
* SCD30 CO2 Sensor
*
*/
Blockly.Arduino.sensebox_scd30 = function () {
var dropdown = this.getFieldValue('dropdown');
Blockly.Arduino.libraries_['scd30_library'] = '#include "SparkFun_SCD30_Arduino_Library.h"'
Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
Blockly.Arduino.definitions_['SCD30'] = 'SCD30 airSensor;';
Blockly.Arduino.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];
}

View File

@ -768,3 +768,5 @@ Blockly.Msg.senseBox_telegram_do_on_message = "bei Nachricht"
Blockly.Msg.senseBox_telegram_message = "Nachricht" Blockly.Msg.senseBox_telegram_message = "Nachricht"
Blockly.Msg.senseBox_telegram_send = "Sende Nachricht" Blockly.Msg.senseBox_telegram_send = "Sende Nachricht"
Blockly.Msg.senseBox_scd30 = "CO2 Sensor (Sensirion SCD30)";

View File

@ -750,3 +750,4 @@ Blockly.Msg.sensebox_sd_filename = "data";
Blockly.Msg.sensebox_soil_smt50 = "Soil Moisture and Temperature (SMT50)"; Blockly.Msg.sensebox_soil_smt50 = "Soil Moisture and Temperature (SMT50)";
Blockly.Msg.sensebox_web_readHTML_filename = "File:"; Blockly.Msg.sensebox_web_readHTML_filename = "File:";
Blockly.Msg.senseBox_scd30 = "CO2 Sensor (Sensirion SCD30)";

View File

@ -44,6 +44,7 @@ class Toolbox extends React.Component {
<Block type="sensebox_sensor_sds011" /> <Block type="sensebox_sensor_sds011" />
<Block type="sensebox_sensor_pressure" /> <Block type="sensebox_sensor_pressure" />
<Block type="sensebox_sensor_bme680_bsec" /> <Block type="sensebox_sensor_bme680_bsec" />
<Block type="sensebox_scd30" />
<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" />

View File

@ -38,7 +38,7 @@ const styles = (theme) => ({
class Compile extends Component { class Compile extends Component {
constructor(props){ constructor(props) {
super(props); super(props);
this.state = { this.state = {
progress: false, progress: false,
@ -50,9 +50,9 @@ class Compile extends Component {
}; };
} }
componentDidUpdate(props){ componentDidUpdate(props) {
if(props.name !== this.props.name){ if (props.name !== this.props.name) {
this.setState({name: this.props.name}); this.setState({ name: this.props.name });
} }
} }
@ -68,17 +68,17 @@ class Compile extends Component {
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data) body: JSON.stringify(data)
}) })
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
console.log(data); console.log(data);
this.setState({id: data.data.id}, () => { this.setState({ id: data.data.id }, () => {
this.createFileName(); 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 = () => { download = () => {
@ -95,33 +95,33 @@ class Compile extends Component {
} }
createFileName = () => { createFileName = () => {
if(this.state.name){ if (this.state.name) {
this.download(); 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\'.' }); 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) => { setFileName = (e) => {
this.setState({name: e.target.value}); this.setState({ name: e.target.value });
} }
render() { render() {
return ( return (
<div style={{}}> <div style={{}}>
{this.props.iconButton ? {this.props.iconButton ?
<Tooltip title='Blöcke kompilieren' arrow style={{marginRight: '5px'}}> <Tooltip title='Blöcke kompilieren' arrow style={{ marginRight: '5px' }}>
<IconButton <IconButton
className={this.props.classes.button} className={this.props.classes.button}
onClick={() => this.compile()} onClick={() => this.compile()}
> >
<FontAwesomeIcon icon={faCogs} size="xs"/> <FontAwesomeIcon icon={faCogs} size="xs" />
</IconButton> </IconButton>
</Tooltip> </Tooltip>
: :
<Button style={{ float: 'right', color: 'white' }} variant="contained" color="primary" onClick={() => this.compile()}> <Button style={{ float: 'right', color: 'white' }} variant="contained" color="primary" onClick={() => this.compile()}>
<FontAwesomeIcon icon={faCogs} style={{marginRight: '5px'}}/> Kompilieren <FontAwesomeIcon icon={faCogs} style={{ marginRight: '5px' }} /> Kompilieren
</Button> </Button>
} }
<Backdrop className={this.props.classes.backdrop} open={this.state.progress}> <Backdrop className={this.props.classes.backdrop} open={this.state.progress}>
@ -132,15 +132,15 @@ class Compile extends Component {
title={this.state.title} title={this.state.title}
content={this.state.content} content={this.state.content}
onClose={this.toggleDialog} 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'} button={this.state.file ? 'Abbrechen' : 'Schließen'}
> >
{this.state.file ? {this.state.file ?
<div style={{marginTop: '10px'}}> <div style={{ marginTop: '10px' }}>
<TextField autoFocus placeholder='Dateiname' value={this.state.name} onChange={this.setFileName} style={{marginRight: '10px'}}/> <TextField autoFocus placeholder='Dateiname' value={this.state.name} onChange={this.setFileName} style={{ marginRight: '10px' }} />
<Button disabled={!this.state.name} variant='contained' color='primary' onClick={() => this.download()}>Eingabe</Button> <Button disabled={!this.state.name} variant='contained' color='primary' onClick={() => this.download()}>Eingabe</Button>
</div> </div>
: null} : null}
</Dialog> </Dialog>
</div> </div>
); );
@ -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));