Skip to content

Commit

Permalink
Merge mb v7.0.26
Browse files Browse the repository at this point in the history
  • Loading branch information
Amerlander committed Aug 28, 2024
1 parent 32ec359 commit 7de7a66
Show file tree
Hide file tree
Showing 10 changed files with 657 additions and 266 deletions.
428 changes: 257 additions & 171 deletions editor/patch.ts

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions fieldeditors/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>

import { FieldGestures } from "./field_gestures";
import { FieldPinPicker } from "./field_pinPicker";

pxt.editor.initFieldExtensionsAsync = function (opts: pxt.editor.FieldExtensionOptions): Promise<pxt.editor.FieldExtensionResult> {
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<pxt.editor.FieldExtensionResult>(res);
}
93 changes: 93 additions & 0 deletions fieldeditors/field_pinPicker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/// <reference path="../node_modules/pxt-core/localtypings/pxtblockly.d.ts"/>

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;
}
}
215 changes: 176 additions & 39 deletions libs/core/blocks-test/pins.blocks
Original file line number Diff line number Diff line change
@@ -1,67 +1,204 @@

<xml xmlns="https://developers.google.com/blockly/xml">
<variables/>
<block type="pins_on_pulsed" x="0" y="0">
<field name="pulse">PulseValue.Low</field>
<value name="pin">
<block type="digital_pin">
<field name="pin">DigitalPin.P5</field>
</block>
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="pins_on_pulsed" x="-157" y="130">
<value name="pin">
<shadow type="digital_pin">
<field name="pin">DigitalPin.P5</field>
</shadow>
</value>
<field name="pulse">PulseValue.Low</field>
<statement name="HANDLER">
<block type="device_set_analog_pin">
<value name="name">
<shadow type="analog_pin">
<field name="pin">AnalogPin.P9</field>
</shadow>
</value>
<value name="value">
<shadow type="math_number">
<field name="NUM">5</field>
</shadow>
</value>
<statement name="HANDLER">
<block type="device_set_analog_pin">
<next>
<block type="device_set_analog_period">
<value name="pin">
<shadow type="analog_pin">
<field name="pin">AnalogPin.P10</field>
</shadow>
</value>
<value name="micros">
<shadow type="math_number">
<field name="NUM">20000</field>
</shadow>
</value>
<next>
<block type="device_set_digital_pin">
<value name="name">
<block type="analog_pin">
<field name="pin">AnalogPin.P9</field>
</block>
<shadow type="digital_pin">
<field name="pin">DigitalPin.P6</field>
</shadow>
</value>
<value name="value">
<shadow type="math_number">
<field name="NUM">5</field>
</shadow>
</value>
<next>
<block type="device_set_analog_period">
<value name="pin">
<block type="analog_pin">
<field name="pin">AnalogPin.P10</field>
</block>
<block type="device_set_servo_pin">
<value name="name">
<shadow type="analog_pin">
<field name="pin">AnalogPin.P13</field>
</shadow>
</value>
<value name="value">
<shadow type="math_number">
<field name="NUM">5</field>
</shadow>
</value>
<next>
<block type="device_set_servo_pulse">
<value name="value">
<shadow type="analog_pin">
<field name="pin">AnalogPin.P8</field>
</shadow>
</value>
<value name="micros">
<shadow type="math_number">
<field name="NUM">20000</field>
</shadow>
<shadow type="math_number" id="Hx4bpmg|8KSH=b_`+XtP">
<field name="NUM">1500</field>
</shadow>
<block type="math_map">
<value name="value">
<shadow type="math_number" id="J%8`=~h4-?O{fY59%(_{">
<field name="NUM">0</field>
</shadow>
<block type="pins_i2c_readnumber">
<field name="format">NumberFormat.Int8BE</field>
<value name="address">
<shadow type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
<value name="repeat">
<shadow type="logic_boolean">
<field name="BOOL">FALSE</field>
</shadow>
</value>
</block>
</value>
<value name="fromLow">
<shadow type="math_number" id="kp(!mScnCVWI/1_X|ar#">
<field name="NUM">0</field>
</shadow>
<block type="pins_pulse_in">
<value name="name">
<shadow type="digital_pin">
<field name="pin">DigitalPin.P9</field>
</shadow>
</value>
<field name="value">PulseValue.Low</field>
</block>
</value>
<value name="fromHigh">
<shadow type="math_number" id="]@F=`[ZuxAk,=05Yyn[{">
<field name="NUM">1023</field>
</shadow>
<block type="pins_pulse_duration"></block>
</value>
<value name="toLow">
<shadow type="math_number" id="sJDL?hoabUE)cDdBJWO=">
<field name="NUM">0</field>
</shadow>
<block type="spi_write">
<value name="value">
<shadow type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
</block>
</value>
<value name="toHigh">
<shadow type="math_number">
<field name="NUM">4</field>
</shadow>
</value>
</block>
</value>
<next>
<block type="device_set_digital_pin">
<value name="name">
<block type="digital_pin">
<field name="pin">DigitalPin.P6</field>
</block>
<shadow type="digital_pin">
<field name="pin">DigitalPin.P9</field>
</shadow>
</value>
<value name="value">
<shadow type="math_number">
<field name="NUM">5</field>
</shadow>
</block>
</value>
<value name="value">
<shadow type="math_number" id="CCl{zdVU/!(bR}aUfG,G">
<field name="NUM">0</field>
</shadow>
<block type="device_get_analog_pin">
<value name="name">
<shadow type="analog_pin">
<field name="pin">AnalogPin.P9</field>
</shadow>
</value>
</block>
</value>
<value name="repeat">
<shadow type="logic_boolean">
<field name="BOOL">FALSE</field>
</shadow>
</value>
<next>
<block type="spi_pins">
<value name="mosi">
<shadow type="digital_pin">
<field name="pin">DigitalPin.P11</field>
</shadow>
</value>
<value name="miso">
<shadow type="digital_pin">
<field name="pin">DigitalPin.P9</field>
</shadow>
</value>
<value name="sck">
<shadow type="digital_pin">
<field name="pin">DigitalPin.P10</field>
</shadow>
</value>
<next>
<block type="device_set_servo_pin">
<value name="name">
<block type="analog_pin">
<field name="pin">AnalogPin.P13</field>
</block>
<block type="device_set_pull">
<value name="pin">
<shadow type="digital_pin">
<field name="pin">DigitalPin.P9</field>
</shadow>
</value>
<field name="pull">PinPullMode.PullDown</field>
<next>
<block type="device_analog_pitch">
<value name="frequency">
<shadow type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
<value name="value">
<shadow type="math_number">
<field name="NUM">5</field>
</shadow>
</value>
<next>
<block type="device_set_servo_pulse">
<value name="value">
<block type="analog_pin">
<field name="pin">AnalogPin.P8</field>
</block>
<block type="device_set_pin_events">
<value name="pin">
<shadow type="digital_pin">
<field name="pin">DigitalPin.P8</field>
</shadow>
</value>
<field name="type">PinEventType.Touch</field>
<next>
<block type="device_analog_set_pitch_pin">
<value name="name">
<shadow type="analog_pin">
<field name="pin">AnalogPin.P9</field>
</shadow>
</value>
<value name="micros">
<shadow type="math_number">
Expand Down
14 changes: 7 additions & 7 deletions libs/core/enums.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)"
Expand Down
Loading

0 comments on commit 7de7a66

Please sign in to comment.