Initial target repo setup to move to master (v3.10)
This commit is contained in:
@ -1,92 +0,0 @@
|
||||
/// <reference path="../node_modules/pxt-core/typings/globals/bluebird/index.d.ts"/>
|
||||
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
||||
/// <reference path="../node_modules/pxt-core/built/pxtrunner.d.ts"/>
|
||||
|
||||
//HACK: allows instructions.html to access pxtblocks without requiring simulator.html to import blocks as well
|
||||
if (!(<any>window).pxt) (<any>window).pxt = {};
|
||||
import pxtrunner = pxt.runner;
|
||||
import pxtdocs = pxt.docs;
|
||||
|
||||
namespace pxsim.instructions {
|
||||
export function drawInstructions() {
|
||||
pxsim.visuals.mkBoardView = (opts: pxsim.visuals.BoardViewOptions): pxsim.visuals.BoardView => {
|
||||
return new visuals.MicrobitBoardSvg({
|
||||
runtime: runtime,
|
||||
theme: visuals.randomTheme(),
|
||||
disableTilt: false,
|
||||
wireframe: opts.wireframe,
|
||||
});
|
||||
}
|
||||
|
||||
let getQsVal = parseQueryString();
|
||||
|
||||
//project name
|
||||
let name = getQsVal("name") || "Untitled";
|
||||
|
||||
// board def
|
||||
const boardDef = JSON.parse(getQsVal("board")) as pxsim.BoardDefinition;
|
||||
|
||||
//parts list
|
||||
let parts = (getQsVal("parts") || "").split(" ");
|
||||
parts.sort();
|
||||
|
||||
// parts definitions
|
||||
let partDefinitions = JSON.parse(getQsVal("partdefs") || "{}") as pxsim.Map<PartDefinition>
|
||||
|
||||
//fn args
|
||||
let fnArgs = JSON.parse((getQsVal("fnArgs") || "{}"));
|
||||
|
||||
//project code
|
||||
let tsCode = getQsVal("code");
|
||||
let tsPackage = getQsVal("package") || "";
|
||||
let codeSpinnerDiv = document.getElementById("proj-code-spinner");
|
||||
let codeContainerDiv = document.getElementById("proj-code-container");
|
||||
if (tsCode) {
|
||||
//we use the docs renderer to decompile the code to blocks and render it
|
||||
//TODO: render the blocks code directly
|
||||
let md =
|
||||
`\`\`\`blocks
|
||||
${tsCode}
|
||||
\`\`\`
|
||||
\`\`\`package
|
||||
${tsPackage}
|
||||
\`\`\`
|
||||
`
|
||||
|
||||
pxtdocs.requireMarked = function () { return (<any>window).marked; }
|
||||
pxtrunner.renderMarkdownAsync(codeContainerDiv, md)
|
||||
.done(function () {
|
||||
let codeSvg = $("#proj-code-container svg");
|
||||
if (codeSvg.length > 0) {
|
||||
//code rendered successfully as blocks
|
||||
codeSvg.css("width", "inherit");
|
||||
codeSvg.css("height", "inherit");
|
||||
//takes the svg out of the wrapper markdown
|
||||
codeContainerDiv.innerHTML = "";
|
||||
codeContainerDiv.appendChild(codeSvg[0]);
|
||||
} else {
|
||||
//code failed to convert to blocks, display as typescript instead
|
||||
codeContainerDiv.innerText = tsCode;
|
||||
}
|
||||
$(codeContainerDiv).show();
|
||||
$(codeSpinnerDiv).hide();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (name)
|
||||
$("#proj-title").text(name);
|
||||
|
||||
//init runtime
|
||||
if (!pxsim.initCurrentRuntime)
|
||||
pxsim.initCurrentRuntime = initRuntimeWithDalBoard;
|
||||
|
||||
renderParts({
|
||||
name,
|
||||
boardDef,
|
||||
parts,
|
||||
partDefinitions,
|
||||
fnArgs
|
||||
})
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ namespace pxsim {
|
||||
namespace pxsim.pins {
|
||||
export function digitalReadPin(pinId: number): number {
|
||||
let pin = getPin(pinId);
|
||||
if (!pin) return;
|
||||
if (!pin) return -1;
|
||||
pin.mode = PinFlags.Digital | PinFlags.Input;
|
||||
return pin.value > 100 ? 1 : 0;
|
||||
}
|
||||
@ -52,7 +52,7 @@ namespace pxsim.pins {
|
||||
|
||||
export function analogReadPin(pinId: number): number {
|
||||
let pin = getPin(pinId);
|
||||
if (!pin) return;
|
||||
if (!pin) return -1;
|
||||
pin.mode = PinFlags.Analog | PinFlags.Input;
|
||||
return pin.value || 0;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ namespace pxsim {
|
||||
this.data = data;
|
||||
}
|
||||
public print() {
|
||||
// console.debug(`Image id:${this.id} refs:${this.refcnt} size:${this.width}x${Image.height}`)
|
||||
console.debug(`Image id:${this.id} refs:${this.refcnt} size:${this.width}x${Image.height}`)
|
||||
}
|
||||
public get(x: number, y: number): number {
|
||||
if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0;
|
||||
@ -66,7 +66,7 @@ namespace pxsim {
|
||||
|
||||
export function createInternalImage(width: number): Image {
|
||||
let img = createImage(width)
|
||||
pxsim.noLeakTracking(img)
|
||||
pxsim.runtime.unregisterLiveObject(img, true)
|
||||
return img
|
||||
}
|
||||
|
||||
|
@ -66,13 +66,15 @@ namespace pxsim.control {
|
||||
board().bus.queue(id, evid)
|
||||
}
|
||||
|
||||
export function eventTimestamp() {
|
||||
return board().bus.getLastEventTime()
|
||||
}
|
||||
// TODO: (microbit master)
|
||||
// export function eventTimestamp() {
|
||||
// return board().bus.getLastEventTime()
|
||||
// }
|
||||
|
||||
export function eventValue() {
|
||||
return board().bus.getLastEventValue()
|
||||
}
|
||||
// TODO: (microbit master)
|
||||
// export function eventValue() {
|
||||
// return board().bus.getLastEventValue()
|
||||
// }
|
||||
}
|
||||
|
||||
namespace pxsim.pxtcore {
|
||||
@ -86,9 +88,10 @@ namespace pxsim.input {
|
||||
return runtime.runningTime();
|
||||
}
|
||||
|
||||
export function runningTimeMicros(): number {
|
||||
return runtime.runningTimeUs();
|
||||
}
|
||||
// TODO: (microbit master)
|
||||
// export function runningTimeMicros(): number {
|
||||
// return runtime.runningTimeUs();
|
||||
// }
|
||||
|
||||
export function calibrateCompass() {
|
||||
// device calibrates...
|
||||
|
@ -154,7 +154,8 @@ namespace pxsim.radio {
|
||||
board().radioState.bus.datagram.send({
|
||||
type: PacketPayloadType.STRING,
|
||||
groupId: board().radioState.groupId,
|
||||
bufferData: data
|
||||
// TODO: (microbit master)
|
||||
//bufferData: data
|
||||
});
|
||||
}
|
||||
|
||||
@ -211,9 +212,10 @@ namespace pxsim.radio {
|
||||
return initString(board().radioState.bus.datagram.lastReceived.payload.stringData || "");
|
||||
}
|
||||
|
||||
export function receivedBuffer(): RefBuffer {
|
||||
return new RefBuffer(board().radioState.bus.datagram.lastReceived.payload.bufferData || new Uint8Array(0))
|
||||
}
|
||||
// TODO: (microbit master)
|
||||
// export function receivedBuffer(): RefBuffer {
|
||||
// return new RefBuffer(board().radioState.bus.datagram.lastReceived.payload.bufferData || new Uint8Array(0))
|
||||
// }
|
||||
|
||||
export function receivedTime(): number {
|
||||
return board().radioState.bus.datagram.lastReceived.time;
|
||||
@ -230,12 +232,13 @@ namespace pxsim.radio {
|
||||
case PacketPayloadType.STRING:
|
||||
b.writeSerial(`{"t":${p.time},"s":${p.serial},"n":"${p.payload.stringData}"}\r\n`)
|
||||
break;
|
||||
case PacketPayloadType.BUFFER:
|
||||
const buf = new Uint8Array(p.payload.bufferData.buffer);
|
||||
let res = "";
|
||||
for (let i = 0; i < buf.length; ++i)
|
||||
res += String.fromCharCode(buf[i]);
|
||||
b.writeSerial(`{"t":${p.time},"s":${p.serial},"b":"${res}"}\r\n`)
|
||||
// TODO: (microbit master)
|
||||
// case PacketPayloadType.BUFFER:
|
||||
// const buf = new Uint8Array(p.payload.bufferData.buffer);
|
||||
// let res = "";
|
||||
// for (let i = 0; i < buf.length; ++i)
|
||||
// res += String.fromCharCode(buf[i]);
|
||||
// b.writeSerial(`{"t":${p.time},"s":${p.serial},"b":"${res}"}\r\n`)
|
||||
default:
|
||||
// unknown type
|
||||
break;
|
||||
|
@ -7,6 +7,9 @@
|
||||
"out": "../built/sim.js",
|
||||
"rootDir": ".",
|
||||
"newLine": "LF",
|
||||
"sourceMap": false
|
||||
"sourceMap": false,
|
||||
"lib": ["dom", "dom.iterable", "scripthost", "es6"],
|
||||
"types": ["jquery", "bluebird"],
|
||||
"typeRoots": ["../node_modules/@types"]
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
/// <reference path="../../node_modules/pxt-core/typings/globals/bluebird/index.d.ts"/>
|
||||
/// <reference path="../../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
||||
|
||||
namespace pxsim.visuals {
|
||||
@ -40,7 +39,7 @@ namespace pxsim.visuals {
|
||||
svg.fills(result.ledsOuter, defaultLedMatrixTheme.ledOff);
|
||||
|
||||
//turn off LEDs
|
||||
result.leds.forEach(l => (<SVGStylable><any>l).style.opacity = 0 + "");
|
||||
result.leds.forEach(l => (<SVGStyleElement><any>l).style.opacity = 0 + "");
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -103,7 +102,7 @@ namespace pxsim.visuals {
|
||||
public updateState() {
|
||||
if (this.state.disabled) {
|
||||
this.leds.forEach((led, i) => {
|
||||
let sel = (<SVGStylable><any>led)
|
||||
let sel = (<SVGStyleElement><any>led)
|
||||
sel.style.opacity = 0 + "";
|
||||
});
|
||||
return;
|
||||
@ -112,7 +111,7 @@ namespace pxsim.visuals {
|
||||
const bw = this.state.displayMode == pxsim.DisplayMode.bw
|
||||
const img = this.state.image;
|
||||
this.leds.forEach((led, i) => {
|
||||
let sel = (<SVGStylable><any>led)
|
||||
let sel = (<SVGStyleElement><any>led)
|
||||
let dx = i % this.DRAW_SIZE;
|
||||
let dy = (i - dx) / this.DRAW_SIZE;
|
||||
if (dx < this.ACTIVE_SIZE && dy < this.ACTIVE_SIZE) {
|
||||
|
@ -381,7 +381,7 @@ namespace pxsim.visuals {
|
||||
|
||||
if (state.ledMatrixState.disabled) {
|
||||
this.leds.forEach((led, i) => {
|
||||
const sel = (<SVGStylable><any>led)
|
||||
const sel = (<SVGStyleElement><any>led)
|
||||
sel.style.opacity = "0";
|
||||
})
|
||||
} else {
|
||||
@ -389,7 +389,7 @@ namespace pxsim.visuals {
|
||||
const img = state.ledMatrixState.image;
|
||||
const br = state.ledMatrixState.brigthness != undefined ? state.ledMatrixState.brigthness : 255;
|
||||
this.leds.forEach((led, i) => {
|
||||
const sel = (<SVGStylable><any>led)
|
||||
const sel = (<SVGStyleElement><any>led)
|
||||
let imgbr = bw ? (img.data[i] > 0 ? br : 0) : img.data[i];
|
||||
// correct brightness
|
||||
const opacity = imgbr > 0 ? imgbr / 255 * 155 + 100 : 0;
|
||||
@ -420,10 +420,10 @@ namespace pxsim.visuals {
|
||||
this.shakeButton = svg.child(this.g, "circle", { cx: 380, cy: 100, r: 16.5, class: "sim-shake" }) as SVGCircleElement;
|
||||
accessibility.makeFocusable(this.shakeButton);
|
||||
svg.fill(this.shakeButton, this.props.theme.virtualButtonUp)
|
||||
this.shakeButton.addEventListener(pointerEvents.down, ev => {
|
||||
pointerEvents.down.forEach(evid => this.shakeButton.addEventListener(evid, ev => {
|
||||
let state = this.board;
|
||||
svg.fill(this.shakeButton, this.props.theme.buttonDown);
|
||||
})
|
||||
}));
|
||||
this.shakeButton.addEventListener(pointerEvents.leave, ev => {
|
||||
let state = this.board;
|
||||
svg.fill(this.shakeButton, this.props.theme.virtualButtonUp);
|
||||
@ -955,11 +955,11 @@ namespace pxsim.visuals {
|
||||
});
|
||||
})
|
||||
this.pins.slice(0, 3).forEach((btn, index) => {
|
||||
btn.addEventListener(pointerEvents.down, ev => {
|
||||
pointerEvents.down.forEach(evid => btn.addEventListener(evid, ev => {
|
||||
let state = this.board;
|
||||
state.edgeConnectorState.pins[index].touched = true;
|
||||
this.updatePin(state.edgeConnectorState.pins[index], index);
|
||||
})
|
||||
}));
|
||||
btn.addEventListener(pointerEvents.leave, ev => {
|
||||
let state = this.board;
|
||||
state.edgeConnectorState.pins[index].touched = false;
|
||||
@ -982,11 +982,11 @@ namespace pxsim.visuals {
|
||||
let bpState = this.board.buttonPairState;
|
||||
let stateButtons = [bpState.aBtn, bpState.bBtn, bpState.abBtn];
|
||||
this.buttonsOuter.slice(0, 2).forEach((btn, index) => {
|
||||
btn.addEventListener(pointerEvents.down, ev => {
|
||||
pointerEvents.down.forEach(evid => btn.addEventListener(evid, ev => {
|
||||
let state = this.board;
|
||||
stateButtons[index].pressed = true;
|
||||
svg.fill(this.buttons[index], this.props.theme.buttonDown);
|
||||
})
|
||||
}));
|
||||
btn.addEventListener(pointerEvents.leave, ev => {
|
||||
let state = this.board;
|
||||
stateButtons[index].pressed = false;
|
||||
@ -1004,7 +1004,7 @@ namespace pxsim.visuals {
|
||||
this.board.bus.queue(stateButtons[index].id, DAL.MICROBIT_BUTTON_EVT_CLICK);
|
||||
});
|
||||
})
|
||||
this.buttonsOuter[2].addEventListener(pointerEvents.down, ev => {
|
||||
pointerEvents.down.forEach(evid => this.buttonsOuter[2].addEventListener(evid, ev => {
|
||||
let state = this.board;
|
||||
stateButtons[0].pressed = true;
|
||||
stateButtons[1].pressed = true;
|
||||
@ -1012,7 +1012,7 @@ 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.buttonsOuter[2].addEventListener(pointerEvents.leave, ev => {
|
||||
let state = this.board;
|
||||
stateButtons[0].pressed = false;
|
||||
|
Reference in New Issue
Block a user