Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump pxt 10 and some other changes #1052

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
118e7af
consume-pxteditor-changes-and-upgrade-code
THEb0nny Feb 7, 2024
f02e716
Update deploy.ts
THEb0nny Feb 7, 2024
20158f9
pxt-core-and-common-packages-bump
THEb0nny Mar 18, 2024
969d2e5
Update extension.ts
THEb0nny Mar 19, 2024
6ac7b2e
Update field_music.ts
THEb0nny Mar 19, 2024
c6f7cb1
Update field_ports.ts
THEb0nny Mar 19, 2024
c0a712c
Update field_music.ts
THEb0nny Mar 19, 2024
5816038
Update field_color.ts
THEb0nny Mar 19, 2024
53a46bf
Update field_music.ts
THEb0nny Mar 19, 2024
62efa39
Update field_music.ts
THEb0nny Mar 19, 2024
536dbad
Update field_motors.ts
THEb0nny Mar 19, 2024
23e2f7c
Update field_brickbuttons.ts
THEb0nny Mar 20, 2024
9bf4852
Update field_motors.ts
THEb0nny Mar 20, 2024
e67e668
Update field_ports.ts
THEb0nny Mar 20, 2024
bc459b5
del_field_ports
THEb0nny Mar 20, 2024
dbaff3f
Update field_brickbuttons.ts
THEb0nny Mar 20, 2024
ec13cf1
Update ultrasonic.ts
THEb0nny Mar 20, 2024
83c0e91
Update field_color.ts
THEb0nny Mar 20, 2024
329bd21
turnRatio-del
THEb0nny Mar 20, 2024
0c685bc
Update field_color.ts
THEb0nny Mar 20, 2024
c63d81e
return-applyColour()
THEb0nny Mar 21, 2024
cd9b5fe
bump_10-0-13
THEb0nny Mar 25, 2024
54eb2e5
bump-10-0-14
THEb0nny Mar 29, 2024
679c698
bump-10-0-16
THEb0nny Apr 8, 2024
ee43257
bump-10.0.18
THEb0nny Apr 16, 2024
2ca3b41
bump-pxt-10.0.20
THEb0nny May 1, 2024
e5d1ff7
fix-button-select
THEb0nny May 3, 2024
a6b84b0
Update field_brickbuttons.ts
THEb0nny May 6, 2024
2e52c18
additions-for-downloading-bluetooth
THEb0nny May 6, 2024
e2ce518
add-functionality-and-upgrade -motors-blocks
THEb0nny May 7, 2024
15d278e
bump-pxt-10.0.23
THEb0nny Jun 13, 2024
6eb8fdb
Update output.ts
THEb0nny Jun 14, 2024
ffaeb88
bump-pxt-10.2.3-and-common-packages-10.0.3
THEb0nny Aug 1, 2024
6c1e22e
bump-pxt-core-10.2.15
THEb0nny Aug 27, 2024
935be39
bump-pxt-10.3.8-and-common-packages-12.1.1
THEb0nny Sep 17, 2024
9eb35cc
bump-pxt-11.2.3
THEb0nny Oct 2, 2024
d15e682
bump_pxt_11.2.10
THEb0nny Oct 14, 2024
bcb9af8
downloadArea-delete-fill
THEb0nny Oct 22, 2024
ac75468
bump-pxt-10.2.15
THEb0nny Oct 22, 2024
a312679
Update light.ts
THEb0nny Oct 22, 2024
9cdace9
suppo-undetectable-analog-sensors
THEb0nny Oct 22, 2024
4bc9901
bump_pxt_11.2.20
THEb0nny Oct 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions editor/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../node_modules/pxt-core/built/pxteditor.d.ts"/>
/// <reference path="../node_modules/pxt-core/localtypings/pxteditor.d.ts"/>
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>

import HF2 = pxt.HF2;
Expand All @@ -14,6 +14,7 @@ export function debug() {
}

// Web Serial API https://wicg.github.io/serial/
// https://www.npmjs.com/package/@types/web-bluetooth
// chromium bug https://bugs.chromium.org/p/chromium/issues/detail?id=884928
// Under experimental features in Chrome Desktop 77+
enum ParityType {
Expand Down Expand Up @@ -63,26 +64,37 @@ class WebSerialPackageIO implements pxt.packetio.PacketIO {
console.log(`serial: new io`)
}

bufferSize(buffer: Uint8Array) {
return HF2.read16(buffer, 0) + 2;
}

async readSerialAsync() {
this._reader = this.port.readable.getReader();
let buffer: Uint8Array;
const reader = this._reader;
while (reader === this._reader) { // will change if we recycle the connection
const { done, value } = await this._reader.read()
const { done, value } = await this._reader.read();
if (!buffer) buffer = value;
else { // concat
let tmp = new Uint8Array(buffer.length + value.byteLength)
tmp.set(buffer, 0)
tmp.set(value, buffer.length)
let tmp = new Uint8Array(buffer.length + value.byteLength);
tmp.set(buffer, 0);
tmp.set(value, buffer.length);
buffer = tmp;
}
if (buffer) {
let size = HF2.read16(buffer, 0);
if (buffer.length == size + 2) {
let size = this.bufferSize(buffer);
if (buffer.length == size) {
this.onData(new Uint8Array(buffer));
buffer = undefined;
} else if (buffer.length > size) {
console.warn(`Received larger bufer then command command: ${buffer.length} recieved but waiting for ${size}`);
let tmp = buffer.slice(0, size - 1);
this.onData(new Uint8Array(tmp));
tmp = buffer.slice(size, buffer.length - 1);
buffer = tmp;
console.debug(`Next buffer size: ${this.bufferSize(buffer)}`);
} else {
console.warn("Incomplete command " + size);
console.warn(`Incomplete command: ${buffer.length} recieved but waiting for ${size}. Keep waiting...`);
}
}
}
Expand All @@ -97,6 +109,9 @@ class WebSerialPackageIO implements pxt.packetio.PacketIO {
const serial = (<any>navigator).serial;
if (serial) {
try {
// const requestOptions: SerialPortRequestOptions = {
// filters: [{ usbVendorId: 0x0694, usbProductId: 0x0005 }],
// };
const requestOptions: SerialPortRequestOptions = {};
const port = await serial.requestPort(requestOptions);

Expand Down
3 changes: 1 addition & 2 deletions editor/extension.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/// <reference path="../node_modules/pxt-core/localtypings/pxtarget.d.ts" />
/// <reference path="../node_modules/pxt-core/built/pxtblocks.d.ts" />
/// <reference path="../node_modules/pxt-core/built/pxtcompiler.d.ts" />
/// <reference path="../node_modules/pxt-core/built/pxtlib.d.ts" />
/// <reference path="../node_modules/pxt-core/built/pxteditor.d.ts"/>
/// <reference path="../node_modules/pxt-core/localtypings/pxteditor.d.ts"/>
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>

import { deployCoreAsync, initAsync } from "./deploy";
Expand Down
114 changes: 114 additions & 0 deletions editor/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,128 @@ export class Ev3Wrapper {
})
}

dumpInputCmd(buf : Uint8Array) {
log(`Reply size: ${HF2.read16(buf, 0)}`);
log(`Message counter: ${HF2.read16(buf, 2)}`);
log(`Reply type: ${buf[4]}`);
switch (buf[5]) {
case 0x03:
log("System command: System command reply OK");
break;
case 0x05:
log("System command: System command reply ERROR");
break;
case 0x00:
log("Reply Status SUCCESS");
break;
case 0x01:
log("Reply Status UNKNOWN_HANDLE");
break;
case 0x02:
log("Reply Status HANDLE_NOT_READY");
break;
case 0x03:
log("Reply Status CORRUPT_FILE");
break;
case 0x04:
log("Reply Status NO_HANDLES_AVAILABLE");
break;
case 0x05:
log("Reply Status NO_PERMISSION");
break;
case 0x06:
log("Reply Status ILLEGAL_PATH");
break;
case 0x07:
log("Reply Status FILE_EXITS");
break;
case 0x08:
log("Reply Status END_OF_FILE");
break;
case 0x09:
log("Reply Status SIZE_ERROR");
break;
case 0x0A:
log("Reply Status UNKNOWN_ERROR");
break;
case 0x0B:
log("Reply Status ILLEGAL_FILENAME");
break;
case 0x0C:
log("Reply Status ILLEGAL_CONNECTION");
break;
}
}

dumpOutputCmd(buf: Uint8Array) {
log(`Command size: ${HF2.read16(buf, 0)}`);
log(`Message counter: ${HF2.read16(buf, 2)}`);
log(`Command type: ${buf[4]}`);
switch (buf[5]) {
case 0x01:
log("System command, reply required");
break;
case 0x81:
log("System command, reply not require");
break;
case 0x92:
log("System command: Begin file download");
break;
case 0x93:
log("System command: Continue file download");
break;
case 0x94:
log("System command: Begin file upload");
break;
case 0x95:
log("System command: Continue file upload");
break;
case 0x96:
log("System command: Begin get bytes from a file (while writing to the file)");
break;
case 0x97:
log("System command: Continue get byte from a file (while writing to the file)");
break;
case 0x98:
log("System command: Close file handle");
break;
case 0x99:
log("System command: List files");
break;
case 0x9A:
log("System command: Continue list files");
break;
case 0x9B:
log("System command: Create directory");
break;
case 0x9C:
log("System command: Delete");
break;
case 0x9D:
log("System command: List handles");
break;
case 0x9E:
log("System command: Write to mailbox");
break;
case 0x9F:
log("System command: Transfer trusted pin code to brick");
break;
case 0xA0:
log("System command: Restart the brick in Firmware update mode");
break;
}
}

talkAsync(buf: Uint8Array, altResponse = 0) {
return this.lock.enqueue("talk", () => {
this.msgs.drain()
if (this.dataDump)
log("TALK: " + U.toHex(buf))
this.dumpOutputCmd(buf)
return this.io.sendPacketAsync(buf)
.then(() => this.msgs.shiftAsync(5000))
.then(resp => {
this.dumpInputCmd(resp)
if (resp[2] != buf[2] || resp[3] != buf[3])
U.userError("msg count de-sync")
if (buf[4] == 1) {
Expand Down
18 changes: 5 additions & 13 deletions fieldeditors/extension.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
/// <reference path="../node_modules/pxt-core/built/pxteditor.d.ts"/>
/// <reference path="../node_modules/pxt-core/localtypings/pxteditor.d.ts"/>
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>

import { FieldPorts } from "./field_ports";
const Blockly = pxt.blocks.requireBlockly();

import { FieldMotors } from "./field_motors";
import { FieldBrickButtons } from "./field_brickbuttons";
import { FieldColorEnum } from "./field_color";
import { FieldMusic } from "./field_music";

pxt.editor.initFieldExtensionsAsync = function (opts: pxt.editor.FieldExtensionOptions): Promise<pxt.editor.FieldExtensionResult> {
pxt.debug('loading pxt-ev3 target extensions...')
pxt.debug('loading pxt-ev3 target extensions...');
updateBlocklyShape();
const res: pxt.editor.FieldExtensionResult = {
fieldEditors: [{
selector: "ports",
editor: FieldPorts
}, {
selector: "motors",
editor: FieldMotors
}, {
Expand Down Expand Up @@ -132,10 +130,4 @@ function updateBlocklyShape() {
*/
(Blockly as any).Flyout.prototype.MARGIN = 8;

}

// When require()d from node, bind the global pxt namespace
// namespace pxt {
// export const dummyExport = 1;
// }
// eval("if (typeof process === 'object' && process + '' === '[object process]') pxt = global.pxt")
}
58 changes: 32 additions & 26 deletions fieldeditors/field_brickbuttons.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
/// <reference path="../node_modules/pxt-core/localtypings/blockly.d.ts"/>
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
/// <reference path="../node_modules/pxt-core/localtypings/pxtblockly.d.ts"/>

export interface FieldPortsOptions extends Blockly.FieldCustomDropdownOptions {
import { BlockSvg } from "blockly";

const Blockly = pxt.blocks.requireBlockly();

export interface FieldBrickButtonsOptions {
data: string;
columns?: string;
width?: string;
}

export class FieldBrickButtons extends Blockly.FieldDropdown implements Blockly.FieldCustom {
public isFieldCustom_ = true;
export class FieldBrickButtons extends Blockly.FieldDropdown {

// Width in pixels
private width_: number;
public isFieldCustom_ = true;

// Columns in grid
private columns_: number;
private width_: number; // Width in pixels
private columns_: number; // Columns in grid

private savedPrimary_: string;

constructor(text: string, options: FieldPortsOptions, validator?: Function) {
super(options.data);

this.columns_ = parseInt(options.columns) || 4;
constructor(text: string, options: FieldBrickButtonsOptions, validator?: Function) {
super(options.data as any);
this.columns_ = parseInt(options.columns) || 1;
this.width_ = parseInt(options.width) || 150;
}

Expand Down Expand Up @@ -84,7 +86,7 @@ export class FieldBrickButtons extends Blockly.FieldDropdown implements Blockly.
d: 'M 157.78865,189.01028 108.18908,189.38233 70.654464,150.794 86.323259,135.4895 v -28.08625 h 14.101921 v 16.11144 a 12.006218,12.006218 0 0 0 11.85346,11.9788 c 11.59882,0.1841 43.13227,0 43.13227,0 a 10.18472,10.18472 0 0 0 10.38059,-10.38058 v -17.70966 h 14.39179 v 28.08632 l 15.3045,15.3045 z'
})

const buttons = [buttonEnter, buttonLeft, buttonRight, buttonTop, buttonBottom];
const buttons = [buttonEnter, buttonLeft, buttonTop, buttonBottom, buttonRight];
const options = this.getOptions();
for (let i = 0, option: any; option = options[i]; i++) {
let content = (options[i] as any)[0]; // Human-readable text or image.
Expand All @@ -96,20 +98,24 @@ export class FieldBrickButtons extends Blockly.FieldDropdown implements Blockly.
const title = pxsim.svg.child(button, 'title');
title.textContent = content;

Blockly.bindEvent_(button, 'click', this, this.buttonClick_);
Blockly.bindEvent_(button, 'mouseup', this, this.buttonClick_);
button.addEventListener("click", (event) => {
this.buttonClick_(event);
});
button.addEventListener("mouseup", (event) => {
this.buttonClick_(event);
});
// These are applied manually instead of using the :hover pseudoclass
// because Android has a bad long press "helper" menu and green highlight
// that we must prevent with ontouchstart preventDefault
Blockly.bindEvent_(button, 'mousedown', button, function (e) {
this.setAttribute('stroke', '#ffffff');
e.preventDefault();
button.addEventListener("mousedown", (event) => {
button.setAttribute('stroke', '#ffffff');
event.preventDefault();
});
Blockly.bindEvent_(button, 'mouseover', button, function () {
this.setAttribute('stroke', '#ffffff');
button.addEventListener("mouseover", (event) => {
button.setAttribute('stroke', '#ffffff');
});
Blockly.bindEvent_(button, 'mouseout', button, function () {
this.setAttribute('stroke', 'transparent');
button.addEventListener("mouseout", (event) => {
button.setAttribute('stroke', 'transparent');
});

button.setAttribute('data-value', value);
Expand All @@ -124,12 +130,12 @@ export class FieldBrickButtons extends Blockly.FieldDropdown implements Blockly.
Blockly.DropDownDiv.showPositionedByField(this, this.onHide_.bind(this));

// Update colour to look selected.
let source = this.sourceBlock_ as Blockly.BlockSvg;
let source = this.sourceBlock_ as BlockSvg;
this.savedPrimary_ = source?.getColour();
if (source?.isShadow()) {
source.setColour(source.getColourTertiary());
} else if (this.borderRect_) {
this.borderRect_.setAttribute('fill', (this.sourceBlock_ as Blockly.BlockSvg).getColourTertiary());
this.borderRect_.setAttribute('fill', (this.sourceBlock_ as BlockSvg).getColourTertiary());
}
}

Expand All @@ -155,7 +161,7 @@ export class FieldBrickButtons extends Blockly.FieldDropdown implements Blockly.
content.removeAttribute('aria-activedescendant');
(content as HTMLElement).style.width = '';
// Update color (deselect) on dropdown hide
let source = this.sourceBlock_ as Blockly.BlockSvg;
let source = this.sourceBlock_ as BlockSvg;
if (source?.isShadow()) {
source.setColour(this.savedPrimary_);
} else if (this.borderRect_) {
Expand Down
Loading