solve compiling warnings

This commit is contained in:
Mario 2020-07-31 11:27:53 +02:00
parent 440622a66c
commit 4e2b25947d
18 changed files with 76 additions and 83 deletions

View File

@ -3,10 +3,8 @@ import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { onChangeWorkspace } from '../../actions/workspaceActions';
import BlocklyComponent, { Block, Value, Field, Shadow, Category } from './';
import BlocklyComponent from './';
import * as Blockly from 'blockly/core';
//import * as De from './msg/de'; // de locale files
import * as En from './msg/en'; // en locale files
import './blocks/index';
import './generator/index';

View File

@ -10,7 +10,6 @@
*
* TODO: maybe change this to a "PIN" BlocklyType
*/
import { defineBlocksWithJsonArray } from 'blockly';
import Blockly from 'blockly/core';
import { selectedBoard } from '../helpers/board'
import * as Types from '../helpers/types'

View File

@ -1,4 +1,3 @@
import { defineBlocksWithJsonArray } from 'blockly';
import Blockly from 'blockly/core';

View File

@ -1,2 +0,0 @@
import Blockly from 'blockly';

View File

@ -1,6 +1,5 @@
import * as Blockly from 'blockly/core';
import { getColour } from '../helpers/colour';
import Block from 'blockly'
Blockly.Blocks['sensebox_osem_connection'] = {
@ -28,8 +27,7 @@ Blockly.Blocks['sensebox_osem_connection'] = {
this.setNextStatement(true, null);
},
onchange: function (e) {
var block = this;
var blocks = block.getDescendants()
//Blockly.Blocks.sensebox.getDescendants = blocks;
},
@ -54,7 +52,7 @@ Blockly.Blocks['sensebox_osem_connection'] = {
updateShape_: function () {
var extraFieldExist = this.getFieldValue('gps');
var input = this.getFieldValue('type');
if ((input == 'Mobile') && extraFieldExist == null) {
if ((input === 'Mobile') && extraFieldExist === null) {
this.appendValueInput('lat', 'Number')
.appendField(Blockly.Msg.senseBox_gps_lat, 'gps');
this.appendValueInput('lng', 'Number')
@ -65,7 +63,7 @@ Blockly.Blocks['sensebox_osem_connection'] = {
.appendField(Blockly.Msg.senseBox_gps_timeStamp);
}
if (input == 'Stationary' && extraFieldExist != null) {
if (input === 'Stationary' && extraFieldExist !== null) {
this.removeInput('lat');
this.removeInput('lng');
this.removeInput('altitude');
@ -98,7 +96,7 @@ Blockly.Blocks['sensebox_send_to_osem'] = {
// Is the block nested in a loop?
var block = this;
do {
if (this.LOOP_TYPES.indexOf(block.type) != -1) {
if (this.LOOP_TYPES.indexOf(block.type) !== -1) {
legal = true;
break;
}

View File

@ -111,7 +111,7 @@ Blockly.Blocks['sensebox_sensor_pressure'] = {
init: function () {
var dropdownOptions = [[Blockly.Msg.senseBox_pressure, "Pressure"], [Blockly.Msg.senseBox_temp, "Temperature"], [Blockly.Msg.senseBox_gps_alt, "Altitude"]];
var dropdown = new Blockly.FieldDropdown(dropdownOptions, function (option) {
var input = (option == 'Pressure') || (option == 'Temperature') || (option == 'Altitude');
var input = (option === 'Pressure') || (option === 'Temperature') || (option === 'Altitude');
this.sourceBlock_.updateShape_(input);
});
this.appendDummyInput()
@ -132,7 +132,7 @@ Blockly.Blocks['sensebox_sensor_pressure'] = {
*/
domToMutation: function (xmlElement) {
var input = (xmlElement.getAttribute('port'));
(xmlElement.getAttribute('port'));
},
/**
@ -156,7 +156,7 @@ Blockly.Blocks['sensebox_sensor_pressure'] = {
updateShape_: function () {
var extraFieldExist = this.getFieldValue('referencePressure');
var input = this.getFieldValue('NAME');
if (input == 'Altitude' && extraFieldExist == null) {
if (input === 'Altitude' && extraFieldExist === null) {
this.appendDummyInput('extraField')
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(Blockly.Msg.senseBox_pressure_referencePressure)
@ -164,13 +164,13 @@ Blockly.Blocks['sensebox_sensor_pressure'] = {
.appendField(Blockly.Msg.senseBox_pressure_referencePressure_dim);
}
if ((input == 'Pressure' || input == 'Temperature') && extraFieldExist != null) {
if ((input === 'Pressure' || input === 'Temperature') && extraFieldExist !== null) {
this.removeInput('extraField');
}
},
getBlockType: function () {
var input = this.getFieldValue('NAME');
if (input == 'Temperature') {
if (input === 'Temperature') {
return Types.DECIMAL.typeId;
} else {
return Types.LARGE_NUMBER.typeId;
@ -215,7 +215,7 @@ Blockly.Blocks['sensebox_sensor_ultrasonic_ranger'] = {
var dropdownOptions = [[Blockly.Msg.senseBox_ultrasonic_port_A, 'A'],
[Blockly.Msg.senseBox_ultrasonic_port_B, 'B'], [Blockly.Msg.senseBox_ultrasonic_port_C, 'C']];
var dropdown = new Blockly.FieldDropdown(dropdownOptions, function (option) {
var input = (option == 'A') || (option == 'B') || (option == 'C');
var input = (option === 'A') || (option === 'B') || (option === 'C');
this.sourceBlock_.updateShape_(input);
});
@ -241,7 +241,7 @@ Blockly.Blocks['sensebox_sensor_ultrasonic_ranger'] = {
* @this Blockly.Block
*/
domToMutation: function (xmlElement) {
var input = (xmlElement.getAttribute('port'));
(xmlElement.getAttribute('port'));
},
/**
@ -277,6 +277,8 @@ Blockly.Blocks['sensebox_sensor_ultrasonic_ranger'] = {
this.setFieldValue('5', 'ultrasonic_trigger');
this.setFieldValue('6', 'ultrasonic_echo');
break;
default:
break;
}
},

View File

@ -1,4 +1,4 @@
import Blockly from 'blockly';

View File

@ -25,7 +25,6 @@
// https://developers.google.com/blockly/guides/create-custom-blocks/generating-code
import * as Blockly from 'blockly/core';
import * as _ from 'lodash';
/**
* Arduino code generator.

View File

@ -1,5 +1,4 @@
import * as Blockly from 'blockly/core';
import { Block } from 'blockly';
/**
* Function for 'set pin' (X) to a state (Y).

View File

@ -1,5 +1,4 @@
import * as Blockly from 'blockly/core';
import { Block } from 'blockly';
Blockly.Arduino['logic_boolean'] = function (Block) {
// Boolean values true and false.

View File

@ -1,5 +1,5 @@
import * as Blockly from 'blockly/core';
import { Block } from 'blockly';
Blockly['Arduino']['controls_repeat_ext'] = function (Block) {
// Repeat n times.
@ -111,6 +111,8 @@ Blockly['Arduino']['controls_flow_statements'] = function (Block) {
return 'break;\n';
case 'CONTINUE':
return 'continue;\n';
default:
break;
}
throw Error('Unknown flow statement.');
};

View File

@ -1,6 +1,5 @@
import * as Blockly from 'blockly/core';
import { Block } from 'blockly';
/**
* @license Licensed under the Apache License, Version 2.0 (the "License"):
@ -23,9 +22,9 @@ import { Block } from 'blockly';
Blockly.Arduino['math_number'] = function (block) {
// Numeric value.
var code = parseFloat(block.getFieldValue('NUM'));
if (code == Infinity) {
if (code === Infinity) {
code = 'INFINITY';
} else if (code == -Infinity) {
} else if (code === -Infinity) {
code = '-INFINITY';
}
return [code, Blockly.Arduino.ORDER_ATOMIC];
@ -71,21 +70,21 @@ Blockly.Arduino['math_single'] = function (block) {
var operator = block.getFieldValue('OP');
var code;
var arg;
if (operator == 'NEG') {
if (operator === 'NEG') {
// Negation is a special case given its different operator precedents.
arg = Blockly.Arduino.valueToCode(block, 'NUM',
Blockly.Arduino.ORDER_UNARY_PREFIX) || '0';
if (arg[0] == '-') {
if (arg[0] === '-') {
// --3 is not legal in C++ in this context.
arg = ' ' + arg;
}
code = '-' + arg;
return [code, Blockly.Arduino.ORDER_UNARY_PREFIX];
}
if (operator == 'ABS' || operator.substring(0, 5) == 'ROUND') {
if (operator === 'ABS' || operator.substring(0, 5) === 'ROUND') {
arg = Blockly.Arduino.valueToCode(block, 'NUM',
Blockly.Arduino.ORDER_UNARY_POSTFIX) || '0';
} else if (operator == 'SIN' || operator == 'COS' || operator == 'TAN') {
} else if (operator === 'SIN' || operator === 'COS' || operator === 'TAN') {
arg = Blockly.Arduino.valueToCode(block, 'NUM',
Blockly.Arduino.ORDER_MULTIPLICATIVE) || '0';
} else {
@ -127,6 +126,8 @@ Blockly.Arduino['math_single'] = function (block) {
case 'TAN':
code = 'tan(' + arg + ' / 180 * Math.PI)';
break;
default:
break;
}
if (code) {
return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX];
@ -146,7 +147,7 @@ Blockly.Arduino['math_single'] = function (block) {
code = 'atan(' + arg + ') / M_PI * 180';
break;
default:
throw 'Unknown math operator: ' + operator;
throw new Error('Unknown math operator: ' + operator);
}
return [code, Blockly.Arduino.ORDER_MULTIPLICATIVE];
};
@ -184,7 +185,7 @@ Blockly.Arduino['math_number_property'] = function (block) {
Blockly.Arduino.ORDER_MULTIPLICATIVE) || '0';
var dropdown_property = block.getFieldValue('PROPERTY');
var code;
if (dropdown_property == 'PRIME') {
if (dropdown_property === 'PRIME') {
var func = [
'boolean ' + Blockly.Arduino.DEF_FUNC_NAME + '(int n) {',
' // https://en.wikipedia.org/wiki/Primality_test#Naive_methods',
@ -232,6 +233,8 @@ Blockly.Arduino['math_number_property'] = function (block) {
Blockly.Arduino.ORDER_MULTIPLICATIVE) || '0';
code = number_to_check + ' % ' + divisor + ' == 0';
break;
default:
break;
}
return [code, Blockly.Arduino.ORDER_EQUALITY];
};

View File

@ -1,5 +1,5 @@
import * as Blockly from 'blockly/core';
import { Block } from 'blockly';
/**
* Code generator to add code into the setup() and loop() functions.
@ -13,7 +13,7 @@ Blockly.Arduino['arduino_functions'] = function (block) {
var targetBlock = block.getInputTargetBlock(name);
var code = Blockly.Arduino.blockToCode(targetBlock);
if (typeof code != 'string') {
throw 'Expecting code from statement block "' + targetBlock.type + '".';
throw new Error('Expecting code from statement block "' + targetBlock.type + '".');
}
return code;
}

View File

@ -1,6 +1,4 @@
import Blockly, { Blocks } from 'blockly';
import { getColour } from '../helpers/colour'
import Block from 'blockly';
import Blockly from 'blockly';
/**
@ -20,7 +18,7 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
var box_id = this.getFieldValue('BoxID');
var host = this.getFieldValue('host');
var branch = Blockly.Arduino.statementToCode(Block, 'DO');
var blocks = Blockly.Block.getDescendants;
//var blocks = Blockly.Block.getDescendants;
var type = this.getFieldValue('type');
var ssl = this.getFieldValue('SSL');
var port = 0;
@ -36,10 +34,10 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
Blockly.Arduino.definitions_['num_sensors'] = 'static const uint8_t NUM_SENSORS = ' + num_sensors + ';'
Blockly.Arduino.definitions_['SenseBoxID'] = 'const char SENSEBOX_ID [] PROGMEM = "' + box_id + '";';
Blockly.Arduino.definitions_['host'] = 'const char server [] PROGMEM =' + host + ';';
if (ssl == 'TRUE') {
if (ssl === 'TRUE') {
Blockly.Arduino.definitions_['WiFiSSLClient'] = 'WiFiSSLClient client;';
port = 443;
} else if (ssl == 'FALSE') {
} else if (ssl === 'FALSE') {
Blockly.Arduino.definitions_['WiFiClient'] = 'WiFiClient client;';
port = 80;
}
@ -170,7 +168,7 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
}
}
}`
var code = '';
code = '';
code += branch;
code += 'submitValues(' + lat + ',' + lng + ',' + altitude + ',' + timestamp + ');\n';
}

View File

@ -1,6 +1,4 @@
import Blockly from 'blockly';
import { getColour } from '../helpers/colour';
import { selectedBoard } from '../helpers/board';
/**
* HDC1080 Temperature and Humidity Sensor
@ -23,16 +21,17 @@ Blockly.Arduino.sensebox_sensor_temp_hum = function () {
Blockly.Arduino.sensebox_sensor_uv_light = function () {
var dropdown_name = this.getFieldValue('NAME');
let code = '';
Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
if (dropdown_name === 'UvIntensity') {
Blockly.Arduino.definitions_['define_veml'] = 'VEML6070 veml;'
Blockly.Arduino.setupCode_['sensebox_sensor_uv_light'] = 'veml.begin();'
var code = 'veml.get' + dropdown_name + '()';
code = 'veml.get' + dropdown_name + '()';
}
if (dropdown_name === 'Illuminance') {
Blockly.Arduino.definitions_['define_tsl'] = 'TSL45315 tsl;'
Blockly.Arduino.setupCode_['sensebox_sensor_illuminance'] = 'tsl.begin();'
var code = 'tsl.get' + dropdown_name + '()';
code = 'tsl.get' + dropdown_name + '()';
}
return [code, Blockly.Arduino.ORDER_ATOMIC];
};
@ -76,15 +75,16 @@ Blockly.Arduino.sensebox_sensor_sds011 = function () {
Blockly.Arduino.sensebox_sensor_pressure = function () {
var dropdown_name = this.getFieldValue('NAME');
var code = '';
var referencePressure = this.getFieldValue('referencePressure');
Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
Blockly.Arduino.definitions_['define_pressure'] = 'BMP280 bmp_sensor;';
Blockly.Arduino.setupCode_['sensebox_bmp_sensor'] = 'bmp_sensor.begin();';
if (dropdown_name === 'Pressure' || dropdown_name == 'Temperature') {
var code = 'bmp_sensor.get' + dropdown_name + '()';
if (dropdown_name === 'Pressure' || dropdown_name === 'Temperature') {
code = 'bmp_sensor.get' + dropdown_name + '()';
}
else if (dropdown_name === 'Altitude') {
var code = 'bmp_sensor.getAltitude(' + referencePressure + ')';
code = 'bmp_sensor.getAltitude(' + referencePressure + ')';
}
return [code, Blockly.Arduino.ORDER_ATOMIC];
};
@ -98,6 +98,7 @@ Blockly.Arduino.sensebox_sensor_pressure = function () {
Blockly.Arduino.sensebox_sensor_bme680_bsec = function () {
var dropdown_name = this.getFieldValue('dropdown');
let code = '';
Blockly.Arduino.libraries_['library_bsec'] = '#include "bsec.h"';
Blockly.Arduino.definitions_['bsec_iaqSensor'] = 'Bsec iaqSensor;'
Blockly.Arduino.variables_['bmeTemperatur'] = 'float bmeTemperatur;';
@ -170,25 +171,27 @@ Blockly.Arduino.sensebox_sensor_bme680_bsec = function () {
`;
switch (dropdown_name) {
case 'temperature':
var code = 'bmeTemperatur';
code = 'bmeTemperatur';
break;
case 'humidity':
var code = 'bmeHumidity';
code = 'bmeHumidity';
break;
case 'pressure':
var code = 'bmePressure'
code = 'bmePressure'
break;
case 'IAQ':
var code = 'bmeIAQ';
code = 'bmeIAQ';
break;
case 'IAQAccuracy':
var code = 'bmeIAQAccuracy';
code = 'bmeIAQAccuracy';
break;
case 'CO2':
var code = 'bmeCO2';
code = 'bmeCO2';
break;
case 'breathVocEquivalent':
var code = 'bmeBreathVocEquivalent';
code = 'bmeBreathVocEquivalent';
break;
default:
break;
}
return [code, Blockly.Arduino.ORDER_ATOMIC];

View File

@ -1,30 +1,29 @@
import * as Blockly from 'blockly/core';
import { Block } from 'blockly';
/**
* Telegram Bot by re:edu
*/
Blockly.Arduino.sensebox_telegram = function (Block) {
let token = Block.getFieldValue('telegram_token');
Blockly['Arduino'].libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
Blockly['Arduino'].libraries_['library_telegram'] = `#include <UniversalTelegramBot.h>`
Blockly['Arduino'].functionNames_['WiFiSSLClient'] = 'WiFiSSLClient client;';
Blockly['Arduino'].functionNames_['telegram_objects'] = `#define BOTtoken "${token}" // your Bot Token (Get from Botfather)
let token = Block.getFieldValue('telegram_token');
Blockly['Arduino'].libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
Blockly['Arduino'].libraries_['library_telegram'] = `#include <UniversalTelegramBot.h>`
Blockly['Arduino'].functionNames_['WiFiSSLClient'] = 'WiFiSSLClient client;';
Blockly['Arduino'].functionNames_['telegram_objects'] = `#define BOTtoken "${token}" // your Bot Token (Get from Botfather)
UniversalTelegramBot bot(BOTtoken, client);`
let code = 'testcode';
return code;
let code = 'testcode';
return code;
};
Blockly.Arduino.sensebox_telegram_do = function (block) {
var messageProcessing = Blockly.Arduino.statementToCode(block, 'telegram_do', Blockly.Arduino.ORDER_ATOMIC);
var messageProcessing = Blockly.Arduino.statementToCode(block, 'telegram_do', Blockly.Arduino.ORDER_ATOMIC);
Blockly.Arduino.definitions_['telegram_variables'] = `int Bot_mtbs = 1000; //mean time between scan messages
Blockly.Arduino.definitions_['telegram_variables'] = `int Bot_mtbs = 1000; //mean time between scan messages
long Bot_lasttime; //last time messages' scan has been done`
Blockly.Arduino.loopCodeOnce_['sensebox_telegram_loop'] = `if (millis() > Bot_lasttime + Bot_mtbs) {
Blockly.Arduino.loopCodeOnce_['sensebox_telegram_loop'] = `if (millis() > Bot_lasttime + Bot_mtbs) {
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
while(numNewMessages) {
for(int i=0; i<numNewMessages; i++) {
@ -37,22 +36,22 @@ Blockly.Arduino.sensebox_telegram_do = function (block) {
}
Bot_lasttime = millis();
}`;
var code = '';
return code;
var code = '';
return code;
};
Blockly.Arduino.sensebox_telegram_do_on_message = function (block) {
var message = this.getFieldValue('telegram_message');
var stuffToDo = Blockly.Arduino.statementToCode(block, 'telegram_do_on_message', Blockly.Arduino.ORDER_ATOMIC);
var code = `
var message = this.getFieldValue('telegram_message');
var stuffToDo = Blockly.Arduino.statementToCode(block, 'telegram_do_on_message', Blockly.Arduino.ORDER_ATOMIC);
var code = `
if (text == "${message}") {
${stuffToDo}
}`;
return code;
return code;
};
Blockly.Arduino.sensebox_telegram_send = function (block) {
var textToSend = Blockly.Arduino.valueToCode(this, 'telegram_text_to_send', Blockly.Arduino.ORDER_ATOMIC) || '"Keine Eingabe"';
var code = `bot.sendMessage(chat_id, String(${textToSend}), "");\n`;
return code;
var textToSend = Blockly.Arduino.valueToCode(this, 'telegram_text_to_send', Blockly.Arduino.ORDER_ATOMIC) || '"Keine Eingabe"';
var code = `bot.sendMessage(chat_id, String(${textToSend}), "");\n`;
return code;
};

View File

@ -33,7 +33,7 @@ const sensebox_mcu = {
i2cPins: { Wire: [['SDA', '17'], ['SCL', '16']] },
i2cSpeed: [['100kHz', '100000L'], ['400kHz', '400000L']],
builtinLed: [['BUILTIN_1', '7'], ['BUILTIN_2', '8']],
interrupt: [['interrupt1', '1'], ['interrupt2', '2'], , ['interrupt3', '3'], ['interrupt4', '4'], ['interrupt5', '5'], ['interrupt6', '6']],
interrupt: [['interrupt1', '1'], ['interrupt2', '2'], ['interrupt3', '3'], ['interrupt4', '4'], ['interrupt5', '5'], ['interrupt6', '6']],
analogPins: [['A1', 'A1'], ['A2', 'A2'], ['A3', 'A3'], ['A4', 'A4'], ['A5', 'A5'], ['A6', 'A6']],
serial_baud_rate: 9600,
parseKey: '_*_'

View File

@ -1,12 +1,9 @@
import React, { Component } from 'react';
import BlocklyComponent, { Block, Value, Field, Shadow, Category } from '../';
import React from 'react';
import { Block, Value, Field, Shadow, Category } from '../';
import { getColour } from '../helpers/colour'
class Toolbox extends React.Component {
constructor(props) {
super(props);
}
render() {
return (