diff --git a/docs/windows10.md b/docs/windows10.md new file mode 100644 index 00000000..fa1c09b9 --- /dev/null +++ b/docs/windows10.md @@ -0,0 +1,18 @@ +# Windows 10 App + +## Features + +The Windows 10 App provides all the existing features of codemicrobit.com plus the following ones: + +* **auto-upload**: the compiled .hex file is automatically deployed to all connected BBC micro:bits +* **serial piping**: all serial data sent by connected BBC micro:bit is automatically imported and analyzed in the editor. + +## Installing the pre-release app + +The following instructions allow to side-load the Windows 10 app. This is required until the app is in the store. + +* Search for “developer settings” in Windows 10 and put your computer in “Developer mode”. +* Download https://pxt.io/codemicrobit.appx and unzip it. **DO NOT try to install from a zipped folder.** +* Open the extracted folder, right-click on `Add-AppDevPackage.ps1` and click on `Run with PowerShell`. Follow the prompts… + +4) In order to communicate with the micro:bit via serial, you need to install the [ARM mbed driver](https://developer.mbed.org/handbook/Windows-serial-configuration). diff --git a/libs/microbit/control.ts b/libs/microbit/control.ts index e4667fef..7c479fe3 100644 --- a/libs/microbit/control.ts +++ b/libs/microbit/control.ts @@ -22,7 +22,7 @@ namespace control { /** * Display specified error code and stop the program. */ - //% shim=pxrt::panic + //% shim=pxtrt::panic export function panic(code:number) { } diff --git a/package.json b/package.json index a4215c75..e2fdb4c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pxt-microbit", - "version": "0.2.54", + "version": "0.2.60", "description": "BBC micro:bit target for PXT", "keywords": [ "JavaScript", @@ -29,6 +29,6 @@ "typescript": "^1.8.7" }, "dependencies": { - "pxt-core": "0.2.58" + "pxt-core": "0.2.62" } } diff --git a/sim/libmbit.ts b/sim/libmbit.ts index 98a0a02b..c2aad553 100644 --- a/sim/libmbit.ts +++ b/sim/libmbit.ts @@ -151,7 +151,7 @@ namespace pxsim.basic { if (interval < 0) return; let leds = createImageFromString(x.toString()); - if (x < 0 || x >= 10) scrollImage(leds, interval, 1); + if (x < 0 || x >= 10) ImageMethods.scrollImage(leds, interval, 1); else showLeds(leds, interval * 5); } @@ -163,7 +163,7 @@ namespace pxsim.basic { } else { let leds = createImageFromString(s); if (s.length == 1) showLeds(leds, interval * 5) - else scrollImage(leds, interval, 1); + else ImageMethods.scrollImage(leds, interval, 1); } } @@ -176,32 +176,12 @@ namespace pxsim.basic { runtime.queueDisplayUpdate() } - function scrollImage(leds: Image, interval: number, stride: number): void { - let cb = getResume() - let off = stride > 0 ? 0 : leds.width - 1; - let display = board().image; - - board().animationQ.enqueue({ - interval: interval, - frame: () => { - if (off >= leds.width || off < 0) return false; - stride > 0 ? display.shiftLeft(stride) : display.shiftRight(-stride); - let c = Math.min(stride, leds.width - off); - leds.copyTo(off, c, display, 5 - stride) - off += stride; - return true; - }, - whenDone: cb - }) - } - export function showAnimation(leds: Image, interval: number = 400): void { - scrollImage(leds, interval, 5); + ImageMethods.scrollImage(leds, interval, 5); } export function plotLeds(leds: Image): void { - leds.copyTo(0, 5, board().image, 0) - runtime.queueDisplayUpdate() + ImageMethods.plotImage(leds, 0); } } @@ -305,6 +285,25 @@ namespace pxsim.input { default: return Math.floor(Math.sqrt(acc.instantaneousAccelerationSquared())); } } + + export function rotation(kind : number) : number { + let b = board(); + let acc = b.accelerometer; + acc.activate(); + let x = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN); + let y = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN); + let z = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN); + + let roll = Math.atan2(y,z); + let pitch = Math.atan(-x / (y*Math.sin(roll) + z*Math.cos(roll))); + + let r = 0; + switch(kind) { + case 0: r = pitch; break; + case 1: r = roll; break; + } + return Math.floor(r / Math.PI * 180); + } export function setAccelerometerRange(range: number) { let b = board(); @@ -365,6 +364,12 @@ namespace pxsim.led { board().displayMode = mode; runtime.queueDisplayUpdate() } + + export function screenshot() : Image { + let img = createImage(5) + board().image.copyTo(0, 5, img, 0); + return img; + } } namespace pxsim.serial { @@ -516,5 +521,39 @@ namespace pxsim.ImageMethods { runtime.queueDisplayUpdate() } - // TODO ... + export function plotImage(leds: Image, offset:number): void { + leds.copyTo(offset, 5, board().image, 0) + runtime.queueDisplayUpdate() + } + + export function clear(i: Image) { + i.clear(); + } + + export function setPixelBrightness(i:Image, x:number, y:number, b:number) { + i.set(x,y,b); + } + + export function pixelBrightness(i:Image, x:number, y:number) : number { + return i.get(x,y); + } + + export function scrollImage(leds: Image, interval: number, stride: number): void { + let cb = getResume() + let off = stride > 0 ? 0 : leds.width - 1; + let display = board().image; + + board().animationQ.enqueue({ + interval: interval, + frame: () => { + if (off >= leds.width || off < 0) return false; + stride > 0 ? display.shiftLeft(stride) : display.shiftRight(-stride); + let c = Math.min(stride, leds.width - off); + leds.copyTo(off, c, display, 5 - stride) + off += stride; + return true; + }, + whenDone: cb + }) + } } diff --git a/sim/state.ts b/sim/state.ts index 9bd0c08b..317c6087 100644 --- a/sim/state.ts +++ b/sim/state.ts @@ -618,12 +618,12 @@ namespace pxsim { this.data = data; } public get(x: number, y: number): number { - // TODO range checking + if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0; return this.data[y * this.width + x]; } public set(x: number, y: number, v: number) { - // TODO range checking - this.data[y * this.width + x] = v; + if (x < 0 || x >= this.width || y < 0 || y >= 5) return; + this.data[y * this.width + x] = Math.max(0, Math.min(255, v)); } public copyTo(xSrcIndex: number, length: number, target: Image, xTargetIndex: number): void { for (let x = 0; x < length; x++) {