diff --git a/blocks/leaphy_common.js b/blocks/leaphy_common.js index d21f089..dd4eb37 100644 --- a/blocks/leaphy_common.js +++ b/blocks/leaphy_common.js @@ -519,6 +519,14 @@ function getBlocks(board) { tooltip: "", helpUrl: "", }, + { + type: "leaphy_get_air_pressure", + message0: "%%{BKY_LEAPHY_GET_AIR_PRESSURE}", + style: "leaphy_blocks", + output: "Number", + tooltip: "", + helpUrl: "", + }, ]; } diff --git a/generators/arduino/leaphy_common.js b/generators/arduino/leaphy_common.js index 0f7ab60..956e41d 100644 --- a/generators/arduino/leaphy_common.js +++ b/generators/arduino/leaphy_common.js @@ -101,6 +101,28 @@ function getCodeGenerators(Arduino) { return ["getTOF()", Arduino.ORDER_ATOMIC]; }; + Arduino.forBlock["leaphy_get_air_pressure"] = function (block) { + Arduino.addInclude("bmp280", "#include "); + Arduino.addDeclaration("bmp280", "Adafruit_BMP280 bmp280;"); + const setup = Arduino.addI2CSetup( + "bmp280", + "bmp280.begin(BMP280_ADDRESS_ALT);\n" + + " bmp280.setSampling(Adafruit_BMP280::MODE_NORMAL,\n" + + " Adafruit_BMP280::SAMPLING_X2,\n" + + " Adafruit_BMP280::SAMPLING_X16,\n" + + " Adafruit_BMP280::FILTER_X16,\n" + + " Adafruit_BMP280::STANDBY_MS_500);\n", + ); + Arduino.addDeclaration( + "bmp280_get_air_pressure", + "double getAirPressure() {\n" + + ` ${setup}\n` + + " return bmp280.readPressure() / 100;\n" + + "}", + ); + return ["getAirPressure()", Arduino.ORDER_ATOMIC]; + }; + Arduino.forBlock["leaphy_gas_sensor"] = function (block) { Arduino.addInclude("leaphy_gas_sensor", "#include "); Arduino.addDeclaration("leaphy_gas_sensor", "Adafruit_SGP30 sgp;"); diff --git a/msg/js/en.js b/msg/js/en.js index b2ea97a..0d2bd6e 100644 --- a/msg/js/en.js +++ b/msg/js/en.js @@ -111,6 +111,7 @@ Blockly.Msg["LEAPHY_FLITZ_LED_R"] = "Red"; Blockly.Msg["LEAPHY_FUNCTIONS_CATEGORY"] = "Custom Blocks"; Blockly.Msg["LEAPHY_GET_DISTANCE"] = "Get distance"; Blockly.Msg["LEAPHY_TOF_GET_DISTANCE"] = "Get ToF"; +Blockly.Msg["LEAPHY_GET_AIR_PRESSURE"] = "Get air pressure"; Blockly.Msg["LEAPHY_GET_GESTURE"] = "Get gesture"; Blockly.Msg["LEAPHY_LED"] = "Led"; Blockly.Msg["LEAPHY_LED_BASIC_BLUE"] = "B"; diff --git a/msg/js/nl.js b/msg/js/nl.js index 6633a9f..c810d2c 100644 --- a/msg/js/nl.js +++ b/msg/js/nl.js @@ -109,6 +109,7 @@ Blockly.Msg["LEAPHY_FLITZ_LED_R"] = "Rood"; Blockly.Msg["LEAPHY_FUNCTIONS_CATEGORY"] = "Eigen blokken"; Blockly.Msg["LEAPHY_GET_DISTANCE"] = "Lees afstand"; Blockly.Msg["LEAPHY_TOF_GET_DISTANCE"] = "Lees ToF"; +Blockly.Msg["LEAPHY_GET_AIR_PRESSURE"] = "Lees luchtdruk"; Blockly.Msg["LEAPHY_GET_GESTURE"] = "Lees gebaar"; Blockly.Msg["LEAPHY_LED"] = "Led"; Blockly.Msg["LEAPHY_LED_BASIC_BLUE"] = "B"; diff --git a/msg/messages.js b/msg/messages.js index 00a07af..c84ea30 100644 --- a/msg/messages.js +++ b/msg/messages.js @@ -74,6 +74,9 @@ Blockly.Msg.LEAPHY_GET_DISTANCE = 'Get distance'; /// Leaphy Get Distance Time of Flight. Blockly.Msg.LEAPHY_TOF_GET_DISTANCE = 'Get ToF'; /** @type {string} */ +/// Leaphy get air pressure +Blockly.Msg.LEAPHY_GET_AIR_PRESSURE = 'Get air pressure'; +/** @type {string} */ /// leaphy Read Digital Pin. Blockly.Msg.LEAPHY_DIGITAL_READ = 'Read digipin'; /** @type {string} */ diff --git a/package.json b/package.json index a3dab94..5498533 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "theme", "categories" ], - "version": "1.13.1", + "version": "1.14.0", "description": "Leaphy custom Blockly blocks and arduino code generator", "name": "@leaphy-robotics/leaphy-blocks" }