Skip to content

Commit

Permalink
Added: rangefinder i2c blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
vertigra committed Oct 28, 2022
1 parent 7dba704 commit eb109da
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 2 deletions.
101 changes: 100 additions & 1 deletion source/blocks/adam_two.js
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,105 @@ Blockly.defineBlocksWithJsonArray([
"colour": 230,
"tooltip": "Инициализация экземпляра класса для работы с дальномерами и колесами",
"helpUrl": ""
}
},

/**
* common_import_rangefinders_i2c
*
*/
{
"type": "common_import_rangefinders_i2c",
"lastDummyAlign0": "RIGHT",
"message0": "инициализировать дальномеры %1 открыть шину I2C %2 показывать ошибки %3",
"args0": [
{
"type": "input_dummy",
"align": "CENTRE"
},
{
"type": "input_value",
"name": "bus_number",
"check": "Number",
"align": "RIGHT"
},
{
"type": "field_checkbox",
"name": "verbose_mode",
"checked": false
}
],
"inputsInline": false,
"output": null,
"colour": 315,
"tooltip": "Инициализирует класс работы с дальномерами и открывает шину I2C",
"helpUrl": ""
},

/**
* rangefinder_get_distance_i2c
*
*/
{
"type": "rangefinder_get_distance_i2c",
"message0": "получить расстояние %1 адрес дальномера %2",
"args0": [
{
"type": "input_dummy"
},
{
"type": "input_value",
"name": "rangefinder_address"
}
],
"inputsInline": false,
"output": null,
"colour": 315,
"tooltip": "Получение данных дальномера с указанным адресом ",
"helpUrl": ""
},

/**
* rangefinder_i2c_address
*
*/
{
"type": "rangefinder_i2c_address",
"message0": "переменные I2C дальномеров %1",
"args0": [
{
"type": "field_dropdown",
"name": "device_addr",
"options": [
[
"0x18",
"24"
],
[
"0x19",
"25"
],
[
"0x1A",
"26"
],
[
"0x1B",
"27"
],
[
"0x1C",
"28"
],
[
"0x1D",
"29"
]
]
}
],
"output": null,
"colour": 315,
"tooltip": "",
"helpUrl": ""
}
]);
43 changes: 42 additions & 1 deletion source/generators/python/adam_two.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

'use strict';
// If any new block imports any library, add that library name here.
Blockly.Python.addReservedWords('math, random, Number, smbus, AdamIMU, MotionAndRangefinders');
Blockly.Python.addReservedWords('math, random, Number, smbus, AdamIMU, MotionAndRangefinders, ReadSensor');

/**
* import_adam_servo_api_with_param
Expand Down Expand Up @@ -449,4 +449,45 @@ Blockly.Python['import_adam_rangefinders'] = function(block) {
Blockly.Python.definitions_['from_motionAndRangefinders_import_MotionAndRangefinders'] = 'from motionAndRangefinders import MotionAndRangefinders';
var code = 'MotionAndRangefinders()';
return [code, Blockly.Python.ORDER_NONE];
};

/**
* common_import_rangefinders_i2c
*
*/
Blockly.Python['common_import_rangefinders_i2c'] = function(block) {
var value_bus_number = Blockly.Python.valueToCode(block, 'bus_number', Blockly.Python.ORDER_ATOMIC);
var checkbox_verbose_mode = block.getFieldValue('verbose_mode') === 'TRUE';
var value_bus_number = Blockly.Python.valueToCode(block, 'bus_number', Blockly.Python.ORDER_ATOMIC);
Blockly.Python.definitions_['from_rangefinders_i2c.ReadSensor_import_ReadSensor'] = 'from rangefinders_i2c.ReadSensor import ReadSensor';

var code0 = 'ReadSensor('+ value_bus_number +')';
var code1 = 'ReadSensor('+ value_bus_number +', True)';

var code = code0

if(checkbox_verbose_mode)
code = code1

return [code, Blockly.Python.ORDER_NONE];
};

/**
* rangefinder_get_distance_i2c
*
*/
Blockly.Python['rangefinder_get_distance_i2c'] = function(block) {
var value_rangefinder_address = Blockly.Python.valueToCode(block, 'rangefinder_address', Blockly.Python.ORDER_ATOMIC);
var code = '.GetDistance('+ value_rangefinder_address +')';
return [code, Blockly.Python.ORDER_ATOMIC];
};

/**
* rangefinder_i2c_address
*
*/
Blockly.Python['rangefinder_i2c_address'] = function(block) {
var dropdown_device_addr = block.getFieldValue('device_addr');
var code = dropdown_device_addr;
return [code, Blockly.Python.ORDER_ATOMIC];
};

0 comments on commit eb109da

Please sign in to comment.