Compare commits

...

21 Commits

Author SHA1 Message Date
9b46145391 0.2.62 2016-04-12 19:45:01 -07:00
3182f7c546 Bump pxt-core to 0.2.65 2016-04-12 19:44:59 -07:00
8aed8548cc Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-04-12 19:11:38 -07:00
5e10bd7cc9 0.2.61 2016-04-12 19:08:41 -07:00
fddb9ff0d8 Bump pxt-core to 0.2.64 2016-04-12 19:08:39 -07:00
a0a0554633 Add String.substr 2016-04-12 19:08:26 -07:00
df92a3daae Remove unused file 2016-04-12 18:51:56 -07:00
26985f2813 Default enum arguments not supported yet 2016-04-12 17:57:16 -07:00
e7fd68e7ee Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-04-12 17:36:52 -07:00
e63b764568 Merge branch 'master' of github.com:Microsoft/kindscript-microbit 2016-04-12 17:10:46 -07:00
ef821e4b8b Add missing Image methods 2016-04-12 17:10:37 -07:00
b7a547c2b4 consisstent title 2016-04-12 16:00:06 -07:00
43d600ab38 0.2.60 2016-04-12 15:19:36 -07:00
b38145e46a Bump pxt-core to 0.2.62 2016-04-12 15:19:34 -07:00
b29f8faa14 0.2.59 2016-04-12 12:47:11 -07:00
e58dd64780 Bump pxt-core to 0.2.60 2016-04-12 12:47:09 -07:00
b1028abb04 implementing missing shims 2016-04-12 08:55:20 -07:00
9f0f63a79e implementing input.rotation 2016-04-12 08:38:48 -07:00
1c403e4ddb 0.2.58 2016-04-12 07:13:23 -07:00
9143b34d9d Bump pxt-core to 0.2.59 2016-04-12 07:13:22 -07:00
f5a41d7c37 0.2.57 2016-04-12 07:08:37 -07:00
9 changed files with 199 additions and 227 deletions

View File

@ -42,6 +42,18 @@ namespace String_ {
{
return ManagedString::EmptyString.leakData();
}
//%
StringData *substr(StringData *s, int start, int length)
{
if (length <= 0)
return mkEmpty();
if (start < 0)
start = max(s->len + start, 0);
length = min(length, s->len - start);
ManagedString x(s);
return x.substring(start, length).leakData();
}
}

View File

@ -1,181 +0,0 @@
/// <reference no-default-lib="true"/>
interface Array<T> {
/**
* Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
*/
//% shim=Array_::length
length: number;
/**
* Appends new elements to an array.
* @param items New elements of the Array.
*/
//% shim=Array_::push
push(item: T): void;
/**
* Removes the last element from an array and returns it.
*/
//% helper=arrayPop
pop(): T;
/**
* Reverses the elements in an Array.
*/
//% helper=arrayReverse
reverse(): void;
/**
* Removes the first element from an array and returns it.
*/
//% helper=arrayShift
shift(): T;
/**
* Returns a section of an array.
* @param start The beginning of the specified portion of the array.
* @param end The end of the specified portion of the array.
*/
//% helper=arraySlice
slice(start: number, end: number): T[];
/** Removes the first occurence of an object. Returns true if removed. */
//% shim=Array_::removeElement
removeElement(element:T) : boolean;
/** Removes the object at position index. */
//% shim=Array_::removeAt
removeAt(idx:number) : void;
/**
* Removes elements from an array.
* @param start The zero-based location in the array from which to start removing elements.
* @param deleteCount The number of elements to remove.
*/
//% helper=arraySplice
splice(start: number, deleteCount: number): void;
/**
* Inserts new elements at the start of an array.
* @param items Elements to insert at the start of the Array.
*/
//% helper=arrayUnshift
unshift(item:T): void;
/**
* Returns the index of the first occurrence of a value in an array.
* @param searchElement The value to locate in the array.
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
*/
//% shim=Array_::indexOf
indexOf(searchElement: T, fromIndex?: number): number;
[n: number]: T;
}
declare interface String {
/**
* Returns the character at the specified index.
* @param pos The zero-based index of the desired character.
*/
//% shim=String_::charAt
charAt(pos: number): string;
/**
* Returns the Unicode value of the character at the specified location.
* @param index The zero-based index of the desired character. If there is no character at the specified index, NaN is returned.
*/
//% shim=String_::charCodeAt
charCodeAt(index: number): number;
/**
* Returns a string that contains the concatenation of two or more strings.
* @param other The string to append to the end of the string.
*/
//% shim=String_::concat
concat(other: string): string;
/**
* Determines whether relative order of two strings (in ASCII encoding).
* @param that String to compare to target string
*/
//% shim=String_::compare
compare(that: string): number;
/** Returns the length of a String object. */
//% property shim=String_::length
length: number;
[index: number]: string;
}
/**
* Converts A string to an integer.
* @param s A string to convert into a number.
*/
//% shim=String_::toNumber
declare function parseInt(s: string): number;
interface Object {}
interface Function {}
interface IArguments {}
interface RegExp {}
declare interface Boolean {
/**
* Returns a string representation of an object.
*/
//% shim=Boolean_::toString
toString(): string;
}
declare namespace String {
/**
* Make a string from the given ASCII character code.
*/
//% shim=String_::fromCharCode
function fromCharCode(code: number): string;
}
declare interface Number {
/**
* Returns a string representation of a number.
*/
//% shim=Number_::toString
toString(): string;
}
/**
* Numbers and arithmetic operators
*/
declare namespace Math {
/**
* Returns the value of a base expression taken to a specified power.
* @param x The base value of the expression.
* @param y The exponent value of the expression.
*/
//% shim=Math_::pow
function pow(x: number, y: number): number;
/**
* Returns a pseudorandom number between 0 and `max`.
*/
//% shim=Math_::random
function random(max: number): number;
/**
* Returns the square root of a number.
* @param x A numeric expression.
*/
//% shim=Math_::sqrt
function sqrt(x: number): number;
}

View File

@ -25,6 +25,14 @@ namespace images {
}
namespace ImageMethods {
/**
* Plots the image at a given column to the screen
*/
//% help=images/plot-image
void plotImage(Image i, int xOffset = 0) {
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0, 0);
}
/**
* Shows an frame from the image at offset ``x offset``.
* @param xOffset TODO
@ -35,6 +43,16 @@ namespace ImageMethods {
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0);
}
/**
* Draws the ``index``-th frame of the image on the screen.
* @param xOffset TODO
*/
//% help=images/plot-frame weight=80
void plotFrame(Image i, int xOffset) {
// TODO showImage() used in original implementation
plotImage(i, xOffset * 5);
}
/**
* Scrolls an image .
* @param frameOffset x offset moved on each animation step, eg: 5, 1, -1
@ -51,14 +69,6 @@ namespace ImageMethods {
}
/**
* Plots the image at a given column to the screen
*/
//% help=images/plot-image
void plotImage(Image i, int xOffset = 0) {
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0, 0);
}
/**
* Sets all pixels off.
*/
@ -85,4 +95,52 @@ namespace ImageMethods {
if (pix < 0) return 0;
return pix;
}
/**
* Gets the width in columns
*/
//% help=functions/width
int width(Image i) {
return i->width;
}
/**
* Gets the height in rows (always 5)
*/
//% shim=
int height(Image i) {
return i->height;
}
/**
* Set a pixel state at position ``(x,y)``
* @param x TODO
* @param y TODO
* @param value TODO
*/
//% help=functions/set-pixel
void setPixel(Image i, int x, int y, bool value) {
setPixelBrightness(i, x, y, value ? 255 : 0);
}
/**
* Get the pixel state at position ``(x,y)``
* @param x TODO
* @param y TODO
*/
//% help=functions/pixel
bool pixel(Image i, int x, int y) {
return pixelBrightness(i, x, y) > 0;
}
/**
* Shows a particular frame of the image strip.
* @param frame TODO
*/
//% weight=70 help=functions/show-frame
void showFrame(Image i, int frame) {
showImage(i, frame * 5);
}
}

View File

@ -134,8 +134,9 @@ namespace music {
*/
//% help=music/beat weight=49
//% blockId=device_beat block="%fraction|beat"
export function beat(fraction : BeatFraction = BeatFraction.Whole): number {
export function beat(fraction?: BeatFraction): number {
init();
if (fraction == null) fraction = BeatFraction.Whole;
let beat = 60000 / beatsPerMinute;
if (fraction == BeatFraction.Whole) return beat;
else if (fraction == BeatFraction.Half) return beat / 2;

View File

@ -24,6 +24,12 @@ declare namespace images {
declare interface Image {
/**
* Plots the image at a given column to the screen
*/
//% help=images/plot-image xOffset.defl=0 shim=ImageMethods::plotImage
plotImage(xOffset?: number): void;
/**
* Shows an frame from the image at offset ``x offset``.
* @param xOffset TODO
@ -32,6 +38,13 @@ declare interface Image {
//% BUGblockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8 xOffset.defl=0 shim=ImageMethods::showImage
showImage(xOffset?: number): void;
/**
* Draws the ``index``-th frame of the image on the screen.
* @param xOffset TODO
*/
//% help=images/plot-frame weight=80 shim=ImageMethods::plotFrame
plotFrame(xOffset: number): void;
/**
* Scrolls an image .
* @param frameOffset x offset moved on each animation step, eg: 5, 1, -1
@ -41,12 +54,6 @@ declare interface Image {
//% BUGblockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8 frameOffset.defl=0 interval.defl=200 shim=ImageMethods::scrollImage
scrollImage(frameOffset?: number, interval?: number): void;
/**
* Plots the image at a given column to the screen
*/
//% help=images/plot-image xOffset.defl=0 shim=ImageMethods::plotImage
plotImage(xOffset?: number): void;
/**
* Sets all pixels off.
*/
@ -64,6 +71,42 @@ declare interface Image {
*/
//% help= shim=ImageMethods::pixelBrightness
pixelBrightness(x: number, y: number): number;
/**
* Gets the width in columns
*/
//% help=functions/width shim=ImageMethods::width
width(): number;
/**
* Gets the height in rows (always 5)
*/
//% shim= shim=ImageMethods::height
height(): number;
/**
* Set a pixel state at position ``(x,y)``
* @param x TODO
* @param y TODO
* @param value TODO
*/
//% help=functions/set-pixel shim=ImageMethods::setPixel
setPixel(x: number, y: number, value: boolean): void;
/**
* Get the pixel state at position ``(x,y)``
* @param x TODO
* @param y TODO
*/
//% help=functions/pixel shim=ImageMethods::pixel
pixel(x: number, y: number): boolean;
/**
* Shows a particular frame of the image strip.
* @param frame TODO
*/
//% weight=70 help=functions/show-frame shim=ImageMethods::showFrame
showFrame(frame: number): void;
}

View File

@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.2.56",
"version": "0.2.62",
"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.65"
}
}

View File

@ -1,7 +1,7 @@
{
"id": "microbit",
"name": "code micro:bit",
"title": "micro:bit",
"title": "code micro:bit",
"corepkg": "microbit",
"bundleddirs": [
"libs/microbit",

View File

@ -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
})
}
}

View File

@ -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++) {