Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/blocks/mrc_display_add_data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @license
* Copyright 2025 Porpoiseful LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview A block that lets you add data to the driver station display.
* @author alan@porpoiseful.com (Alan Smith)
*/

/* NOTE: This will likely go away when we can parse the driver station display class
* but it doesn't exist yet, so this is a placeholder.
*/

import * as Blockly from 'blockly/core';
import { Order, PythonGenerator } from 'blockly/python';
import { MRC_STYLE_DRIVER_STATION } from '../themes/styles';


export const BLOCK_NAME = 'mrc_display_add_data';

export const setup = function() {
Blockly.Blocks[BLOCK_NAME] = {
init: function() {
this.appendDummyInput()
.appendField("Display.add_data");
this.appendValueInput("CAPTION")
.setCheck("String")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg['CAPTION']);
this.appendValueInput("VALUE")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg['VALUE']);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setStyle(MRC_STYLE_DRIVER_STATION);
this.setTooltip(Blockly.Msg['DISPLAY_ADD_DATA_TOOLTIP']);
},
};
};

export const pythonFromBlock = function(
block: Blockly.Block,
generator: PythonGenerator,
) {
const caption = generator.valueToCode(block, "CAPTION", Order.NONE);
const value = generator.valueToCode(block, "VALUE", Order.NONE);
// TODO: Update this when the actual driver station display class is implemented
return `display.add_data(${caption}, ${value})\n`;
};
56 changes: 56 additions & 0 deletions src/blocks/mrc_gamepad_analog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license
* Copyright 2026 Porpoiseful LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview A block for interfacing with the gamepad analog (sticks)
* @author alan@porpoiseful.com (Alan Smith)
*/

/* NOTE: This will likely go away when we can parse the gamepad class
* but it doesn't exist yet, so this is a placeholder.
*/

import * as Blockly from 'blockly/core';
import { PythonGenerator } from 'blockly/python';
import { MRC_STYLE_DRIVER_STATION } from '../themes/styles';
import * as Gamepad from '../fields/field_gamepads';

export const BLOCK_NAME = 'mrc_gamepad_analog';


export const setup = function() {
Blockly.Blocks[BLOCK_NAME] = {
init: function() {
this.appendDummyInput()
.appendField(Gamepad.createTitleField())
.appendField(Gamepad.createPortField(), Gamepad.PORT_FIELD_NAME)
.appendField(Gamepad.createAnalogAxisField(), Gamepad.AXIS_FIELD_NAME);
this.setOutput(true, 'Number');
this.setStyle(MRC_STYLE_DRIVER_STATION);
},
};
};

export const pythonFromBlock = function(
block: Blockly.Block,
_: PythonGenerator,
) {
return Gamepad.methodForAxis(
block.getFieldValue(Gamepad.PORT_FIELD_NAME),
block.getFieldValue(Gamepad.AXIS_FIELD_NAME)
);
};
57 changes: 57 additions & 0 deletions src/blocks/mrc_gamepad_boolean.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @license
* Copyright 2026 Porpoiseful LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview A block for interfacing with the gamepad boolean (button)
* @author alan@porpoiseful.com (Alan Smith)
*/

/* NOTE: This will likely go away when we can parse the gamepad class
* but it doesn't exist yet, so this is a placeholder.
*/

import * as Blockly from 'blockly/core';
import { PythonGenerator } from 'blockly/python';
import { MRC_STYLE_DRIVER_STATION } from '../themes/styles';
import * as Gamepad from '../fields/field_gamepads';

export const BLOCK_NAME = 'mrc_gamepad_boolean';

export const setup = function() {
Blockly.Blocks[BLOCK_NAME] = {
init: function() {
this.appendDummyInput()
.appendField(Gamepad.createTitleField())
.appendField(Gamepad.createPortField(), Gamepad.PORT_FIELD_NAME)
.appendField(Gamepad.createButtonField(), Gamepad.BUTTON_FIELD_NAME)
this.appendDummyInput()
.appendField(Gamepad.createActionField(), Gamepad.ACTION_FIELD_NAME);
this.setOutput(true, 'Boolean');
this.setStyle(MRC_STYLE_DRIVER_STATION);
},
};
};

export const pythonFromBlock = function(
block: Blockly.Block,
_: PythonGenerator,
) {
return Gamepad.methodForButton(
block.getFieldValue(Gamepad.PORT_FIELD_NAME),
block.getFieldValue(Gamepad.BUTTON_FIELD_NAME),
block.getFieldValue(Gamepad.ACTION_FIELD_NAME));
}
62 changes: 62 additions & 0 deletions src/blocks/mrc_gamepad_boolean_event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @license
* Copyright 2026 Porpoiseful LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview A block for interfacing with the gamepad events
* @author alan@porpoiseful.com (Alan Smith)
*/

/* NOTE: This will likely go away when we can parse the gamepad class
* but it doesn't exist yet, so this is a placeholder.
*/

import * as Blockly from 'blockly/core';
import { PythonGenerator } from 'blockly/python';
import { MRC_STYLE_EVENT_HANDLER, MRC_STYLE_EVENTS } from '../themes/styles';
import * as Gamepad from '../fields/field_gamepads';

export const BLOCK_NAME = 'mrc_gamepad_boolean_event';

export const setup = function () {
Blockly.Blocks[BLOCK_NAME] = {
init: function () {
this.appendDummyInput()
.appendField(Gamepad.createEventField(), Gamepad.EVENT_FIELD_NAME);
this.appendDummyInput()
.appendField(Gamepad.createTitleField())
.appendField(Gamepad.createPortField(), Gamepad.PORT_FIELD_NAME)
.appendField(Gamepad.createButtonField(), Gamepad.BUTTON_FIELD_NAME)
this.setOutput(false);
this.setStyle(MRC_STYLE_EVENT_HANDLER);
this.appendStatementInput('STACK').appendField('');
this.setPreviousStatement(false);
this.setNextStatement(false);

this.setStyle(MRC_STYLE_EVENTS);
},
};
};

export const pythonFromBlock = function (
block: Blockly.Block,
_: PythonGenerator,
) {
// TODO: Update this when the actual driver station display class is implemented
return '# ' + block.getFieldValue(Gamepad.EVENT_FIELD_NAME) + ' for button '
+ block.getFieldValue(Gamepad.BUTTON_FIELD_NAME) + ' on gamepad '
+ block.getFieldValue(Gamepad.PORT_FIELD_NAME) + '\n';
};
10 changes: 9 additions & 1 deletion src/blocks/setup_custom_blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import * as SetPythonVariable from './mrc_set_python_variable';
import * as Steps from './mrc_steps';
import * as StepContainer from './mrc_step_container';
import * as JumpToStep from './mrc_jump_to_step';
import * as DisplayAddData from './mrc_display_add_data';
import * as GamepadBoolean from './mrc_gamepad_boolean';
import * as GamepadAnalog from './mrc_gamepad_analog';
import * as GamepadBooleanEvent from './mrc_gamepad_boolean_event';

const customBlocks = [
CallPythonFunction,
Expand All @@ -44,7 +48,11 @@ const customBlocks = [
SetPythonVariable,
Steps,
StepContainer,
JumpToStep
JumpToStep,
DisplayAddData,
GamepadBoolean,
GamepadAnalog,
GamepadBooleanEvent,
];

export const setup = function(forBlock: any) {
Expand Down
34 changes: 34 additions & 0 deletions src/blocks/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,37 @@ export function customTokens(t: (key: string) => string): typeof Blockly.Msg {
GET_ENUM_VALUE_TOOLTIP: t('BLOCKLY.TOOLTIP.GET_ENUM_VALUE'),
SET: t('BLOCKLY.SET'),
TO: t('BLOCKLY.TO'),
CAPTION: t('BLOCKLY.CAPTION'),
VALUE: t('BLOCKLY.VALUE'),
DISPLAY_ADD_DATA_TOOLTIP: t('BLOCKLY.TOOLTIP.DISPLAY_ADD_DATA'),
GAMEPAD: t('BLOCKLY.GAMEPAD.TITLE'),
GAMEPAD_BUTTON_A: t('BLOCKLY.GAMEPAD.BUTTON_A'),
GAMEPAD_BUTTON_B: t('BLOCKLY.GAMEPAD.BUTTON_B'),
GAMEPAD_BUTTON_X: t('BLOCKLY.GAMEPAD.BUTTON_X'),
GAMEPAD_BUTTON_Y: t('BLOCKLY.GAMEPAD.BUTTON_Y'),
GAMEPAD_DPAD_UP: t('BLOCKLY.GAMEPAD.DPAD_UP'),
GAMEPAD_DPAD_DOWN: t('BLOCKLY.GAMEPAD.DPAD_DOWN'),
GAMEPAD_DPAD_LEFT: t('BLOCKLY.GAMEPAD.DPAD_LEFT'),
GAMEPAD_DPAD_RIGHT: t('BLOCKLY.GAMEPAD.DPAD_RIGHT'),
GAMEPAD_LEFT_BUMPER: t('BLOCKLY.GAMEPAD.LEFT_BUMPER'),
GAMEPAD_RIGHT_BUMPER: t('BLOCKLY.GAMEPAD.RIGHT_BUMPER'),
GAMEPAD_BACK: t('BLOCKLY.GAMEPAD.BACK'),
GAMEPAD_START: t('BLOCKLY.GAMEPAD.START'),
GAMEPAD_GUIDE: t('BLOCKLY.GAMEPAD.GUIDE'),
GAMEPAD_LEFT_STICK_BUTTON: t('BLOCKLY.GAMEPAD.LEFT_STICK_BUTTON'),
GAMEPAD_RIGHT_STICK_BUTTON: t('BLOCKLY.GAMEPAD.RIGHT_STICK_BUTTON'),
GAMEPAD_LEFT_STICK_X: t('BLOCKLY.GAMEPAD.LEFT_STICK_X'),
GAMEPAD_LEFT_STICK_Y: t('BLOCKLY.GAMEPAD.LEFT_STICK_Y'),
GAMEPAD_RIGHT_STICK_X: t('BLOCKLY.GAMEPAD.RIGHT_STICK_X'),
GAMEPAD_RIGHT_STICK_Y: t('BLOCKLY.GAMEPAD.RIGHT_STICK_Y'),
GAMEPAD_LEFT_TRIGGER: t('BLOCKLY.GAMEPAD.LEFT_TRIGGER'),
GAMEPAD_RIGHT_TRIGGER: t('BLOCKLY.GAMEPAD.RIGHT_TRIGGER'),
GAMEPAD_IS_DOWN: t('BLOCKLY.GAMEPAD.IS_DOWN'),
GAMEPAD_PRESSED: t('BLOCKLY.GAMEPAD.PRESSED'),
GAMEPAD_RELEASED: t('BLOCKLY.GAMEPAD.RELEASED'),
GAMEPAD_EVENT_PRESSED: t('BLOCKLY.GAMEPAD.EVENT_PRESSED'),
GAMEPAD_EVENT_RELEASED: t('BLOCKLY.GAMEPAD.EVENT_RELEASED'),
GAMEPAD_EVENT_CHANGED: t('BLOCKLY.GAMEPAD.EVENT_CHANGED'),
SET_MODULE_VARIABLE_TOOLTIP: t('BLOCKLY.TOOLTIP.SET_MODULE_VARIABLE'),
SET_CLASS_VARIABLE_TOOLTIP: t('BLOCKLY.TOOLTIP.SET_CLASS_VARIABLE'),
SET_INSTANCE_VARIABLE_TOOLTIP: t('BLOCKLY.TOOLTIP.SET_INSTANCE_VARIABLE'),
Expand Down Expand Up @@ -135,6 +166,9 @@ export function customTokens(t: (key: string) => string): typeof Blockly.Msg {
MRC_CATEGORY_ADD_MECHANISM: t('BLOCKLY.CATEGORY.ADD_MECHANISM'),
MRC_CATEGORY_ADD_COMPONENT: t('BLOCKLY.CATEGORY.ADD_COMPONENT'),
MRC_CATEGORY_TEST: t('BLOCKLY.CATEGORY.TEST'),
MRC_CATEGORY_DRIVER_STATION: t('BLOCKLY.CATEGORY.DRIVER_STATION'),
MRC_CATEGORY_DRIVER_STATION_DISPLAY: t('BLOCKLY.CATEGORY.DRIVER_STATION_DISPLAY'),
MRC_CATEGORY_DRIVER_STATION_GAMEPADS: t('BLOCKLY.CATEGORY.DRIVER_STATION_GAMEPADS'),
MRC_PRINT: t('BLOCKLY.PRINT'),
CUSTOM_EVENTS_LABEL: t('BLOCKLY.CUSTOM_EVENTS_LABEL'),
CUSTOM_METHODS_LABEL: t('BLOCKLY.CUSTOM_METHODS_LABEL'),
Expand Down
Loading