Skip to content

Commit

Permalink
Script merge 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Frogbots4634 committed Jan 15, 2020
1 parent 5e1d8d3 commit a8b07bb
Show file tree
Hide file tree
Showing 99 changed files with 3,435 additions and 439 deletions.
4 changes: 2 additions & 2 deletions Blocks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 67
versionName "11.9"
versionCode 70
versionName "11.12"
}

buildTypes {
Expand Down
1 change: 1 addition & 0 deletions Blocks/src/main/assets/FtcBlocks.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"blocks/led.js",
"blocks/light_sensor.js",
"blocks/linear_op_mode.js",
"blocks/locale.js",
"blocks/lynx_i2c_color_range_sensor.js",
"blocks/magnetic_flux.js",
"blocks/matrix_f.js",
Expand Down
2 changes: 2 additions & 0 deletions Blocks/src/main/assets/FtcBlocksProjects.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<script type="text/javascript" src="blockly/javascript_compressed.js"></script>
<script type="text/javascript" src="ftcblockly/generators/ftcjava.js"></script>

<script type="text/javascript" src="/js/websocket-iframe.js"></script>
<script type="text/javascript" src="server"></script>
<script type="text/javascript" src="blocks/FtcBlocksProjects_common.js"></script>

Expand Down Expand Up @@ -56,6 +57,7 @@
<script type="text/javascript" src="blocks/led.js"></script>
<script type="text/javascript" src="blocks/light_sensor.js"></script>
<script type="text/javascript" src="blocks/linear_op_mode.js"></script>
<script type="text/javascript" src="blocks/locale.js"></script>
<script type="text/javascript" src="blocks/lynx_i2c_color_range_sensor.js"></script>
<script type="text/javascript" src="blocks/magnetic_flux.js"></script>
<script type="text/javascript" src="blocks/matrix_f.js"></script>
Expand Down
1 change: 1 addition & 0 deletions Blocks/src/main/assets/FtcOfflineBlocks.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<script type="text/javascript" src="blocks/led.js"></script>
<script type="text/javascript" src="blocks/light_sensor.js"></script>
<script type="text/javascript" src="blocks/linear_op_mode.js"></script>
<script type="text/javascript" src="blocks/locale.js"></script>
<script type="text/javascript" src="blocks/lynx_i2c_color_range_sensor.js"></script>
<script type="text/javascript" src="blocks/magnetic_flux.js"></script>
<script type="text/javascript" src="blocks/matrix_f.js"></script>
Expand Down
1 change: 1 addition & 0 deletions Blocks/src/main/assets/FtcOfflineBlocksProjects.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<script type="text/javascript" src="blocks/led.js"></script>
<script type="text/javascript" src="blocks/light_sensor.js"></script>
<script type="text/javascript" src="blocks/linear_op_mode.js"></script>
<script type="text/javascript" src="blocks/locale.js"></script>
<script type="text/javascript" src="blocks/lynx_i2c_color_range_sensor.js"></script>
<script type="text/javascript" src="blocks/magnetic_flux.js"></script>
<script type="text/javascript" src="blocks/matrix_f.js"></script>
Expand Down
10 changes: 10 additions & 0 deletions Blocks/src/main/assets/blocks/FtcBlocksProjects_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function initializeFtcBlocksProjects() {
window.addEventListener('resize', resize, false);
resize();

setUpWebSocket();

fetchJavaScriptForHardware(function(jsHardware, errorMessage) {
if (jsHardware) {
var newScript = document.createElement('script');
Expand Down Expand Up @@ -46,6 +48,14 @@ function resize() {
projectsTableScroll.style.height = (window.innerHeight - y) + 'px';
}


// TODO(Noah): Replace this placeholder function used to enable time syncing with correct implementation
function setUpWebSocket() {
if (typeof WEBSOCKET_LIB !== 'undefined') {
WEBSOCKET_LIB.webSocketManager.subscribeToNamespace("ControlHubUpdater");
}
}

function initializeProjects() {
projects = [];
fetchProjects(function(jsonProjects, errorMessage) {
Expand Down
31 changes: 21 additions & 10 deletions Blocks/src/main/assets/blocks/FtcBlocks_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,13 +504,14 @@ function checkBlock(block, missingHardware) {
var visibleIdentifierName;
if (block.data) {
if (block.data.startsWith('{')) {
var visibleIdentifierNames = JSON.parse(block.data);
var visibleIdentifierNames = parseBlockDataJSON(block);
visibleIdentifierName = visibleIdentifierNames[identifierFieldName];
} else {
// Some older versions save as plain text instead of JSON.
visibleIdentifierName = block.data;
}
} else {
// If the blocks file is older, we don't know what the visible name actually is.
// If the blocks file is even older, we don't know what the visible name actually is.
// The best we can do is to remove the hardware identifier suffix if there is one.
visibleIdentifierName = removeHardwareIdentifierSuffix(identifierFieldValue);
}
Expand Down Expand Up @@ -612,10 +613,18 @@ function removeHardwareIdentifierSuffix(identifierFieldValue) {
return identifierFieldValue;
}

function saveBlockWarningHidden(block) {
var data = (block.data && block.data.startsWith('{'))
? JSON.parse(block.data) : null;
function parseBlockDataJSON(block) {
if (block.data && block.data.startsWith('{')) {
try {
return JSON.parse(block.data);
} catch (err) {
}
}
return null;
}

function saveBlockWarningHidden(block) {
var data = parseBlockDataJSON(block);
if (block.warning) {
if (!block.warning.isVisible()) {
if (!data) {
Expand All @@ -633,8 +642,8 @@ function saveBlockWarningHidden(block) {
}

function readBlockWarningHidden(block) {
if (block.data && block.data.startsWith('{')) {
var data = JSON.parse(block.data);
var data = parseBlockDataJSON(block);
if (data) {
if (data.block_warning_hidden) {
return true;
}
Expand All @@ -644,8 +653,7 @@ function readBlockWarningHidden(block) {
}

function saveVisibleIdentifiers(block) {
var data = (block.data && block.data.startsWith('{'))
? JSON.parse(block.data) : null;
var data = parseBlockDataJSON(block);

for (var iFieldName = 0; iFieldName < identifierFieldNames.length; iFieldName++) {
var identifierFieldName = identifierFieldNames[iFieldName];
Expand All @@ -658,7 +666,10 @@ function saveVisibleIdentifiers(block) {
if (!data) {
data = Object.create(null);
}
data[identifierFieldName] = field.getText();
// field.getText() returns the text with spaces changed to non-breakable spaces \u00A0.
// Here we change them back to normal spaces. Without this, the character becomes &nbsp; in
// the blk file when saved with Safari.
data[identifierFieldName] = field.getText().replace(/\u00A0/g, ' ');
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Blocks/src/main/assets/blocks/color_sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Blockly.Blocks['colorSensor_getProperty'] = {
init: function() {
var PROPERTY_CHOICES = [
['Alpha', 'Alpha'],
['Argb', 'Arbg'],
['Argb', 'Argb'],
['Blue', 'Blue'],
['Green', 'Green'],
['I2cAddress7Bit', 'I2cAddress7Bit'],
Expand Down Expand Up @@ -212,7 +212,7 @@ Blockly.Blocks['colorSensor_getProperty_Number'] = {
init: function() {
var PROPERTY_CHOICES = [
['Alpha', 'Alpha'],
['Argb', 'Arbg'],
['Argb', 'Argb'],
['Blue', 'Blue'],
['Green', 'Green'],
['I2cAddress7Bit', 'I2cAddress7Bit'],
Expand Down
152 changes: 152 additions & 0 deletions Blocks/src/main/assets/blocks/dc_motor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1389,3 +1389,155 @@ Blockly.FtcJava['dcMotor_setPositionPIDFCoefficients'] = function(block) {
Blockly.FtcJava.generateImport_('DcMotorEx');
return '((DcMotorEx) ' + identifier + ').setPositionPIDFCoefficients(' + p + ');\n';
};

Blockly.Blocks['dcMotor_getCurrent'] = {
init: function() {
this.setOutput(true, 'Number');
this.appendDummyInput()
.appendField('call')
.appendField(createDcMotorExDropdown(), 'IDENTIFIER')
.appendField('.')
.appendField(createNonEditableField('getCurrent'));
this.appendValueInput('CURRENT_UNIT').setCheck('CurrentUnit')
.appendField('currentUnit')
.setAlign(Blockly.ALIGN_RIGHT);
this.setColour(functionColor);
this.setTooltip('Returns the current consumed by this motor. ' +
'Not all DcMotors support this feature.');
this.getFtcJavaOutputType = function() {
return 'double';
};
}
};

Blockly.JavaScript['dcMotor_getCurrent'] = function(block) {
var identifier = block.getFieldValue('IDENTIFIER');
var currentUnit = Blockly.JavaScript.valueToCode(
block, 'CURRENT_UNIT', Blockly.JavaScript.ORDER_NONE);
var code = identifier + '.getCurrent(' + currentUnit + ')';
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
};

Blockly.FtcJava['dcMotor_getCurrent'] = function(block) {
var identifier = Blockly.FtcJava.importDeclareAssign_(block, 'IDENTIFIER', 'DcMotor');
var currentUnit = Blockly.FtcJava.valueToCode(
block, 'CURRENT_UNIT', Blockly.FtcJava.ORDER_NONE);
// This java code will throw ClassCastException if the DcMotor is not a DcMotorEx.
Blockly.FtcJava.generateImport_('DcMotorEx');
var code = '((DcMotorEx) ' + identifier + ').getCurrent(' + currentUnit + ')';
return [code, Blockly.FtcJava.ORDER_FUNCTION_CALL];
};

Blockly.Blocks['dcMotor_getCurrentAlert'] = {
init: function() {
this.setOutput(true, 'Number');
this.appendDummyInput()
.appendField('call')
.appendField(createDcMotorExDropdown(), 'IDENTIFIER')
.appendField('.')
.appendField(createNonEditableField('getCurrentAlert'));
this.appendValueInput('CURRENT_UNIT').setCheck('CurrentUnit')
.appendField('currentUnit')
.setAlign(Blockly.ALIGN_RIGHT);
this.setColour(functionColor);
this.setTooltip('Returns the current alert for this motor. ' +
'Not all DcMotors support this feature.');
this.getFtcJavaOutputType = function() {
return 'double';
};
}
};

Blockly.JavaScript['dcMotor_getCurrentAlert'] = function(block) {
var identifier = block.getFieldValue('IDENTIFIER');
var currentUnit = Blockly.JavaScript.valueToCode(
block, 'CURRENT_UNIT', Blockly.JavaScript.ORDER_NONE);
var code = identifier + '.getCurrentAlert(' + currentUnit + ')';
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
};

Blockly.FtcJava['dcMotor_getCurrentAlert'] = function(block) {
var identifier = Blockly.FtcJava.importDeclareAssign_(block, 'IDENTIFIER', 'DcMotor');
var currentUnit = Blockly.FtcJava.valueToCode(
block, 'CURRENT_UNIT', Blockly.FtcJava.ORDER_NONE);
// This java code will throw ClassCastException if the DcMotor is not a DcMotorEx.
Blockly.FtcJava.generateImport_('DcMotorEx');
var code = '((DcMotorEx) ' + identifier + ').getCurrentAlert(' + currentUnit + ')';
return [code, Blockly.FtcJava.ORDER_FUNCTION_CALL];
};

Blockly.Blocks['dcMotor_setCurrentAlert'] = {
init: function() {
this.appendDummyInput()
.appendField('call')
.appendField(createDcMotorExDropdown(), 'IDENTIFIER')
.appendField('.')
.appendField(createNonEditableField('setCurrentAlert'));
this.appendValueInput('CURRENT').setCheck('Number')
.appendField('current')
.setAlign(Blockly.ALIGN_RIGHT);
this.appendValueInput('CURRENT_UNIT').setCheck('CurrentUnit')
.appendField('currentUnit')
.setAlign(Blockly.ALIGN_RIGHT);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setColour(functionColor);
this.setTooltip('Sets the current alert for this motor. ' +
'Not all DcMotors support this feature.');
this.getFtcJavaInputType = function(inputName) {
switch (inputName) {
case 'CURRENT':
return 'double';
}
return '';
};
}
};

Blockly.JavaScript['dcMotor_setCurrentAlert'] = function(block) {
var identifier = block.getFieldValue('IDENTIFIER');
var current = Blockly.JavaScript.valueToCode(
block, 'CURRENT', Blockly.JavaScript.ORDER_COMMA);
var currentUnit = Blockly.JavaScript.valueToCode(
block, 'CURRENT_UNIT', Blockly.JavaScript.ORDER_COMMA);
return identifier + '.setCurrentAlert(' + current + ', ' + currentUnit + ');\n';
};

Blockly.FtcJava['dcMotor_setCurrentAlert'] = function(block) {
var identifier = Blockly.FtcJava.importDeclareAssign_(block, 'IDENTIFIER', 'DcMotor');
var current = Blockly.FtcJava.valueToCode(
block, 'CURRENT', Blockly.FtcJava.ORDER_COMMA);
var currentUnit = Blockly.FtcJava.valueToCode(
block, 'CURRENT_UNIT', Blockly.FtcJava.ORDER_COMMA);
// This java code will throw ClassCastException if the DcMotor is not a DcMotorEx.
Blockly.FtcJava.generateImport_('DcMotorEx');
return '((DcMotorEx) ' + identifier + ').setCurrentAlert(' + current + ', ' + currentUnit + ');\n';
};

Blockly.Blocks['dcMotor_isOverCurrent'] = {
init: function() {
this.setOutput(true, 'Boolean');
this.appendDummyInput()
.appendField('call')
.appendField(createDcMotorExDropdown(), 'IDENTIFIER')
.appendField('.')
.appendField(createNonEditableField('isOverCurrent'));
this.setColour(functionColor);
this.setTooltip('Returns true if the current consumption of this motor exceeds the alert threshold. ' +
'Not all DcMotors support this feature.');
}
};

Blockly.JavaScript['dcMotor_isOverCurrent'] = function(block) {
var identifier = block.getFieldValue('IDENTIFIER');
var code = identifier + '.isOverCurrent()';
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
};

Blockly.FtcJava['dcMotor_isOverCurrent'] = function(block) {
var identifier = Blockly.FtcJava.importDeclareAssign_(block, 'IDENTIFIER', 'DcMotor');
// This java code will throw ClassCastException if the DcMotor is not a DcMotorEx.
Blockly.FtcJava.generateImport_('DcMotorEx');
var code = '((DcMotorEx) ' + identifier + ').isOverCurrent()';
return [code, Blockly.FtcJava.ORDER_FUNCTION_CALL];
};
Loading

0 comments on commit a8b07bb

Please sign in to comment.