Skip to content

Commit 0e0accb

Browse files
authored
Merge pull request #907 from MatzElectronics/demo
ADC additions, block improvements
2 parents 842b5fa + e0f8e1e commit 0e0accb

File tree

6 files changed

+281
-18
lines changed

6 files changed

+281
-18
lines changed

src/main/resources/com/parallax/server/blocklyprop/internationalization/translations.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ project.create.previouslink = Previous
121121
project.board.activity-board = Propeller Activity Board WX
122122
project.board.s3 = Scribbler Robot
123123
project.board.heb = Hackable Electronic Badge
124-
project.board.flip = Propeller Flip
124+
project.board.flip = Propeller FLiP or Project Board
125125
project.board.other = Other
126126

127127
confirm.request.title = Email confirm request

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ var profile = {
183183
contiguous_pins_end: 11
184184
},
185185
"flip": {
186-
description: "Propeller Flip Board",
186+
description: "Propeller FLiP or Project Board",
187187
digital: [["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"], ["12", "12"], ["13", "13"], ["14", "14"], ["15", "15"], ["16", "16"], ["17", "17"], ["18", "18"], ["19", "19"], ["20", "20"], ["21", "21"], ["22", "22"], ["23", "23"], ["24", "24"], ["25", "25"], ["26", "26"], ["27", "27"], ["28", "28"], ["29", "29"], ["30", "30"], ["31", "31"]],
188188
servo: [["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"], ["12", "12"], ["13", "13"], ["14", "14"], ["15", "15"], ["16", "16"], ["17", "17"], ["18", "18"], ["19", "19"], ["20", "20"], ["21", "21"], ["22", "22"], ["23", "23"], ["24", "24"], ["25", "25"], ["26", "26"], ["27", "27"], ["28", "28"], ["29", "29"], ["30", "30"], ["31", "31"]],
189189
analog: [["A0", "A0"], ["A1", "A1"], ["A2", "A2"], ["A3", "A3"], ["A4", "A4"], ["A5", "A5"]],

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

Lines changed: 134 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,133 @@ Blockly.propc.serial_receive_text = function () {
473473
}
474474
};
475475

476+
477+
//--------------- Shift In/Out Blocks ------------------------------------------
478+
Blockly.Blocks.shift_in = {
479+
helpUrl: Blockly.MSG_PROTOCOLS_HELPURL,
480+
init: function() {
481+
this.setTooltip(Blockly.MSG_SHIFT_IN_TOOLTIP);
482+
this.setColour(colorPalette.getColor('protocols'));
483+
this.appendDummyInput()
484+
.appendField("shift in")
485+
.appendField(new Blockly.FieldDropdown(
486+
[['2','2'],
487+
['3','3'],
488+
['4','4'],
489+
['5','5'],
490+
['6','6'],
491+
['7','7'],
492+
['8','8'],
493+
['9','9'],
494+
['10','10'],
495+
['11','11'],
496+
['12','12'],
497+
['13','13'],
498+
['14','14'],
499+
['15','15'],
500+
['16','16'],
501+
['17','17'],
502+
['18','18'],
503+
['19','19'],
504+
['20','20'],
505+
['21','21'],
506+
['22','22'],
507+
['23','23'],
508+
['24','24'],
509+
['25','25'],
510+
['26','26'],
511+
['27','27'],
512+
['28','28'],
513+
['29','29'],
514+
['30','30'],
515+
['31','31'],
516+
['32','32']]), "BITS")
517+
.appendField("bits")
518+
.appendField(new Blockly.FieldDropdown([["MSB first","MSB"], ["LSB first","LSB"]]), "MODE")
519+
.appendField(new Blockly.FieldDropdown([["before clock","PRE"], ["after clock","POST"]]), "ORDER")
520+
.appendField("DATA")
521+
.appendField(new Blockly.FieldDropdown(profile.default.digital), "DATA")
522+
.appendField("CLK")
523+
.appendField(new Blockly.FieldDropdown(profile.default.digital), "CLK");
524+
this.setInputsInline(true);
525+
this.setOutput(true, null);
526+
}
527+
};
528+
529+
Blockly.propc.shift_in = function() {
530+
var bits = this.getFieldValue('BITS');
531+
var mode = this.getFieldValue('MODE');
532+
var ord = this.getFieldValue('ORDER');
533+
var dat = this.getFieldValue('DATA');
534+
var clk = this.getFieldValue('CLK');
535+
536+
return ['shift_in(' + dat + ', ' + clk + ', ' + mode + ord + ', ' + bits + ')', Blockly.propc.ORDER_NONE];
537+
};
538+
539+
Blockly.Blocks.shift_out = {
540+
helpUrl: Blockly.MSG_PROTOCOLS_HELPURL,
541+
init: function() {
542+
this.setTooltip(Blockly.MSG_SHIFT_OUT_TOOLTIP);
543+
this.setColour(colorPalette.getColor('protocols'));
544+
this.appendValueInput("VALUE")
545+
.setCheck("Number")
546+
.appendField("shift out the")
547+
.appendField(new Blockly.FieldDropdown(
548+
[['2','2'],
549+
['3','3'],
550+
['4','4'],
551+
['5','5'],
552+
['6','6'],
553+
['7','7'],
554+
['8','8'],
555+
['9','9'],
556+
['10','10'],
557+
['11','11'],
558+
['12','12'],
559+
['13','13'],
560+
['14','14'],
561+
['15','15'],
562+
['16','16'],
563+
['17','17'],
564+
['18','18'],
565+
['19','19'],
566+
['20','20'],
567+
['21','21'],
568+
['22','22'],
569+
['23','23'],
570+
['24','24'],
571+
['25','25'],
572+
['26','26'],
573+
['27','27'],
574+
['28','28'],
575+
['29','29'],
576+
['30','30'],
577+
['31','31'],
578+
['32','32']]), "BITS")
579+
.appendField("lowest bits of");
580+
this.appendDummyInput()
581+
.appendField(new Blockly.FieldDropdown([["MSB first","MSBFIRST"], ["LSB first","LSBFIRST"]]), "MODE")
582+
.appendField("DATA")
583+
.appendField(new Blockly.FieldDropdown(profile.default.digital), "DATA")
584+
.appendField("CLK")
585+
.appendField(new Blockly.FieldDropdown(profile.default.digital), "CLK");
586+
this.setInputsInline(true);
587+
this.setPreviousStatement(true, null);
588+
this.setNextStatement(true, null);
589+
}
590+
};
591+
592+
Blockly.propc.shift_out = function() {
593+
var bits = this.getFieldValue('BITS');
594+
var mode = this.getFieldValue('MODE');
595+
var dat = this.getFieldValue('DATA');
596+
var clk = this.getFieldValue('CLK');
597+
var val = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_NONE) || '0';
598+
599+
return 'shift_out(' + dat + ', ' + clk + ', ' + mode + ', ' + bits + ', ' + val + ');\n';
600+
};
601+
602+
476603
//--------------- Serial LCD Blocks --------------------------------------------
477604
Blockly.Blocks.debug_lcd_init = {
478605
helpUrl: Blockly.MSG_SERIAL_LCD_HELPURL,
@@ -1497,12 +1624,12 @@ Blockly.Blocks.wx_init = {
14971624
bkg_colors.setColours(['#FFFFFF','#000000']).setColumns(2);
14981625
this.setColour(colorPalette.getColor('protocols'));
14991626
this.appendDummyInput()
1500-
.appendField("Simple WX initialize DO")
1501-
.appendField(new Blockly.FieldDropdown([['31 (WX)', '31']].concat(profile.default.digital)), "DO")
1627+
.appendField("Simple WX initialize mode")
1628+
.appendField(new Blockly.FieldDropdown([['Terminal on USB', 'USB_PGM_TERM'], ['Terminal on WX', 'USB_PGM'], ['Term & Programming on WX', 'WX_ALL_COM']]), "MODE") // .concat(profile.default.digital)
1629+
.appendField(" DO")
1630+
.appendField(new Blockly.FieldDropdown([['WX Socket', '31']].concat(profile.default.digital)), "DO")
15021631
.appendField("DI")
1503-
.appendField(new Blockly.FieldDropdown([['30 (WX)', '30']].concat(profile.default.digital)), "DI")
1504-
.appendField(" mode")
1505-
.appendField(new Blockly.FieldDropdown([['Terminal via Wifi', 'USB_PGM'], ['Terminal via USB', 'USB_PGM_TERM']].concat(profile.default.digital)), "MODE");
1632+
.appendField(new Blockly.FieldDropdown([['WX Socket', '30']].concat(profile.default.digital)), "DI");
15061633
this.setInputsInline(false);
15071634
this.setPreviousStatement(true, null);
15081635
this.setNextStatement(true, null);
@@ -1515,7 +1642,7 @@ Blockly.propc.wx_init = function() {
15151642
var bkg = (this.getFieldValue('BKG') === '#FFFFFF') ? '1' : '0';
15161643
var title = this.getFieldValue('TITLE');
15171644
var mode = this.getFieldValue('MODE');
1518-
if(pin_do === '31' && pin_di === '30' && mode === 'USB_PGM') mode = 'WX_ALL_COM';
1645+
//if(pin_do === '31' && pin_di === '30' && mode === 'USB_PGM') mode = 'WX_ALL_COM';
15191646
var code = '';
15201647
code += 'wifi_start(' + pin_do + ', ' + pin_di + ', 115200, ' + mode + ');\n';
15211648
code += 'wifi_setBuffer(__wxBffr, sizeof(__wxBffr));\n';
@@ -1537,7 +1664,7 @@ Blockly.propc.wx_init = function() {
15371664
Blockly.Blocks.wx_config_page = {
15381665
helpUrl: Blockly.MSG_SWX_HELPURL,
15391666
init: function() {
1540-
this.setTooltip(Blockly.MSG_SWX_INIT_TOOLTIP);
1667+
this.setTooltip(Blockly.MSG_SWX_CONFIG_PAGE_TOOLTIP);
15411668
var bkg_colors = new Blockly.FieldColour("#FFFFFF");
15421669
bkg_colors.setColours(['#FFFFFF','#000000']).setColumns(2);
15431670
this.setColour(colorPalette.getColor('protocols'));

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

Lines changed: 120 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,14 +1053,127 @@ Blockly.propc.activitybot_display_calibration = function() {
10531053

10541054
code = '';
10551055
code += 'if(!abd_intTabSetup) interpolation_table_setup();\n';
1056-
code += 'print("=== LEFT SERVO ===\\n");\n';
1057-
code += 'print("Table Entries = %d, Zero Speed Index = %d\\n\\n", abd_elCntL, abd_cntrLidx);\n';
1056+
code += 'print("=== LEFT SERVO ===\\r");\n';
1057+
code += 'print("Table Entries = %d, Zero Speed Index = %d\\r\\r", abd_elCntL, abd_cntrLidx);\n';
10581058
code += 'print("Index, Servo Drive, Encoder Ticks/Second\\n");\n';
1059-
code += 'for(int __rIdx = 0; __rIdx < abd_elCntL; __rIdx++) print("%d, %d, %d\\n", __rIdx, abd_spdrL[__rIdx], abd_spdmL[__rIdx]);\n';
1060-
code += 'print("\\n\\n=== RIGHT SERVO ===\\n");\n';
1061-
code += 'print("Table Entries = %d, Zero Speed Index = %d\\n\\n", abd_elCntR, abd_cntrRidx);\n';
1062-
code += 'print("Index, Servo Drive, Encoder Ticks/Second\\n");\n';
1063-
code += 'for(int __rIdx = 0; __rIdx < abd_elCntR; __rIdx++) print("%d, %d, %d\\n", __rIdx, abd_spdrR[__rIdx], abd_spdmR[__rIdx]);\n';
1059+
code += 'for(int __rIdx = 0; __rIdx < abd_elCntL; __rIdx++) print("%d, %d, %d\\r", __rIdx, abd_spdrL[__rIdx], abd_spdmL[__rIdx]);\n';
1060+
code += 'print("\\r\\r=== RIGHT SERVO ===\\r");\n';
1061+
code += 'print("Table Entries = %d, Zero Speed Index = %d\\r\\r", abd_elCntR, abd_cntrRidx);\n';
1062+
code += 'print("Index, Servo Drive, Encoder Ticks/Second\\r");\n';
1063+
code += 'for(int __rIdx = 0; __rIdx < abd_elCntR; __rIdx++) print("%d, %d, %d\\r", __rIdx, abd_spdrR[__rIdx], abd_spdmR[__rIdx]);\n';
10641064

10651065
return code;
10661066
};
1067+
1068+
Blockly.Blocks.mcp320x_read = {
1069+
helpUrl: Blockly.MSG_ANALOG_PULSES_HELPURL,
1070+
init: function() {
1071+
this.setTooltip(Blockly.MSG_MCP320X_READ_TOOLTIP);
1072+
this.setColour(colorPalette.getColor('io'));
1073+
this.appendDummyInput()
1074+
.appendField(new Blockly.FieldDropdown([["MCP3202","2"], ["MCP3204","4"], ["MCP8208","8"]], function (ch_c) {
1075+
this.sourceBlock_.updateShape_({"CH_C": ch_c});}), "CHIP")
1076+
.appendField("CS")
1077+
.appendField(new Blockly.FieldDropdown(profile.default.digital), "CS_PIN")
1078+
.appendField("CLK")
1079+
.appendField(new Blockly.FieldDropdown(profile.default.digital), "CLK_PIN")
1080+
.appendField("DO")
1081+
.appendField(new Blockly.FieldDropdown(profile.default.digital), "DO_PIN")
1082+
.appendField("DI")
1083+
.appendField(new Blockly.FieldDropdown(profile.default.digital), "DI_PIN");
1084+
this.appendDummyInput('CHANNELS')
1085+
.setAlign(Blockly.ALIGN_RIGHT)
1086+
.appendField("channel")
1087+
.appendField(new Blockly.FieldDropdown([["1","1"], ["2", "2"]]), "CHAN")
1088+
.appendField("read (0-3.3V) in volt-100ths");
1089+
this.setInputsInline(false);
1090+
this.setOutput(true, null);
1091+
},
1092+
mutationToDom: function () {
1093+
var container = document.createElement('mutation');
1094+
var ch_c = this.getFieldValue('CHIP');
1095+
container.setAttribute('chip', ch_c);
1096+
return container;
1097+
},
1098+
domToMutation: function (xmlElement) {
1099+
var ch_c = xmlElement.getAttribute('chip');
1100+
this.updateShape_({"CH_C": ch_c});
1101+
},
1102+
updateShape_: function (details) {
1103+
1104+
var num = details['CH_C'];
1105+
if (details['CH_C'] === undefined) {
1106+
num = this.getFieldValue('CH_C');
1107+
}
1108+
1109+
var chan_count = [];
1110+
1111+
for (var i = 1; i <= num; i++) {
1112+
chan_count.push([i.toString(), i.toString()]);
1113+
}
1114+
1115+
this.removeInput('CHANNELS');
1116+
this.appendDummyInput('CHANNELS')
1117+
.setAlign(Blockly.ALIGN_RIGHT)
1118+
.appendField("channel")
1119+
.appendField(new Blockly.FieldDropdown(chan_count), "CHAN")
1120+
.appendField("read (0-3.3V) in volt-100ths");
1121+
}
1122+
};
1123+
1124+
Blockly.propc.mcp320x_read = function() {
1125+
var chip = parseInt(this.getFieldValue('CHIP'));
1126+
var cs_pin = this.getFieldValue('CS_PIN');
1127+
var clk_pin = this.getFieldValue('CLK_PIN');
1128+
var do_pin = this.getFieldValue('DO_PIN');
1129+
var di_pin = this.getFieldValue('DI_PIN');
1130+
var channel = '000' + parseInt(this.getFieldValue('CHANNEL')).toString(2) + "1";
1131+
1132+
if(chip < 4) {
1133+
channel = "11" + channel.substr(0,1) + "1";
1134+
} else {
1135+
channel = "11" + channel.substr(0,3) + "0";
1136+
}
1137+
1138+
var func = '';
1139+
func += 'int __Mvref = 330;';
1140+
func += 'int read_mcp320x(int __McsPin, int __MclkPin, int __MdoPin, int __MdiPin, int __Mbits, int __Mdata, int __MVr) {\n';
1141+
func += ' high(__McsPin); low(__MclkPin); low(__McsPin);\n';
1142+
func += ' shift_out(__MdiPin, __MclkPin, MSBFIRST, __Mbits, __Mdata);\n';
1143+
func += ' int __Mvolts = shift_in(__MdiPin, __MclkPin, MSBPOST, 12);\n';
1144+
func += ' high(__McsPin); high(__MclkPin);\n return ((__Mvolts * __MVr) / 4096);}';
1145+
Blockly.propc.global_vars_["mcp320x_read"] = func;
1146+
1147+
1148+
var code = '';
1149+
code += 'read_mcp320x(' + cs_pin + ', ' + clk_pin + ', ' + do_pin;
1150+
code += ', ' + di_pin + ', ' + channel.length + ', 0b' + channel + ', __Mvref)';
1151+
1152+
return [code, Blockly.propc.ORDER_NONE];
1153+
};
1154+
1155+
Blockly.Blocks.mcp320x_set_vref = {
1156+
helpUrl: Blockly.MSG_ANALOG_PULSES_HELPURL,
1157+
init: function() {
1158+
this.setTooltip(Blockly.MSG_MCP320X_SET_VREF_TOOLTIP);
1159+
this.setColour(colorPalette.getColor('io'));
1160+
this.appendDummyInput()
1161+
.appendField("MCP320X set Vref to")
1162+
.appendField(new Blockly.FieldTextInput('330',
1163+
Blockly.FieldTextInput.numberValidator), "VREF")
1164+
.appendField("volt 100ths");
1165+
this.setInputsInline(true);
1166+
this.setPreviousStatement(true, null);
1167+
this.setNextStatement(true, null);
1168+
}
1169+
};
1170+
1171+
Blockly.propc.mcp320x_set_vref = function() {
1172+
var vref = parseInt(this.getFieldValue('VREF'));
1173+
1174+
var code = '';
1175+
if(Blockly.propc.global_vars_["mcp320x_read"] !== undefined) {
1176+
code += '__Mvref = ' + vref + ';\n';
1177+
}
1178+
return code;
1179+
};

src/main/webapp/cdn/blockly/language/en/_messages.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ Blockly.MSG_SERIAL_TX_TOOLTIP = "Serial transmit number: sends 32-bit integer as
308308
Blockly.MSG_SERIAL_SEND_TEXT_TOOLTIP = "Serial transmit text: sends text as characters terminated by a 0 (NULL).";
309309
Blockly.MSG_SERIAL_RX_TOOLTIP = "Serial receive number: receives 4 bytes MSB first and stores a a 32-bit integer.";
310310
Blockly.MSG_SERIAL_RECEIVE_TEXT_TOOLTIP = "Serial receive text: receives and stores characters into a variable until a 0 (NULL).";
311-
Blockly.MSG_SWX_INIT_TOOLTIP = "Simple WX initialize: Requires simplewx.html file. Match DO/DI to Propeller I/O pin connections. Set terminal routing, page title, and background color.";
311+
Blockly.MSG_SHIFT_IN_TOOLTIP = "Shift In: serially shifts in a specified number of bits and provides an integer value.";
312+
Blockly.MSG_SHIFT_OUT_TOOLTIP = "Shift Out: serially shifts in a specified number of bits from the specified value.";
313+
Blockly.MSG_SWX_INIT_TOOLTIP = "Simple WX initialize: Requires simplewx.html file. Match DO/DI to Propeller I/O pin connections, set terminal and program routing.";
314+
Blockly.MSG_SWX_CONFIG_PAGE_TOOLTIP = "Simple WX configure page: Requires simplewx.html file. Set terminal page title and background color.";
312315
Blockly.MSG_SWX_SET_TOOLTIP = "Simple WX set widget: Requires simplewx.html file. Set location, type, color, and values for a new widget.";
313316
Blockly.MSG_SWX_READ_TOOLTIP = "Simple WX read widgets: Requires simplewx.html file. Reads the current values of all the widgets.";
314317
Blockly.MSG_SWX_GET_TOOLTIP = "Simple WX widget value: Requires simplewx.html file. Provides the value of a widget from when it was last read.";
@@ -357,6 +360,8 @@ Blockly.MSG_PULSE_OUT_TOOLTIP = "Pulse-out: outputs a high or low pulse to the s
357360
Blockly.MSG_PWM_START_TOOLTIP = "PWM initialize: sets up PWM object in the Propeller.";
358361
Blockly.MSG_PWM_SET_TOOLTIP = "PWM set: sends the specified PWM pulses out the Propeller I/O pin specified. Set duty cycle to 0 to stop sending pulses.";
359362
Blockly.MSG_PWM_STOP_TOOLTIP = "PWM stop: Stops PWM object, frees up resources used on the Propeller.";
363+
Blockly.MSG_MCP320X_SET_VREF_TOOLTIP = "MCP320X set Vref: Set to the Vref voltage of the A/D chip.";
364+
Blockly.MSG_MCP320X_READ_TOOLTIP = "MCP320X read: Reads an analog voltage from the specified channel. Match to Propeller I/O pin connections.";
360365
Blockly.MSG_WAV_PLAY_TOOLTIP = "WAV play: Plays the specified .WAV file stored on the SD card.";
361366
Blockly.MSG_WAV_STATUS_TOOLTIP = "WAV status: returns 1/true if a .WAV file is playing, returns 0/false if not.";
362367
Blockly.MSG_WAV_VOLUME_TOOLTIP = "WAV volume: sets the volume of the WAV player - 0 (quietest) to 10 (loudest).";

src/main/webapp/frame/framec.jsp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,14 @@
477477
<block type="serial_send_text"></block>
478478
<block type="serial_rx"></block>
479479
<block type="serial_receive_text"></block>
480+
<block type="shift_in"></block>
481+
<block type="shift_out">
482+
<value name="VALUE">
483+
<block type="math_number">
484+
<field name="NUM">10</field>
485+
</block>
486+
</value>
487+
</block>
480488
</category>
481489
<category name="<fmt:message key="category.communicate.WS2812B" />">
482490
<block type="ws2812b_init"></block>
@@ -557,7 +565,13 @@
557565
<block type="wx_init"></block>
558566
<block type="wx_config_page"></block>
559567
<block type="wx_set_widget"></block>
560-
<block type="wx_send_widget"></block>
568+
<block type="wx_send_widget">
569+
<value name="NUM">
570+
<block type="math_number">
571+
<field name="NUM">10</field>
572+
</block>
573+
</value>
574+
</block>
561575
<block type="wx_read_widgets"></block>
562576
<block type="wx_get_widget"></block>
563577
<block type="wx_evt_connected"></block>
@@ -682,6 +696,10 @@
682696
</value>
683697
</block>
684698
</category>
699+
<category name="<fmt:message key="category.analog-pulses.voltage" />" include="flip">
700+
<block type="mcp320x_read"></block>
701+
<block type="mcp320x_set_vref"></block>
702+
</category>
685703
</category>
686704
<category name="<fmt:message key="category.audio" />" exclude="s3" colour="200">
687705
<category name="<fmt:message key="category.audio.freqout" />" exclude="s3">

0 commit comments

Comments
 (0)