Skip to content

Commit

Permalink
Merge pull request #49 from toklinke/simplified_blocks
Browse files Browse the repository at this point in the history
Add simplified blocks
  • Loading branch information
toklinke authored Feb 3, 2021
2 parents e29d3e8 + eb7adc6 commit 830b6c5
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 1 deletion.
37 changes: 37 additions & 0 deletions webserver/static/js/custom_blocks_eye.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,40 @@ Blockly.Python.eye_colour_rgb = function(block) {
var code = varName + '.set_color(' + r + ', ' + g + ', ' + b + ')\n';
return code;
};


Blockly.Blocks.eye_colour_rgb_simple = {
init: function () {
this.setColour(Blockly.Msg['HUCON_EYE_HUE']);

this.appendDummyInput()
.appendField(Blockly.Msg['HUCON_EYE_SIMPLE_SET']);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(MACHINE_EYES), 'Eye');
this.appendValueInput('R')
.setCheck('Number')
.appendField(Blockly.Msg['HUCON_EYE_COLOUR_RGB_RED']);
this.appendValueInput('G')
.setCheck('Number')
.appendField(Blockly.Msg['HUCON_EYE_COLOUR_RGB_GREEN']);
this.appendValueInput('B')
.setCheck('Number')
.appendField(Blockly.Msg['HUCON_EYE_COLOUR_RGB_BLUE']);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);

this.setTooltip(Blockly.Msg["HUCON_EYE_SIMPLE_TOOLTIP"]);
}
};
Blockly.Python.eye_colour_rgb_simple = function(block) {
Blockly.Python.definitions_.import_eye = 'from hucon import Eye';

var channel = block.getFieldValue('Eye');
var r = Blockly.Python.valueToCode(block, 'R', Blockly.Python.ORDER_ATOMIC) || '0';
var g = Blockly.Python.valueToCode(block, 'G', Blockly.Python.ORDER_ATOMIC) || '0';
var b = Blockly.Python.valueToCode(block, 'B', Blockly.Python.ORDER_ATOMIC) || '0';

var code = 'Eye(' + channel + ', Eye.RGB)' + '.set_color(' + r + ', ' + g + ', ' + b + ')\n';
return code;
};
27 changes: 27 additions & 0 deletions webserver/static/js/custom_blocks_motor.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,30 @@ Blockly.Python.motor_set_speed = function (block) {
var code = varName + '.set_speed(' + value + ')\n';
return code;
};

Blockly.Blocks.motor_set_speed_simple = {
init: function () {
this.setColour(Blockly.Msg['HUCON_MOTOR_HUE']);

this.appendDummyInput()
.appendField(Blockly.Msg['HUCON_MOTOR_SPEED_SIMPLE_SET'])
.appendField(new Blockly.FieldDropdown(MACHINE_MOTOR_PINS), 'channel');
this.appendValueInput('Speed')
.setCheck('Number')
.appendField(Blockly.Msg['HUCON_MOTOR_SPEED_SIMPLE_SPEED']);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);

this.setTooltip(Blockly.Msg["HUCON_MOTOR_SPEED_SIMPLE_TOOLTIP"]);
}
};
Blockly.Python.motor_set_speed_simple = function(block) {
Blockly.Python.definitions_.import_motor = 'from hucon import Motor';

var channel = block.getFieldValue('channel');
var speed = Blockly.Python.valueToCode(block, 'Speed', Blockly.Python.ORDER_ATOMIC) || '0';

var code = 'Motor(' + channel + ')' + '.set_speed(' + speed + ')\n';
return code;
};
27 changes: 27 additions & 0 deletions webserver/static/js/custom_blocks_servo.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,30 @@ Blockly.Python.servo_set_angle = function (block) {
var code = varName + '.set_angle(' + angle + ')\n';
return code;
};

Blockly.Blocks.servo_set_angle_simple = {
init: function () {
this.setColour(Blockly.Msg['HUCON_SERVO_HUE']);

this.appendDummyInput()
.appendField(Blockly.Msg['HUCON_SERVO_ANGLE_SIMPLE_SET'])
.appendField(new Blockly.FieldDropdown(MACHINE_SERVO_PINS), 'channel');
this.appendValueInput('Angle')
.setCheck('Number')
.appendField(Blockly.Msg['HUCON_SERVO_ANGLE_SIMPLE_ANGLE']);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);

this.setTooltip(Blockly.Msg["HUCON_SERVO_ANGLE_SIMPLE_TOOLTIP"]);
}
};
Blockly.Python.servo_set_angle_simple = function(block) {
Blockly.Python.definitions_.import_servo = 'from hucon import Servo';

var channel = block.getFieldValue('channel');
var angle = Blockly.Python.valueToCode(block, 'Angle', Blockly.Python.ORDER_ATOMIC) || '0';

var code = 'Servo(' + channel + ')' + '.set_angle(' + angle + ')\n';
return code;
};
8 changes: 8 additions & 0 deletions webserver/static/xml/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Blockly.Msg["HUCON_EYE_COLOUR_RGB_RED"] = "Rot";
Blockly.Msg["HUCON_EYE_COLOUR_RGB_GREEN"] = "Grün";
Blockly.Msg["HUCON_EYE_COLOUR_RGB_BLUE"] = "Blau";
Blockly.Msg["HUCON_EYE_COLOUR_RGB_TOOLTIP"] = "Setz die Farbe für das Auge. Benutze sepperate Werte für Rot, Grün und Blau.";
Blockly.Msg["HUCON_EYE_SIMPLE_SET"] = "Setze Augenfarbe an";
Blockly.Msg["HUCON_EYE_SIMPLE_TOOLTIP"] = "Setze die Farbe für ein Auge.";

Blockly.Msg["HUCON_SERVO_HUE"] = "30";
Blockly.Msg["HUCON_SERVO_CAT"] = "Servo";
Expand Down Expand Up @@ -72,6 +74,9 @@ Blockly.Msg["HUCON_SERVO_OFFSET_TOOLTIP"] = "Setz den Offset vom Servo. Der Wert
Blockly.Msg["HUCON_SERVO_ANGLE_SET"] = "setz für";
Blockly.Msg["HUCON_SERVO_ANGLE_ANGLE"] = "den Winkel auf";
Blockly.Msg["HUCON_SERVO_ANGLE_TOOLTIP"] = "Setz den Winkel vom Servo zwischen 0 und 180 Grad.";
Blockly.Msg["HUCON_SERVO_ANGLE_SIMPLE_SET"] = "setz für Servo auf";
Blockly.Msg["HUCON_SERVO_ANGLE_SIMPLE_ANGLE"] = "den Winkel auf";
Blockly.Msg["HUCON_SERVO_ANGLE_SIMPLE_TOOLTIP"] = "Setz den Winkel eines Servos auf einen Wert zwischen 0 und 180° Grad.";

Blockly.Msg["HUCON_MOTOR_HUE"] = "60";
Blockly.Msg["HUCON_MOTOR_CAT"] = "Motor";
Expand Down Expand Up @@ -99,6 +104,9 @@ Blockly.Msg["HUCON_MOTOR_OFFSET_TOOLTIP"] = "Setz den Offset vom Servo. Der Wert
Blockly.Msg["HUCON_MOTOR_SPEED_SET"] = "setz für";
Blockly.Msg["HUCON_MOTOR_SPEED_SPEED"] = "Die Geschwindigkeit auf";
Blockly.Msg["HUCON_MOTOR_SPEED_TOOLTIP"] = "Setz die Geschwindigkeit vom Motor zwischen -100 (rückwärts) und 100 (vorwärts).";
Blockly.Msg["HUCON_MOTOR_SPEED_SIMPLE_SET"] = "setz für Motor auf";
Blockly.Msg["HUCON_MOTOR_SPEED_SIMPLE_SPEED"] = "die Geschwindigkeit auf";
Blockly.Msg["HUCON_MOTOR_SPEED_SIMPLE_TOOLTIP"] = "Setz die Geschwindigkeit eines Motors auf einen Wert zwischen -100 (rückwärts) und 100 (vorwärts).";

Blockly.Msg["HUCON_MPU_HUE"] = "90";
Blockly.Msg["HUCON_MPU_CAT"] = "Bewegungserkennung";
Expand Down
8 changes: 8 additions & 0 deletions webserver/static/xml/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Blockly.Msg["HUCON_EYE_COLOUR_RGB_RED"] = "red";
Blockly.Msg["HUCON_EYE_COLOUR_RGB_GREEN"] = "green";
Blockly.Msg["HUCON_EYE_COLOUR_RGB_BLUE"] = "blue";
Blockly.Msg["HUCON_EYE_COLOUR_RGB_TOOLTIP"] = "Set the color for the eye. Use seperated values for red, green and blue.";
Blockly.Msg["HUCON_EYE_SIMPLE_SET"] = "set eye color for";
Blockly.Msg["HUCON_EYE_SIMPLE_TOOLTIP"] = "Set the color for an eye.";

Blockly.Msg["HUCON_SERVO_HUE"] = "30";
Blockly.Msg["HUCON_SERVO_CAT"] = "Servo";
Expand Down Expand Up @@ -72,6 +74,9 @@ Blockly.Msg["HUCON_SERVO_OFFSET_TOOLTIP"] = "Set the servo offset. The Value can
Blockly.Msg["HUCON_SERVO_ANGLE_SET"] = "set";
Blockly.Msg["HUCON_SERVO_ANGLE_ANGLE"] = "angle";
Blockly.Msg["HUCON_SERVO_ANGLE_TOOLTIP"] = "Set the servo angle between 0 and 180 degree.";
Blockly.Msg["HUCON_SERVO_ANGLE_SIMPLE_SET"] = "set servo on";
Blockly.Msg["HUCON_SERVO_ANGLE_SIMPLE_ANGLE"] = "angle";
Blockly.Msg["HUCON_SERVO_ANGLE_SIMPLE_TOOLTIP"] = "Set the the angle for a servo to a value between 0 and 180 degrees.";

Blockly.Msg["HUCON_MOTOR_HUE"] = "60";
Blockly.Msg["HUCON_MOTOR_CAT"] = "Motor";
Expand Down Expand Up @@ -99,6 +104,9 @@ Blockly.Msg["HUCON_MOTOR_OFFSET_TOOLTIP"] = "Set the motor offset. The Value can
Blockly.Msg["HUCON_MOTOR_SPEED_SET"] = "set";
Blockly.Msg["HUCON_MOTOR_SPEED_SPEED"] = "speed to";
Blockly.Msg["HUCON_MOTOR_SPEED_TOOLTIP"] = "Set the motor speed between -100 (backward) and 100 (forward).";
Blockly.Msg["HUCON_MOTOR_SPEED_SIMPLE_SET"] = "set motor on";
Blockly.Msg["HUCON_MOTOR_SPEED_SIMPLE_SPEED"] = "speed";
Blockly.Msg["HUCON_MOTOR_SPEED_SIMPLE_TOOLTIP"] = "Set the speed of a motor to a value between -100 (backward) and 100 (forward).";

Blockly.Msg["HUCON_MPU_HUE"] = "90";
Blockly.Msg["HUCON_MPU_CAT"] = "Motion Tracking";
Expand Down
33 changes: 32 additions & 1 deletion webserver/static/xml/toolbox.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,23 @@
</shadow>
</value>
</block>
<block type="eye_colour_rgb_simple">
<value name="R">
<shadow type="math_number">
<field name="NUM">255</field>
</shadow>
</value>
<value name="G">
<shadow type="math_number">
<field name="NUM">127</field>
</shadow>
</value>
<value name="B">
<shadow type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
</block>
</category>
<category colour="%{BKY_HUCON_SERVO_HUE}" name="%{BKY_HUCON_SERVO_CAT}">
<block type="machine_servo_channel"></block>
Expand All @@ -322,6 +339,13 @@
</shadow>
</value>
</block>
<block type="servo_set_angle_simple">
<value name="Angle">
<shadow type="math_number">
<field name="NUM">90</field>
</shadow>
</value>
</block>
</category>
<category colour="%{BKY_HUCON_MOTOR_HUE}" name="%{BKY_HUCON_MOTOR_CAT}">
<block type="machine_motor_channel"></block>
Expand All @@ -340,6 +364,13 @@
</shadow>
</value>
</block>
<block type="motor_set_speed_simple">
<value name="Speed">
<shadow type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
</block>
</category>
<category colour="%{BKY_HUCON_MPU_HUE}" name="%{BKY_HUCON_MPU_CAT}">
<block type="mpu_object"></block>
Expand Down Expand Up @@ -375,4 +406,4 @@
</value>
</block>
</category>
</xml>
</xml>

0 comments on commit 830b6c5

Please sign in to comment.