diff --git a/editor/patch.ts b/editor/patch.ts index 1914c456e03..47051b2d14b 100644 --- a/editor/patch.ts +++ b/editor/patch.ts @@ -67,9 +67,12 @@ export function patchBlocks(pkgTargetVersion: string, dom: Element) { const valueNode = node.ownerDocument.createElement("value"); valueNode.setAttribute("name", oldPinNode.getAttribute("name")); + let nodeText = oldPinNode.textContent; const pinShadowNode = node.ownerDocument.createElement("shadow"); + const [enumName, pinName] = nodeText.split("."); + let pinBlockType; - switch (oldPinNode.textContent.split(".")[0]) { + switch (enumName) { case "DigitalPin": pinBlockType = "digital_pin_shadow"; break; @@ -78,11 +81,27 @@ export function patchBlocks(pkgTargetVersion: string, dom: Element) { break; } if (!pinBlockType) return; + + // If this is one of the read/write pins, narrow to the read write shadow + if (blockType === "device_get_analog_pin") { + switch (pinName) { + case "P0": + case "P1": + case "P2": + case "P3": + case "P4": + case "P10": + pinBlockType = "analog_read_write_pin_shadow"; + nodeText = `AnalogReadWritePin.${pinName}`; + break; + } + } + pinShadowNode.setAttribute("type", pinBlockType); const fieldNode = node.ownerDocument.createElement("field"); fieldNode.setAttribute("name", "pin"); - fieldNode.textContent = oldPinNode.textContent; + fieldNode.textContent = nodeText; pinShadowNode.appendChild(fieldNode); valueNode.appendChild(pinShadowNode); diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index ff3c470d4e0..68e2c7bd216 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -7,19 +7,6 @@ "AcceleratorRange.OneG|block": "1g", "AcceleratorRange.TwoG": "The accelerator measures forces up to 2 gravity", "AcceleratorRange.TwoG|block": "2g", - "AnalogPin.P11|block": "P11", - "AnalogPin.P12|block": "P12", - "AnalogPin.P13|block": "P13", - "AnalogPin.P14|block": "P14", - "AnalogPin.P15|block": "P15", - "AnalogPin.P16|block": "P16", - "AnalogPin.P19|block": "P19", - "AnalogPin.P20|block": "P20", - "AnalogPin.P5|block": "P5", - "AnalogPin.P6|block": "P6", - "AnalogPin.P7|block": "P7", - "AnalogPin.P8|block": "P8", - "AnalogPin.P9|block": "P9", "Array._pickRandom|block": "get random value from %list", "Array._popStatement|block": "remove last value from %list", "Array._removeAtStatement|block": "%list| remove value at %index", diff --git a/libs/core/enums.d.ts b/libs/core/enums.d.ts index 02e9123142f..b1cee579e99 100644 --- a/libs/core/enums.d.ts +++ b/libs/core/enums.d.ts @@ -483,46 +483,33 @@ declare namespace led { //% blockIdentity="pins._analogPin" P4 = 104, // MICROBIT_ID_IO_P4 //% blockIdentity="pins._analogPin" - P10 = 110, // MICROBIT_ID_IO_P10 - //% blockIdentity="pins._analogPin" - //% block="P5" P5 = 105, // MICROBIT_ID_IO_P5 //% blockIdentity="pins._analogPin" - //% block="P6" P6 = 106, // MICROBIT_ID_IO_P6 //% blockIdentity="pins._analogPin" - //% block="P7" P7 = 107, // MICROBIT_ID_IO_P7 //% blockIdentity="pins._analogPin" - //% block="P8" P8 = 108, // MICROBIT_ID_IO_P8 //% blockIdentity="pins._analogPin" - //% block="P9" P9 = 109, // MICROBIT_ID_IO_P9 //% blockIdentity="pins._analogPin" - //% block="P11" + P10 = 110, // MICROBIT_ID_IO_P10 + //% blockIdentity="pins._analogPin" P11 = 111, // MICROBIT_ID_IO_P11 //% blockIdentity="pins._analogPin" - //% block="P12" P12 = 112, // MICROBIT_ID_IO_P12 //% blockIdentity="pins._analogPin" - //% block="P13" P13 = 113, // MICROBIT_ID_IO_P13 //% blockIdentity="pins._analogPin" - //% block="P14" P14 = 114, // MICROBIT_ID_IO_P14 //% blockIdentity="pins._analogPin" - //% block="P15" P15 = 115, // MICROBIT_ID_IO_P15 //% blockIdentity="pins._analogPin" - //% block="P16" P16 = 116, // MICROBIT_ID_IO_P16 //% blockIdentity="pins._analogPin" - //% block="P19" //% blockHidden=1 P19 = 119, // MICROBIT_ID_IO_P19 //% blockIdentity="pins._analogPin" - //% block="P20" //% blockHidden=1 P20 = 120, // MICROBIT_ID_IO_P20 } diff --git a/libs/core/pins.cpp b/libs/core/pins.cpp index eb81dc92e6c..365fb5fa410 100644 --- a/libs/core/pins.cpp +++ b/libs/core/pins.cpp @@ -64,46 +64,33 @@ enum class AnalogPin { //% blockIdentity="pins._analogPin" P4 = MICROBIT_ID_IO_P4, //% blockIdentity="pins._analogPin" - P10 = MICROBIT_ID_IO_P10, - //% blockIdentity="pins._analogPin" - //% block="P5" P5 = MICROBIT_ID_IO_P5, //% blockIdentity="pins._analogPin" - //% block="P6" P6 = MICROBIT_ID_IO_P6, //% blockIdentity="pins._analogPin" - //% block="P7" P7 = MICROBIT_ID_IO_P7, //% blockIdentity="pins._analogPin" - //% block="P8" P8 = MICROBIT_ID_IO_P8, //% blockIdentity="pins._analogPin" - //% block="P9" P9 = MICROBIT_ID_IO_P9, //% blockIdentity="pins._analogPin" - //% block="P11" + P10 = MICROBIT_ID_IO_P10, + //% blockIdentity="pins._analogPin" P11 = MICROBIT_ID_IO_P11, //% blockIdentity="pins._analogPin" - //% block="P12" P12 = MICROBIT_ID_IO_P12, //% blockIdentity="pins._analogPin" - //% block="P13" P13 = MICROBIT_ID_IO_P13, //% blockIdentity="pins._analogPin" - //% block="P14" P14 = MICROBIT_ID_IO_P14, //% blockIdentity="pins._analogPin" - //% block="P15" P15 = MICROBIT_ID_IO_P15, //% blockIdentity="pins._analogPin" - //% block="P16" P16 = MICROBIT_ID_IO_P16, //% blockIdentity="pins._analogPin" - //% block="P19" //% blockHidden=1 P19 = MICROBIT_ID_IO_P19, //% blockIdentity="pins._analogPin" - //% block="P20" //% blockHidden=1 P20 = MICROBIT_ID_IO_P20 }; diff --git a/libs/core/pins.ts b/libs/core/pins.ts index 33c32cb9cfe..00d66ffa9c1 100644 --- a/libs/core/pins.ts +++ b/libs/core/pins.ts @@ -33,6 +33,8 @@ namespace pins { //% pin.fieldEditor=pinpicker //% pin.fieldOptions.columns=4 //% pin.fieldOptions.tooltips="false" + //% group="Pins" + //% weight=16 //% blockGap=8 //% advanced=true export function _analogPin(pin: AnalogPin): number {