Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 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
200746f
bump-pxt-11.3.4-and-common-packages-12.2.1
THEb0nny Nov 29, 2024
8003521
bump-pxt-11.4.7-and-common-packages-12.3.5
THEb0nny Apr 1, 2025
5fd4c91
Update storage-core.ts
THEb0nny May 4, 2025
d846656
bump-pxt-11.4.28-and-common-packages-12.3.31
THEb0nny Jun 13, 2025
c77058b
Update field_motors.ts
THEb0nny Jun 14, 2025
0d0b93c
Update field_brickbuttons.ts
THEb0nny Jun 14, 2025
419f6d9
Update field_brickbuttons.ts
THEb0nny Jun 14, 2025
0cad591
Update field_music.ts
THEb0nny Jun 14, 2025
df15c6d
Update storage-core.ts
THEb0nny Jun 15, 2025
72cb0d2
Update field_motors.ts, field_music.ts
THEb0nny Jun 15, 2025
f5ff38f
Update field_music.ts
THEb0nny Jun 15, 2025
0548d6b
Update field_music.ts
THEb0nny Jun 18, 2025
251c326
theme-support
THEb0nny Jun 18, 2025
0932aab
Update field_music.ts
THEb0nny Jun 18, 2025
58a22a9
Update field_music.ts
THEb0nny Jun 18, 2025
b34009d
Bluetooth log fix and improvements
THEb0nny Jun 18, 2025
ac0cd8e
Update deploy.ts
THEb0nny Jun 18, 2025
c0f295a
allow_underscores_in_filename
THEb0nny Jun 23, 2025
b028d10
bump-pxt-11.4.40
THEb0nny Jul 1, 2025
69de621
Update blockly.less
THEb0nny Jul 1, 2025
9a02f69
changes_in_MMapMethods.buf()_for_sim_recovery
THEb0nny Jul 10, 2025
650b8a1
bump-pxt-12.1.5-and-common-packages-13.1.0
THEb0nny Aug 4, 2025
35e898d
bump-pxt-12.2.8-and-common-packages-13.1.4
THEb0nny Nov 15, 2025
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
49 changes: 36 additions & 13 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 All @@ -23,6 +24,7 @@ enum ParityType {
"mark",
"space"
}

declare interface SerialOptions {
baudRate?: number;
databits?: number;
Expand All @@ -34,15 +36,18 @@ declare interface SerialOptions {
xoff?: boolean;
xany?: boolean;
}

type SerialPortInfo = pxt.Map<string>;
type SerialPortRequestOptions = any;

declare class SerialPort {
open(options?: SerialOptions): Promise<void>;
close(): void;
readonly readable: any;
readonly writable: any;
//getInfo(): SerialPortInfo;
// getInfo(): SerialPortInfo;
}

declare interface Serial extends EventTarget {
onconnect: any;
ondisconnect: any;
Expand All @@ -60,29 +65,40 @@ class WebSerialPackageIO implements pxt.packetio.PacketIO {
private _writer: any;

constructor(private port: SerialPort, private options: SerialOptions) {
console.log(`serial: new io`)
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);
Comment on lines +95 to +97
Copy link

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using slice(0, size - 1) drops the last byte of the intended payload. It should be slice(0, size) to include all bytes of the frame header and body.

Suggested change
let tmp = buffer.slice(0, size - 1);
this.onData(new Uint8Array(tmp));
tmp = buffer.slice(size, buffer.length - 1);
let tmp = buffer.slice(0, size);
this.onData(new Uint8Array(tmp));
tmp = buffer.slice(size, buffer.length);

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember what this change was connected with, but Bluetooth download didn't break for me.

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...`);
Comment on lines +94 to +101
Copy link

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix spelling and grammar: "bufer" → "buffer", "then" → "than", and "recieved" → "received".

Copilot uses AI. Check for mistakes.
}
}
}
Expand All @@ -93,11 +109,14 @@ class WebSerialPackageIO implements pxt.packetio.PacketIO {
}

static portIos: WebSerialPackageIO[] = [];

static async mkPacketIOAsync(): Promise<pxt.packetio.PacketIO> {
const serial = (<any>navigator).serial;
if (serial) {
try {
const requestOptions: SerialPortRequestOptions = {};
const requestOptions: SerialPortRequestOptions = {
// filters: [{ usbVendorId: 0x0694, usbProductId: 0x0005 }],
};
const port = await serial.requestPort(requestOptions);

let io = WebSerialPackageIO.portIos.filter(i => i.port == port)[0];
Expand All @@ -111,7 +130,7 @@ class WebSerialPackageIO implements pxt.packetio.PacketIO {
}
return io;
} catch (e) {
console.log(`connection error`, e)
console.log(`Connection error`, e)
}
}
throw new Error("could not open serial port");
Expand All @@ -123,7 +142,8 @@ class WebSerialPackageIO implements pxt.packetio.PacketIO {
}

private openAsync() {
console.log(`serial: opening port`)
console.log(`serial: Opening port`);
// this.io.onConnectionChanged();
if (!!this._reader) return Promise.resolve();
this._reader = undefined;
this._writer = undefined;
Expand Down Expand Up @@ -189,6 +209,7 @@ function hf2Async() {

let useHID = false;
let useWebSerial = false;

export function initAsync(): Promise<void> {
if (pxt.U.isNodeJS) {
// doesn't seem to work ATM
Expand Down Expand Up @@ -234,6 +255,7 @@ async function cleanupAsync() {
}

let initPromise: Promise<Ev3Wrapper>

function initHidAsync() { // needs to run within a click handler
if (initPromise)
return initPromise
Expand Down Expand Up @@ -261,6 +283,7 @@ const rbfTemplate = `
4c45474f580000006d000100000000001c000000000000000e000000821b038405018130813e8053
74617274696e672e2e2e0084006080XX00448581644886488405018130813e80427965210084000a
`

export function deployCoreAsync(resp: pxtc.CompileResult) {
let filename = resp.downloadFileBaseName || "pxt"
filename = filename.replace(/^lego-/, "")
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
104 changes: 101 additions & 3 deletions editor/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,112 @@ export class Ev3Wrapper {
})
}

dumpInputCmd(buf : Uint8Array) {
log(`Reply size: ${HF2.read16(buf, 0)}, Message counter: ${HF2.read16(buf, 2)}, Reply type: ${buf[4]} (${buf[4] === 0x03 ? "System command reply OK" : buf[4] === 0x05 ? "System command reply ERROR" : "Unknown"})`);
switch (buf[6]) {
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)}, Message counter: ${HF2.read16(buf, 2)}, Command type: ${buf[4]} (${buf[4] === 0x01 ? "System command, reply required" : buf[4] === 0x81 ? "System command, reply not required" : "Unknown"})`);
switch (buf[5]) {
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 All @@ -132,7 +230,7 @@ export class Ev3Wrapper {
}

flashAsync(path: string, file: Uint8Array) {
log(`write ${file.length} bytes to ${path}`)
log(`Write ${file.length} bytes to ${path}`)

let handle = -1

Expand Down Expand Up @@ -274,13 +372,13 @@ export class Ev3Wrapper {
reconnectAsync(first = false): Promise<void> {
this.resetState()
if (first) return this.initAsync()
log(`reconnect`);
log(`Reconnect`);
return this.io.reconnectAsync()
.then(() => this.initAsync())
}

disconnectAsync() {
log(`disconnect`);
log(`Disconnect`);
return this.io.disconnectAsync()
}
}
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")
}
Loading