From fa34fe5fd2d08af66551c988ceaaf2cc4f916789 Mon Sep 17 00:00:00 2001 From: Juri Wolf Date: Thu, 30 Jun 2022 19:01:19 +0200 Subject: [PATCH] Beta v4 updates (#195) * fix simulator - fix buttons - fix analog max value * BLE Set max table size * reset defaults * add coding4coconut/pxt-lcd128x160-st7735s * add coding4coconut/pxt-oled128x128-sh1107 * enable partial flashing --- libs/core/_locales/core-jsdoc-strings.json | 11 +- libs/core/_locales/core-strings.json | 12 ++- libs/core/basic.cpp | 4 +- libs/core/basic.ts | 2 +- libs/core/icons.ts | 6 +- libs/core/input.cpp | 51 +++++++++ libs/core/pins.cpp | 26 +++++ libs/core/pins.ts | 5 + libs/core/pxt.json | 7 +- libs/core/shims.d.ts | 115 ++++++++++++++++----- package.json | 2 +- sim/visuals/microbit.ts | 11 +- targetconfig.json | 2 + 13 files changed, 212 insertions(+), 42 deletions(-) diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index d1dc3163..0a923049 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -268,7 +268,7 @@ "basic.showCompass|param|interval": "the amount of time (milliseconds) to show the needle. Default is 600.", "basic.showIcon": "Draws the selected icon on the LED screen", "basic.showIcon|param|icon": "the predefined icon id", - "basic.showIcon|param|interval": "the amount of time (milliseconds) to block the LED Matrix for showing the icon. Default is 200.", + "basic.showIcon|param|interval": "the amount of time (milliseconds) to block the LED Matrix for showing the icon. Default is 600.", "basic.showLeds": "Draws an image on the LED screen.", "basic.showLeds|param|interval": "time in milliseconds to pause after drawing", "basic.showLeds|param|leds": "the pattern of LED to turn on/off", @@ -442,9 +442,18 @@ "input.onButtonEvent|param|body": "code to run when event is raised", "input.onButtonEvent|param|button": "the button", "input.onButtonEvent|param|eventType": "event Type", + "input.onButtonPressed": "Do something when a button (A, B or both A+B) is pushed down and released again.", + "input.onButtonPressed|param|body": "code to run when event is raised", + "input.onButtonPressed|param|button": "the button that needs to be pressed", "input.onGesture": "Do something when when a gesture is done (like shaking the micro:bit).", "input.onGesture|param|body": "code to run when gesture is raised", "input.onGesture|param|gesture": "the type of gesture to track, eg: Gesture.Shake", + "input.onPinPressed": "Do something when a pin is touched and released again (while also touching the GND pin).", + "input.onPinPressed|param|body": "the code to run when the pin is pressed", + "input.onPinPressed|param|name": "the pin that needs to be pressed, eg: TouchPin.P0", + "input.onPinReleased": "Do something when a pin is released.", + "input.onPinReleased|param|body": "the code to run when the pin is released", + "input.onPinReleased|param|name": "the pin that needs to be released, eg: TouchPin.P0", "input.onPinTouchEvent": "Do something when a pin receives an touch event (while also touching the GND pin).", "input.onPinTouchEvent|param|body": "the code to run when event is fired on pin", "input.onPinTouchEvent|param|name": "the pin, eg: TouchPin.P0", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index fc32f1eb..56cbaa8f 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -345,7 +345,10 @@ "input.lightLevel|block": "light level", "input.magneticForce|block": "magnetic force (µT)|%NAME", "input.onButtonEvent|block": "on button %NAME| %eventType=control_button_event_value_id", + "input.onButtonPressed|block": "on button|%NAME|pressed", "input.onGesture|block": "on |%NAME", + "input.onPinPressed|block": "on pin %name|pressed", + "input.onPinReleased|block": "on pin %NAME|released", "input.onPinTouchEvent|block": "on pin %name| %eventType=control_button_event_value_id", "input.pinIsPressed|block": "pin %NAME|is pressed", "input.rotation|block": "rotation (°)|%NAME", @@ -484,8 +487,10 @@ "{id:category}String": "String", "{id:category}Text": "Text", "{id:category}_py": "_py", + "{id:group}Analog": "Analog", "{id:group}Configuration": "Configuration", "{id:group}Control": "Control", + "{id:group}Digital": "Digital", "{id:group}Events": "Events", "{id:group}Get": "Get", "{id:group}LED matrix": "LED matrix", @@ -493,15 +498,20 @@ "{id:group}Melody Advanced": "Melody Advanced", "{id:group}Modify": "Modify", "{id:group}Operations": "Operations", + "{id:group}Pitch": "Pitch", + "{id:group}Pulse": "Pulse", "{id:group}Put": "Put", "{id:group}RGB LED": "RGB LED", "{id:group}Read": "Read", "{id:group}Remove": "Remove", "{id:group}Sensors": "Sensors", + "{id:group}Servo": "Servo", "{id:group}Silence": "Silence", "{id:group}States": "States", "{id:group}System": "System", "{id:group}Tempo": "Tempo", "{id:group}Tone": "Tone", - "{id:group}Volume": "Volume" + "{id:group}Volume": "Volume", + "{id:group}i2c": "i2c", + "{id:group}spi": "spi" } \ No newline at end of file diff --git a/libs/core/basic.cpp b/libs/core/basic.cpp index 263092f0..daa7ee2c 100644 --- a/libs/core/basic.cpp +++ b/libs/core/basic.cpp @@ -35,9 +35,9 @@ namespace basic { //% parts="ledmatrix" //% text.shadowOptions.toString=true //% expandableArgumentMode="toggle" - //% interval.defl=80 + //% interval.defl=150 //% group="LED matrix" - void showString(String text, int interval = 80) { + void showString(String text, int interval = 150) { if (interval <= 0) interval = 1; int l = text ? text->getUTF8Size() : 0; diff --git a/libs/core/basic.ts b/libs/core/basic.ts index 8fc6b83f..cb84c6d3 100644 --- a/libs/core/basic.ts +++ b/libs/core/basic.ts @@ -52,7 +52,7 @@ namespace basic { //% async //% parts="ledmatrix" //% expandableArgumentMode="toggle" - //% interval.defl=80 + //% interval.defl=150 //% group="LED matrix" export function showNumber(value: number, interval?: number) { showString(Math.roundWithPrecision(value, 2).toString(), interval); diff --git a/libs/core/icons.ts b/libs/core/icons.ts index 8e912d75..3fb3291e 100644 --- a/libs/core/icons.ts +++ b/libs/core/icons.ts @@ -196,7 +196,7 @@ namespace basic { /** * Draws the selected icon on the LED screen * @param icon the predefined icon id - * @param interval the amount of time (milliseconds) to block the LED Matrix for showing the icon. Default is 200. + * @param interval the amount of time (milliseconds) to block the LED Matrix for showing the icon. Default is 600. */ //% weight=90 blockGap=8 //% blockId=basic_show_icon @@ -208,9 +208,9 @@ namespace basic { //% icon.fieldOptions.width="380" //% icon.fieldOptions.maxRows=4 //% expandableArgumentMode="toggle" - //% interval.defl=200 + //% interval.defl=600 //% group="LED matrix" - export function showIcon(icon: IconNames, interval = 200) { + export function showIcon(icon: IconNames, interval = 600) { let res = images.iconImage(icon) res.showImage(0, interval) } diff --git a/libs/core/input.cpp b/libs/core/input.cpp index 1ed3c05b..d1b41273 100644 --- a/libs/core/input.cpp +++ b/libs/core/input.cpp @@ -262,6 +262,57 @@ namespace input { return false; } + /** + * Do something when a button (A, B or both A+B) is pushed down and released again. + * @param button the button that needs to be pressed + * @param body code to run when event is raised + */ + //% help=input/on-button-pressed weight=85 blockGap=16 + //% blockId=device_button_event block="on button|%NAME|pressed" + //% parts="buttonpair" + //% deprecated=true + //% group="Events" + void onButtonPressed(Button button, Action body) { + registerWithDal((int)button, MICROBIT_BUTTON_EVT_CLICK, body); + } + + /** + * Do something when a pin is touched and released again (while also touching the GND pin). + * @param name the pin that needs to be pressed, eg: TouchPin.P0 + * @param body the code to run when the pin is pressed + */ + //% help=input/on-pin-pressed weight=83 blockGap=16 + //% blockId=device_pin_event block="on pin %name|pressed" + //% group="Events" + //% deprecated=true + void onPinPressed(TouchPin name, Action body) { + auto pin = getPin((int)name); + if (!pin) return; + + // Forces the PIN to switch to makey-makey style detection. + pin->isTouched(); + registerWithDal((int)name, MICROBIT_BUTTON_EVT_CLICK, body); + } + + /** + * Do something when a pin is released. + * @param name the pin that needs to be released, eg: TouchPin.P0 + * @param body the code to run when the pin is released + */ + //% help=input/on-pin-released weight=6 blockGap=16 + //% blockId=device_pin_released block="on pin %NAME|released" + //% advanced=true + //% group="Events" + //% deprecated=true + void onPinReleased(TouchPin name, Action body) { + auto pin = getPin((int)name); + if (!pin) return; + + // Forces the PIN to switch to makey-makey style detection. + pin->isTouched(); + registerWithDal((int)name, MICROBIT_BUTTON_EVT_UP, body); + } + /** * Get the pin state (pressed or not). Requires to hold the ground to close the circuit. * @param name pin used to detect the touch, eg: TouchPin.P0 diff --git a/libs/core/pins.cpp b/libs/core/pins.cpp index c092521d..bfd322eb 100644 --- a/libs/core/pins.cpp +++ b/libs/core/pins.cpp @@ -124,6 +124,7 @@ namespace pins { //% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8 //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% group="Digital" int digitalReadPin(DigitalPin name) { PINREAD(getDigitalValue()); } @@ -138,6 +139,7 @@ namespace pins { //% value.min=0 value.max=1 //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% group="Digital" void digitalWritePin(DigitalPin name, int value) { PINOP(setDigitalValue(value)); } @@ -150,6 +152,7 @@ namespace pins { //% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8" //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% group="Analog" int analogReadPin(AnalogPin name) { PINREAD(getAnalogValue()); } @@ -164,6 +167,7 @@ namespace pins { //% value.min=0 value.max=1023 //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% group="Analog" void analogWritePin(AnalogPin name, int value) { PINOP(setAnalogValue(value)); } @@ -178,6 +182,7 @@ namespace pins { //% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros" //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 //% pin.fieldOptions.tooltips="false" + //% group="Analog" void analogSetPeriod(AnalogPin name, int micros) { PINOP(setAnalogPeriodUs(micros)); } @@ -191,6 +196,7 @@ namespace pins { //% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse" //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% group="Pulse" void onPulsed(DigitalPin name, PulseValue pulse, Action body) { MicroBitPin* pin = getPin((int)name); if (!pin) return; @@ -205,6 +211,7 @@ namespace pins { //% help=pins/pulse-duration advanced=true //% blockId=pins_pulse_duration block="pulse duration (µs)" //% weight=21 blockGap=8 + //% group="Pulse" int pulseDuration() { return pxt::lastEvent.timestamp; } @@ -220,6 +227,7 @@ namespace pins { //% help=pins/pulse-in //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% group="Pulse" int pulseIn(DigitalPin name, PulseValue value, int maxDuration = 2000000) { MicroBitPin* pin = getPin((int)name); if (!pin) return 0; @@ -275,6 +283,7 @@ namespace pins { //% value.min=0 value.max=180 //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% group="Servo" void servoWritePin(AnalogPin name, int value) { PINOP(setServoValue(value)); } @@ -283,6 +292,7 @@ namespace pins { * Specifies that a continuous servo is connected. */ //% + //% group="Servo" void servoSetContinuous(AnalogPin name, bool value) { // handled in simulator } @@ -296,6 +306,7 @@ namespace pins { //% blockId=device_set_servo_pulse block="servo set pulse|pin %value|to (µs) %micros" //% value.fieldEditor="gridpicker" value.fieldOptions.columns=4 //% value.fieldOptions.tooltips="false" value.fieldOptions.width="250" + //% group="Servo" void servoSetPulse(AnalogPin name, int micros) { fixMotorIssue(name); PINOP(setServoPulseUs(micros)); @@ -316,6 +327,7 @@ namespace pins { //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" //% blockHidden=true + //% group="Pitch" void analogSetPitchPin(AnalogPin name) { pitchPin = getPin((int)name); pitchPin2 = NULL; @@ -339,6 +351,7 @@ namespace pins { //% help=pins/analog-set-pitch-volume weight=3 advanced=true //% volume.min=0 volume.max=255 //% blockHidden=true + //% group="Pitch" void analogSetPitchVolume(int volume) { pitchVolume = max(0, min(0xff, volume)); @@ -355,6 +368,7 @@ namespace pins { //% blockId=device_analog_pitch_volume block="analog pitch volume" //% help=pins/analog-pitch-volume weight=3 advanced=true //% blockHidden=true + //% group="Pitch" int analogPitchVolume() { return pitchVolume; } @@ -367,6 +381,7 @@ namespace pins { //% blockId=device_analog_pitch block="analog pitch %frequency|for (ms) %ms" //% help=pins/analog-pitch weight=4 async advanced=true blockGap=8 //% blockHidden=true + //% group="Pitch" void analogPitch(int frequency, int ms) { // init pins if needed if (NULL == pitchPin) { @@ -402,6 +417,7 @@ namespace pins { //% blockId=device_set_pull block="set pull|pin %pin|to %pull" //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% group="Digital" void setPull(DigitalPin name, PinPullMode pull) { #if MICROBIT_CODAL codal::PullMode m = pull == PinPullMode::PullDown @@ -428,6 +444,7 @@ namespace pins { //% blockId=device_set_pin_events block="set pin %pin|to emit %type|events" //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% group="Digital" void setEvents(DigitalPin name, PinEventType type) { getPin((int)name)->eventOn((int)type); } @@ -467,6 +484,7 @@ namespace pins { * Read `size` bytes from a 7-bit I2C `address`. */ //% + //% group="i2c" Buffer i2cReadBuffer(int address, int size, bool repeat = false) { Buffer buf = createBuffer(size); @@ -478,6 +496,7 @@ namespace pins { * Write bytes to a 7-bit I2C `address`. */ //% + //% group="i2c" int i2cWriteBuffer(int address, Buffer buf, bool repeat = false) { return uBit.i2c.write(address << 1, (BUFFER_TYPE)buf->data, buf->length, repeat); @@ -496,6 +515,7 @@ namespace pins { */ //% help=pins/spi-write weight=5 advanced=true //% blockId=spi_write block="spi write %value" + //% group="spi" int spiWrite(int value) { auto p = allocSPI(); return p->write(value); @@ -507,6 +527,7 @@ namespace pins { * @param response Data received from the SPI slave (can be null) */ //% help=pins/spi-transfer argsNullable + //% group="spi" void spiTransfer(Buffer command, Buffer response) { if (!command && !response) target_panic(PANIC_INVALID_ARGUMENT); @@ -531,6 +552,7 @@ namespace pins { */ //% help=pins/spi-frequency weight=4 advanced=true //% blockId=spi_frequency block="spi frequency %frequency" + //% group="spi" void spiFrequency(int frequency) { auto p = allocSPI(); p->frequency(frequency); @@ -543,6 +565,7 @@ namespace pins { */ //% help=pins/spi-format weight=3 advanced=true //% blockId=spi_format block="spi format|bits %bits|mode %mode" + //% group="spi" void spiFormat(int bits, int mode) { auto p = allocSPI(); p->format(bits, mode); @@ -566,6 +589,7 @@ namespace pins { //% miso.fieldOptions.tooltips="false" miso.fieldOptions.width="250" //% sck.fieldEditor="gridpicker" sck.fieldOptions.columns=4 //% sck.fieldOptions.tooltips="false" sck.fieldOptions.width="250" + //% group="spi" void spiPins(DigitalPin mosi, DigitalPin miso, DigitalPin sck) { if (NULL != spi) { delete spi; @@ -578,6 +602,7 @@ namespace pins { * Mounts a push button on the given pin */ //% help=pins/push-button advanced=true + //% group="Digital" void pushButton(DigitalPin pin) { new MicroBitButton((PinName)getPin((int)(pin))->name, (int)pin, MICROBIT_BUTTON_ALL_EVENTS, PinMode::PullUp); } @@ -592,6 +617,7 @@ namespace pins { //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" //% weight=1 //% blockHidden=true + //% group="Pitch" void setAudioPin(AnalogPin name) { #if MICROBIT_CODAL uBit.audio.setPin(*getPin((int)name)); diff --git a/libs/core/pins.ts b/libs/core/pins.ts index ab4d7c72..052eab0d 100644 --- a/libs/core/pins.ts +++ b/libs/core/pins.ts @@ -3,6 +3,8 @@ */ //% color=#A80000 weight=30 icon="\uf140" //% advanced=true +//% groups=['Analog', 'Digital', 'Servos', 'Pulse', 'Pitch', 'i2c', 'spi'] + namespace pins { /** * Map a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc. @@ -14,6 +16,7 @@ namespace pins { */ //% help=pins/map weight=23 //% blockId=pin_map block="map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh" + //% deprecated=true export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number { return ((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow) + toLow; } @@ -23,6 +26,7 @@ namespace pins { */ //% help=pins/i2c-read-number blockGap=8 advanced=true //% blockId=pins_i2c_readnumber block="i2c read number|at address %address|of format %format|repeated %repeat" weight=7 + //% group="i2c" export function i2cReadNumber(address: number, format: NumberFormat, repeated?: boolean): number { let buf = pins.i2cReadBuffer(address, pins.sizeOf(format), repeated) return buf.getNumber(format, 0) @@ -33,6 +37,7 @@ namespace pins { */ //% help=pins/i2c-write-number blockGap=8 advanced=true //% blockId=i2c_writenumber block="i2c write number|at address %address|with value %value|of format %format|repeated %repeat" weight=6 + //% group="i2c" export function i2cWriteNumber(address: number, value: number, format: NumberFormat, repeated?: boolean): void { let buf = createBuffer(pins.sizeOf(format)) buf.setNumber(format, 0, value) diff --git a/libs/core/pxt.json b/libs/core/pxt.json index a81255c5..1dc9d66a 100644 --- a/libs/core/pxt.json +++ b/libs/core/pxt.json @@ -116,6 +116,7 @@ "pairing_mode": 1, "private_addressing": 0, "open": 1, + "partial_flashing": 1, "security_level": null, "whitelist": 1, "advertising_timeout": 0, @@ -125,7 +126,7 @@ "device_info_service": 0 }, "stack_size": 1280, - "gatt_table_size": "0xD8", + "gatt_table_size": "0x200", "panic_on_heap_full": 0, "debug": 0, "heap_debug": 0, @@ -139,7 +140,7 @@ "config": { "microbit-dal": { "stack_size": 2048, - "gatt_table_size": "0x600", + "gatt_table_size": "0x700", "sram_end": "0x20008000", "RAM_SIZE": "\"32K\"" } @@ -150,7 +151,7 @@ "config": { "microbit-dal": { "stack_size": 1280, - "gatt_table_size": "0xD8", + "gatt_table_size": "0x200", "sram_end": "0x20004000", "RAM_SIZE": "\"16K\"" } diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index b73cb154..99eac323 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -160,7 +160,7 @@ declare namespace basic { //% text.shadowOptions.toString=true //% expandableArgumentMode="toggle" //% - //% group="LED matrix" interval.defl=80 shim=basic::showString + //% group="LED matrix" interval.defl=150 shim=basic::showString function showString(text: string, interval?: int32): void; /** @@ -294,6 +294,41 @@ declare namespace input { //% group="States" shim=input::buttonIsPressed function buttonIsPressed(button: Button): boolean; + /** + * Do something when a button (A, B or both A+B) is pushed down and released again. + * @param button the button that needs to be pressed + * @param body code to run when event is raised + */ + //% help=input/on-button-pressed weight=85 blockGap=16 + //% blockId=device_button_event block="on button|%NAME|pressed" + //% parts="buttonpair" + //% deprecated=true + //% group="Events" shim=input::onButtonPressed + function onButtonPressed(button: Button, body: () => void): void; + + /** + * Do something when a pin is touched and released again (while also touching the GND pin). + * @param name the pin that needs to be pressed, eg: TouchPin.P0 + * @param body the code to run when the pin is pressed + */ + //% help=input/on-pin-pressed weight=83 blockGap=16 + //% blockId=device_pin_event block="on pin %name|pressed" + //% group="Events" + //% deprecated=true shim=input::onPinPressed + function onPinPressed(name: TouchPin, body: () => void): void; + + /** + * Do something when a pin is released. + * @param name the pin that needs to be released, eg: TouchPin.P0 + * @param body the code to run when the pin is released + */ + //% help=input/on-pin-released weight=6 blockGap=16 + //% blockId=device_pin_released block="on pin %NAME|released" + //% advanced=true + //% group="Events" + //% deprecated=true shim=input::onPinReleased + function onPinReleased(name: TouchPin, body: () => void): void; + /** * Get the pin state (pressed or not). Requires to hold the ground to close the circuit. * @param name pin used to detect the touch, eg: TouchPin.P0 @@ -783,7 +818,8 @@ declare namespace pins { //% help=pins/digital-read-pin weight=30 //% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8 //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" shim=pins::digitalReadPin + //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% group="Digital" shim=pins::digitalReadPin function digitalReadPin(name: DigitalPin): int32; /** @@ -795,7 +831,8 @@ declare namespace pins { //% blockId=device_set_digital_pin block="digital write|pin %name|to %value" //% value.min=0 value.max=1 //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" shim=pins::digitalWritePin + //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% group="Digital" shim=pins::digitalWritePin function digitalWritePin(name: DigitalPin, value: int32): void; /** @@ -805,7 +842,8 @@ declare namespace pins { //% help=pins/analog-read-pin weight=25 //% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8" //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" shim=pins::analogReadPin + //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% group="Analog" shim=pins::analogReadPin function analogReadPin(name: AnalogPin): int32; /** @@ -817,7 +855,8 @@ declare namespace pins { //% blockId=device_set_analog_pin block="analog write|pin %name|to %value" blockGap=8 //% value.min=0 value.max=1023 //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" shim=pins::analogWritePin + //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% group="Analog" shim=pins::analogWritePin function analogWritePin(name: AnalogPin, value: int32): void; /** @@ -829,7 +868,8 @@ 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.fieldEditor="gridpicker" pin.fieldOptions.columns=4 - //% pin.fieldOptions.tooltips="false" shim=pins::analogSetPeriod + //% pin.fieldOptions.tooltips="false" + //% group="Analog" shim=pins::analogSetPeriod function analogSetPeriod(name: AnalogPin, micros: int32): void; /** @@ -840,7 +880,8 @@ declare namespace pins { //% help=pins/on-pulsed weight=22 blockGap=16 advanced=true //% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse" //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 - //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" shim=pins::onPulsed + //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% group="Pulse" shim=pins::onPulsed function onPulsed(name: DigitalPin, pulse: PulseValue, body: () => void): void; /** @@ -848,7 +889,8 @@ declare namespace pins { */ //% help=pins/pulse-duration advanced=true //% blockId=pins_pulse_duration block="pulse duration (µs)" - //% weight=21 blockGap=8 shim=pins::pulseDuration + //% weight=21 blockGap=8 + //% group="Pulse" shim=pins::pulseDuration function pulseDuration(): int32; /** @@ -861,7 +903,8 @@ declare namespace pins { //% weight=20 advanced=true //% help=pins/pulse-in //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" maxDuration.defl=2000000 shim=pins::pulseIn + //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% group="Pulse" maxDuration.defl=2000000 shim=pins::pulseIn function pulseIn(name: DigitalPin, value: PulseValue, maxDuration?: int32): int32; /** @@ -874,13 +917,15 @@ declare namespace pins { //% parts=microservo trackArgs=0 //% value.min=0 value.max=180 //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" shim=pins::servoWritePin + //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% group="Servo" shim=pins::servoWritePin function servoWritePin(name: AnalogPin, value: int32): void; /** * Specifies that a continuous servo is connected. */ - //% shim=pins::servoSetContinuous + //% + //% group="Servo" shim=pins::servoSetContinuous function servoSetContinuous(name: AnalogPin, value: boolean): void; /** @@ -891,7 +936,8 @@ 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.fieldEditor="gridpicker" value.fieldOptions.columns=4 - //% value.fieldOptions.tooltips="false" value.fieldOptions.width="250" shim=pins::servoSetPulse + //% value.fieldOptions.tooltips="false" value.fieldOptions.width="250" + //% group="Servo" shim=pins::servoSetPulse function servoSetPulse(name: AnalogPin, micros: int32): void; /** @@ -902,7 +948,8 @@ declare namespace pins { //% help=pins/analog-set-pitch-pin weight=3 advanced=true //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" - //% blockHidden=true shim=pins::analogSetPitchPin + //% blockHidden=true + //% group="Pitch" shim=pins::analogSetPitchPin function analogSetPitchPin(name: AnalogPin): void; /** @@ -912,7 +959,8 @@ declare namespace pins { //% blockId=device_analog_set_pitch_volume block="analog set pitch volume $volume" //% help=pins/analog-set-pitch-volume weight=3 advanced=true //% volume.min=0 volume.max=255 - //% blockHidden=true shim=pins::analogSetPitchVolume + //% blockHidden=true + //% group="Pitch" shim=pins::analogSetPitchVolume function analogSetPitchVolume(volume: int32): void; /** @@ -920,7 +968,8 @@ declare namespace pins { */ //% blockId=device_analog_pitch_volume block="analog pitch volume" //% help=pins/analog-pitch-volume weight=3 advanced=true - //% blockHidden=true shim=pins::analogPitchVolume + //% blockHidden=true + //% group="Pitch" shim=pins::analogPitchVolume function analogPitchVolume(): int32; /** @@ -930,7 +979,8 @@ declare namespace pins { */ //% blockId=device_analog_pitch block="analog pitch %frequency|for (ms) %ms" //% help=pins/analog-pitch weight=4 async advanced=true blockGap=8 - //% blockHidden=true shim=pins::analogPitch + //% blockHidden=true + //% group="Pitch" shim=pins::analogPitch function analogPitch(frequency: int32, ms: int32): void; /** @@ -941,7 +991,8 @@ declare namespace pins { //% help=pins/set-pull weight=3 advanced=true //% blockId=device_set_pull block="set pull|pin %pin|to %pull" //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 - //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" shim=pins::setPull + //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% group="Digital" shim=pins::setPull function setPull(name: DigitalPin, pull: PinPullMode): void; /** @@ -953,7 +1004,8 @@ 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.fieldEditor="gridpicker" pin.fieldOptions.columns=4 - //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" shim=pins::setEvents + //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% group="Digital" shim=pins::setEvents function setEvents(name: DigitalPin, type: PinEventType): void; /** @@ -980,13 +1032,15 @@ declare namespace pins { /** * Read `size` bytes from a 7-bit I2C `address`. */ - //% repeat.defl=0 shim=pins::i2cReadBuffer + //% + //% group="i2c" repeat.defl=0 shim=pins::i2cReadBuffer function i2cReadBuffer(address: int32, size: int32, repeat?: boolean): Buffer; /** * Write bytes to a 7-bit I2C `address`. */ - //% repeat.defl=0 shim=pins::i2cWriteBuffer + //% + //% group="i2c" repeat.defl=0 shim=pins::i2cWriteBuffer function i2cWriteBuffer(address: int32, buf: Buffer, repeat?: boolean): int32; /** @@ -994,7 +1048,8 @@ declare namespace pins { * @param value Data to be sent to the SPI slave */ //% help=pins/spi-write weight=5 advanced=true - //% blockId=spi_write block="spi write %value" shim=pins::spiWrite + //% blockId=spi_write block="spi write %value" + //% group="spi" shim=pins::spiWrite function spiWrite(value: int32): int32; /** @@ -1002,7 +1057,8 @@ declare namespace pins { * @param command Data to be sent to the SPI slave (can be null) * @param response Data received from the SPI slave (can be null) */ - //% help=pins/spi-transfer argsNullable shim=pins::spiTransfer + //% help=pins/spi-transfer argsNullable + //% group="spi" shim=pins::spiTransfer function spiTransfer(command: Buffer, response: Buffer): void; /** @@ -1010,7 +1066,8 @@ declare namespace pins { * @param frequency the clock frequency, eg: 1000000 */ //% help=pins/spi-frequency weight=4 advanced=true - //% blockId=spi_frequency block="spi frequency %frequency" shim=pins::spiFrequency + //% blockId=spi_frequency block="spi frequency %frequency" + //% group="spi" shim=pins::spiFrequency function spiFrequency(frequency: int32): void; /** @@ -1019,7 +1076,8 @@ declare namespace pins { * @param mode the mode, eg: 3 */ //% help=pins/spi-format weight=3 advanced=true - //% blockId=spi_format block="spi format|bits %bits|mode %mode" shim=pins::spiFormat + //% blockId=spi_format block="spi format|bits %bits|mode %mode" + //% group="spi" shim=pins::spiFormat function spiFormat(bits: int32, mode: int32): void; /** @@ -1033,13 +1091,15 @@ declare namespace pins { //% miso.fieldEditor="gridpicker" miso.fieldOptions.columns=4 //% miso.fieldOptions.tooltips="false" miso.fieldOptions.width="250" //% sck.fieldEditor="gridpicker" sck.fieldOptions.columns=4 - //% sck.fieldOptions.tooltips="false" sck.fieldOptions.width="250" shim=pins::spiPins + //% sck.fieldOptions.tooltips="false" sck.fieldOptions.width="250" + //% group="spi" shim=pins::spiPins function spiPins(mosi: DigitalPin, miso: DigitalPin, sck: DigitalPin): void; /** * Mounts a push button on the given pin */ - //% help=pins/push-button advanced=true shim=pins::pushButton + //% help=pins/push-button advanced=true + //% group="Digital" shim=pins::pushButton function pushButton(pin: DigitalPin): void; /** @@ -1051,7 +1111,8 @@ declare namespace pins { //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" //% weight=1 - //% blockHidden=true shim=pins::setAudioPin + //% blockHidden=true + //% group="Pitch" shim=pins::setAudioPin function setAudioPin(name: AnalogPin): void; } diff --git a/package.json b/package.json index a364e2e1..e9c94b6c 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,6 @@ }, "dependencies": { "pxt-common-packages": "9.0.1", - "pxt-core": "7.0.16" + "pxt-core": "7.0.17" } } diff --git a/sim/visuals/microbit.ts b/sim/visuals/microbit.ts index 19de4b80..eb229f71 100644 --- a/sim/visuals/microbit.ts +++ b/sim/visuals/microbit.ts @@ -1873,7 +1873,7 @@ namespace pxsim.visuals { if (!this.board.edgeConnectorState.pins[index]) return; let pt = this.element.createSVGPoint(); let xpos = (index === 0 || index === 3) ? 300 : 520; - let vMax = (index === 0 || index === 3) ? 1 : 1032; + let vMax = (index === 0 || index === 3) ? 1 : 1023; svg.buttonEvents(pin, // move ev => { @@ -1978,8 +1978,8 @@ namespace pxsim.visuals { private attachABEvents() { const bpState = this.board.buttonPairState; const stateButtons: Button[] = [bpState.aBtn, bpState.bBtn]; - const elButtonOuters = this.buttonsOuter.slice(6, 8); - const elButtons = this.buttons.slice(6, 8); + const elButtonOuters = this.buttonsOuter.slice(0,2); + const elButtons = this.buttons.slice(0,2); elButtonOuters.forEach((btn, index) => { let pressedTime: number; @@ -2015,6 +2015,7 @@ namespace pxsim.visuals { private attachAPlusBEvents() { const bpState = this.board.buttonPairState; + const stateButtons: Button[] = [bpState.aBtn, bpState.bBtn]; let pressedTime: number; // A+B pointerEvents.down.forEach(evid => this.buttonsOuter[2].addEventListener(evid, ev => { @@ -2024,6 +2025,8 @@ namespace pxsim.visuals { svg.fill(this.buttons[0], this.props.theme.buttonDown); svg.fill(this.buttons[1], this.props.theme.buttonDown); svg.fill(this.buttons[2], this.props.theme.buttonDown); + this.board.bus.queue(stateButtons[0].id, DAL.MICROBIT_BUTTON_EVT_DOWN); + this.board.bus.queue(stateButtons[1].id, DAL.MICROBIT_BUTTON_EVT_DOWN); this.board.bus.queue(bpState.abBtn.id, DAL.MICROBIT_BUTTON_EVT_DOWN); pressedTime = runtime.runningTime() })); @@ -2043,6 +2046,8 @@ namespace pxsim.visuals { svg.fill(this.buttons[1], this.props.theme.buttonUps[1]); svg.fill(this.buttons[2], this.props.theme.virtualButtonUp); + this.board.bus.queue(stateButtons[0].id, DAL.MICROBIT_BUTTON_EVT_UP); + this.board.bus.queue(stateButtons[1].id, DAL.MICROBIT_BUTTON_EVT_UP); this.board.bus.queue(bpState.abBtn.id, DAL.MICROBIT_BUTTON_EVT_UP); const currentTime = runtime.runningTime() if (currentTime - pressedTime > DAL.DEVICE_BUTTON_LONG_CLICK_TIME) diff --git a/targetconfig.json b/targetconfig.json index 2c9189c2..7821d4b4 100644 --- a/targetconfig.json +++ b/targetconfig.json @@ -5,6 +5,8 @@ "51bit/SFC", "51bit/SmartTools", "51bit/dfplayermini", + "coding4coconut/pxt-lcd128x160-st7735s", + "coding4coconut/pxt-oled128x128-sh1107", "Freenove/Makecode-Extension-Starter-Kit", "joernalraun/pxt-remember-int", "KitronikLtd/pxt-kitronik-I2C-16-servo",