@@ -836,23 +836,23 @@ Blockly.propc.console_print_multiple = function() {
836
836
orIt = '0' ;
837
837
}
838
838
839
+ // Get the resulting code from Blockly core
840
+ const result = Blockly . propc . valueToCode (
841
+ this , 'PRINT' + i , Blockly . propc . ORDER_NONE ) || orIt ;
842
+
839
843
if ( ! this . getFieldValue ( 'TYPE' + i ) . includes ( 'float point divide by' ) ) {
840
- varList += ', ' + ( Blockly . propc . valueToCode (
841
- this ,
842
- 'PRINT' + i ,
843
- Blockly . propc . ORDER_NONE ) . replace ( / % / g, '%%' ) || orIt ) ;
844
+ varList += ', ' + result ;
844
845
} else {
845
- varList += ', ((float) ' + ( Blockly . propc . valueToCode (
846
- this ,
847
- 'PRINT' + i ,
848
- Blockly . propc . ORDER_NONE ) || orIt ) +
849
- ') / ' + this . getFieldValue ( 'DIV' + i ) + '.0' ;
846
+ varList += ', ((float) ' + result + ') / ' +
847
+ this . getFieldValue ( 'DIV' + i ) + '.0' ;
850
848
}
851
849
i ++ ;
852
850
}
851
+
853
852
if ( this . getFieldValue ( 'ck_nl' ) === 'TRUE' ) {
854
853
code += '\\r' ;
855
854
}
855
+
856
856
code += '"' + varList + ');\n' ;
857
857
858
858
// TODO: Replace .getAllBlocks() with getAllBlocksByType()
@@ -1527,46 +1527,60 @@ Blockly.Blocks.serial_receive_text = {
1527
1527
onchange : Blockly . Blocks [ 'serial_send_text' ] . onchange ,
1528
1528
} ;
1529
1529
1530
+
1530
1531
/**
1531
1532
* Serial Receive Text code generator
1532
1533
* @return {string }
1534
+ * @description Generate C source code to scan data from a serial port input.
1533
1535
*/
1534
1536
Blockly . propc . serial_receive_text = function ( ) {
1535
1537
let p = '' ;
1538
+
1539
+ /* Is a serial pin defined? */
1536
1540
if ( this . ser_pins . length > 0 ) {
1537
- p = this . ser_pins [ 0 ] . replace ( ',' , '_' ) . replace ( / N o n e / g, 'N' ) ;
1541
+ p = this . ser_pins [ 0 ]
1542
+ . replace ( ',' , '_' ) // Replace commas with underscores
1543
+ . replace ( / N o n e / g, 'N' ) ; // Replace 'None' with 'N' in all occurrences.
1538
1544
}
1545
+
1546
+ /* Get serial pins in use */
1539
1547
if ( this . getInput ( 'SERPIN' ) ) {
1540
1548
p = this . getFieldValue ( 'SER_PIN' )
1541
1549
. replace ( ',' , '_' )
1542
1550
. replace ( / N o n e / g, 'N' ) ;
1543
1551
}
1544
- const allBlocks = Blockly . getMainWorkspace ( ) . getAllBlocks ( ) . toString ( ) ;
1545
- if ( allBlocks . indexOf ( 'Serial initialize' ) === - 1 ) {
1552
+
1553
+ if ( ! Blockly . getMainWorkspace ( )
1554
+ . getBlocksByType ( 'Serial initialize' , false ) ) {
1546
1555
return '// ERROR: Serial is not initialized!\n' ;
1547
1556
} else {
1548
- const data = Blockly . propc . variableDB_ . getName (
1549
- this . getFieldValue ( 'VALUE' ) ,
1550
- Blockly . VARIABLE_CATEGORY_NAME ) ;
1557
+ const data = Blockly . propc . variableDB_
1558
+ . getName ( this . getFieldValue ( 'VALUE' ) , Blockly . VARIABLE_CATEGORY_NAME ) ;
1551
1559
1552
- const type = this . getFieldValue ( 'TYPE' ) ;
1560
+ switch ( this . getFieldValue ( 'TYPE' ) ) {
1561
+ case 'BYTE' :
1562
+ return data + ' = fdserial_rxChar(fdser' + p + ');\n' ;
1553
1563
1554
- if ( type === 'BYTE' ) {
1555
- return data + ' = fdserial_rxChar(fdser' + p + ');\n' ;
1556
- } else if ( type === 'INT' ) {
1557
- return 'dscan(fdser' + p + ', "%d", &' + data + ');\n' ;
1558
- } else if ( type === 'BIN' ) {
1559
- return 'dscan(fdser' + p + ', "%b", &' + data + ');\n' ;
1560
- } else if ( type === 'HEX' ) {
1561
- return 'dscan(fdser' + p + ', "%x", &' + data + ');\n' ;
1562
- } else {
1563
- Blockly . propc . vartype_ [ data ] = 'char *' ;
1564
+ case 'INT' :
1565
+ return 'dscan(fdser' + p + ', "%d", &' + data + ');\n' ;
1566
+
1567
+ case 'BIN' :
1568
+ return 'dscan(fdser' + p + ', "%b", &' + data + ');\n' ;
1569
+
1570
+ case 'HEX' :
1571
+ return 'dscan(fdser' + p + ', "%x", &' + data + ');\n' ;
1564
1572
1565
- return 'dscan(fdser' + p + ', "%s", ' + data + ');\n' ;
1573
+ case 'TEXT' :
1574
+ default :
1575
+ Blockly . propc . vartype_ [ data ] = 'char *' ;
1566
1576
}
1577
+
1578
+ // This will return a string up to the first whitespace character.
1579
+ return 'dscan(fdser' + p + ', "%s", ' + data + ');\n' ;
1567
1580
}
1568
1581
} ;
1569
1582
1583
+
1570
1584
/**
1571
1585
* Serial Status block definition
1572
1586
* @type {{
0 commit comments