Skip to content

Commit

Permalink
reorder pins, fix pin block location, improve pin patch (#5871)
Browse files Browse the repository at this point in the history
  • Loading branch information
riknoll authored Aug 28, 2024
1 parent 9c04fe3 commit a545e39
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 45 deletions.
23 changes: 21 additions & 2 deletions editor/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
13 changes: 0 additions & 13 deletions libs/core/_locales/core-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 2 additions & 15 deletions libs/core/enums.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 2 additions & 15 deletions libs/core/pins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
2 changes: 2 additions & 0 deletions libs/core/pins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a545e39

Please sign in to comment.