Compare commits
31 Commits
Author | SHA1 | Date | |
---|---|---|---|
5dbbc2266f | |||
2a22001e02 | |||
214ff25995 | |||
f4768d99ff | |||
8792f9fe36 | |||
3d45bef910 | |||
3de6b33163 | |||
3f1c03ea51 | |||
a4063d636d | |||
92b5b76171 | |||
51d285b0b0 | |||
4d8afdd3ae | |||
13b21ad275 | |||
d90a43a6d8 | |||
6fd14e718d | |||
c79f043529 | |||
3a676c7151 | |||
0023710209 | |||
0756091e8c | |||
8144df0023 | |||
b2137e2622 | |||
39b30c8ae1 | |||
1c5d6316cc | |||
6d4d681898 | |||
7053fd1490 | |||
e7a49acac0 | |||
d76cfb6e2e | |||
538f08052d | |||
b6fed71c58 | |||
6c86f98b66 | |||
8b46698f50 |
15
.vscode/settings.json
vendored
15
.vscode/settings.json
vendored
@ -1,5 +1,20 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"file.autoSave": "afterDelay",
|
||||
"files.watcherExclude": {
|
||||
"**/.git/objects/**": true,
|
||||
"**/built/**": true,
|
||||
"**/node_modules/**": true,
|
||||
"**/yotta_modules/**": true,
|
||||
"**/yotta_targets": true,
|
||||
"**/pxt_modules/**": true
|
||||
},
|
||||
"search.exclude": {
|
||||
"**/node_modules": true,
|
||||
"**/yotta_modules/**": true,
|
||||
"**/yotta_targets": true,
|
||||
"**/pxt_modules/**": true
|
||||
},
|
||||
"tslint.enable": true,
|
||||
"tslint.rulesDirectory": "node_modules/tslint-microsoft-contrib"
|
||||
}
|
@ -9,16 +9,16 @@ let execAsync: (cmd: string, options?: { cwd?: string }) => Promise<Buffer> = Pr
|
||||
let readDirAsync = Promise.promisify(fs.readdir)
|
||||
|
||||
|
||||
export function deployCoreAsync(res: ts.pxt.CompileResult) {
|
||||
export function deployCoreAsync(res: pxtc.CompileResult) {
|
||||
return getBitDrivesAsync()
|
||||
.then(drives => {
|
||||
if (drives.length == 0) {
|
||||
console.log("cannot find any drives to deploy to")
|
||||
} else {
|
||||
console.log(`copy ${ts.pxt.BINARY_HEX} to ` + drives.join(", "))
|
||||
console.log(`copy ${pxtc.BINARY_HEX} to ` + drives.join(", "))
|
||||
}
|
||||
return Promise.map(drives, d =>
|
||||
writeFileAsync(d + ts.pxt.BINARY_HEX, res.outfiles[ts.pxt.BINARY_HEX])
|
||||
writeFileAsync(d + pxtc.BINARY_HEX, res.outfiles[pxtc.BINARY_HEX])
|
||||
.then(() => {
|
||||
console.log("wrote hex file to " + d)
|
||||
}))
|
||||
|
BIN
docs/favicon.ico
Normal file
BIN
docs/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
@ -23,7 +23,7 @@ To remove a package, click on the garbage button in the file list next to the pa
|
||||
|
||||
## Publishing packages
|
||||
|
||||
Packages can be published from the pxt command line. We are still sorting out the details.
|
||||
Packages can be published from the pxt command line. Check out [the docs](https://www.pxt.io/packages).
|
||||
|
||||
## Localizing packages
|
||||
|
||||
|
@ -1,21 +1,28 @@
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta name="twitter:site" content="@codethemicrobit" />
|
||||
<meta name="twitter:title" content="@name@" />
|
||||
<meta name="twitter:description" content="@description@" />
|
||||
<meta name="twitter:image" content="@cardLogo@" />
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta name="twitter:site" content="@codethemicrobit" />
|
||||
<meta name="twitter:title" content="@name@" />
|
||||
<meta name="twitter:description" content="@description@" />
|
||||
<meta name="twitter:image" content="@cardLogo@" />
|
||||
|
||||
<meta property="og:title" content="@name@" />
|
||||
<meta property="og:site_name" content="code the micro:bit" />
|
||||
<meta property="og:description" content="@description@" />
|
||||
<meta property="og:image" content="@cardLogo@" />
|
||||
<!--
|
||||
<meta property="og:title" content="@name@" />
|
||||
<meta property="og:site_name" content="code the micro:bit" />
|
||||
<meta property="og:description" content="@description@" />
|
||||
<meta property="og:image" content="@cardLogo@" />
|
||||
<!--
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="fb:app_id" content="" />
|
||||
-->
|
||||
|
||||
<link rel="apple-touch-icon" href="@appLogo@">
|
||||
<link rel="icon" type="image/png" href="@appLogo@">
|
||||
<link rel="mask-icon" href="https://az851932.vo.msecnd.net/pub/zwxazere/safari-pinned-tab.svg" color="#000000">
|
||||
<link rel="shortcut icon" href="@appLogo@">
|
||||
<meta name="theme-color" content="@accentColor@">
|
||||
|
||||
<link rel="apple-touch-icon" href="@appLogo@">
|
||||
<link rel="icon" type="image/png" href="@appLogo@">
|
||||
<link rel="mask-icon" href="https://az851932.vo.msecnd.net/pub/zwxazere/safari-pinned-tab.svg" color="#000000">
|
||||
<link rel="shortcut icon" href="@appLogo@">
|
||||
<meta name="theme-color" content="@accentColor@">
|
||||
|
||||
<style>
|
||||
#root .avatar .avatar-image {
|
||||
background-image: url(https://az851932.vo.msecnd.net/pub/jovrytni/microbit.simplified.svg);
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
</style>
|
@ -32,6 +32,7 @@ namespace bluetooth {
|
||||
*/
|
||||
//% help=bluetooth/start-io-pin-service
|
||||
//% blockId=bluetooth_start_io_pin_service block="bluetooth io pin service" blockGap=8
|
||||
//% parts="bluetooth"
|
||||
void startIOPinService() {
|
||||
new MicroBitIOPinService(*uBit.ble, uBit.io);
|
||||
}
|
||||
@ -41,6 +42,7 @@ namespace bluetooth {
|
||||
*/
|
||||
//% help=bluetooth/start-led-service
|
||||
//% blockId=bluetooth_start_led_service block="bluetooth led service" blockGap=8
|
||||
//% parts="bluetooth"
|
||||
void startLEDService() {
|
||||
new MicroBitLEDService(*uBit.ble, uBit.display);
|
||||
}
|
||||
@ -50,6 +52,7 @@ namespace bluetooth {
|
||||
*/
|
||||
//% help=bluetooth/start-temperature-service
|
||||
//% blockId=bluetooth_start_temperature_service block="bluetooth temperature service" blockGap=8
|
||||
//% parts="bluetooth"
|
||||
void startTemperatureService() {
|
||||
new MicroBitTemperatureService(*uBit.ble, uBit.thermometer);
|
||||
}
|
||||
@ -59,6 +62,7 @@ namespace bluetooth {
|
||||
*/
|
||||
//% help=bluetooth/start-magnetometer-service
|
||||
//% blockId=bluetooth_start_magnetometer_service block="bluetooth magnetometer service" blockGap=8
|
||||
//% parts="bluetooth"
|
||||
void startMagnetometerService() {
|
||||
new MicroBitMagnetometerService(*uBit.ble, uBit.compass);
|
||||
}
|
||||
@ -68,6 +72,7 @@ namespace bluetooth {
|
||||
*/
|
||||
//% help=bluetooth/start-accelerometer-service
|
||||
//% blockId=bluetooth_start_accelerometer_service block="bluetooth accelerometer service" blockGap=8
|
||||
//% parts="bluetooth"
|
||||
void startAccelerometerService() {
|
||||
new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer);
|
||||
}
|
||||
@ -77,6 +82,7 @@ namespace bluetooth {
|
||||
*/
|
||||
//% help=bluetooth/start-button-service
|
||||
//% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8
|
||||
//% parts="bluetooth"
|
||||
void startButtonService() {
|
||||
new MicroBitButtonService(*uBit.ble);
|
||||
}
|
||||
@ -86,6 +92,7 @@ namespace bluetooth {
|
||||
*/
|
||||
//% help=bluetooth/start-uart-service
|
||||
//% blockId=bluetooth_start_uart_service block="bluetooth uart service" blockGap=8
|
||||
//% parts="bluetooth"
|
||||
void startUartService() {
|
||||
if (uart) return;
|
||||
// 61 octet buffer size is 3 x (MTU - 3) + 1
|
||||
@ -99,6 +106,7 @@ namespace bluetooth {
|
||||
*/
|
||||
//% help=bluetooth/uart-write
|
||||
//% blockId=bluetooth_uart_write block="bluetooth uart write %data" blockGap=8
|
||||
//% parts="bluetooth"
|
||||
void uartWrite(StringData *data) {
|
||||
startUartService();
|
||||
uart->send(ManagedString(data));
|
||||
@ -109,6 +117,7 @@ namespace bluetooth {
|
||||
*/
|
||||
//% help=bluetooth/uart-read
|
||||
//% blockId=bluetooth_uart_read block="bluetooth uart read %del=bluetooth_uart_delimiter_conv" blockGap=8
|
||||
//% parts="bluetooth"
|
||||
StringData* uartRead(StringData *del) {
|
||||
startUartService();
|
||||
return uart->readUntil(ManagedString(del)).leakData();
|
||||
@ -119,6 +128,7 @@ namespace bluetooth {
|
||||
*/
|
||||
//% blockId="bluetooth_uart_delimiter_conv" block="%del"
|
||||
//% weight=1
|
||||
//% parts="bluetooth"
|
||||
StringData* delimiters(Delimiters del) {
|
||||
ManagedString c("\n\n,$:.#"[max(0, min(6, (int)del))]);
|
||||
return c.leakData();
|
||||
@ -129,6 +139,7 @@ namespace bluetooth {
|
||||
*/
|
||||
//% help=bluetooth/on-bluetooth-connected weight=20
|
||||
//% blockId=bluetooth_on_connected block="on bluetooth connected" blockGap=8
|
||||
//% parts="bluetooth"
|
||||
void onBluetoothConnected(Action body) {
|
||||
registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, body);
|
||||
}
|
||||
@ -139,6 +150,7 @@ namespace bluetooth {
|
||||
*/
|
||||
//% help=bluetooth/on-bluetooth-disconnected weight=19
|
||||
//% blockId=bluetooth_on_disconnected block="on bluetooth disconnected"
|
||||
//% parts="bluetooth"
|
||||
void onBluetoothDisconnected(Action body) {
|
||||
registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, body);
|
||||
}
|
||||
|
36
libs/microbit-bluetooth/shims.d.ts
vendored
36
libs/microbit-bluetooth/shims.d.ts
vendored
@ -11,70 +11,80 @@ declare namespace bluetooth {
|
||||
* Starts the Bluetooth IO pin service.
|
||||
*/
|
||||
//% help=bluetooth/start-io-pin-service
|
||||
//% blockId=bluetooth_start_io_pin_service block="bluetooth io pin service" blockGap=8 shim=bluetooth::startIOPinService
|
||||
//% blockId=bluetooth_start_io_pin_service block="bluetooth io pin service" blockGap=8
|
||||
//% parts="bluetooth" shim=bluetooth::startIOPinService
|
||||
function startIOPinService(): void;
|
||||
|
||||
/**
|
||||
* Starts the Bluetooth LED service
|
||||
*/
|
||||
//% help=bluetooth/start-led-service
|
||||
//% blockId=bluetooth_start_led_service block="bluetooth led service" blockGap=8 shim=bluetooth::startLEDService
|
||||
//% blockId=bluetooth_start_led_service block="bluetooth led service" blockGap=8
|
||||
//% parts="bluetooth" shim=bluetooth::startLEDService
|
||||
function startLEDService(): void;
|
||||
|
||||
/**
|
||||
* Starts the Bluetooth temperature service
|
||||
*/
|
||||
//% help=bluetooth/start-temperature-service
|
||||
//% blockId=bluetooth_start_temperature_service block="bluetooth temperature service" blockGap=8 shim=bluetooth::startTemperatureService
|
||||
//% blockId=bluetooth_start_temperature_service block="bluetooth temperature service" blockGap=8
|
||||
//% parts="bluetooth" shim=bluetooth::startTemperatureService
|
||||
function startTemperatureService(): void;
|
||||
|
||||
/**
|
||||
* Starts the Bluetooth magnetometer service
|
||||
*/
|
||||
//% help=bluetooth/start-magnetometer-service
|
||||
//% blockId=bluetooth_start_magnetometer_service block="bluetooth magnetometer service" blockGap=8 shim=bluetooth::startMagnetometerService
|
||||
//% blockId=bluetooth_start_magnetometer_service block="bluetooth magnetometer service" blockGap=8
|
||||
//% parts="bluetooth" shim=bluetooth::startMagnetometerService
|
||||
function startMagnetometerService(): void;
|
||||
|
||||
/**
|
||||
* Starts the Bluetooth accelerometer service
|
||||
*/
|
||||
//% help=bluetooth/start-accelerometer-service
|
||||
//% blockId=bluetooth_start_accelerometer_service block="bluetooth accelerometer service" blockGap=8 shim=bluetooth::startAccelerometerService
|
||||
//% blockId=bluetooth_start_accelerometer_service block="bluetooth accelerometer service" blockGap=8
|
||||
//% parts="bluetooth" shim=bluetooth::startAccelerometerService
|
||||
function startAccelerometerService(): void;
|
||||
|
||||
/**
|
||||
* Starts the Bluetooth button service
|
||||
*/
|
||||
//% help=bluetooth/start-button-service
|
||||
//% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8 shim=bluetooth::startButtonService
|
||||
//% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8
|
||||
//% parts="bluetooth" shim=bluetooth::startButtonService
|
||||
function startButtonService(): void;
|
||||
|
||||
/**
|
||||
* Starts the Bluetooth UART service
|
||||
*/
|
||||
//% help=bluetooth/start-uart-service
|
||||
//% blockId=bluetooth_start_uart_service block="bluetooth uart service" blockGap=8 shim=bluetooth::startUartService
|
||||
//% blockId=bluetooth_start_uart_service block="bluetooth uart service" blockGap=8
|
||||
//% parts="bluetooth" shim=bluetooth::startUartService
|
||||
function startUartService(): void;
|
||||
|
||||
/**
|
||||
* Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device.
|
||||
*/
|
||||
//% help=bluetooth/uart-write
|
||||
//% blockId=bluetooth_uart_write block="bluetooth uart write %data" blockGap=8 shim=bluetooth::uartWrite
|
||||
//% blockId=bluetooth_uart_write block="bluetooth uart write %data" blockGap=8
|
||||
//% parts="bluetooth" shim=bluetooth::uartWrite
|
||||
function uartWrite(data: string): void;
|
||||
|
||||
/**
|
||||
* Reads from the Bluetooth UART service buffer, returning its contents when the specified delimiter character is encountered.
|
||||
*/
|
||||
//% help=bluetooth/uart-read
|
||||
//% blockId=bluetooth_uart_read block="bluetooth uart read %del=bluetooth_uart_delimiter_conv" blockGap=8 shim=bluetooth::uartRead
|
||||
//% blockId=bluetooth_uart_read block="bluetooth uart read %del=bluetooth_uart_delimiter_conv" blockGap=8
|
||||
//% parts="bluetooth" shim=bluetooth::uartRead
|
||||
function uartRead(del: string): string;
|
||||
|
||||
/**
|
||||
* Returns the delimiter corresponding string
|
||||
*/
|
||||
//% blockId="bluetooth_uart_delimiter_conv" block="%del"
|
||||
//% weight=1 shim=bluetooth::delimiters
|
||||
//% weight=1
|
||||
//% parts="bluetooth" shim=bluetooth::delimiters
|
||||
function delimiters(del: Delimiters): string;
|
||||
|
||||
/**
|
||||
@ -82,7 +92,8 @@ declare namespace bluetooth {
|
||||
* @param body Code to run when a Bluetooth connection is established
|
||||
*/
|
||||
//% help=bluetooth/on-bluetooth-connected weight=20
|
||||
//% blockId=bluetooth_on_connected block="on bluetooth connected" blockGap=8 shim=bluetooth::onBluetoothConnected
|
||||
//% blockId=bluetooth_on_connected block="on bluetooth connected" blockGap=8
|
||||
//% parts="bluetooth" shim=bluetooth::onBluetoothConnected
|
||||
function onBluetoothConnected(body: () => void): void;
|
||||
|
||||
/**
|
||||
@ -90,7 +101,8 @@ declare namespace bluetooth {
|
||||
* @param body Code to run when a Bluetooth connection is lost
|
||||
*/
|
||||
//% help=bluetooth/on-bluetooth-disconnected weight=19
|
||||
//% blockId=bluetooth_on_disconnected block="on bluetooth disconnected" shim=bluetooth::onBluetoothDisconnected
|
||||
//% blockId=bluetooth_on_disconnected block="on bluetooth disconnected"
|
||||
//% parts="bluetooth" shim=bluetooth::onBluetoothDisconnected
|
||||
function onBluetoothDisconnected(body: () => void): void;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ namespace basic {
|
||||
//% weight=96
|
||||
//% blockId=device_show_number block="show|number %number" blockGap=8 icon="\uf1ec"
|
||||
//% async
|
||||
//% parts="ledmatrix"
|
||||
void showNumber(int value, int interval = 150) {
|
||||
if (interval < 0)
|
||||
return;
|
||||
@ -37,6 +38,7 @@ namespace basic {
|
||||
//% imageLiteral=1 async
|
||||
//% blockId=device_show_leds
|
||||
//% block="show leds" icon="\uf00a"
|
||||
//% parts="ledmatrix"
|
||||
void showLeds(ImageLiteral leds, int interval = 400) {
|
||||
uBit.display.print(MicroBitImage(imageBytes(leds)), 0, 0, 0, interval);
|
||||
}
|
||||
@ -51,6 +53,7 @@ namespace basic {
|
||||
//% block="show|string %text" icon="\uf031"
|
||||
//% async
|
||||
//% blockId=device_print_message
|
||||
//% parts="ledmatrix"
|
||||
void showString(StringData *text, int interval = 150) {
|
||||
if (interval < 0)
|
||||
return;
|
||||
@ -71,6 +74,7 @@ namespace basic {
|
||||
*/
|
||||
//% help=basic/clear-screen weight=79
|
||||
//% blockId=device_clear_display block="clear screen" icon="\uf12d"
|
||||
//% parts="ledmatrix"
|
||||
void clearScreen() {
|
||||
uBit.display.image.clear();
|
||||
}
|
||||
@ -81,6 +85,7 @@ namespace basic {
|
||||
* @param interval time in milliseconds between each redraw
|
||||
*/
|
||||
//% help=basic/show-animation imageLiteral=1 async
|
||||
//% parts="ledmatrix"
|
||||
void showAnimation(ImageLiteral leds, int interval = 400) {
|
||||
uBit.display.animate(MicroBitImage(imageBytes(leds)), interval, 5, 0);
|
||||
}
|
||||
@ -90,6 +95,7 @@ namespace basic {
|
||||
* @param leds pattern of LEDs to turn on/off
|
||||
*/
|
||||
//% help=basic/plot-leds weight=80
|
||||
//% parts="ledmatrix"
|
||||
void plotLeds(ImageLiteral leds) {
|
||||
MicroBitImage i(imageBytes(leds));
|
||||
uBit.display.print(i, 0, 0, 0, 0);
|
||||
|
@ -261,36 +261,6 @@ namespace pxtrt {
|
||||
r->unref();
|
||||
}
|
||||
|
||||
//%
|
||||
uint32_t ldglb(int idx) {
|
||||
check(0 <= idx && idx < numGlobals, ERR_OUT_OF_BOUNDS, 7);
|
||||
return globals[idx];
|
||||
}
|
||||
|
||||
//%
|
||||
uint32_t ldglbRef(int idx) {
|
||||
check(0 <= idx && idx < numGlobals, ERR_OUT_OF_BOUNDS, 7);
|
||||
uint32_t tmp = globals[idx];
|
||||
incr(tmp);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// note the idx comes last - it's more convenient that way in the emitter
|
||||
//%
|
||||
void stglb(uint32_t v, int idx)
|
||||
{
|
||||
check(0 <= idx && idx < numGlobals, ERR_OUT_OF_BOUNDS, 7);
|
||||
globals[idx] = v;
|
||||
}
|
||||
|
||||
//%
|
||||
void stglbRef(uint32_t v, int idx)
|
||||
{
|
||||
check(0 <= idx && idx < numGlobals, ERR_OUT_OF_BOUNDS, 7);
|
||||
decr(globals[idx]);
|
||||
globals[idx] = v;
|
||||
}
|
||||
|
||||
// Store a captured local in a closure. It returns the action, so it can be chained.
|
||||
//%
|
||||
RefAction *stclo(RefAction *a, int idx, uint32_t v)
|
||||
@ -306,6 +276,34 @@ namespace pxtrt {
|
||||
microbit_panic(code);
|
||||
}
|
||||
|
||||
//%
|
||||
int stringToBool(StringData *s) {
|
||||
if (s == NULL) return 0;
|
||||
if (s->len == 0) {
|
||||
s->decr();
|
||||
return 0;
|
||||
}
|
||||
s->decr();
|
||||
return 1;
|
||||
}
|
||||
|
||||
//%
|
||||
StringData* emptyToNull(StringData *s) {
|
||||
if (!s || s->len == 0)
|
||||
return NULL;
|
||||
return s;
|
||||
}
|
||||
|
||||
//%
|
||||
int ptrToBool(uint32_t p) {
|
||||
if (p) {
|
||||
decr(p);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Debugger
|
||||
//
|
||||
|
@ -41,6 +41,7 @@ namespace game {
|
||||
*/
|
||||
//% weight=60
|
||||
//% blockId=game_create_sprite block="create sprite at|x: %x|y: %y"
|
||||
//% parts="ledmatrix"
|
||||
export function createSprite(x: number, y: number): LedSprite {
|
||||
init();
|
||||
let p = new LedSprite(x, y);
|
||||
@ -64,6 +65,7 @@ namespace game {
|
||||
*/
|
||||
//% weight=10 help=game/add-score
|
||||
//% blockId=game_add_score block="change score by|%points" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
export function addScore(points: number): void {
|
||||
setScore(_score + points);
|
||||
control.inBackground(() => {
|
||||
@ -82,6 +84,7 @@ namespace game {
|
||||
*/
|
||||
//% weight=9 help=game/start-countdown
|
||||
//% blockId=game_start_countdown block="start countdown|(ms) %duration" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
export function startCountdown(ms: number): void {
|
||||
if (checkStart()) {
|
||||
basic.showAnimation(`1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0
|
||||
@ -104,6 +107,7 @@ namespace game {
|
||||
*/
|
||||
//% weight=8 help=game/game-over
|
||||
//% blockId=game_game_over block="game over"
|
||||
//% parts="ledmatrix"
|
||||
export function gameOver(): void {
|
||||
if (!_isGameOver) {
|
||||
_isGameOver = true;
|
||||
@ -194,6 +198,7 @@ namespace game {
|
||||
* @param life TODO
|
||||
*/
|
||||
//% weight=10
|
||||
//% parts="ledmatrix"
|
||||
export function removeLife(life: number): void {
|
||||
setLife(_life - life);
|
||||
control.inBackground(() => {
|
||||
@ -210,6 +215,7 @@ namespace game {
|
||||
* Increments the level and display a message.
|
||||
*/
|
||||
//% weight=10
|
||||
//% parts="ledmatrix"
|
||||
export function levelUp(): void {
|
||||
_level = _level + 1;
|
||||
basic.showString("LEVEL:", 150);
|
||||
@ -246,6 +252,7 @@ namespace game {
|
||||
* Displays the score on the screen.
|
||||
*/
|
||||
//% weight=60
|
||||
//% parts="ledmatrix"
|
||||
export function showScore(): void {
|
||||
basic.showString(" SCORE ", 100);
|
||||
basic.showNumber(_score, 150);
|
||||
@ -303,6 +310,7 @@ namespace game {
|
||||
*/
|
||||
//% weight=50
|
||||
//% blockId=game_move_sprite block="%sprite|move by %leds" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
public move(leds: number): void {
|
||||
if (this._dir == 0) {
|
||||
this._y = this._y - leds;
|
||||
@ -336,6 +344,7 @@ namespace game {
|
||||
* @param x TODO
|
||||
* @param y TODO
|
||||
*/
|
||||
//% parts="ledmatrix"
|
||||
public goTo(x: number, y: number): void {
|
||||
this._x = x;
|
||||
this._y = y;
|
||||
@ -350,6 +359,7 @@ namespace game {
|
||||
*/
|
||||
//% weight=18
|
||||
//% blockId=game_sprite_bounce block="%sprite|if on edge, bounce"
|
||||
//% parts="ledmatrix"
|
||||
public ifOnEdgeBounce(): void {
|
||||
if (this._dir == 0 && this._y == 0) {
|
||||
this._dir = 180;
|
||||
@ -484,6 +494,7 @@ namespace game {
|
||||
* @param this TODO
|
||||
* @param degrees TODO
|
||||
*/
|
||||
//% parts="ledmatrix"
|
||||
public setDirection(degrees: number): void {
|
||||
this._dir = ((degrees / 45) % 8) * 45;
|
||||
if (this._dir <= -180) {
|
||||
@ -596,6 +607,7 @@ namespace game {
|
||||
* @param this TODO
|
||||
* @param brightness TODO
|
||||
*/
|
||||
//% parts="ledmatrix"
|
||||
public setBrightness(brightness: number): void {
|
||||
this._brightness = Math.clamp(0, 255, brightness);
|
||||
plot();
|
||||
@ -664,6 +676,7 @@ namespace game {
|
||||
}
|
||||
|
||||
//% weight=-1
|
||||
//% parts="ledmatrix"
|
||||
public _plot(now: number) {
|
||||
let ps = this
|
||||
if (ps._brightness > 0) {
|
||||
@ -701,6 +714,7 @@ namespace game {
|
||||
/**
|
||||
* Plots the current sprites on the screen
|
||||
*/
|
||||
//% parts="ledmatrix"
|
||||
function plot(): void {
|
||||
if (game.isGameOver()) {
|
||||
return;
|
||||
|
@ -10,6 +10,7 @@ namespace images {
|
||||
*/
|
||||
//% weight=75 help=images/create-image
|
||||
//% blockId=device_build_image block="create image"
|
||||
//% parts="ledmatrix"
|
||||
Image createImage(ImageLiteral leds) {
|
||||
return MicroBitImage(imageBytes(leds)).clone().leakData();
|
||||
}
|
||||
@ -19,6 +20,7 @@ namespace images {
|
||||
*/
|
||||
//% weight=74 help=images/create-big-image
|
||||
//% blockId=device_build_big_image block="create big image" imageLiteral=2
|
||||
//% parts="ledmatrix"
|
||||
Image createBigImage(ImageLiteral leds) {
|
||||
return createImage(leds);
|
||||
}
|
||||
@ -29,6 +31,7 @@ namespace ImageMethods {
|
||||
* Plots the image at a given column to the screen
|
||||
*/
|
||||
//% help=images/plot-image
|
||||
//% parts="ledmatrix"
|
||||
void plotImage(Image i, int xOffset = 0) {
|
||||
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0, 0);
|
||||
}
|
||||
@ -39,6 +42,7 @@ namespace ImageMethods {
|
||||
*/
|
||||
//% help=images/show-image weight=80 blockNamespace=images
|
||||
//% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
void showImage(Image sprite, int xOffset) {
|
||||
uBit.display.print(MicroBitImage(sprite), -xOffset, 0, 0);
|
||||
}
|
||||
@ -48,6 +52,7 @@ namespace ImageMethods {
|
||||
* @param xOffset column index to start displaying the image
|
||||
*/
|
||||
//% help=images/plot-frame weight=80
|
||||
//% parts="ledmatrix"
|
||||
void plotFrame(Image i, int xOffset) {
|
||||
// TODO showImage() used in original implementation
|
||||
plotImage(i, xOffset * 5);
|
||||
@ -60,6 +65,7 @@ namespace ImageMethods {
|
||||
*/
|
||||
//% help=images/show-image weight=79 async blockNamespace=images
|
||||
//% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
void scrollImage(Image id, int frameOffset, int interval) {
|
||||
MicroBitImage i(id);
|
||||
if (i.getWidth() <= 5)
|
||||
@ -73,6 +79,7 @@ namespace ImageMethods {
|
||||
* Sets all pixels off.
|
||||
*/
|
||||
//% help=images/clear
|
||||
//% parts="ledmatrix"
|
||||
void clear(Image i) {
|
||||
MicroBitImage(i).clear();
|
||||
}
|
||||
@ -81,6 +88,7 @@ namespace ImageMethods {
|
||||
* Sets a specific pixel brightness at a given position
|
||||
*/
|
||||
//%
|
||||
//% parts="ledmatrix"
|
||||
void setPixelBrightness(Image i, int x, int y, int value) {
|
||||
MicroBitImage(i).setPixelValue(x, y, value);
|
||||
}
|
||||
@ -90,6 +98,7 @@ namespace ImageMethods {
|
||||
* Gets the pixel brightness ([0..255]) at a given position
|
||||
*/
|
||||
//%
|
||||
//% parts="ledmatrix"
|
||||
int pixelBrightness(Image i, int x, int y) {
|
||||
int pix = MicroBitImage(i).getPixelValue(x, y);
|
||||
if (pix < 0) return 0;
|
||||
@ -120,6 +129,7 @@ namespace ImageMethods {
|
||||
* @param value TODO
|
||||
*/
|
||||
//% help=images/set-pixel
|
||||
//% parts="ledmatrix"
|
||||
void setPixel(Image i, int x, int y, bool value) {
|
||||
setPixelBrightness(i, x, y, value ? 255 : 0);
|
||||
}
|
||||
@ -130,6 +140,7 @@ namespace ImageMethods {
|
||||
* @param y TODO
|
||||
*/
|
||||
//% help=images/pixel
|
||||
//% parts="ledmatrix"
|
||||
bool pixel(Image i, int x, int y) {
|
||||
return pixelBrightness(i, x, y) > 0;
|
||||
}
|
||||
@ -140,6 +151,7 @@ namespace ImageMethods {
|
||||
* @param frame TODO
|
||||
*/
|
||||
//% weight=70 help=images/show-frame
|
||||
//% parts="ledmatrix"
|
||||
void showFrame(Image i, int frame) {
|
||||
showImage(i, frame * 5);
|
||||
}
|
||||
|
@ -116,6 +116,7 @@ namespace input {
|
||||
*/
|
||||
//% help=input/on-button-pressed weight=85 blockGap=8
|
||||
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192"
|
||||
//% parts="buttonpair"
|
||||
void onButtonPressed(Button button, Action body) {
|
||||
registerWithDal((int)button, MICROBIT_BUTTON_EVT_CLICK, body);
|
||||
}
|
||||
@ -126,6 +127,7 @@ namespace input {
|
||||
*/
|
||||
//% help=input/on-gesture weight=84 blockGap=8
|
||||
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135"
|
||||
//% parts="accelerometer"
|
||||
void onGesture(Gesture gesture, Action body) {
|
||||
if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
|
||||
uBit.accelerometer.setRange(4);
|
||||
@ -134,7 +136,7 @@ namespace input {
|
||||
registerWithDal(MICROBIT_ID_GESTURE, (int)gesture, body);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Do something when a pin is pressed.
|
||||
* @param name the pin that needs to be pressed
|
||||
* @param body the code to run when the pin is pressed
|
||||
@ -173,6 +175,7 @@ namespace input {
|
||||
//% block="button|%NAME|is pressed"
|
||||
//% blockId=device_get_button2
|
||||
//% icon="\uf192" blockGap=8
|
||||
//% parts="buttonpair"
|
||||
bool buttonIsPressed(Button button) {
|
||||
if (button == Button::A)
|
||||
return uBit.buttonA.isPressed();
|
||||
@ -201,6 +204,7 @@ namespace input {
|
||||
//% help=input/compass-heading
|
||||
//% weight=56 icon="\uf14e"
|
||||
//% blockId=device_heading block="compass heading (°)" blockGap=8
|
||||
//% parts="compass"
|
||||
int compassHeading() {
|
||||
return uBit.compass.heading();
|
||||
}
|
||||
@ -212,6 +216,7 @@ namespace input {
|
||||
//% weight=55 icon="\uf06d"
|
||||
//% help=input/temperature
|
||||
//% blockId=device_temperature block="temperature (°C)" blockGap=8
|
||||
//% parts="thermometer"
|
||||
int temperature() {
|
||||
return uBit.thermometer.getTemperature();
|
||||
}
|
||||
@ -229,6 +234,7 @@ namespace input {
|
||||
*/
|
||||
//% help=input/acceleration weight=54 icon="\uf135"
|
||||
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8
|
||||
//% parts="accelerometer"
|
||||
int acceleration(Dimension dimension) {
|
||||
switch (dimension) {
|
||||
case Dimension::X: return uBit.accelerometer.getX();
|
||||
@ -245,6 +251,7 @@ namespace input {
|
||||
*/
|
||||
//% help=input/light-level weight=53
|
||||
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185"
|
||||
//% parts="ledmatrix"
|
||||
int lightLevel() {
|
||||
return uBit.display.readLightLevel();
|
||||
}
|
||||
@ -255,6 +262,7 @@ namespace input {
|
||||
*/
|
||||
//% help=input/rotation weight=52
|
||||
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197"
|
||||
//% parts="accelerometer"
|
||||
int rotation(Rotation kind) {
|
||||
switch (kind) {
|
||||
case Rotation::Pitch: return uBit.accelerometer.getPitch();
|
||||
@ -269,6 +277,7 @@ namespace input {
|
||||
*/
|
||||
//% help=input/magnetic-force weight=51
|
||||
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076"
|
||||
//% parts="compass"
|
||||
int magneticForce(Dimension dimension) {
|
||||
if (!uBit.compass.isCalibrated())
|
||||
uBit.compass.calibrate();
|
||||
@ -304,6 +313,7 @@ namespace input {
|
||||
//% help=input/set-accelerometer-range
|
||||
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135"
|
||||
//% weight=5
|
||||
//% parts="accelerometer"
|
||||
void setAccelerometerRange(AcceleratorRange range) {
|
||||
uBit.accelerometer.setRange((int)range);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ namespace led {
|
||||
*/
|
||||
//% help=led/plot weight=78
|
||||
//% blockId=device_plot block="plot|x %x|y %y" icon="\uf205" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
void plot(int x, int y) {
|
||||
uBit.display.image.setPixelValue(x, y, 1);
|
||||
}
|
||||
@ -29,6 +30,7 @@ namespace led {
|
||||
*/
|
||||
//% help=led/unplot weight=77
|
||||
//% blockId=device_unplot block="unplot|x %x|y %y" icon="\uf204" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
void unplot(int x, int y) {
|
||||
uBit.display.image.setPixelValue(x, y, 0);
|
||||
}
|
||||
@ -40,6 +42,7 @@ namespace led {
|
||||
*/
|
||||
//% help=led/point weight=76
|
||||
//% blockId=device_point block="point|x %x|y %y" icon="\uf10c"
|
||||
//% parts="ledmatrix"
|
||||
bool point(int x, int y) {
|
||||
int pix = uBit.display.image.getPixelValue(x, y);
|
||||
return pix > 0;
|
||||
@ -50,6 +53,7 @@ namespace led {
|
||||
*/
|
||||
//% help=led/brightness weight=60
|
||||
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
int brightness() {
|
||||
return uBit.display.getBrightness();
|
||||
}
|
||||
@ -60,6 +64,7 @@ namespace led {
|
||||
*/
|
||||
//% help=led/set-brightness weight=59
|
||||
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042"
|
||||
//% parts="ledmatrix"
|
||||
void setBrightness(int value) {
|
||||
uBit.display.setBrightness(value);
|
||||
}
|
||||
@ -69,6 +74,7 @@ namespace led {
|
||||
*/
|
||||
//% weight=50 help=led/stop-animation
|
||||
//% blockId=device_stop_animation block="stop animation" icon="\uf04d"
|
||||
//% parts="ledmatrix"
|
||||
void stopAnimation() {
|
||||
uBit.display.stopAnimation();
|
||||
}
|
||||
@ -78,6 +84,7 @@ namespace led {
|
||||
* @param mode TODO
|
||||
*/
|
||||
//% weight=1 help=led/set-display-mode
|
||||
//% parts="ledmatrix"
|
||||
void setDisplayMode(DisplayMode_ mode) {
|
||||
uBit.display.setDisplayMode((DisplayMode)mode);
|
||||
}
|
||||
@ -86,6 +93,7 @@ namespace led {
|
||||
* Takes a screenshot of the LED screen and returns an image.
|
||||
*/
|
||||
//% help=led/screenshot
|
||||
//% parts="ledmatrix"
|
||||
Image screenshot() {
|
||||
return uBit.display.screenShot().leakData();
|
||||
/*
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
//% help=led/plot-bar-graph weight=20
|
||||
//% blockId=device_plot_bar_graph block="plot bar graph of %value |up to %high" icon="\uf080" blockExternalInputs=true
|
||||
//% parts="ledmatrix"
|
||||
export function plotBarGraph(value: number, high: number): void {
|
||||
let now = input.runningTime();
|
||||
serial.writeString(value.toString() + "\r\n");
|
||||
@ -53,6 +54,7 @@
|
||||
*/
|
||||
//% help=led/toggle weight=77
|
||||
//% blockId=device_led_toggle block="toggle|x %x|y %y" icon="\uf204" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
export function toggle(x: number, y: number): void {
|
||||
if (led.point(x, y)) {
|
||||
led.unplot(x, y);
|
||||
@ -65,6 +67,7 @@
|
||||
* Turns all LEDS on
|
||||
*/
|
||||
//% help=led/plot-all
|
||||
//% parts="ledmatrix"
|
||||
export function plotAll(): void {
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
@ -77,6 +80,7 @@
|
||||
* Inverts the current LED display
|
||||
*/
|
||||
//% help=led/toggle-all
|
||||
//% parts="ledmatrix"
|
||||
export function toggleAll(): void {
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
@ -90,6 +94,7 @@
|
||||
* @param ms TODO
|
||||
*/
|
||||
//% help=led/fade-in
|
||||
//% parts="ledmatrix"
|
||||
export function fadeIn(ms: number = 700): void {
|
||||
if (ms < 20) {
|
||||
led.setBrightness(255);
|
||||
@ -112,6 +117,7 @@
|
||||
* @param ms TODO
|
||||
*/
|
||||
//% help=led/fade-out
|
||||
//% parts="ledmatrix"
|
||||
export function fadeOut(ms: number = 700): void {
|
||||
if (ms < 20) {
|
||||
led.setBrightness(0);
|
||||
|
108
libs/microbit/shims.d.ts
vendored
108
libs/microbit/shims.d.ts
vendored
@ -11,14 +11,16 @@ 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
|
||||
//% blockId=device_build_image block="create image"
|
||||
//% parts="ledmatrix" 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
|
||||
//% blockId=device_build_big_image block="create big image" imageLiteral=2
|
||||
//% parts="ledmatrix" shim=images::createBigImage
|
||||
function createBigImage(leds: string): Image;
|
||||
}
|
||||
|
||||
@ -27,7 +29,8 @@ declare interface Image {
|
||||
/**
|
||||
* Plots the image at a given column to the screen
|
||||
*/
|
||||
//% help=images/plot-image xOffset.defl=0 shim=ImageMethods::plotImage
|
||||
//% help=images/plot-image
|
||||
//% parts="ledmatrix" xOffset.defl=0 shim=ImageMethods::plotImage
|
||||
plotImage(xOffset?: number): void;
|
||||
|
||||
/**
|
||||
@ -35,14 +38,16 @@ declare interface Image {
|
||||
* @param xOffset column index to start displaying the image
|
||||
*/
|
||||
//% help=images/show-image weight=80 blockNamespace=images
|
||||
//% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8 shim=ImageMethods::showImage
|
||||
//% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8
|
||||
//% parts="ledmatrix" shim=ImageMethods::showImage
|
||||
showImage(xOffset: number): void;
|
||||
|
||||
/**
|
||||
* Draws the ``index``-th frame of the image on the screen.
|
||||
* @param xOffset column index to start displaying the image
|
||||
*/
|
||||
//% help=images/plot-frame weight=80 shim=ImageMethods::plotFrame
|
||||
//% help=images/plot-frame weight=80
|
||||
//% parts="ledmatrix" shim=ImageMethods::plotFrame
|
||||
plotFrame(xOffset: number): void;
|
||||
|
||||
/**
|
||||
@ -51,25 +56,29 @@ declare interface Image {
|
||||
* @param interval time between each animation step in milli seconds, eg: 200
|
||||
*/
|
||||
//% help=images/show-image weight=79 async blockNamespace=images
|
||||
//% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8 shim=ImageMethods::scrollImage
|
||||
//% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8
|
||||
//% parts="ledmatrix" shim=ImageMethods::scrollImage
|
||||
scrollImage(frameOffset: number, interval: number): void;
|
||||
|
||||
/**
|
||||
* Sets all pixels off.
|
||||
*/
|
||||
//% help=images/clear shim=ImageMethods::clear
|
||||
//% help=images/clear
|
||||
//% parts="ledmatrix" shim=ImageMethods::clear
|
||||
clear(): void;
|
||||
|
||||
/**
|
||||
* Sets a specific pixel brightness at a given position
|
||||
*/
|
||||
//% shim=ImageMethods::setPixelBrightness
|
||||
//%
|
||||
//% parts="ledmatrix" shim=ImageMethods::setPixelBrightness
|
||||
setPixelBrightness(x: number, y: number, value: number): void;
|
||||
|
||||
/**
|
||||
* Gets the pixel brightness ([0..255]) at a given position
|
||||
*/
|
||||
//% shim=ImageMethods::pixelBrightness
|
||||
//%
|
||||
//% parts="ledmatrix" shim=ImageMethods::pixelBrightness
|
||||
pixelBrightness(x: number, y: number): number;
|
||||
|
||||
/**
|
||||
@ -90,7 +99,8 @@ declare interface Image {
|
||||
* @param y TODO
|
||||
* @param value TODO
|
||||
*/
|
||||
//% help=images/set-pixel shim=ImageMethods::setPixel
|
||||
//% help=images/set-pixel
|
||||
//% parts="ledmatrix" shim=ImageMethods::setPixel
|
||||
setPixel(x: number, y: number, value: boolean): void;
|
||||
|
||||
/**
|
||||
@ -98,14 +108,16 @@ declare interface Image {
|
||||
* @param x TODO
|
||||
* @param y TODO
|
||||
*/
|
||||
//% help=images/pixel shim=ImageMethods::pixel
|
||||
//% help=images/pixel
|
||||
//% parts="ledmatrix" shim=ImageMethods::pixel
|
||||
pixel(x: number, y: number): boolean;
|
||||
|
||||
/**
|
||||
* Shows a particular frame of the image strip.
|
||||
* @param frame TODO
|
||||
*/
|
||||
//% weight=70 help=images/show-frame shim=ImageMethods::showFrame
|
||||
//% weight=70 help=images/show-frame
|
||||
//% parts="ledmatrix" shim=ImageMethods::showFrame
|
||||
showFrame(frame: number): void;
|
||||
}
|
||||
|
||||
@ -123,7 +135,8 @@ declare namespace basic {
|
||||
//% help=basic/show-number
|
||||
//% weight=96
|
||||
//% blockId=device_show_number block="show|number %number" blockGap=8 icon="\uf1ec"
|
||||
//% async interval.defl=150 shim=basic::showNumber
|
||||
//% async
|
||||
//% parts="ledmatrix" interval.defl=150 shim=basic::showNumber
|
||||
function showNumber(value: number, interval?: number): void;
|
||||
|
||||
/**
|
||||
@ -135,7 +148,8 @@ declare namespace basic {
|
||||
//% weight=95 blockGap=8
|
||||
//% imageLiteral=1 async
|
||||
//% blockId=device_show_leds
|
||||
//% block="show leds" icon="\uf00a" interval.defl=400 shim=basic::showLeds
|
||||
//% block="show leds" icon="\uf00a"
|
||||
//% parts="ledmatrix" interval.defl=400 shim=basic::showLeds
|
||||
function showLeds(leds: string, interval?: number): void;
|
||||
|
||||
/**
|
||||
@ -147,14 +161,16 @@ declare namespace basic {
|
||||
//% weight=87 blockGap=8
|
||||
//% block="show|string %text" icon="\uf031"
|
||||
//% async
|
||||
//% blockId=device_print_message interval.defl=150 shim=basic::showString
|
||||
//% blockId=device_print_message
|
||||
//% parts="ledmatrix" interval.defl=150 shim=basic::showString
|
||||
function showString(text: string, interval?: number): void;
|
||||
|
||||
/**
|
||||
* Turn off all LEDs
|
||||
*/
|
||||
//% help=basic/clear-screen weight=79
|
||||
//% blockId=device_clear_display block="clear screen" icon="\uf12d" shim=basic::clearScreen
|
||||
//% blockId=device_clear_display block="clear screen" icon="\uf12d"
|
||||
//% parts="ledmatrix" shim=basic::clearScreen
|
||||
function clearScreen(): void;
|
||||
|
||||
/**
|
||||
@ -162,14 +178,16 @@ declare namespace basic {
|
||||
* @param leds pattern of LEDs to turn on/off
|
||||
* @param interval time in milliseconds between each redraw
|
||||
*/
|
||||
//% help=basic/show-animation imageLiteral=1 async interval.defl=400 shim=basic::showAnimation
|
||||
//% help=basic/show-animation imageLiteral=1 async
|
||||
//% parts="ledmatrix" interval.defl=400 shim=basic::showAnimation
|
||||
function showAnimation(leds: string, interval?: number): void;
|
||||
|
||||
/**
|
||||
* Draws an image on the LED screen.
|
||||
* @param leds pattern of LEDs to turn on/off
|
||||
*/
|
||||
//% help=basic/plot-leds weight=80 imageLiteral=1 shim=basic::plotLeds
|
||||
//% help=basic/plot-leds weight=80
|
||||
//% parts="ledmatrix" imageLiteral=1 shim=basic::plotLeds
|
||||
function plotLeds(leds: string): void;
|
||||
|
||||
/**
|
||||
@ -201,7 +219,8 @@ declare namespace input {
|
||||
* @param body TODO
|
||||
*/
|
||||
//% help=input/on-button-pressed weight=85 blockGap=8
|
||||
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192" shim=input::onButtonPressed
|
||||
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192"
|
||||
//% parts="buttonpair" shim=input::onButtonPressed
|
||||
function onButtonPressed(button: Button, body: () => void): void;
|
||||
|
||||
/**
|
||||
@ -209,7 +228,8 @@ declare namespace input {
|
||||
* @param body TODO
|
||||
*/
|
||||
//% help=input/on-gesture weight=84 blockGap=8
|
||||
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135" shim=input::onGesture
|
||||
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135"
|
||||
//% parts="accelerometer" shim=input::onGesture
|
||||
function onGesture(gesture: Gesture, body: () => void): void;
|
||||
|
||||
/**
|
||||
@ -236,7 +256,8 @@ declare namespace input {
|
||||
//% help=input/button-is-pressed weight=57
|
||||
//% block="button|%NAME|is pressed"
|
||||
//% blockId=device_get_button2
|
||||
//% icon="\uf192" blockGap=8 shim=input::buttonIsPressed
|
||||
//% icon="\uf192" blockGap=8
|
||||
//% parts="buttonpair" shim=input::buttonIsPressed
|
||||
function buttonIsPressed(button: Button): boolean;
|
||||
|
||||
/**
|
||||
@ -253,7 +274,8 @@ declare namespace input {
|
||||
*/
|
||||
//% help=input/compass-heading
|
||||
//% weight=56 icon="\uf14e"
|
||||
//% blockId=device_heading block="compass heading (°)" blockGap=8 shim=input::compassHeading
|
||||
//% blockId=device_heading block="compass heading (°)" blockGap=8
|
||||
//% parts="compass" shim=input::compassHeading
|
||||
function compassHeading(): number;
|
||||
|
||||
/**
|
||||
@ -261,7 +283,8 @@ declare namespace input {
|
||||
*/
|
||||
//% weight=55 icon="\uf06d"
|
||||
//% help=input/temperature
|
||||
//% blockId=device_temperature block="temperature (°C)" blockGap=8 shim=input::temperature
|
||||
//% blockId=device_temperature block="temperature (°C)" blockGap=8
|
||||
//% parts="thermometer" shim=input::temperature
|
||||
function temperature(): number;
|
||||
|
||||
/**
|
||||
@ -269,14 +292,16 @@ declare namespace input {
|
||||
* @param dimension TODO
|
||||
*/
|
||||
//% help=input/acceleration weight=54 icon="\uf135"
|
||||
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8 shim=input::acceleration
|
||||
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8
|
||||
//% parts="accelerometer" shim=input::acceleration
|
||||
function acceleration(dimension: Dimension): number;
|
||||
|
||||
/**
|
||||
* Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.
|
||||
*/
|
||||
//% help=input/light-level weight=53
|
||||
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185" shim=input::lightLevel
|
||||
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185"
|
||||
//% parts="ledmatrix" shim=input::lightLevel
|
||||
function lightLevel(): number;
|
||||
|
||||
/**
|
||||
@ -284,7 +309,8 @@ declare namespace input {
|
||||
* @param kind TODO
|
||||
*/
|
||||
//% help=input/rotation weight=52
|
||||
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197" shim=input::rotation
|
||||
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197"
|
||||
//% parts="accelerometer" shim=input::rotation
|
||||
function rotation(kind: Rotation): number;
|
||||
|
||||
/**
|
||||
@ -292,7 +318,8 @@ declare namespace input {
|
||||
* @param dimension TODO
|
||||
*/
|
||||
//% help=input/magnetic-force weight=51
|
||||
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076" shim=input::magneticForce
|
||||
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076"
|
||||
//% parts="compass" shim=input::magneticForce
|
||||
function magneticForce(dimension: Dimension): number;
|
||||
|
||||
/**
|
||||
@ -314,7 +341,8 @@ declare namespace input {
|
||||
*/
|
||||
//% help=input/set-accelerometer-range
|
||||
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135"
|
||||
//% weight=5 shim=input::setAccelerometerRange
|
||||
//% weight=5
|
||||
//% parts="accelerometer" shim=input::setAccelerometerRange
|
||||
function setAccelerometerRange(range: AcceleratorRange): void;
|
||||
}
|
||||
|
||||
@ -400,7 +428,8 @@ declare namespace led {
|
||||
* @param y TODO
|
||||
*/
|
||||
//% help=led/plot weight=78
|
||||
//% blockId=device_plot block="plot|x %x|y %y" icon="\uf205" blockGap=8 shim=led::plot
|
||||
//% blockId=device_plot block="plot|x %x|y %y" icon="\uf205" blockGap=8
|
||||
//% parts="ledmatrix" shim=led::plot
|
||||
function plot(x: number, y: number): void;
|
||||
|
||||
/**
|
||||
@ -409,7 +438,8 @@ declare namespace led {
|
||||
* @param y TODO
|
||||
*/
|
||||
//% help=led/unplot weight=77
|
||||
//% blockId=device_unplot block="unplot|x %x|y %y" icon="\uf204" blockGap=8 shim=led::unplot
|
||||
//% blockId=device_unplot block="unplot|x %x|y %y" icon="\uf204" blockGap=8
|
||||
//% parts="ledmatrix" shim=led::unplot
|
||||
function unplot(x: number, y: number): void;
|
||||
|
||||
/**
|
||||
@ -418,14 +448,16 @@ declare namespace led {
|
||||
* @param y TODO
|
||||
*/
|
||||
//% help=led/point weight=76
|
||||
//% blockId=device_point block="point|x %x|y %y" icon="\uf10c" shim=led::point
|
||||
//% blockId=device_point block="point|x %x|y %y" icon="\uf10c"
|
||||
//% parts="ledmatrix" shim=led::point
|
||||
function point(x: number, y: number): boolean;
|
||||
|
||||
/**
|
||||
* Get the screen brightness from 0 (off) to 255 (full bright).
|
||||
*/
|
||||
//% help=led/brightness weight=60
|
||||
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8 shim=led::brightness
|
||||
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8
|
||||
//% parts="ledmatrix" shim=led::brightness
|
||||
function brightness(): number;
|
||||
|
||||
/**
|
||||
@ -433,27 +465,31 @@ declare namespace led {
|
||||
* @param value the brightness value, eg:255, 127, 0
|
||||
*/
|
||||
//% help=led/set-brightness weight=59
|
||||
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042" shim=led::setBrightness
|
||||
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042"
|
||||
//% parts="ledmatrix" shim=led::setBrightness
|
||||
function setBrightness(value: number): void;
|
||||
|
||||
/**
|
||||
* Cancels the current animation and clears other pending animations.
|
||||
*/
|
||||
//% weight=50 help=led/stop-animation
|
||||
//% blockId=device_stop_animation block="stop animation" icon="\uf04d" shim=led::stopAnimation
|
||||
//% blockId=device_stop_animation block="stop animation" icon="\uf04d"
|
||||
//% parts="ledmatrix" shim=led::stopAnimation
|
||||
function stopAnimation(): void;
|
||||
|
||||
/**
|
||||
* Sets the display mode between black and white and greyscale for rendering LEDs.
|
||||
* @param mode TODO
|
||||
*/
|
||||
//% weight=1 help=led/set-display-mode shim=led::setDisplayMode
|
||||
//% weight=1 help=led/set-display-mode
|
||||
//% parts="ledmatrix" shim=led::setDisplayMode
|
||||
function setDisplayMode(mode: DisplayMode): void;
|
||||
|
||||
/**
|
||||
* Takes a screenshot of the LED screen and returns an image.
|
||||
*/
|
||||
//% help=led/screenshot shim=led::screenshot
|
||||
//% help=led/screenshot
|
||||
//% parts="ledmatrix" shim=led::screenshot
|
||||
function screenshot(): Image;
|
||||
}
|
||||
declare namespace pins {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-microbit",
|
||||
"version": "0.3.43",
|
||||
"version": "0.3.51",
|
||||
"description": "micro:bit target for PXT",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@ -29,6 +29,6 @@
|
||||
"typescript": "^1.8.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-core": "0.3.47"
|
||||
"pxt-core": "0.3.56"
|
||||
}
|
||||
}
|
||||
|
@ -31,12 +31,14 @@
|
||||
"description": "",
|
||||
"files": [
|
||||
"main.blocks",
|
||||
"main.ts"
|
||||
"main.ts",
|
||||
"README.md"
|
||||
]
|
||||
},
|
||||
"files": {
|
||||
"main.blocks": "<xml xmlns=\"http://www.w3.org/1999/xhtml\">\n<block type=\"device_forever\">\n<statement name=\"HANDLER\">\n<block type=\"device_show_leds\">\n<field name=\"LED00\">FALSE</field>\n<field name=\"LED10\">FALSE</field>\n<field name=\"LED20\">FALSE</field>\n<field name=\"LED30\">FALSE</field>\n<field name=\"LED40\">FALSE</field>\n<field name=\"LED01\">FALSE</field>\n<field name=\"LED11\">TRUE</field>\n<field name=\"LED21\">FALSE</field>\n<field name=\"LED31\">TRUE</field>\n<field name=\"LED41\">FALSE</field>\n<field name=\"LED02\">FALSE</field>\n<field name=\"LED12\">FALSE</field>\n<field name=\"LED22\">FALSE</field>\n<field name=\"LED32\">FALSE</field>\n<field name=\"LED42\">FALSE</field>\n<field name=\"LED03\">TRUE</field>\n<field name=\"LED13\">FALSE</field>\n<field name=\"LED23\">FALSE</field>\n<field name=\"LED33\">FALSE</field>\n<field name=\"LED43\">TRUE</field>\n<field name=\"LED04\">FALSE</field>\n<field name=\"LED14\">TRUE</field>\n<field name=\"LED24\">TRUE</field>\n<field name=\"LED34\">TRUE</field>\n<field name=\"LED44\">FALSE</field>\n<next>\n<block type=\"device_show_leds\">\n<field name=\"LED00\">FALSE</field>\n<field name=\"LED10\">FALSE</field>\n<field name=\"LED20\">FALSE</field>\n<field name=\"LED30\">FALSE</field>\n<field name=\"LED40\">FALSE</field>\n<field name=\"LED01\">FALSE</field>\n<field name=\"LED11\">FALSE</field>\n<field name=\"LED21\">FALSE</field>\n<field name=\"LED31\">FALSE</field>\n<field name=\"LED41\">FALSE</field>\n<field name=\"LED02\">FALSE</field>\n<field name=\"LED12\">FALSE</field>\n<field name=\"LED22\">FALSE</field>\n<field name=\"LED32\">FALSE</field>\n<field name=\"LED42\">FALSE</field>\n<field name=\"LED03\">FALSE</field>\n<field name=\"LED13\">FALSE</field>\n<field name=\"LED23\">FALSE</field>\n<field name=\"LED33\">FALSE</field>\n<field name=\"LED43\">FALSE</field>\n<field name=\"LED04\">FALSE</field>\n<field name=\"LED14\">FALSE</field>\n<field name=\"LED24\">FALSE</field>\n<field name=\"LED34\">FALSE</field>\n<field name=\"LED44\">FALSE</field>\n</block>\n</next>\n</block>\n</statement>\n</block>\n</xml>",
|
||||
"main.ts": "basic.forever(() => {\r\n basic.showLeds(`\r\n . # . # .\r\n # . # . #\r\n # . . . #\r\n . # . # .\r\n . . # . .\r\n `)\r\n basic.showLeds(`\r\n . . . . .\r\n . . . . .\r\n . . . . .\r\n . . . . .\r\n . . . . .\r\n `)\r\n})\r\n"
|
||||
"main.ts": "basic.forever(() => {\r\n basic.showLeds(`\r\n . # . # .\r\n # . # . #\r\n # . . . #\r\n . # . # .\r\n . . # . .\r\n `)\r\n basic.showLeds(`\r\n . . . . .\r\n . . . . .\r\n . . . . .\r\n . . . . .\r\n . . . . .\r\n `)\r\n})\r\n",
|
||||
"README.md": ""
|
||||
}
|
||||
},
|
||||
"tsprj": {
|
||||
@ -49,11 +51,13 @@
|
||||
},
|
||||
"description": "",
|
||||
"files": [
|
||||
"main.ts"
|
||||
"main.ts",
|
||||
"README.md"
|
||||
]
|
||||
},
|
||||
"files": {
|
||||
"main.ts": "basic.showLeds(`\r\n . . . . .\r\n . # . # .\r\n . . . . .\r\n # . . . #\r\n . # # # .\r\n `);"
|
||||
"main.ts": "basic.showLeds(`\r\n . . . . .\r\n . # . # .\r\n . . . . .\r\n # . . . #\r\n . # # # .\r\n `);",
|
||||
"README.md": ""
|
||||
}
|
||||
},
|
||||
"compile": {
|
||||
|
19
sim/state.ts
19
sim/state.ts
@ -470,7 +470,7 @@ namespace pxsim {
|
||||
radio: RadioBus;
|
||||
|
||||
// display
|
||||
image = createImage(5);
|
||||
image = createInternalImage(5);
|
||||
brigthness = 255;
|
||||
displayMode = DisplayMode.bw;
|
||||
font: Image = createFont();
|
||||
@ -608,14 +608,19 @@ namespace pxsim {
|
||||
}
|
||||
}
|
||||
|
||||
export class Image {
|
||||
export class Image extends RefObject {
|
||||
public static height: number = 5;
|
||||
public width: number;
|
||||
public data: number[];
|
||||
constructor(width: number, data: number[]) {
|
||||
super()
|
||||
this.width = width;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public print() {
|
||||
console.log(`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;
|
||||
return this.data[y * this.width + x];
|
||||
@ -650,6 +655,12 @@ namespace pxsim {
|
||||
}
|
||||
}
|
||||
|
||||
export function createInternalImage(width: number): Image {
|
||||
let img = createImage(width)
|
||||
pxsim.noLeakTracking(img)
|
||||
return img
|
||||
}
|
||||
|
||||
export function createImage(width: number): Image {
|
||||
return new Image(width, new Array(width * 5));
|
||||
}
|
||||
@ -661,7 +672,7 @@ namespace pxsim {
|
||||
export function createImageFromString(text: string): Image {
|
||||
let font = board().font;
|
||||
let w = font.width;
|
||||
let sprite = createImage(6 * text.length - 1);
|
||||
let sprite = createInternalImage(6 * text.length - 1);
|
||||
let k = 0;
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
let charCode = text.charCodeAt(i);
|
||||
@ -685,7 +696,7 @@ namespace pxsim {
|
||||
|
||||
let nb = data.length;
|
||||
let n = nb / 5;
|
||||
let font = createImage(nb);
|
||||
let font = createInternalImage(nb);
|
||||
for (let c = 0; c < n; c++) {
|
||||
for (let row = 0; row < 5; row++) {
|
||||
let char = data[c * 5 + row];
|
||||
|
8
tests/base/tsconfig.json
Normal file
8
tests/base/tsconfig.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"noImplicitAny": true,
|
||||
"outDir": "built",
|
||||
"rootDir": "."
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user