solve compiling warnings
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
import { Block } from 'blockly';
|
||||
|
||||
/**
|
||||
* Function for 'set pin' (X) to a state (Y).
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.');
|
||||
};
|
||||
@@ -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];
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user