Skip to content

Commit

Permalink
feat: add air pressure sensor block (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoesbergen authored Feb 18, 2024
1 parent cf28f32 commit 1c8ebd5
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
8 changes: 8 additions & 0 deletions blocks/leaphy_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
},
];
}

Expand Down
22 changes: 22 additions & 0 deletions generators/arduino/leaphy_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ function getCodeGenerators(Arduino) {
return ["getTOF()", Arduino.ORDER_ATOMIC];
};

Arduino.forBlock["leaphy_get_air_pressure"] = function (block) {
Arduino.addInclude("bmp280", "#include <Adafruit_BMP280.h>");
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 <Adafruit_SGP30.h>");
Arduino.addDeclaration("leaphy_gas_sensor", "Adafruit_SGP30 sgp;");
Expand Down
1 change: 1 addition & 0 deletions msg/js/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions msg/js/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 3 additions & 0 deletions msg/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 1c8ebd5

Please sign in to comment.