Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4e57e0165 | ||
|
|
a55ddcbab3 | ||
|
|
f58508afa2 | ||
|
|
4b92de7516 | ||
|
|
6176963504 |
@@ -150,12 +150,17 @@ namespace control {
|
|||||||
*/
|
*/
|
||||||
//% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source|with value %value=control_event_value" blockExternalInputs=1
|
//% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source|with value %value=control_event_value" blockExternalInputs=1
|
||||||
//% mode.defl=CREATE_AND_QUEUE
|
//% mode.defl=CREATE_AND_QUEUE
|
||||||
void raiseEvent(int src, int value, EventCreationMode mode) { }
|
void raiseEvent(int src, int value, EventCreationMode mode) {
|
||||||
|
MicroBitEvent evt(src, value, (MicroBitEventLaunchMode)mode);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raises an event in the event bus.
|
* Raises an event in the event bus.
|
||||||
*/
|
*/
|
||||||
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source|with value %value=control_event_value"
|
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source|with value %value=control_event_value"
|
||||||
//% blockExternalInputs=1 blockStatement=1
|
//% blockExternalInputs=1 blockStatement=1
|
||||||
void onEvent(int src, int value, Action handler) { }
|
void onEvent(int src, int value, Action handler) {
|
||||||
|
// not exposed yet
|
||||||
|
// bitvm::registerWithDal(src, value, handler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
libs/microbit/enums.d.ts
vendored
8
libs/microbit/enums.d.ts
vendored
@@ -1,4 +1,6 @@
|
|||||||
// Auto-generated. Do not edit.
|
// Auto-generated. Do not edit.
|
||||||
|
declare namespace images {
|
||||||
|
}
|
||||||
declare namespace basic {
|
declare namespace basic {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,11 +34,11 @@ declare namespace basic {
|
|||||||
|
|
||||||
|
|
||||||
declare enum TouchPin {
|
declare enum TouchPin {
|
||||||
//% enumval=uBit.io.P0
|
//% enumval=micro_bit::ioP0
|
||||||
P0 = 0,
|
P0 = 0,
|
||||||
//% enumval=uBit.io.P1
|
//% enumval=micro_bit::ioP1
|
||||||
P1 = 1,
|
P1 = 1,
|
||||||
//% enumval=uBit.io.P2
|
//% enumval=micro_bit::ioP2
|
||||||
P2 = 2,
|
P2 = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace game {
|
|||||||
var _countdownPause: number = 0;
|
var _countdownPause: number = 0;
|
||||||
var _level: number = 1;
|
var _level: number = 1;
|
||||||
var _gameId: number = 0;
|
var _gameId: number = 0;
|
||||||
var img: images.Image;
|
var img: Image;
|
||||||
var sprites: LedSprite[];
|
var sprites: LedSprite[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
87
libs/microbit/images.cpp
Normal file
87
libs/microbit/images.cpp
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#include "BitVM.h"
|
||||||
|
|
||||||
|
typedef ImageData* Image;
|
||||||
|
|
||||||
|
//% color=45 weight=31
|
||||||
|
namespace images {
|
||||||
|
/**
|
||||||
|
* Creates an image that fits on the LED screen.
|
||||||
|
*/
|
||||||
|
//% weight=75 help=images/create-image
|
||||||
|
//% blockId=device_build_image block="create image"
|
||||||
|
Image createImage(ImageLiteral leds) {
|
||||||
|
return MicroBitImage(getbytes(leds)).clone().leakData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an image with 2 frames.
|
||||||
|
*/
|
||||||
|
//% weight=74 help=images/create-big-image
|
||||||
|
//% blockId=device_build_big_image block="create big image" imageLiteral=2
|
||||||
|
Image createBigImage(ImageLiteral leds) {
|
||||||
|
return createImage(leds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ImageMethods {
|
||||||
|
/**
|
||||||
|
* Shows an frame from the image at offset ``x offset``.
|
||||||
|
* @param xOffset TODO
|
||||||
|
*/
|
||||||
|
//% help=images/show-image weight=80 async
|
||||||
|
//% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8
|
||||||
|
void showImage(Image i, int xOffset = 0) {
|
||||||
|
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scrolls an image .
|
||||||
|
* @param frameOffset x offset moved on each animation step, eg: 5, 1, -1
|
||||||
|
* @param interval time between each animation step in milli seconds, eg: 200
|
||||||
|
*/
|
||||||
|
//% help=images/show-image weight=79 async
|
||||||
|
//% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8
|
||||||
|
void scrollImage(Image id, int frameOffset = 0, int interval = 200) {
|
||||||
|
MicroBitImage i(id);
|
||||||
|
if (i.getWidth() <= 5)
|
||||||
|
showImage(id, 0);
|
||||||
|
else
|
||||||
|
uBit.display.animate(i, interval, frameOffset, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
//% help=images/clear
|
||||||
|
void clear(Image i) {
|
||||||
|
MicroBitImage(i).clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a specific pixel brightness at a given position
|
||||||
|
*/
|
||||||
|
//% help=
|
||||||
|
void setPixelBrightness(Image i, int x, int y, int value) {
|
||||||
|
MicroBitImage(i).setPixelValue(x, y, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the pixel brightness ([0..255]) at a given position
|
||||||
|
*/
|
||||||
|
//% help=
|
||||||
|
int pixelBrightness(Image i, int x, int y) {
|
||||||
|
int pix = MicroBitImage(i).getPixelValue(x, y);
|
||||||
|
if (pix < 0) return 0;
|
||||||
|
return pix;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
//% color=45 weight=31
|
|
||||||
namespace images {
|
|
||||||
/**
|
|
||||||
* Creates an image that fits on the LED screen.
|
|
||||||
*/
|
|
||||||
//% weight=75 help=images/create-image
|
|
||||||
//% blockId=device_build_image block="create image" imageLiteral=1
|
|
||||||
export function createImage(leds: string): Image {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an image with 2 frames.
|
|
||||||
*/
|
|
||||||
//% weight=74 help=images/create-big-image
|
|
||||||
//% blockId=device_build_big_image block="create big image" imageLiteral=2
|
|
||||||
export function createBigImage(leds: string): Image {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Image {
|
|
||||||
/**
|
|
||||||
* Shows an frame from the image at offset ``x offset``.
|
|
||||||
* @param xOffset TODO
|
|
||||||
*/
|
|
||||||
//% help=images/show-image weight=80 shim=micro_bit::showImage
|
|
||||||
//% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8
|
|
||||||
public showImage(xOffset: number = 0): void {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Scrolls an image .
|
|
||||||
* @param frameOffset x offset moved on each animation step, eg: 5, 1, -1
|
|
||||||
* @param interval time between each animation step in milli seconds, eg: 200
|
|
||||||
*/
|
|
||||||
//% help=images/show-image weight=79 shim=micro_bit::scrollImage async
|
|
||||||
//% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8
|
|
||||||
public scrollImage(frameOffset: number = 0, interval : number = 200) {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plots the image at a given column to the screen
|
|
||||||
*/
|
|
||||||
public plotImage(xOffset: number = 0): void {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets all pixels off.
|
|
||||||
*/
|
|
||||||
public clear(): void {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a specific pixel brightness at a given position
|
|
||||||
*/
|
|
||||||
public setPixelBrightness(x: number, y: number, v: number): void {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the pixel brightness ([0..255]) at a given position
|
|
||||||
*/
|
|
||||||
public pixelBrightness(x: number, y: number): number {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -26,11 +26,11 @@ enum class Rotation {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum class TouchPin {
|
enum class TouchPin {
|
||||||
//% enumval=uBit.io.P0
|
//% enumval=micro_bit::ioP0
|
||||||
P0,
|
P0,
|
||||||
//% enumval=uBit.io.P1
|
//% enumval=micro_bit::ioP1
|
||||||
P1,
|
P1,
|
||||||
//% enumval=uBit.io.P2
|
//% enumval=micro_bit::ioP2
|
||||||
P2,
|
P2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
"shims.d.ts",
|
"shims.d.ts",
|
||||||
"core.d.ts",
|
"core.d.ts",
|
||||||
"mbit.ts",
|
"mbit.ts",
|
||||||
"images.ts",
|
"images.cpp",
|
||||||
"basic.cpp",
|
"basic.cpp",
|
||||||
"input.cpp",
|
"input.cpp",
|
||||||
"input.ts",
|
"input.ts",
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ namespace led {
|
|||||||
* Takes a screenshot of the LED screen and returns an image.
|
* Takes a screenshot of the LED screen and returns an image.
|
||||||
*/
|
*/
|
||||||
//% shim=uBit.display.screenShot help=led/screenshot
|
//% shim=uBit.display.screenShot help=led/screenshot
|
||||||
export function screenshot(): images.Image {
|
export function screenshot(): Image {
|
||||||
/*
|
/*
|
||||||
let img: Image;
|
let img: Image;
|
||||||
img = image.createImage("");
|
img = image.createImage("");
|
||||||
|
|||||||
@@ -1,56 +1,56 @@
|
|||||||
enum DigitalPin {
|
enum DigitalPin {
|
||||||
//% enumval=uBit.io.P0
|
//% enumval=micro_bit::ioP0
|
||||||
P0,
|
P0,
|
||||||
//% enumval=uBit.io.P1
|
//% enumval=micro_bit::ioP1
|
||||||
P1,
|
P1,
|
||||||
//% enumval=uBit.io.P2
|
//% enumval=micro_bit::ioP2
|
||||||
P2,
|
P2,
|
||||||
//% enumval=uBit.io.P3
|
//% enumval=micro_bit::ioP3
|
||||||
P3,
|
P3,
|
||||||
//% enumval=uBit.io.P4
|
//% enumval=micro_bit::ioP4
|
||||||
P4,
|
P4,
|
||||||
//% enumval=uBit.io.P5
|
//% enumval=micro_bit::ioP5
|
||||||
P5,
|
P5,
|
||||||
//% enumval=uBit.io.P6
|
//% enumval=micro_bit::ioP6
|
||||||
P6,
|
P6,
|
||||||
//% enumval=uBit.io.P7
|
//% enumval=micro_bit::ioP7
|
||||||
P7,
|
P7,
|
||||||
//% enumval=uBit.io.P8
|
//% enumval=micro_bit::ioP8
|
||||||
P8,
|
P8,
|
||||||
//% enumval=uBit.io.P9
|
//% enumval=micro_bit::ioP9
|
||||||
P9,
|
P9,
|
||||||
//% enumval=uBit.io.P10
|
//% enumval=micro_bit::ioP10
|
||||||
P10,
|
P10,
|
||||||
//% enumval=uBit.io.P11
|
//% enumval=micro_bit::ioP11
|
||||||
P11,
|
P11,
|
||||||
//% enumval=uBit.io.P12
|
//% enumval=micro_bit::ioP12
|
||||||
P12,
|
P12,
|
||||||
//% enumval=uBit.io.P13
|
//% enumval=micro_bit::ioP13
|
||||||
P13,
|
P13,
|
||||||
//% enumval=uBit.io.P14
|
//% enumval=micro_bit::ioP14
|
||||||
P14,
|
P14,
|
||||||
//% enumval=uBit.io.P15
|
//% enumval=micro_bit::ioP15
|
||||||
P15,
|
P15,
|
||||||
//% enumval=uBit.io.P16
|
//% enumval=micro_bit::ioP16
|
||||||
P16,
|
P16,
|
||||||
//% enumval=uBit.io.P19
|
//% enumval=micro_bit::ioP19
|
||||||
P19,
|
P19,
|
||||||
//% enumval=uBit.io.P20
|
//% enumval=micro_bit::ioP20
|
||||||
P20,
|
P20,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum AnalogPin {
|
enum AnalogPin {
|
||||||
//% enumval=uBit.io.P0
|
//% enumval=micro_bit::ioP0
|
||||||
P0,
|
P0,
|
||||||
//% enumval=uBit.io.P1
|
//% enumval=micro_bit::ioP1
|
||||||
P1,
|
P1,
|
||||||
//% enumval=uBit.io.P2
|
//% enumval=micro_bit::ioP2
|
||||||
P2,
|
P2,
|
||||||
//% enumval=uBit.io.P3
|
//% enumval=micro_bit::ioP3
|
||||||
P3,
|
P3,
|
||||||
//% enumval=uBit.io.P4
|
//% enumval=micro_bit::ioP4
|
||||||
P4,
|
P4,
|
||||||
//% enumval=uBit.io.P10
|
//% enumval=micro_bit::ioP10
|
||||||
P10,
|
P10,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
78
libs/microbit/shims.d.ts
vendored
78
libs/microbit/shims.d.ts
vendored
@@ -1,6 +1,70 @@
|
|||||||
// Auto-generated. Do not edit.
|
// Auto-generated. Do not edit.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//% color=45 weight=31
|
||||||
|
declare namespace images {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an image that fits on the LED screen.
|
||||||
|
*/
|
||||||
|
//% weight=75 help=images/create-image
|
||||||
|
//% blockId=device_build_image block="create image" imageLiteral=1 shim=images::createImage
|
||||||
|
function createImage(leds: string): Image;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an image with 2 frames.
|
||||||
|
*/
|
||||||
|
//% weight=74 help=images/create-big-image
|
||||||
|
//% blockId=device_build_big_image block="create big image" imageLiteral=2 shim=images::createBigImage
|
||||||
|
function createBigImage(leds: string): Image;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
declare interface Image {
|
||||||
|
/**
|
||||||
|
* Shows an frame from the image at offset ``x offset``.
|
||||||
|
* @param xOffset TODO
|
||||||
|
*/
|
||||||
|
//% help=images/show-image weight=80 async
|
||||||
|
//% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8 xOffset.defl=0 shim=ImageMethods::showImage
|
||||||
|
showImage(xOffset?: number): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scrolls an image .
|
||||||
|
* @param frameOffset x offset moved on each animation step, eg: 5, 1, -1
|
||||||
|
* @param interval time between each animation step in milli seconds, eg: 200
|
||||||
|
*/
|
||||||
|
//% help=images/show-image weight=79 async
|
||||||
|
//% blockId=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.
|
||||||
|
*/
|
||||||
|
//% help=images/clear shim=ImageMethods::clear
|
||||||
|
clear(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a specific pixel brightness at a given position
|
||||||
|
*/
|
||||||
|
//% help= shim=ImageMethods::setPixelBrightness
|
||||||
|
setPixelBrightness(x: number, y: number, value: number): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the pixel brightness ([0..255]) at a given position
|
||||||
|
*/
|
||||||
|
//% help= shim=ImageMethods::pixelBrightness
|
||||||
|
pixelBrightness(x: number, y: number): number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides access to basic micro:bit functionality.
|
* Provides access to basic micro:bit functionality.
|
||||||
*/
|
*/
|
||||||
@@ -14,8 +78,7 @@ declare namespace basic {
|
|||||||
//% help=basic/show-number
|
//% help=basic/show-number
|
||||||
//% weight=96
|
//% weight=96
|
||||||
//% blockId=device_show_number block="show|number %number" blockGap=8 icon="\uf1ec"
|
//% blockId=device_show_number block="show|number %number" blockGap=8 icon="\uf1ec"
|
||||||
//% async
|
//% async interval.defl=150 shim=basic::showNumber
|
||||||
//% interval.defl=150 shim=basic::showNumber
|
|
||||||
function showNumber(value: number, interval?: number): void;
|
function showNumber(value: number, interval?: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,8 +90,7 @@ declare namespace basic {
|
|||||||
//% weight=95 blockGap=8
|
//% weight=95 blockGap=8
|
||||||
//% imageLiteral=1 async
|
//% imageLiteral=1 async
|
||||||
//% blockId=device_show_leds
|
//% blockId=device_show_leds
|
||||||
//% block="show leds" icon="\uf00a"
|
//% block="show leds" icon="\uf00a" interval.defl=400 shim=basic::showLeds
|
||||||
//% interval.defl=400 imageLiteral=1 shim=basic::showLeds
|
|
||||||
function showLeds(leds: string, interval?: number): void;
|
function showLeds(leds: string, interval?: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,8 +102,7 @@ declare namespace basic {
|
|||||||
//% weight=87 blockGap=8
|
//% weight=87 blockGap=8
|
||||||
//% block="show|string %text" icon="\uf031"
|
//% block="show|string %text" icon="\uf031"
|
||||||
//% async
|
//% async
|
||||||
//% blockId=device_print_message
|
//% blockId=device_print_message interval.defl=150 shim=basic::showString
|
||||||
//% interval.defl=150 shim=basic::showString
|
|
||||||
function showString(text: string, interval?: number): void;
|
function showString(text: string, interval?: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,8 +117,7 @@ declare namespace basic {
|
|||||||
* @param leds TODO
|
* @param leds TODO
|
||||||
* @param interval TODO
|
* @param interval TODO
|
||||||
*/
|
*/
|
||||||
//% help=basic/show-animation shim=micro_bit::showAnimation imageLiteral=1 async
|
//% help=basic/show-animation shim=micro_bit::showAnimation imageLiteral=1 async interval.defl=400 shim=basic::showAnimation
|
||||||
//% interval.defl=400 imageLiteral=1 shim=basic::showAnimation
|
|
||||||
function showAnimation(leds: string, interval?: number): void;
|
function showAnimation(leds: string, interval?: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,7 +171,7 @@ declare namespace control {
|
|||||||
* @param mode optional definition of how the event should be processed after construction (default is CREATE_AND_QUEUE).
|
* @param mode optional definition of how the event should be processed after construction (default is CREATE_AND_QUEUE).
|
||||||
*/
|
*/
|
||||||
//% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source|with value %value=control_event_value" blockExternalInputs=1
|
//% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source|with value %value=control_event_value" blockExternalInputs=1
|
||||||
//% mode.defl=CREATE_AND_QUEUE shim=control::raiseEvent
|
//% mode.defl=1 shim=control::raiseEvent
|
||||||
function raiseEvent(src: number, value: number, mode: EventCreationMode ): void;
|
function raiseEvent(src: number, value: number, mode: EventCreationMode ): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "kindscript-microbit",
|
"name": "kindscript-microbit",
|
||||||
"version": "0.2.10",
|
"version": "0.2.11",
|
||||||
"description": "BBC micro:bit target for KindScript",
|
"description": "BBC micro:bit target for KindScript",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"JavaScript",
|
"JavaScript",
|
||||||
@@ -30,6 +30,6 @@
|
|||||||
"typescript": "^1.8.7"
|
"typescript": "^1.8.7"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"kindscript": "0.2.10"
|
"kindscript": "0.2.11"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user