diff --git a/editor/patch.ts b/editor/patch.ts
index a07f1279cf9..f684a824515 100644
--- a/editor/patch.ts
+++ b/editor/patch.ts
@@ -1,47 +1,96 @@
-/**
- *
- FALSE
- FALSE
- FALSE
- FALSE
- FALSE
- FALSE
- FALSE
- FALSE
- TRUE
- FALSE
- FALSE
- FALSE
- FALSE
- FALSE
- FALSE
- FALSE
- TRUE
- FALSE
- FALSE
- FALSE
- FALSE
- FALSE
- FALSE
- FALSE
- FALSE
-
-
- to
-
- `
- # # # # #
- . . . . #
- . . . . .
- . . . . #
- . . . . #
- `
-
-
- */
-
export function patchBlocks(pkgTargetVersion: string, dom: Element) {
+ if (pxt.semver.majorCmp(pkgTargetVersion || "0.0.0", "7.0.13") <= 0) {
+ // Variable pin param
+ /*
+
+ DigitalPin.P0
+
+
+ converts to
+
+
+
+
+ DigitalPin.P0
+
+
+
+ */
+ pxt.U.toArray(dom.querySelectorAll("block[type=device_get_digital_pin]"))
+ .concat(pxt.U.toArray(dom.querySelectorAll("shadow[type=device_get_digital_pin]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=device_set_digital_pin]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=device_get_analog_pin]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("shadow[type=device_get_analog_pin]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=device_set_analog_pin]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=device_set_analog_period]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=pins_on_pulsed]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=pins_pulse_in]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("shadow[type=pins_pulse_in]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=device_set_servo_pin]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=device_set_servo_pulse]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=device_analog_set_pitch_pin]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=device_set_pull]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=device_set_pin_events]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=pin_neopixel_matrix_width]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=spi_pins]")))
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=pin_set_audio_pin]")))
+ .forEach(node => {
+ const blockType = node.getAttribute("type");
+ pxt.U.toArray(node.children)
+ .filter(oldPinNode => {
+ if (oldPinNode.tagName != "field") return false;
+ switch (blockType) {
+ case "device_get_digital_pin":
+ case "device_set_digital_pin":
+ case "device_get_analog_pin":
+ case "device_set_analog_pin":
+ case "pins_pulse_in":
+ case "device_set_servo_pin":
+ case "device_analog_set_pitch_pin":
+ case "pin_set_audio_pin":
+ return oldPinNode.getAttribute("name") === "name";
+ case "device_set_analog_period":
+ case "pins_on_pulsed":
+ case "device_set_pull":
+ case "device_set_pin_events":
+ case "pin_neopixel_matrix_width":
+ return oldPinNode.getAttribute("name") === "pin";
+ case "device_set_servo_pulse":
+ return oldPinNode.getAttribute("name") === "value";
+ case "spi_pins":
+ return ["mosi", "miso", "sck"].includes(oldPinNode.getAttribute("name"));
+ }
+ return false;
+ })
+ .forEach(oldPinNode => {
+ const valueNode = node.ownerDocument.createElement("value");
+ valueNode.setAttribute("name", oldPinNode.getAttribute("name"));
+
+ const pinShadowNode = node.ownerDocument.createElement("shadow");
+ let pinBlockType;
+ switch (oldPinNode.textContent.split(".")[0]) {
+ case "DigitalPin":
+ pinBlockType = "digital_pin";
+ break;
+ case "AnalogPin":
+ pinBlockType = "analog_pin";
+ break;
+ }
+ if (!pinBlockType) return;
+ pinShadowNode.setAttribute("type", pinBlockType);
+
+ const fieldNode = node.ownerDocument.createElement("field");
+ fieldNode.setAttribute("name", "pin");
+ fieldNode.textContent = oldPinNode.textContent;
+
+ pinShadowNode.appendChild(fieldNode);
+ valueNode.appendChild(pinShadowNode);
+ node.replaceChild(valueNode, oldPinNode);
+ });
+ });
+ }
+
if (pxt.semver.majorCmp(pkgTargetVersion || "0.0.0", "5.0.12") <= 0) {
// Eighth note misspelling
/*
@@ -79,64 +128,106 @@ export function patchBlocks(pkgTargetVersion: string, dom: Element) {
if (pxt.semver.majorCmp(pkgTargetVersion || "0.0.0", "1.0.0") >= 0) return;
// showleds
- const nodes = pxt.U.toArray(dom.querySelectorAll("block[type=device_show_leds]"))
+ /**
+
+ FALSE
+ FALSE
+ FALSE
+ FALSE
+ FALSE
+ FALSE
+ FALSE
+ FALSE
+ TRUE
+ FALSE
+ FALSE
+ FALSE
+ FALSE
+ FALSE
+ FALSE
+ FALSE
+ TRUE
+ FALSE
+ FALSE
+ FALSE
+ FALSE
+ FALSE
+ FALSE
+ FALSE
+ FALSE
+
+
+ converts to
+
+
+ `
+ . . . . .
+ . . . # .
+ . . . . .
+ . # . . .
+ . . . . .
+ `
+
+
+ */
+ pxt.U.toArray(dom.querySelectorAll("block[type=device_show_leds]"))
.concat(pxt.U.toArray(dom.querySelectorAll("block[type=device_build_image]")))
.concat(pxt.U.toArray(dom.querySelectorAll("shadow[type=device_build_image]")))
.concat(pxt.U.toArray(dom.querySelectorAll("block[type=device_build_big_image]")))
- .concat(pxt.U.toArray(dom.querySelectorAll("shadow[type=device_build_big_image]")));
- nodes.forEach(node => {
- // don't rewrite if already upgraded, eg. field LEDS already present
- if (pxt.U.toArray(node.children).filter(child => child.tagName == "field" && "LEDS" == child.getAttribute("name"))[0])
- return;
- // read LEDxx value and assmebly into a new field
- const leds: string[][] = [[], [], [], [], []];
- pxt.U.toArray(node.children)
- .filter(child => child.tagName == "field" && /^LED\d+$/.test(child.getAttribute("name")))
- .forEach(lednode => {
- let n = lednode.getAttribute("name");
- let col = parseInt(n[3]);
- let row = parseInt(n[4]);
- leds[row][col] = lednode.innerHTML == "TRUE" ? "#" : ".";
- // remove node
- node.removeChild(lednode);
- });
- // add new field
- const f = node.ownerDocument.createElement("field");
- f.setAttribute("name", "LEDS");
- const s = '`\n' + leds.map(row => row.join('')).join('\n') + '\n`';
- f.appendChild(node.ownerDocument.createTextNode(s));
- node.insertBefore(f, null);
- });
+ .concat(pxt.U.toArray(dom.querySelectorAll("shadow[type=device_build_big_image]")))
+ .forEach(node => {
+ // don't rewrite if already upgraded, eg. field LEDS already present
+ if (pxt.U.toArray(node.children).filter(child => child.tagName == "field" && "LEDS" == child.getAttribute("name"))[0])
+ return;
+ // read LEDxx value and assmebly into a new field
+ const leds: string[][] = [[], [], [], [], []];
+ pxt.U.toArray(node.children)
+ .filter(child => child.tagName == "field" && /^LED\d+$/.test(child.getAttribute("name")))
+ .forEach(lednode => {
+ let n = lednode.getAttribute("name");
+ let col = parseInt(n[3]);
+ let row = parseInt(n[4]);
+ leds[row][col] = lednode.innerHTML == "TRUE" ? "#" : ".";
+ // remove node
+ node.removeChild(lednode);
+ });
+ // add new field
+ const f = node.ownerDocument.createElement("field");
+ f.setAttribute("name", "LEDS");
+ const s = '`\n' + leds.map(row => row.join('')).join('\n') + '\n`';
+ f.appendChild(node.ownerDocument.createTextNode(s));
+ node.insertBefore(f, null);
+ });
// radio
/*
-
-
-receivedNumber
-
-
-
-name
-value
-
-
-
-receivedString
-
-
-converts to
-
-
-receivedNumber
-
-
-name
-value
-
-
-receivedString
-
-*/
+
+
+ receivedNumber
+
+
+
+ name
+ value
+
+
+
+ receivedString
+
+
+ converts to
+
+
+ receivedNumber
+
+
+ name
+ value
+
+
+ receivedString
+
+ */
const varids: pxt.Map = {};
function addField(node: Element, renameMap: pxt.Map, name: string) {
diff --git a/libs/core/blocks-test/pins.blocks b/libs/core/blocks-test/pins.blocks
index 294ec6edfd8..3f435c70a72 100755
--- a/libs/core/blocks-test/pins.blocks
+++ b/libs/core/blocks-test/pins.blocks
@@ -1,17 +1,17 @@
-
+
DigitalPin.P5
-
+
PulseValue.Low
-
+
AnalogPin.P9
-
+
@@ -21,9 +21,9 @@
-
+
AnalogPin.P10
-
+
@@ -33,9 +33,9 @@
-
+
DigitalPin.P6
-
+
@@ -45,9 +45,9 @@
-
+
AnalogPin.P13
-
+
@@ -57,9 +57,9 @@
-
+
AnalogPin.P8
-
+
@@ -90,9 +90,9 @@
-
+
DigitalPin.P9
-
+
PulseValue.Low
@@ -131,9 +131,9 @@
-
+
DigitalPin.P9
-
+
@@ -143,9 +143,9 @@
-
+
AnalogPin.P9
-
+
@@ -157,26 +157,26 @@
-
+
DigitalPin.P11
-
+
-
+
DigitalPin.P9
-
+
-
+
DigitalPin.P10
-
+
-
+
DigitalPin.P9
-
+
PinPullMode.PullDown
@@ -194,17 +194,17 @@
-
+
DigitalPin.P8
-
+
PinEventType.Touch
-
+
AnalogPin.P9
-
+
diff --git a/libs/core/blocks-test/test.blocks b/libs/core/blocks-test/test.blocks
index d812a4350a7..881db51f2c4 100755
--- a/libs/core/blocks-test/test.blocks
+++ b/libs/core/blocks-test/test.blocks
@@ -151,9 +151,9 @@
-
+
AnalogPin.P4
-
+
@@ -162,18 +162,18 @@
-
+
AnalogPin.P13
-
+
-
+
DigitalPin.P10
-
+
@@ -182,18 +182,18 @@
-
+
DigitalPin.P15
-
+
-
+
AnalogPin.P9
-
+
@@ -239,9 +239,9 @@
-
+
AnalogPin.P20
-
+
@@ -255,9 +255,9 @@
-
+
AnalogPin.P14
-
+
@@ -539,9 +539,9 @@
-
+
DigitalPin.P10
-
+
PulseValue.Low
@@ -577,9 +577,9 @@
-
+
DigitalPin.P0
-
+
PinEventType.Touch
@@ -592,16 +592,16 @@
-
+
AnalogPin.P2
-
+
-
+
DigitalPin.P2
-
+
PinPullMode.PullDown
@@ -619,19 +619,19 @@
-
+
DigitalPin.P9
-
+
-
+
DigitalPin.P14
-
+
-
+
DigitalPin.P16
-
+