diff --git a/external_samples/port.py b/external_samples/port.py index ba71747d..8b463ff6 100644 --- a/external_samples/port.py +++ b/external_samples/port.py @@ -17,22 +17,27 @@ # @author alan@porpoiseful.com (Alan Smith) from abc import ABC, abstractmethod from enum import Enum -from typing import Self +from typing import Final, Self + +_BASE_COMPOUND: Final[int] = 256 class PortType(Enum): + # Ports on the SystemCore. CAN_PORT = 1 SMART_IO_PORT = 2 - SMART_MOTOR_PORT = 3 - SERVO_PORT = 4 - I2C_PORT = 5 - USB_PORT = 6 - EXPANSION_HUB_MOTOR_PORT = 7 # This is the port on the expansion hub - EXPANSION_HUB_SERVO_PORT = 8 # This is the port on the expansion hub + I2C_PORT = 3 + USB_PORT = 4 + + # Ports on other devices. + USB_HUB_PORT = 5 # A port on a usb hub. + EXPANSION_HUB_MOTOR_PORT = 6 # A motor port on an Expansion Hub. + EXPANSION_HUB_SERVO_PORT = 7 # A servo port on an Expansion Hub. + # TODO: Add the ports for MotionCore. - BASE_COMPOUND = 256 - USB_HUB = BASE_COMPOUND + 1 - EXPANSION_HUB_MOTOR = BASE_COMPOUND + 2 # This is combination expansion hub and motor - EXPANSION_HUB_SERVO = BASE_COMPOUND + 3 # This is combination expansion hub and servo + # Compound ports + USB_HUB = _BASE_COMPOUND + 1 # A compound port with USB_PORT and USB_HUB_PORT. + EXPANSION_HUB_MOTOR = _BASE_COMPOUND + 2 # A compound port with USB_PORT and EXPANSION_HUB_MOTOR_PORT. + EXPANSION_HUB_SERVO = _BASE_COMPOUND + 3 # A compound port with USB_PORT and EXPANSION_HUB_SERVO_PORT. class Port(ABC): """Abstract base class for all port types.""" @@ -58,7 +63,7 @@ def __init__(self, port_type: PortType, location: int): port_type: PortType for this port (must be a simple type) location: int location for this port """ - if port_type.value >= PortType.BASE_COMPOUND.value: + if port_type.value >= _BASE_COMPOUND: raise ValueError("Port must be of a simple type") super().__init__(port_type) self.location = location @@ -80,7 +85,7 @@ def __init__(self, port_type: PortType, port1: Port, port2: Port): port1: First Port for compound ports port2: Second Port for compound ports """ - if port_type.value < PortType.BASE_COMPOUND.value: + if port_type.value < _BASE_COMPOUND: raise ValueError("Port must be of a compound type") super().__init__(port_type) self.port1 = port1 diff --git a/external_samples/servo.py b/external_samples/servo.py deleted file mode 100644 index 242b5dd2..00000000 --- a/external_samples/servo.py +++ /dev/null @@ -1,61 +0,0 @@ -# @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 This is a sample for a servo -# @author alan@porpoiseful.com (Alan Smith) - -from typing import Self -from component import Component, PortType, InvalidPortException -from port import Port, PortType - -class Servo(Component): - def __init__(self, port : Port): - super().__init__(port, PortType.SERVO_PORT) - - def get_manufacturer(self) -> str: - return "REV Robotics" - - def get_name(self) -> str: - return "SRS Servo" - - def get_part_number(self) -> str: - return "REV-41-1097" - - def get_url(self) -> str: - return "https://www.revrobotics.com/rev-41-1097/" - - def get_version(self) -> tuple[int, int, int]: - return (1, 0, 0) - - def stop(self) -> None: - # TODO: De-energize servo port - pass - - def reset(self) -> None: - pass - - def periodic(self) -> None: - pass - - # Component specific methods - - def set_position(self, pos: float) -> None: - '''Set the servo to a position between 0 and 1''' - # sends to the hardware the position of the servo - pass - - def set_angle_degrees(self, angle: float) -> None: - '''Set the servo to an angle between 0 and 270''' - self.set_position(angle / 270.0) diff --git a/python_tools/generate_json.py b/python_tools/generate_json.py index e31cb2e6..80c75272 100644 --- a/python_tools/generate_json.py +++ b/python_tools/generate_json.py @@ -63,7 +63,6 @@ import expansion_hub_servo import port import rev_touch_sensor -import servo import smart_motor import spark_mini import sparkfun_led_stick @@ -126,7 +125,6 @@ def main(argv): expansion_hub_servo, port, rev_touch_sensor, - servo, smart_motor, spark_mini, sparkfun_led_stick, diff --git a/src/blocks/mrc_port.ts b/src/blocks/mrc_port.ts index eeb2ad0f..e48f267a 100644 --- a/src/blocks/mrc_port.ts +++ b/src/blocks/mrc_port.ts @@ -30,22 +30,40 @@ import { createFieldNumberDropdown } from '../fields/field_number_dropdown'; export const BLOCK_NAME = 'mrc_port'; export const OUTPUT_NAME = 'mrc_port'; -export type MrcPortType = { - portType: string, - portNumber: number, -}; +// PortType enum values defined in external_samples/port.py. +const PORT_TYPE_CAN_PORT = 'CAN_PORT'; +const PORT_TYPE_SMART_IO_PORT = 'SMART_IO_PORT'; +const PORT_TYPE_I2C_PORT = 'I2C_PORT'; +const PORT_TYPE_USB_PORT = 'USB_PORT'; +const PORT_TYPE_SMART_MOTOR_PORT = 'SMART_MOTOR_PORT'; +const PORT_TYPE_USB_HUB_PORT = 'USB_HUB_PORT'; +const PORT_TYPE_EXPANSION_HUB_MOTOR_PORT = 'EXPANSION_HUB_MOTOR_PORT'; +const PORT_TYPE_EXPANSION_HUB_SERVO_PORT = 'EXPANSION_HUB_SERVO_PORT'; +const PORT_TYPE_USB_HUB = 'USB_HUB'; +const PORT_TYPE_EXPANSION_HUB_MOTOR = 'EXPANSION_HUB_MOTOR'; +const PORT_TYPE_EXPANSION_HUB_SERVO = 'EXPANSION_HUB_SERVO'; + +const FIELD_PREFIX_TYPE = 'TYPE_'; +const FIELD_PREFIX_PORT_NUM = 'PORT_NUM_'; -type PortBlock = Blockly.Block & PortMixin; +const VISIBLE_PORT_LABEL_CAN = 'can'; +const VISIBLE_PORT_LABEL_SMART_IO = 'smart i/o'; +const VISIBLE_PORT_LABEL_I2C = 'i2c'; +const VISIBLE_PORT_LABEL_USB = 'usb'; +const VISIBLE_PORT_LABEL_MOTIONCORE = 'MotionCore port'; +const VISIBLE_PORT_LABEL_USB_HUB = 'usb hub'; +const VISIBLE_PORT_LABEL_MOTOR = 'motor'; +const VISIBLE_PORT_LABEL_SERVO = 'servo'; + +export type PortBlock = Blockly.Block & PortMixin; interface PortMixin extends PortMixinType { - portType_ : string, - ports_ : MrcPortType[], + mrcPortType: string, + mrcPortCount: number, } type PortMixinType = typeof PORT; type PortExtraState = { - //TODO(Alan) - Figure out how to not have this duplicated for a simple port portType: string, - ports: MrcPortType[], } const PORT = { @@ -62,8 +80,7 @@ const PORT = { */ saveExtraState: function (this: PortBlock): PortExtraState { const state: PortExtraState = { - portType: this.portType_, - ports: this.ports_ + portType: this.mrcPortType, }; return state; @@ -73,36 +90,35 @@ const PORT = { * Load the ports from the block's extra state. */ loadExtraState: function (this: PortBlock, state: PortExtraState): void { - this.portType_ = state.portType || ''; - this.ports_ = state.ports || []; - this.updateShape_(); - }, - - /** - * Update the block's shape based on the current ports. - */ - updateShape_: function (this: PortBlock): void { - // Remove all existing inputs - for (let i = this.inputList.length - 1; i >= 0; i--) { - const input = this.inputList[i]; - if (input && (input.name.startsWith('PORT_'))) { - this.removeInput(input.name, true); - } - } - - // Initialize ports if not set - if (!this.ports_) { - this.ports_ = [{ portType: '', portNumber: 0 }]; - } - - // Add inputs for each port - for (let i = 0; i < this.ports_.length; i++) { - const port = this.ports_[i]; - this.appendDummyInput('PORT_' + i) - .appendField(createFieldNonEditableText(port.portType), 'TYPE_' + i) - .appendField(createFieldDropdownForPortType(port.portType, port.portNumber), 'PORT_NUM_' + i) - .setAlign(Blockly.inputs.Align.RIGHT); + let iField = 0; + switch (state.portType) { + case PORT_TYPE_CAN_PORT: + case PORT_TYPE_SMART_IO_PORT: + case PORT_TYPE_I2C_PORT: + case PORT_TYPE_USB_PORT: + case PORT_TYPE_SMART_MOTOR_PORT: + case PORT_TYPE_USB_HUB_PORT: + case PORT_TYPE_EXPANSION_HUB_MOTOR_PORT: + case PORT_TYPE_EXPANSION_HUB_SERVO_PORT: + appendFields(this.appendDummyInput(), state.portType, iField++); + break; + case PORT_TYPE_USB_HUB: + appendFields(this.appendDummyInput(), PORT_TYPE_USB_PORT, iField++); + appendFields(this.appendDummyInput(), PORT_TYPE_USB_HUB_PORT, iField++); + break; + case PORT_TYPE_EXPANSION_HUB_MOTOR: + appendFields(this.appendDummyInput(), PORT_TYPE_USB_PORT, iField++); + appendFields(this.appendDummyInput(), PORT_TYPE_EXPANSION_HUB_MOTOR_PORT, iField++); + break; + case PORT_TYPE_EXPANSION_HUB_SERVO: + appendFields(this.appendDummyInput(), PORT_TYPE_USB_PORT, iField++); + appendFields(this.appendDummyInput(), PORT_TYPE_EXPANSION_HUB_SERVO_PORT, iField++); + break; + default: + throw new Error('Unexpected portType: ' + state.portType) } + this.mrcPortType = state.portType; + this.mrcPortCount = iField; }, } @@ -116,122 +132,129 @@ export const pythonFromBlock = function ( generator.addImport('port'); const ports: string[] = []; - - for (let i = 0; i < block.inputList.length; i++) { - const input = block.inputList[i]; - if (input.name.startsWith('PORT_')) { - const portNumField = input.fieldRow.find(field => field.name === 'PORT_NUM_' + i); - if (portNumField) { - ports.push(portNumField.getValue() as string); - } - } + for (let i = 0; i < block.mrcPortCount; i++) { + ports.push(block.getFieldValue(FIELD_PREFIX_PORT_NUM + i)); } + let code = 'port.'; - + if (ports.length === 1) { - code += `SimplePort(port_type = port.PortType.${block.portType_}, location = ${ports[0]})`; + code += `SimplePort(port_type = port.PortType.${block.mrcPortType}, location = ${ports[0]})`; } else if (ports.length === 2) { let port1Type = 'UNKNOWN'; let port2Type = 'UNKNOWN'; - switch (block.portType_) { - case 'USB_HUB': - port1Type = 'USB_PORT'; - port2Type = 'USB_PORT'; + switch (block.mrcPortType) { + case PORT_TYPE_USB_HUB: + port1Type = PORT_TYPE_USB_PORT; + port2Type = PORT_TYPE_USB_HUB_PORT; break; - case 'EXPANSION_HUB_MOTOR': - port1Type = 'USB_PORT'; - port2Type = 'EXPANSION_HUB_MOTOR_PORT'; + case PORT_TYPE_EXPANSION_HUB_MOTOR: + port1Type = PORT_TYPE_USB_PORT; + port2Type = PORT_TYPE_EXPANSION_HUB_MOTOR_PORT; break; - case 'EXPANSION_HUB_SERVO': - port1Type = 'USB_PORT'; - port2Type = 'EXPANSION_HUB_SERVO_PORT'; + case PORT_TYPE_EXPANSION_HUB_SERVO: + port1Type = PORT_TYPE_USB_PORT; + port2Type = PORT_TYPE_EXPANSION_HUB_SERVO_PORT; break; } - code += `CompoundPort(port_type = port.PortType.${block.portType_},`; - code += `\\ \n${generator.INDENT}port1 = port.SimplePort(port_type = port.PortType.${port1Type}, location = ${ports[0]}), `; - code += `\\ \n${generator.INDENT}port2 = port.SimplePort(port_type = port.PortType.${port2Type}, location = ${ports[1]}))`; + code += `CompoundPort(port_type = port.PortType.${block.mrcPortType},\n`; + code += `${generator.INDENT}port1 = port.SimplePort(port_type = port.PortType.${port1Type}, location = ${ports[0]}),\n`; + code += `${generator.INDENT}port2 = port.SimplePort(port_type = port.PortType.${port2Type}, location = ${ports[1]}))`; } - return [code, Order.ATOMIC]; + return [code, Order.FUNCTION_CALL]; +} + +function appendFields(input: Blockly.Input, portType: string, iField: number): void { + // Create the fields but don't set the field values. The field values will be + // set by blockly as the block is loaded. + input + .appendField(createFieldNonEditableText(''), FIELD_PREFIX_TYPE + iField) + .appendField(createFieldDropdownForPortNumber(portType), FIELD_PREFIX_PORT_NUM + iField) + .setAlign(Blockly.inputs.Align.RIGHT); } -function createFieldDropdownForPortType(portType: string, defaultVal: number): Blockly.Field { +function createFieldDropdownForPortNumber(portType: string): Blockly.Field { switch (portType) { - case 'can': - return createFieldNumberDropdown(0, 4, defaultVal); - case 'smartio': - return createFieldNumberDropdown(0, 5, defaultVal); - case 'MotionCore port': - return createFieldNumberDropdown(1, 6, defaultVal); - case 'i2c': - return createFieldNumberDropdown(0, 1, defaultVal); - case 'usb in': - return createFieldNumberDropdown(0, 3, defaultVal); - case 'motor': - return createFieldNumberDropdown(1, 6, defaultVal); - case 'servo': - return createFieldNumberDropdown(1, 6, defaultVal); + case PORT_TYPE_CAN_PORT: + return createFieldNumberDropdown(0, 4); + case PORT_TYPE_SMART_IO_PORT: + return createFieldNumberDropdown(0, 5); + case PORT_TYPE_I2C_PORT: + return createFieldNumberDropdown(0, 1); + case PORT_TYPE_USB_PORT: + return createFieldNumberDropdown(0, 3); + case PORT_TYPE_SMART_MOTOR_PORT: + return createFieldNumberDropdown(1, 6); + case PORT_TYPE_USB_HUB_PORT: + // TODO: How many ports are on a USB hub? Some have 2, some have 4. Should they be numbered 0..N-1 or 1..N? + return createFieldNumberDropdown(0, 3); + case PORT_TYPE_EXPANSION_HUB_MOTOR_PORT: + return createFieldNumberDropdown(0, 4); + case PORT_TYPE_EXPANSION_HUB_SERVO_PORT: + return createFieldNumberDropdown(0, 5); default: - return createFieldNumberDropdown(0, 99, defaultVal); + throw new Error('Unexpected portType: ' + portType) } } -export function createPort(portType: string) { - // Based off of the port type, create the right number and type of ports - const ports: MrcPortType[] = []; +export function createPort(portType: string): any { + // Based on the port type, specify the appropriate fields. + const fields: {[key: string]: any} = {}; + let iField = 0; switch (portType) { - case 'CAN_PORT': - ports.push({ portType: 'can', portNumber: 1 }); - break; - case 'SMART_IO_PORT': - ports.push({ portType: 'smartio', portNumber: 1 }); - break; - case 'SMART_MOTOR_PORT': - ports.push({ portType: 'MotionCore port', portNumber: 1 }); - break; - case 'SERVO_PORT': - ports.push({ portType: 'servo', portNumber: 1 }); + case PORT_TYPE_CAN_PORT: + fields[FIELD_PREFIX_TYPE + iField] = VISIBLE_PORT_LABEL_CAN; + fields[FIELD_PREFIX_PORT_NUM + iField] = '1'; break; - case 'I2C_PORT': - ports.push({ portType: 'i2c', portNumber: 1 }); + case PORT_TYPE_SMART_IO_PORT: + fields[FIELD_PREFIX_TYPE + iField] = VISIBLE_PORT_LABEL_SMART_IO; + fields[FIELD_PREFIX_PORT_NUM + iField] = '1'; break; - case 'USB_PORT': - ports.push({ portType: 'usb', portNumber: 1 }); + case PORT_TYPE_I2C_PORT: + fields[FIELD_PREFIX_TYPE + iField] = VISIBLE_PORT_LABEL_I2C; + fields[FIELD_PREFIX_PORT_NUM + iField] = '1'; break; - case 'EXPANSION_HUB_MOTOR_PORT': - ports.push({ portType: 'motor', portNumber: 1 }); + case PORT_TYPE_USB_PORT: + fields[FIELD_PREFIX_TYPE + iField] = VISIBLE_PORT_LABEL_USB; + fields[FIELD_PREFIX_PORT_NUM + iField] = '1'; break; - case 'EXPANSION_HUB_SERVO_PORT': - ports.push({ portType: 'servo', portNumber: 1 }); + case PORT_TYPE_SMART_MOTOR_PORT: + fields[FIELD_PREFIX_TYPE + iField] = VISIBLE_PORT_LABEL_MOTIONCORE; + fields[FIELD_PREFIX_PORT_NUM + iField] = '1'; break; - case 'USB_HUB': - ports.push({ portType: 'usb in', portNumber: 1 }); - ports.push({ portType: 'usb out', portNumber: 1 }); + case PORT_TYPE_USB_HUB: + fields[FIELD_PREFIX_TYPE + iField] = VISIBLE_PORT_LABEL_USB; + fields[FIELD_PREFIX_PORT_NUM + iField] = '1'; + iField++; + fields[FIELD_PREFIX_TYPE + iField] = VISIBLE_PORT_LABEL_USB_HUB; + fields[FIELD_PREFIX_PORT_NUM + iField] = '1'; break; - case 'EXPANSION_HUB_MOTOR': - ports.push({ portType: 'usb in', portNumber: 1 }); - ports.push({ portType: 'motor', portNumber: 1 }); + case PORT_TYPE_EXPANSION_HUB_MOTOR: + fields[FIELD_PREFIX_TYPE + iField] = VISIBLE_PORT_LABEL_USB; + fields[FIELD_PREFIX_PORT_NUM + iField] = '1'; + iField++; + fields[FIELD_PREFIX_TYPE + iField] = VISIBLE_PORT_LABEL_MOTOR; + fields[FIELD_PREFIX_PORT_NUM + iField] = '1'; break; - case 'EXPANSION_HUB_SERVO': - ports.push({ portType: 'usb in', portNumber: 1 }); - ports.push({ portType: 'servo', portNumber: 1 }); - break; - default: - ports.push({ portType: 'unknown' + portType, portNumber: 1 }); + case PORT_TYPE_EXPANSION_HUB_SERVO: + fields[FIELD_PREFIX_TYPE + iField] = VISIBLE_PORT_LABEL_USB; + fields[FIELD_PREFIX_PORT_NUM + iField] = '1'; + iField++; + fields[FIELD_PREFIX_TYPE + iField] = VISIBLE_PORT_LABEL_SERVO; + fields[FIELD_PREFIX_PORT_NUM + iField] = '1'; break; } + const extraState: PortExtraState = { + portType: portType, + }; return { block: { - type: 'mrc_port', - extraState: { - portType: portType, - ports: ports.map(port => ({ - portType: port.portType, - portNumber: port.portNumber - })) - }, + type: BLOCK_NAME, + extraState, + fields, }, }; } diff --git a/src/blocks/utils/generated/external_samples_data.json b/src/blocks/utils/generated/external_samples_data.json index ff1306f2..7f589f1d 100644 --- a/src/blocks/utils/generated/external_samples_data.json +++ b/src/blocks/utils/generated/external_samples_data.json @@ -1582,211 +1582,6 @@ "moduleName": "rev_touch_sensor", "staticMethods": [] }, - { - "className": "servo.Servo", - "classVariables": [], - "constructors": [ - { - "args": [ - { - "defaultValue": "", - "name": "port", - "type": "port.Port" - } - ], - "declaringClassName": "servo.Servo", - "expectedPortType": "SERVO_PORT", - "functionName": "__init__", - "returnType": "servo.Servo", - "tooltip": "" - } - ], - "enums": [], - "instanceMethods": [ - { - "args": [ - { - "defaultValue": "", - "name": "self", - "type": "servo.Servo" - } - ], - "declaringClassName": "servo.Servo", - "functionName": "get_connection_port_type", - "returnType": "port.PortType | None", - "tooltip": "" - }, - { - "args": [ - { - "defaultValue": "", - "name": "self", - "type": "servo.Servo" - } - ], - "declaringClassName": "servo.Servo", - "functionName": "get_manufacturer", - "returnType": "str", - "tooltip": "" - }, - { - "args": [ - { - "defaultValue": "", - "name": "self", - "type": "servo.Servo" - } - ], - "declaringClassName": "servo.Servo", - "functionName": "get_name", - "returnType": "str", - "tooltip": "" - }, - { - "args": [ - { - "defaultValue": "", - "name": "self", - "type": "servo.Servo" - } - ], - "declaringClassName": "servo.Servo", - "functionName": "get_part_number", - "returnType": "str", - "tooltip": "" - }, - { - "args": [ - { - "defaultValue": "", - "name": "self", - "type": "servo.Servo" - } - ], - "declaringClassName": "servo.Servo", - "functionName": "get_url", - "returnType": "str", - "tooltip": "" - }, - { - "args": [ - { - "defaultValue": "", - "name": "self", - "type": "servo.Servo" - } - ], - "declaringClassName": "servo.Servo", - "functionName": "get_version", - "returnType": "tuple[int, int, int]", - "tooltip": "" - }, - { - "args": [ - { - "defaultValue": "", - "name": "self", - "type": "servo.Servo" - } - ], - "declaringClassName": "servo.Servo", - "functionName": "periodic", - "returnType": "None", - "tooltip": "" - }, - { - "args": [ - { - "defaultValue": "", - "name": "self", - "type": "servo.Servo" - } - ], - "declaringClassName": "servo.Servo", - "functionName": "reset", - "returnType": "None", - "tooltip": "" - }, - { - "args": [ - { - "defaultValue": "", - "name": "self", - "type": "servo.Servo" - }, - { - "defaultValue": "", - "name": "angle", - "type": "float" - } - ], - "declaringClassName": "servo.Servo", - "functionName": "set_angle_degrees", - "returnType": "None", - "tooltip": "Set the servo to an angle between 0 and 270" - }, - { - "args": [ - { - "defaultValue": "", - "name": "self", - "type": "servo.Servo" - }, - { - "defaultValue": "", - "name": "pos", - "type": "float" - } - ], - "declaringClassName": "servo.Servo", - "functionName": "set_position", - "returnType": "None", - "tooltip": "Set the servo to a position between 0 and 1" - }, - { - "args": [ - { - "defaultValue": "", - "name": "self", - "type": "servo.Servo" - } - ], - "declaringClassName": "servo.Servo", - "functionName": "start", - "returnType": "None", - "tooltip": "" - }, - { - "args": [ - { - "defaultValue": "", - "name": "self", - "type": "servo.Servo" - } - ], - "declaringClassName": "servo.Servo", - "functionName": "stop", - "returnType": "None", - "tooltip": "" - }, - { - "args": [ - { - "defaultValue": "", - "name": "self", - "type": "servo.Servo" - } - ], - "declaringClassName": "servo.Servo", - "functionName": "update", - "returnType": "None", - "tooltip": "" - } - ], - "instanceVariables": [], - "moduleName": "servo", - "staticMethods": [] - }, { "className": "smart_motor.SmartMotor", "classVariables": [], @@ -2775,17 +2570,15 @@ { "enumClassName": "port.PortType", "enumValues": [ - "BASE_COMPOUND", "CAN_PORT", "EXPANSION_HUB_MOTOR", "EXPANSION_HUB_MOTOR_PORT", "EXPANSION_HUB_SERVO", "EXPANSION_HUB_SERVO_PORT", "I2C_PORT", - "SERVO_PORT", "SMART_IO_PORT", - "SMART_MOTOR_PORT", "USB_HUB", + "USB_HUB_PORT", "USB_PORT" ], "moduleName": "port", @@ -2802,12 +2595,6 @@ "moduleName": "rev_touch_sensor", "moduleVariables": [] }, - { - "enums": [], - "functions": [], - "moduleName": "servo", - "moduleVariables": [] - }, { "enums": [], "functions": [], @@ -2833,7 +2620,6 @@ "expansion_hub_motor.ExpansionHubMotor", "expansion_hub_servo.ExpansionHubServo", "rev_touch_sensor.RevTouchSensor", - "servo.Servo", "smart_motor.SmartMotor", "spark_mini.SparkMini", "sparkfun_led_stick.SparkFunLEDStick" diff --git a/src/fields/field_number_dropdown.ts b/src/fields/field_number_dropdown.ts index 1fe3bea1..8adf3562 100644 --- a/src/fields/field_number_dropdown.ts +++ b/src/fields/field_number_dropdown.ts @@ -23,12 +23,10 @@ import * as Blockly from 'blockly/core'; import { createFieldDropdown } from './FieldDropdown'; -export function createFieldNumberDropdown(min: number, max: number, defaultVal: number): Blockly.Field { +export function createFieldNumberDropdown(min: number, max: number): Blockly.Field { const items: string[] = []; for (let i = min; i <= max; i++) { items.push(i.toString()); } - const field = createFieldDropdown(items); - field.setValue(defaultVal.toString()); - return field; -} \ No newline at end of file + return createFieldDropdown(items); +}