Skip to content

Commit db2316d

Browse files
author
Matthew Matz
committed
add set ranges to blocks
1 parent 0460868 commit db2316d

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

src/main/webapp/cdn/blockly/generators/propc/base.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ Blockly.Blocks.math_number = {
176176
}
177177
if (rangeVals[0] === 'R' && (range[2] < range[0] || range[2] > range[1]) && Math.abs(range[0] - range[1]) <= 10000000) {
178178
if (this.getField('TITLE')) {
179-
if (range[1] >= 2147483648) {
179+
if (range[1] >= 2147483647) {
180180
this.setFieldValue('(\u2265 ' + range[0].toString(10) + ')', 'TITLE');
181-
} else if (range[0] <= -2147483648) {
181+
} else if (range[0] <= -2147483647) {
182182
this.setFieldValue('(\u2264' + range[1].toString(10) + ')', 'TITLE');
183183
} else {
184184
this.setFieldValue('(' + range[0].toString(10) + ' to ' + range[1].toString(10) + ')', 'TITLE');
@@ -835,12 +835,17 @@ Blockly.Blocks.color_value_from = {
835835
this.appendDummyInput()
836836
.appendField("color value from:");
837837
this.appendValueInput("RED_VALUE")
838+
.appendField('R,0,255,0', 'RANGEVALS0')
838839
.appendField("red");
839840
this.appendValueInput("GREEN_VALUE")
841+
.appendField('R,0,255,0', 'RANGEVALS1')
840842
.appendField("green");
841843
this.appendValueInput("BLUE_VALUE")
844+
.appendField('R,0,255,0', 'RANGEVALS2')
842845
.appendField("blue");
843-
846+
this.getField('RANGEVALS0').setVisible(false);
847+
this.getField('RANGEVALS1').setVisible(false);
848+
this.getField('RANGEVALS2').setVisible(false);
844849
this.setOutput(true, "Number");
845850
this.setInputsInline(true);
846851
this.setPreviousStatement(false, null);

src/main/webapp/cdn/blockly/generators/propc/communicate.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,13 +1456,9 @@ Blockly.Blocks.oled_set_cursor = {
14561456
this.appendValueInput('X_POS')
14571457
.setCheck('Number')
14581458
.appendField("OLED set cursor at (x)");
1459-
// .appendField('R,-75,75,5', 'RANGEVALS0');
14601459
this.appendValueInput('Y_POS')
14611460
.setCheck('Number')
14621461
.appendField("(y)");
1463-
// .appendField('R,-50,50,5', 'RANGEVALS1');
1464-
// this.getField('RANGEVALS0').setVisible(false);
1465-
// this.getField('RANGEVALS1').setVisible(false);
14661462
this.setInputsInline(true);
14671463
this.setPreviousStatement(true, null);
14681464
this.setNextStatement(true, null);

src/main/webapp/cdn/blockly/generators/propc/gpio.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ Blockly.Blocks.check_pin_input = {
120120
init: function () {
121121
this.setTooltip(Blockly.MSG_CHECK_PIN_INPUT_TOOLTIP);
122122
this.setColour(colorPalette.getColor('io'));
123-
this.appendDummyInput("")
124-
.appendField("check PIN");
125123
this.appendValueInput('PIN')
126-
.setCheck('Number');
124+
.appendField("check PIN")
125+
.setCheck('Number')
126+
.appendField('A,' + profile.default.digital.toString(), 'RANGEVALS0');
127+
this.getField('RANGEVALS0').setVisible(false);
127128
this.setOutput(true, 'Number');
128129
this.setInputsInline(true);
129130
}
@@ -531,10 +532,12 @@ Blockly.Blocks.eeprom_read = {
531532
.setCheck("Number")
532533
.appendField("EEPROM read")
533534
.appendField(new Blockly.FieldDropdown([["number", "NUMBER"], ["text", "TEXT"], ["byte", "BYTE"]]), "TYPE")
535+
.appendField('R,0,7675,0', 'RANGEVALS0')
534536
.appendField("from address");
535537
this.appendDummyInput()
536538
.appendField("store in")
537539
.appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VALUE');
540+
this.getField('RANGEVALS0').setVisible(false);
538541
this.setInputsInline(true);
539542
this.setPreviousStatement(true, null);
540543
this.setNextStatement(true, null);
@@ -716,7 +719,9 @@ Blockly.Blocks.ab_volt_out = {
716719
this.appendValueInput("VALUE")
717720
.setCheck('Number')
718721
.setAlign(Blockly.ALIGN_RIGHT)
722+
.appendField('R,0,330,0', 'RANGEVALS1')
719723
.appendField("volt-100ths");
724+
this.getField('RANGEVALS1').setVisible(false);
720725
this.setInputsInline(true);
721726
this.setPreviousStatement(true, null);
722727
this.setNextStatement(true, null);
@@ -767,9 +772,10 @@ Blockly.Blocks.pwm_set = {
767772
.appendField("channel")
768773
.appendField(new Blockly.FieldDropdown([["A", "0"], ["B", "1"]]), "CHANNEL");
769774
this.appendValueInput("DUTY_CYCLE", Number)
775+
.appendField('R,0,100,0', 'RANGEVALS1')
770776
.setCheck('Number')
771-
.appendField("duty cycle (0 - 100)");
772-
777+
.appendField("duty cycle (%)");
778+
this.getField('RANGEVALS1').setVisible(false);
773779
this.setInputsInline(true);
774780
this.setPreviousStatement(true, null);
775781
this.setNextStatement(true, null);
@@ -862,7 +868,9 @@ Blockly.Blocks.wav_volume = {
862868
this.setTooltip(Blockly.MSG_WAV_VOLUME_TOOLTIP);
863869
this.setColour(colorPalette.getColor('io'));
864870
this.appendValueInput('VOLUME')
865-
.appendField("WAV volume (0 - 10)");
871+
.appendField("WAV volume (0 - 10)")
872+
.appendField('R,0,10,0', 'RANGEVALS1');
873+
this.getField('RANGEVALS1').setVisible(false);
866874
this.setInputsInline(true);
867875
this.setPreviousStatement(true, null);
868876
this.setNextStatement(true, null);
@@ -874,13 +882,12 @@ Blockly.propc.wav_volume = function () {
874882

875883
Blockly.propc.definitions_["include wavplayer"] = '#include "wavplayer.h"';
876884

877-
if (Number(volume) < 0) {
878-
volume = '0';
879-
} else if (Number(volume) > 10) {
880-
volume = '10';
881-
}
885+
var setup_code = '// Constrain Function\nint constrain(int __cVal, int __cMin, int __cMax) {';
886+
setup_code += 'if(__cVal < __cMin) __cVal = __cMin;\n';
887+
setup_code += 'if(__cVal > __cMax) __cVal = __cMax;\nreturn __cVal;\n}\n';
888+
Blockly.propc.global_vars_["constrain_function"] = setup_code;
882889

883-
var code = 'wav_volume(' + volume + ');\n';
890+
var code = 'wav_volume(constrain(' + volume + ', 0, 10));\n';
884891
return code;
885892
};
886893

@@ -1015,13 +1022,17 @@ Blockly.Blocks.ab_drive_goto = {
10151022
.appendField('Robot drive distance in')
10161023
.appendField(new Blockly.FieldDropdown([["ticks", "TICK"], ["centimeters", "CM"], ["inches", "INCH"]]), "UNITS");
10171024
this.appendValueInput("LEFT")
1025+
.appendField('R,-4227330,4227330,0', 'RANGEVALS0')
10181026
.setCheck('Number')
10191027
.setAlign(Blockly.ALIGN_RIGHT)
10201028
.appendField("left");
10211029
this.appendValueInput("RIGHT")
1030+
.appendField('R,-4227330,4227330,0', 'RANGEVALS1')
10221031
.setCheck('Number')
10231032
.setAlign(Blockly.ALIGN_RIGHT)
10241033
.appendField("right");
1034+
this.getField('RANGEVALS0').setVisible(false);
1035+
this.getField('RANGEVALS1').setVisible(false);
10251036
this.setInputsInline(false);
10261037
this.setPreviousStatement(true, null);
10271038
this.setNextStatement(true, null);

0 commit comments

Comments
 (0)