diff --git a/editor/patch.ts b/editor/patch.ts
index f00a645c9..0edb9133f 100644
--- a/editor/patch.ts
+++ b/editor/patch.ts
@@ -1,7 +1,98 @@
export function patchBlocks(pkgTargetVersion: string, dom: Element) {
- // is this a old script?
+ if (pxt.semver.majorCmp(pkgTargetVersion || "0.0.0", "7.0.0") <= 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_shadow";
+ break;
+ case "AnalogPin":
+ pinBlockType = "analog_pin_shadow";
+ 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.0") >= 0) return;
// Motor Names mapping
@@ -28,42 +119,39 @@ export function patchBlocks(pkgTargetVersion: string, dom: Element) {
node.setAttribute('type', 'soundLevel');
});
-
-
- // is this a old script?
if (pxt.semver.majorCmp(pkgTargetVersion || "0.0.0", "4.0.20") >= 0) return;
- // button and pin pressed/released blocks
-/*
-
- Button.A
-
-
- TouchPin.P0
-
-
- TouchPin.P1
-
+ // button and pin pressed/released blocks
+ /*
+
+ Button.A
+
+
+ TouchPin.P0
+
+
+ TouchPin.P1
+
- converts to
+ converts to
-
- Button.B
-
-
- ButtonEvent.Click
-
-
-
-
- TouchPin.P2
-
-
- ButtonEvent.Up
-
-
-
-*/
-const inputNodes = pxt.U.toArray(dom.querySelectorAll("block[type=device_button_event]"))
+
+ Button.B
+
+
+ ButtonEvent.Click
+
+
+
+
+ TouchPin.P2
+
+
+ ButtonEvent.Up
+
+
+
+ */
+ const inputNodes = pxt.U.toArray(dom.querySelectorAll("block[type=device_button_event]"))
.concat(pxt.U.toArray(dom.querySelectorAll("block[type=device_pin_event]")))
.concat(pxt.U.toArray(dom.querySelectorAll("block[type=device_pin_released]")))
inputNodes.forEach(node => {
@@ -102,125 +190,81 @@ const inputNodes = pxt.U.toArray(dom.querySelectorAll("block[type=device_button_
-// loudness
- /*
-
+ // loudness
+ /*
+
- converts to
+ converts to
-
- */
- const loudnessNodes = pxt.U.toArray(dom.querySelectorAll("block[type=loudness]"))
- loudnessNodes.forEach(node => {
- node.setAttribute("type", "soundLevel");
- });
+
+ */
+ const loudnessNodes = pxt.U.toArray(dom.querySelectorAll("block[type=loudness]"))
+ loudnessNodes.forEach(node => {
+ node.setAttribute("type", "soundLevel");
+ });
- // rgbw to rgb block
- const rgbwNodes = pxt.U.toArray(dom.querySelectorAll("block[type=core_rgbw]"))
- rgbwNodes.forEach(node => {
- node.setAttribute("type", "core_rgb");
- node.querySelectorAll("value[name=white]")[0].remove();
- });
+ // rgbw to rgb block
+ const rgbwNodes = pxt.U.toArray(dom.querySelectorAll("block[type=core_rgbw]"))
+ rgbwNodes.forEach(node => {
+ node.setAttribute("type", "core_rgb");
+ node.querySelectorAll("value[name=white]")[0].remove();
+ });
- // arrow blocks
- /*
-
-
-
- ArrowNames.North
-
-
-
+ // arrow blocks
+ /*
+
+
+
+ ArrowNames.North
+
+
+
- converts to
+ converts to
-
-
- IconNames.ArrowNorth
-
- */
-const arrowNodes = pxt.U.toArray(dom.querySelectorAll("block[type=basic_show_arrow]"))
-arrowNodes.forEach(node => {
- node.setAttribute("type", "basic_show_icon");
- const arrowNode = node.querySelectorAll("value[name=i]")[0]
- const iconName = "IconNames.Arrow" + arrowNode.querySelectorAll("field[name=arrow]")[0].textContent.split('.')[1];
-
- const iconNode = node.ownerDocument.createElement("field");
- iconNode.setAttribute("name", "i")
- iconNode.textContent = iconName;
-
- const mutationNode = node.ownerDocument.createElement("mutation");
- // mutationNode.setAttribute("xmlns", "http://www.w3.org/1999/xhtml")
- mutationNode.setAttribute("_expanded", "0")
- mutationNode.setAttribute("_input_init", "false")
-
- node.prepend(iconNode)
- node.prepend(mutationNode)
- node.removeChild(arrowNode);
-});
-
- // arrow icons
- /*
-
- ArrowNames.East
-
+
+
+ IconNames.ArrowNorth
+
+ */
+ const arrowNodes = pxt.U.toArray(dom.querySelectorAll("block[type=basic_show_arrow]"))
+ arrowNodes.forEach(node => {
+ node.setAttribute("type", "basic_show_icon");
+ const arrowNode = node.querySelectorAll("value[name=i]")[0]
+ const iconName = "IconNames.Arrow" + arrowNode.querySelectorAll("field[name=arrow]")[0].textContent.split('.')[1];
+
+ const iconNode = node.ownerDocument.createElement("field");
+ iconNode.setAttribute("name", "i")
+ iconNode.textContent = iconName;
+
+ const mutationNode = node.ownerDocument.createElement("mutation");
+ // mutationNode.setAttribute("xmlns", "http://www.w3.org/1999/xhtml")
+ mutationNode.setAttribute("_expanded", "0")
+ mutationNode.setAttribute("_input_init", "false")
+
+ node.prepend(iconNode)
+ node.prepend(mutationNode)
+ node.removeChild(arrowNode);
+ });
- converts to
+ // arrow icons
+ /*
+
+ ArrowNames.East
+
-
- IconNames.ArrowEast
-
- */
-const arrowImageNodes = pxt.U.toArray(dom.querySelectorAll("block[type=builtin_arrow_image]"))
-arrowImageNodes.forEach(node => {
- node.setAttribute("type", "builtin_image");
- const arrowNode = node.querySelectorAll("field[name=i]")[0];
- arrowNode.textContent = "IconNames.Arrow" + arrowNode.textContent.split('.')[1];
-});
-
- // 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
-
-
- to
-
- `
- # # # # #
- . . . . #
- . . . . .
- . . . . #
- . . . . #
- `
-
-
- */
+ converts to
+
+ IconNames.ArrowEast
+
+ */
+ const arrowImageNodes = pxt.U.toArray(dom.querySelectorAll("block[type=builtin_arrow_image]"))
+ arrowImageNodes.forEach(node => {
+ node.setAttribute("type", "builtin_image");
+ const arrowNode = node.querySelectorAll("field[name=i]")[0];
+ arrowNode.textContent = "IconNames.Arrow" + arrowNode.textContent.split('.')[1];
+ });
if (pxt.semver.majorCmp(pkgTargetVersion || "0.0.0", "5.0.12") <= 0) {
@@ -260,6 +304,48 @@ arrowImageNodes.forEach(node => {
if (pxt.semver.majorCmp(pkgTargetVersion || "0.0.0", "1.0.0") >= 0) return;
// showleds
+ /**
+
+ 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
+
+
+ `
+ . . . . .
+ . . . # .
+ . . . . .
+ . # . . .
+ . . . . .
+ `
+
+
+ */
const nodes = 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]")))
@@ -293,33 +379,33 @@ arrowImageNodes.forEach(node => {
// 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/fieldeditors/extensions.ts b/fieldeditors/extensions.ts
index 225b7ea8c..c7e4aae1b 100644
--- a/fieldeditors/extensions.ts
+++ b/fieldeditors/extensions.ts
@@ -2,14 +2,21 @@
///
import { FieldGestures } from "./field_gestures";
+import { FieldPinPicker } from "./field_pinPicker";
pxt.editor.initFieldExtensionsAsync = function (opts: pxt.editor.FieldExtensionOptions): Promise {
pxt.debug('loading pxt-microbit field editors...')
const res: pxt.editor.FieldExtensionResult = {
- fieldEditors: [{
- selector: "gestures",
- editor: FieldGestures
- }]
+ fieldEditors: [
+ {
+ selector: "gestures",
+ editor: FieldGestures
+ },
+ {
+ selector: "pinpicker",
+ editor: FieldPinPicker
+ }
+ ]
};
return Promise.resolve(res);
}
\ No newline at end of file
diff --git a/fieldeditors/field_pinPicker.ts b/fieldeditors/field_pinPicker.ts
new file mode 100644
index 000000000..965200a23
--- /dev/null
+++ b/fieldeditors/field_pinPicker.ts
@@ -0,0 +1,93 @@
+///
+
+const pxtblockly = pxt.blocks.requirePxtBlockly()
+const Blockly = pxt.blocks.requireBlockly();
+
+const WARNING_ID = "pinpicker_warning";
+
+export class FieldPinPicker extends pxtblockly.FieldGridPicker {
+ protected warningVisible: boolean;
+
+ override init() {
+ super.init();
+
+ const sourceBlock = this.sourceBlock_;
+ if (sourceBlock.isShadow() || sourceBlock.isInFlyout) {
+ return;
+ }
+
+ sourceBlock.workspace.addChangeListener(this.changeListener);
+ }
+
+ private changeListener = (e: any) => {
+ if (e.type === Blockly.Events.BLOCK_MOVE && e.blockId === this.sourceBlock_.id) {
+ this.updateWarning();
+ }
+ }
+
+ protected override doValueUpdate_(newValue: string): void {
+ super.doValueUpdate_(newValue);
+ this.updateWarning();
+ }
+
+ protected updateWarning() {
+ this.hideWarning();
+ const sourceBlock = this.sourceBlock_;
+
+ if (!sourceBlock || !this.value_ || sourceBlock.isShadow() || sourceBlock.isInFlyout) {
+ return;
+ }
+
+ const pin = this.value_.split(".")[1];
+
+ if (!isAnalogWriteOnlyPin(pin)) {
+ return;
+ }
+
+ const parent = sourceBlock.outputConnection.targetBlock();
+
+ if (!parent || parent.type !== "device_get_analog_pin") {
+ return;
+ }
+
+ this.showWarning(pin);
+ }
+
+ protected showWarning(pin: string) {
+ if (!this.sourceBlock_) {
+ return;
+ }
+ this.sourceBlock_.setWarningText(pxt.U.lf("{0} is a write only analog pin", pin), WARNING_ID);
+ }
+
+ protected hideWarning() {
+ if (!this.sourceBlock_) {
+ return;
+ }
+ this.sourceBlock_.setWarningText(null, WARNING_ID)
+ }
+
+ override dispose(): void {
+ super.dispose();
+ this.sourceBlock_?.workspace?.removeChangeListener(this.changeListener);
+ }
+}
+
+function isAnalogWriteOnlyPin(pin: string) {
+ switch (pin) {
+ case "P5":
+ case "P6":
+ case "P7":
+ case "P8":
+ case "P9":
+ case "P11":
+ case "P12":
+ case "P13":
+ case "P14":
+ case "P15":
+ case "P16":
+ return true;
+ default:
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/libs/core/blocks-test/pins.blocks b/libs/core/blocks-test/pins.blocks
index 73477ff68..9025d9d25 100755
--- a/libs/core/blocks-test/pins.blocks
+++ b/libs/core/blocks-test/pins.blocks
@@ -1,19 +1,41 @@
-
-
-
-
- PulseValue.Low
-
-
- DigitalPin.P5
-
+
+
+
+
+ DigitalPin.P5
+
+
+ PulseValue.Low
+
+
+
+
+ AnalogPin.P9
+
+
+
+
+ 5
+
-
-
+
+
+
+
+ AnalogPin.P10
+
+
+
+
+ 20000
+
+
+
+
-
- AnalogPin.P9
-
+
+ DigitalPin.P6
+
@@ -21,35 +43,142 @@
-
-
-
- AnalogPin.P10
-
+
+
+
+ AnalogPin.P13
+
+
+
+
+ 5
+
+
+
+
+
+
+ AnalogPin.P8
+
-
- 20000
-
+
+ 1500
+
+
+
+
+ 0
+
+
+ NumberFormat.Int8BE
+
+
+ 0
+
+
+
+
+ FALSE
+
+
+
+
+
+
+ 0
+
+
+
+
+ DigitalPin.P9
+
+
+ PulseValue.Low
+
+
+
+
+ 1023
+
+
+
+
+
+ 0
+
+
+
+
+ 0
+
+
+
+
+
+
+ 4
+
+
+
-
- DigitalPin.P6
-
+
+ DigitalPin.P9
+
-
-
- 5
-
+
+
+
+
+ 0
+
+
+
+
+ AnalogPin.P9
+
+
+
+
+
+
+ FALSE
+
+
+
+
+
+
+ DigitalPin.P11
+
+
+
+
+ DigitalPin.P9
+
+
+
+
+ DigitalPin.P10
+
-
-
-
- AnalogPin.P13
-
+
+
+
+ DigitalPin.P9
+
+
+ PinPullMode.PullDown
+
+
+
+
+ 0
+
@@ -57,11 +186,19 @@
-
-
-
- AnalogPin.P8
-
+
+
+
+ DigitalPin.P8
+
+
+ PinEventType.Touch
+
+
+
+
+ AnalogPin.P9
+
diff --git a/libs/core/enums.d.ts b/libs/core/enums.d.ts
index 54521799d..3763a03ab 100644
--- a/libs/core/enums.d.ts
+++ b/libs/core/enums.d.ts
@@ -440,13 +440,13 @@ declare namespace input {
declare const enum DigitalPin {
- //% blockIdentity="pins.digitalPin"
+ //% blockIdentity="pins._digitalPin"
P0 = 100, // MICROBIT_ID_IO_P0
- //% blockIdentity="pins.digitalPin"
+ //% blockIdentity="pins._digitalPin"
P1 = 101, // MICROBIT_ID_IO_P1
- //% blockIdentity="pins.digitalPin"
+ //% blockIdentity="pins._digitalPin"
P2 = 102, // MICROBIT_ID_IO_P2
- //% blockIdentity="pins.digitalPin"
+ //% blockIdentity="pins._digitalPin"
P3 = 103, // MICROBIT_ID_IO_P3
//% blockIdentity="pins.digitalPin"
C4 = 104, // MICROBIT_ID_IO_P4
@@ -559,11 +559,11 @@ declare namespace input {
declare const enum AnalogPin {
- //% blockIdentity="pins.analogPin"
+ //% blockIdentity="pins._analogPin"
P0 = 100, // MICROBIT_ID_IO_P0
- //% blockIdentity="pins.analogPin"
+ //% blockIdentity="pins._analogPin"
P1 = 101, // MICROBIT_ID_IO_P1
- //% blockIdentity="pins.analogPin"
+ //% blockIdentity="pins._analogPin"
P2 = 102, // MICROBIT_ID_IO_P2
//% blockIdentity="pins.analogPin"
//% block="P3 (write only)"
diff --git a/libs/core/pins.cpp b/libs/core/pins.cpp
index 9e040177a..c6b7a3e31 100644
--- a/libs/core/pins.cpp
+++ b/libs/core/pins.cpp
@@ -356,7 +356,7 @@ namespace pins {
*/
//% help=pins/digital-read-pin weight=30
//% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8
- //% name.shadow=digital_pin
+ //% name.shadow=digital_pin_shadow
int digitalReadPin(int name) {
PINREAD(getDigitalValue());
}
@@ -369,7 +369,7 @@ namespace pins {
//% help=pins/digital-write-pin weight=29
//% blockId=device_set_digital_pin block="digital write|pin %name|to %value"
//% value.min=0 value.max=1
- //% name.shadow=digital_pin
+ //% name.shadow=digital_pin_shadow
void digitalWritePin(int name, int value) {
PINOP(setDigitalValue(value));
}
@@ -380,7 +380,7 @@ namespace pins {
*/
//% help=pins/analog-read-pin weight=25
//% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8"
- //% name.shadow=analog_pin
+ //% name.shadow=analog_read_write_pin_shadow
int analogReadPin(int name) {
PINREAD(getAnalogValue());
}
@@ -393,7 +393,7 @@ namespace pins {
//% help=pins/analog-write-pin weight=24
//% blockId=device_set_analog_pin block="analog write|pin %name|to %value" blockGap=8
//% value.min=0 value.max=1023
- //% name.shadow=analog_pin
+ //% name.shadow=analog_pin_shadow
void analogWritePin(int name, int value) {
PINOP(setAnalogValue(value));
}
@@ -406,7 +406,7 @@ namespace pins {
*/
//% help=pins/analog-set-period weight=23 blockGap=8
//% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros"
- //% pin.shadow=analog_pin
+ //% pin.shadow=analog_pin_shadow
void analogSetPeriod(int name, int micros) {
PINOP(setAnalogPeriodUs(micros));
}
@@ -418,7 +418,7 @@ namespace pins {
*/
//% help=pins/on-pulsed weight=22 blockGap=16 advanced=true
//% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse"
- //% pin.shadow=digital_pin
+ //% pin.shadow=digital_pin_shadow
//% group="Pulse"
//% weight=25
//% blockGap=8
@@ -450,7 +450,7 @@ namespace pins {
//% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value"
//% weight=20 advanced=true
//% help=pins/pulse-in
- //% name.shadow=digital_pin
+ //% name.shadow=digital_pin_shadow
//% group="Pulse"
//% weight=23
//% blockGap=8
@@ -510,7 +510,7 @@ namespace pins {
//% blockId=device_set_servo_pin block="servo write|pin %name|to %value" blockGap=8
//% parts=microservo trackArgs=0
//% value.min=0 value.max=180
- //% name.shadow=analog_pin
+ //% name.shadow=analog_pin_shadow
//% group="Servo"
void servoWritePin(int name, int value) {
PINOP(setServoValue(value));
@@ -531,7 +531,7 @@ namespace pins {
*/
//% help=pins/servo-set-pulse weight=19
//% blockId=device_set_servo_pulse block="servo set pulse|pin %value|to (µs) %micros"
- //% value.shadow=analog_pin
+ //% value.shadow=analog_pin_shadow
//% group="Servo"
void servoSetPulse(int name, int micros) {
PINOP(setServoPulseUs(micros));
@@ -550,7 +550,7 @@ namespace pins {
*/
//% blockId=device_analog_set_pitch_pin block="analog set pitch pin %name"
//% help=pins/analog-set-pitch-pin advanced=true
- //% name.shadow=analog_pin
+ //% name.shadow=analog_pin_shadow
//% group="Pins"
//% weight=12
//% blockGap=8
@@ -657,7 +657,7 @@ namespace pins {
*/
//% help=pins/set-pull weight=3 advanced=true
//% blockId=device_set_pull block="set pull|pin %pin|to %pull"
- //% pin.shadow=digital_pin
+ //% pin.shadow=digital_pin_shadow
//% group="Pins"
//% weight=15
//% blockGap=8
@@ -685,7 +685,7 @@ namespace pins {
*/
//% help=pins/set-events weight=4 advanced=true
//% blockId=device_set_pin_events block="set pin %pin|to emit %type|events"
- //% pin.shadow=digital_pin
+ //% pin.shadow=digital_pin_shadow
//% group="Pins"
//% weight=13
//% blockGap=8
@@ -712,7 +712,7 @@ namespace pins {
*/
//% help=pins/neopixel-matrix-width advanced=true
//% blockId=pin_neopixel_matrix_width block="neopixel matrix width|pin %pin %width"
- //% pin.shadow=digital_pin
+ //% pin.shadow=digital_pin_shadow
//% width.defl=5 width.min=2
//% group="Pins"
//% weight=11
@@ -828,9 +828,9 @@ namespace pins {
*/
//% help=pins/spi-pins weight=2 advanced=true
//% blockId=spi_pins block="spi set pins|MOSI %mosi|MISO %miso|SCK %sck"
- //% mosi.shadow=digital_pin
- //% miso.shadow=digital_pin
- //% sck.shadow=digital_pin
+ //% mosi.shadow=digital_pin_shadow
+ //% miso.shadow=digital_pin_shadow
+ //% sck.shadow=digital_pin_shadow
//% group="SPI"
//% blockGap=8
//% weight=51
@@ -856,7 +856,7 @@ namespace pins {
*/
//% blockId=pin_set_audio_pin block="set audio pin $name"
//% help=pins/set-audio-pin
- //% name.shadow=digital_pin
+ //% name.shadow=digital_pin_shadow
//% weight=1
//% blockGap=8
void setAudioPin(int name) {
diff --git a/libs/core/pins.ts b/libs/core/pins.ts
index ad9fabfea..b02490574 100644
--- a/libs/core/pins.ts
+++ b/libs/core/pins.ts
@@ -9,26 +9,79 @@ namespace pins {
/**
* Returns the value of a C++ runtime constant
*/
- //% help=pins/digital-pin blockGap=8 advanced=true shim=TD_ID
- //% blockId="digital_pin" block="digital pin %pin"
- //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
+ //% help=pins/digital-pin
+ //% shim=TD_ID
+ //% blockId=digital_pin
+ //% block="digital pin $pin"
+ //% pin.fieldEditor=pinpicker
+ //% pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false"
//% group="Pins"
//% weight=17
- export function digitalPin(pin: DigitalPin): number {
+ //% blockGap=8
+ //% advanced=true
+ export function _digitalPin(pin: DigitalPin): number {
return pin;
}
/**
* Returns the value of a C++ runtime constant
*/
- //% help=pins/analog-pin blockGap=8 advanced=true shim=TD_ID
- //% blockId="analog_pin" block="analog pin %pin"
- //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
+ //% help=pins/analog-pin
+ //% shim=TD_ID
+ //% blockId=analog_pin
+ //% block="analog pin $pin"
+ //% pin.fieldEditor=pinpicker
+ //% pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false"
- //% group="Pins"
- //% weight=16
- export function analogPin(pin: AnalogPin): number {
+ //% blockGap=8
+ //% advanced=true
+ export function _analogPin(pin: AnalogPin): number {
+ return pin;
+ }
+
+ /**
+ * Returns the value of a C++ runtime constant
+ */
+ //% help=pins/digital-pin
+ //% shim=TD_ID
+ //% blockId=digital_pin_shadow
+ //% block="$pin"
+ //% pin.fieldEditor=pinpicker
+ //% pin.fieldOptions.columns=4
+ //% pin.fieldOptions.tooltips="false"
+ //% blockHidden=1
+ export function _digitalPinShadow(pin: DigitalPin): number {
+ return pin;
+ }
+
+ /**
+ * Returns the value of a C++ runtime constant
+ */
+ //% help=pins/analog-pin
+ //% shim=TD_ID
+ //% blockId=analog_pin_shadow
+ //% block="$pin"
+ //% pin.fieldEditor=pinpicker
+ //% pin.fieldOptions.columns=4
+ //% pin.fieldOptions.tooltips="false"
+ //% blockHidden=1
+ export function _analogPinShadow(pin: AnalogPin): number {
+ return pin;
+ }
+
+ /**
+ * Returns the value of a C++ runtime constant
+ */
+ //% help=pins/analog-pin
+ //% shim=TD_ID
+ //% blockId=analog_read_write_pin_shadow
+ //% block="$pin"
+ //% pin.fieldEditor=pinpicker
+ //% pin.fieldOptions.columns=4
+ //% pin.fieldOptions.tooltips="false"
+ //% blockHidden=1
+ export function _analogReadWritePinShadow(pin: AnalogReadWritePin): number {
return pin;
}
diff --git a/libs/core/pinscompat.ts b/libs/core/pinscompat.ts
index 1f3aa186a..bff350b05 100644
--- a/libs/core/pinscompat.ts
+++ b/libs/core/pinscompat.ts
@@ -9,6 +9,21 @@ enum PinEvent {
Fall = DAL.MICROBIT_PIN_EVT_FALL, // DEVICE_PIN_EVT_FALL
}
+enum AnalogReadWritePin {
+ //% blockIdentity="pins._analogReadWritePinShadow"
+ P0 = AnalogPin.P0,
+ //% blockIdentity="pins._analogReadWritePinShadow"
+ P1 = AnalogPin.P1,
+ //% blockIdentity="pins._analogReadWritePinShadow"
+ P2 = AnalogPin.P2,
+ //% blockIdentity="pins._analogReadWritePinShadow"
+ P3 = AnalogPin.P3,
+ //% blockIdentity="pins._analogReadWritePinShadow"
+ P4 = AnalogPin.P4,
+ //% blockIdentity="pins._analogReadWritePinShadow"
+ P10 = AnalogPin.P10,
+}
+
//% noRefCounting fixedInstances
interface DigitalInOutPin {
digitalRead(): boolean;
diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts
index ebc7a275b..f748c4167 100644
--- a/libs/core/shims.d.ts
+++ b/libs/core/shims.d.ts
@@ -736,7 +736,7 @@ declare namespace pins {
*/
//% help=pins/digital-read-pin weight=30
//% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8
- //% name.shadow=digital_pin shim=pins::digitalReadPin
+ //% name.shadow=digital_pin_shadow shim=pins::digitalReadPin
function digitalReadPin(name: int32): int32;
/**
@@ -747,7 +747,7 @@ declare namespace pins {
//% help=pins/digital-write-pin weight=29
//% blockId=device_set_digital_pin block="digital write|pin %name|to %value"
//% value.min=0 value.max=1
- //% name.shadow=digital_pin shim=pins::digitalWritePin
+ //% name.shadow=digital_pin_shadow shim=pins::digitalWritePin
function digitalWritePin(name: int32, value: int32): void;
/**
@@ -756,7 +756,7 @@ declare namespace pins {
*/
//% help=pins/analog-read-pin weight=25
//% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8"
- //% name.shadow=analog_pin shim=pins::analogReadPin
+ //% name.shadow=analog_read_write_pin_shadow shim=pins::analogReadPin
function analogReadPin(name: int32): int32;
/**
@@ -767,7 +767,7 @@ declare namespace pins {
//% help=pins/analog-write-pin weight=24
//% blockId=device_set_analog_pin block="analog write|pin %name|to %value" blockGap=8
//% value.min=0 value.max=1023
- //% name.shadow=analog_pin shim=pins::analogWritePin
+ //% name.shadow=analog_pin_shadow shim=pins::analogWritePin
function analogWritePin(name: int32, value: int32): void;
/**
@@ -778,7 +778,7 @@ declare namespace pins {
*/
//% help=pins/analog-set-period weight=23 blockGap=8
//% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros"
- //% pin.shadow=analog_pin shim=pins::analogSetPeriod
+ //% pin.shadow=analog_pin_shadow shim=pins::analogSetPeriod
function analogSetPeriod(name: int32, micros: int32): void;
/**
@@ -788,7 +788,7 @@ declare namespace pins {
*/
//% help=pins/on-pulsed weight=22 blockGap=16 advanced=true
//% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse"
- //% pin.shadow=digital_pin
+ //% pin.shadow=digital_pin_shadow
//% group="Pulse"
//% weight=25
//% blockGap=8 shim=pins::onPulsed
@@ -812,7 +812,7 @@ declare namespace pins {
//% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value"
//% weight=20 advanced=true
//% help=pins/pulse-in
- //% name.shadow=digital_pin
+ //% name.shadow=digital_pin_shadow
//% group="Pulse"
//% weight=23
//% blockGap=8 maxDuration.defl=2000000 shim=pins::pulseIn
@@ -827,7 +827,7 @@ declare namespace pins {
//% blockId=device_set_servo_pin block="servo write|pin %name|to %value" blockGap=8
//% parts=microservo trackArgs=0
//% value.min=0 value.max=180
- //% name.shadow=analog_pin
+ //% name.shadow=analog_pin_shadow
//% group="Servo" shim=pins::servoWritePin
function servoWritePin(name: int32, value: int32): void;
@@ -844,7 +844,7 @@ declare namespace pins {
*/
//% help=pins/servo-set-pulse weight=19
//% blockId=device_set_servo_pulse block="servo set pulse|pin %value|to (µs) %micros"
- //% value.shadow=analog_pin
+ //% value.shadow=analog_pin_shadow
//% group="Servo" shim=pins::servoSetPulse
function servoSetPulse(name: int32, micros: int32): void;
@@ -854,7 +854,7 @@ declare namespace pins {
*/
//% blockId=device_analog_set_pitch_pin block="analog set pitch pin %name"
//% help=pins/analog-set-pitch-pin advanced=true
- //% name.shadow=analog_pin
+ //% name.shadow=analog_pin_shadow
//% group="Pins"
//% weight=12
//% blockGap=8 shim=pins::analogSetPitchPin
@@ -900,7 +900,7 @@ declare namespace pins {
*/
//% help=pins/set-pull weight=3 advanced=true
//% blockId=device_set_pull block="set pull|pin %pin|to %pull"
- //% pin.shadow=digital_pin
+ //% pin.shadow=digital_pin_shadow
//% group="Pins"
//% weight=15
//% blockGap=8 shim=pins::setPull
@@ -914,7 +914,7 @@ declare namespace pins {
*/
//% help=pins/set-events weight=4 advanced=true
//% blockId=device_set_pin_events block="set pin %pin|to emit %type|events"
- //% pin.shadow=digital_pin
+ //% pin.shadow=digital_pin_shadow
//% group="Pins"
//% weight=13
//% blockGap=8 shim=pins::setEvents
@@ -935,7 +935,7 @@ declare namespace pins {
*/
//% help=pins/neopixel-matrix-width advanced=true
//% blockId=pin_neopixel_matrix_width block="neopixel matrix width|pin %pin %width"
- //% pin.shadow=digital_pin
+ //% pin.shadow=digital_pin_shadow
//% width.min=2
//% group="Pins"
//% weight=11
@@ -999,9 +999,9 @@ declare namespace pins {
*/
//% help=pins/spi-pins weight=2 advanced=true
//% blockId=spi_pins block="spi set pins|MOSI %mosi|MISO %miso|SCK %sck"
- //% mosi.shadow=digital_pin
- //% miso.shadow=digital_pin
- //% sck.shadow=digital_pin
+ //% mosi.shadow=digital_pin_shadow
+ //% miso.shadow=digital_pin_shadow
+ //% sck.shadow=digital_pin_shadow
//% group="SPI"
//% blockGap=8
//% weight=51 shim=pins::spiPins
@@ -1019,7 +1019,7 @@ declare namespace pins {
*/
//% blockId=pin_set_audio_pin block="set audio pin $name"
//% help=pins/set-audio-pin
- //% name.shadow=digital_pin
+ //% name.shadow=digital_pin_shadow
//% weight=1
//% blockGap=8 shim=pins::setAudioPin
function setAudioPin(name: int32): void;
diff --git a/package.json b/package.json
index 554cac818..d82271b3e 100644
--- a/package.json
+++ b/package.json
@@ -47,6 +47,6 @@
},
"dependencies": {
"pxt-common-packages": "12.0.3",
- "pxt-core": "10.2.15"
+ "pxt-core": "10.2.16"
}
}