Compare commits
55 Commits
Author | SHA1 | Date | |
---|---|---|---|
98bc8d2a27 | |||
58d0e238e3 | |||
60f8dd8228 | |||
a34bcee7a2 | |||
d011cdb37e | |||
b37e823b57 | |||
8cb31daa48 | |||
e856d59235 | |||
32753d3395 | |||
7b11a04727 | |||
6d6c053e4f | |||
1008fdd371 | |||
ddc2b7437b | |||
b9c95ebb1e | |||
b16d02ec66 | |||
38fb36087a | |||
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 | |||
26797545c6 | |||
3ce8aa1f47 | |||
8b46698f50 | |||
47401e947c | |||
718cc9d530 | |||
b83d777144 | |||
cfb9acea34 | |||
53189830a1 | |||
67da22c135 |
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.
|
// 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.enable": true,
|
||||||
"tslint.rulesDirectory": "node_modules/tslint-microsoft-contrib"
|
"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)
|
let readDirAsync = Promise.promisify(fs.readdir)
|
||||||
|
|
||||||
|
|
||||||
export function deployCoreAsync(res: ts.pxt.CompileResult) {
|
export function deployCoreAsync(res: ts.pxtc.CompileResult) {
|
||||||
return getBitDrivesAsync()
|
return getBitDrivesAsync()
|
||||||
.then(drives => {
|
.then(drives => {
|
||||||
if (drives.length == 0) {
|
if (drives.length == 0) {
|
||||||
console.log("cannot find any drives to deploy to")
|
console.log("cannot find any drives to deploy to")
|
||||||
} else {
|
} else {
|
||||||
console.log(`copy ${ts.pxt.BINARY_HEX} to ` + drives.join(", "))
|
console.log(`copy ${ts.pxtc.BINARY_HEX} to ` + drives.join(", "))
|
||||||
}
|
}
|
||||||
return Promise.map(drives, d =>
|
return Promise.map(drives, d =>
|
||||||
writeFileAsync(d + ts.pxt.BINARY_HEX, res.outfiles[ts.pxt.BINARY_HEX])
|
writeFileAsync(d + ts.pxtc.BINARY_HEX, res.outfiles[ts.pxtc.BINARY_HEX])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log("wrote hex file to " + d)
|
console.log("wrote hex file to " + d)
|
||||||
}))
|
}))
|
||||||
|
17
docs/cli.md
Normal file
17
docs/cli.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Command Line Interface
|
||||||
|
|
||||||
|
```sim
|
||||||
|
basic.forever(() => {
|
||||||
|
basic.showString("CLI<3")
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
It is possible to use the codethemicrobit tools from a command line interface (CLI). The PXT CLI allows to
|
||||||
|
* edit, compile or deploy JavaScript programs
|
||||||
|
* can easily be integrated in most IDEs. It comes with built-in support for [Visual Studio Code](/code)!
|
||||||
|
* run a local web server for the web editor
|
||||||
|
* author packages using JavaScript and/or C++
|
||||||
|
|
||||||
|
Using the CLI assumes that you have some experience with programming and will require to install tools on your machine as well.
|
||||||
|
|
||||||
|
* **[LET'S GET STARTED](https://pxt.io/cli)**
|
50
docs/code.md
50
docs/code.md
@ -1,54 +1,16 @@
|
|||||||
# Visual Studio Code
|
# Visual Studio Code
|
||||||
|
|
||||||
Visual Studio Code is a Free Open Source code editor that you can use to edit your programs.
|
[Visual Studio Code](https://code.visualstudio.com) is a Free Open Source code editor that you can use to edit your programs.
|
||||||
|
|
||||||
Working from Visual Studio code allows you to benefit from all the features
|
Working from Visual Studio code allows you to benefit from all the features
|
||||||
of a professional IDE while working with PXT: working with files,
|
of a professional IDE while working with PXT: working with files,
|
||||||
git integration (or source control of your choice), hundreds of extensions.
|
git integration (or source control of your choice), hundreds of extensions.
|
||||||
|
|
||||||

|
* background compilation
|
||||||
|
* auto-completion
|
||||||
|
* pxt command line integration
|
||||||
|
|
||||||
## Setup
|
**Follow [these instructions](https://pxt.io/cli)** to setup your machine and edit your programs in Visual Studio Code.
|
||||||
|
|
||||||
Follow these instructions to setup your machine and edit your programs in Visual Studio Code.
|

|
||||||
|
|
||||||
* install [Visual Studio Code](https://code.visualstudio.com/)
|
|
||||||
* install [Node.JS](https://nodejs.org/en/)
|
|
||||||
* install the PXT Tools (on Mac or Linux, you might have to add ``sudo`` to the command).
|
|
||||||
```
|
|
||||||
pxt install -g pxt
|
|
||||||
```
|
|
||||||
* create a folder for your projects
|
|
||||||
```
|
|
||||||
mkdir microbit
|
|
||||||
```
|
|
||||||
* install the microbit target
|
|
||||||
```
|
|
||||||
pxt target microbit
|
|
||||||
```
|
|
||||||
|
|
||||||
That's it! You are ready to create new projects in code or open existing projects.
|
|
||||||
|
|
||||||
## Creating a new project
|
|
||||||
|
|
||||||
Open a shell to your ``microbit`` folder.
|
|
||||||
|
|
||||||
```
|
|
||||||
# create a new subfolder for your project
|
|
||||||
mkdir myproject
|
|
||||||
cd myproject
|
|
||||||
# start the project set
|
|
||||||
pxt init
|
|
||||||
# open code
|
|
||||||
code .
|
|
||||||
```
|
|
||||||
|
|
||||||
## Opening an existing project
|
|
||||||
|
|
||||||
You can extract a project from the embedded URL or .hex file. Open a shell to your projects folder
|
|
||||||
|
|
||||||
```
|
|
||||||
# extract the project from the URL
|
|
||||||
pxt extract EMBEDURL
|
|
||||||
```
|
|
||||||
where ``EMBEDURL`` is the published project URL.
|
|
@ -40,7 +40,7 @@ Next, compile your script:
|
|||||||
|
|
||||||
2. Open your script (find the script in **My Scripts** and click `Edit`).
|
2. Open your script (find the script in **My Scripts** and click `Edit`).
|
||||||
|
|
||||||
3. Click `compile`. Your script is converted into a hex file that you can transfer and run on your micro:bit.
|
3. Click **Download**. Your script is converted into a hex file that you can transfer and run on your micro:bit.
|
||||||
|
|
||||||
4. When prompted, choose to save the compiled file on your computer (or anywhere other than the micro:bit). Depending on which browser you are using, the download will adopt the download behaviour of that particular browser.
|
4. When prompted, choose to save the compiled file on your computer (or anywhere other than the micro:bit). Depending on which browser you are using, the download will adopt the download behaviour of that particular browser.
|
||||||
|
|
||||||
@ -66,13 +66,13 @@ A dialogue box will appear, asking whether you would like to open or save your h
|
|||||||
|
|
||||||
**IE10**
|
**IE10**
|
||||||
|
|
||||||
Click on compile. You will see a message “Do you want to save this .hex file.” Select **Save**.
|
Click on **Download**. You will see a message “Do you want to save this .hex file.” Select **Save**.
|
||||||
|
|
||||||
### Mac
|
### Mac
|
||||||
|
|
||||||
** Safari**
|
** Safari**
|
||||||
|
|
||||||
When you select **compile** in Safari on Mac, your file will be downloaded to your downloads folder. Go to your downloads folder and open the file. In Safari the file will appear as unknown.txt rather than a named .hex file. Drag and drop it onto your MICROBIT drive.
|
When you select **Download** in Safari on Mac, your file will be downloaded to your downloads folder. Go to your downloads folder and open the file. In Safari the file will appear as unknown.txt rather than a named .hex file. Drag and drop it onto your MICROBIT drive.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@ -86,7 +86,7 @@ A dialogue box will appear, asking whether you would like to open or save your h
|
|||||||
|
|
||||||
**Chrome**
|
**Chrome**
|
||||||
|
|
||||||
When you select **compile** in Chrome, the file will be downloaded to the bottom of the browser in .hex format. Click on the small arrow and select **Show in Finder**. This will show the file in your download folder. Drag and drop the file onto your MICROBIT drive.
|
When you select **Download** in Chrome, the file will be downloaded to the bottom of the browser in .hex format. Click on the small arrow and select **Show in Finder**. This will show the file in your download folder. Drag and drop the file onto your MICROBIT drive.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
@ -26,4 +26,5 @@
|
|||||||
|
|
||||||
### Developers
|
### Developers
|
||||||
|
|
||||||
|
* [Command Line Interface](/cli)
|
||||||
* Learn about [packages](/packages)
|
* Learn about [packages](/packages)
|
||||||
|
BIN
docs/favicon.ico
Normal file
BIN
docs/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
@ -35,7 +35,7 @@ When this program runs, you will see a smiley face, then a blank
|
|||||||
screen, then a smiley again -- it never stops! (That's because of the
|
screen, then a smiley again -- it never stops! (That's because of the
|
||||||
``forever`` block.)
|
``forever`` block.)
|
||||||
|
|
||||||
Click **Compile** to move your program to the BBC micro:bit!
|
Click **Download** to move your program to the BBC micro:bit!
|
||||||
Make sure to follow the instructions.
|
Make sure to follow the instructions.
|
||||||
|
|
||||||
### ~button /getting-started/screen
|
### ~button /getting-started/screen
|
||||||
|
@ -37,7 +37,7 @@ You can find the letter `B` by clicking the letter `A` on the
|
|||||||
|
|
||||||
#### ~
|
#### ~
|
||||||
|
|
||||||
Click **Compile** to move your program to the BBC micro:bit!
|
Click **Download** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
#### Your turn!
|
#### Your turn!
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ input.onPinPressed(TouchPin.P0, () => {
|
|||||||
. . # . .`);
|
. . # . .`);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
Click **Compile** to move your program to the BBC micro:bit!
|
Click **Download** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
## ~hint
|
## ~hint
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ That's why you can use an ``else`` instead of an ``else if``.
|
|||||||
|
|
||||||
Your game is ready!
|
Your game is ready!
|
||||||
|
|
||||||
Click **Compile** to move your program to the BBC micro:bit!
|
Click **Download** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
Have fun!
|
Have fun!
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ input.onButtonPressed(Button.B, () => {
|
|||||||
basic.showNumber(game.score())
|
basic.showNumber(game.score())
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
Click **Compile** to move your program to the BBC micro:bit!
|
Click **Download** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
### ~button /projects
|
### ~button /projects
|
||||||
NEXT: PROJECTS!
|
NEXT: PROJECTS!
|
||||||
|
@ -32,7 +32,7 @@ basic.forever(() => {
|
|||||||
`)
|
`)
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
Click **Compile** to move your program to the BBC micro:bit!
|
Click **Download** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
### Your turn!
|
### Your turn!
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ basic.forever(() => {
|
|||||||
`)
|
`)
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
Click **Compile** to move your program to the BBC micro:bit!
|
Click **Download** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
#### ~hint
|
#### ~hint
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ input.onGesture(Gesture.Shake, () => {
|
|||||||
# . . . #`);
|
# . . . #`);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
Click **Compile** to move your program to the BBC micro:bit!
|
Click **Download** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
### ~button /getting-started/coin-flipper
|
### ~button /getting-started/coin-flipper
|
||||||
NEXT: COIN FLIPPER GAME
|
NEXT: COIN FLIPPER GAME
|
||||||
|
@ -42,7 +42,7 @@ We want the message "Press A!" to scroll across the BBC micro:bit, so right-clic
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
So, to recap: the `forever` block makes sure our code runs forever. The BBC micro:bit checks if the user is pressing the left button, if the user is not then the “Press the button!” message will scroll across the LEDs. If the user is pressing the button then the “hello, world!” message will scroll across the screen. Check this in the simulator or attach the BBC micro:bit to the computer then click **compile** to send the code onto the BBC micro:bit.
|
So, to recap: the `forever` block makes sure our code runs forever. The BBC micro:bit checks if the user is pressing the left button, if the user is not then the “Press the button!” message will scroll across the LEDs. If the user is pressing the button then the “hello, world!” message will scroll across the screen. Check this in the simulator or attach the BBC micro:bit to the computer then click **Download** to send the code onto the BBC micro:bit.
|
||||||
|
|
||||||
## What is a condition?
|
## What is a condition?
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ Connect a micro:bit to your computer using your USB cable
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
Click or tap the compile button for the seismograph program to run the program on the micro:bit.
|
Click or tap the **Download** button for the seismograph program to run the program on the micro:bit.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ Connect the 2nd micro:bit to your computer using your USB cable. We should have
|
|||||||
|
|
||||||
## 8.
|
## 8.
|
||||||
|
|
||||||
Click or tap the compile button for the seismograph program to run the program on the 1st micro:bit and 2nd micro:bit.
|
Click or tap the **Download** button for the seismograph program to run the program on the 1st micro:bit and 2nd micro:bit.
|
||||||
|
|
||||||
## 9.
|
## 9.
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ To remove a package, click on the garbage button in the file list next to the pa
|
|||||||
|
|
||||||
## Publishing packages
|
## 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
|
## Localizing packages
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ input.onButtonPressed(Button.A, () => {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
* click *compile* and run your code on the micro:bit.
|
* click **Download** and run your code on the micro:bit.
|
||||||
|
|
||||||
### ~button /projects/banana-keyboard
|
### ~button /projects/banana-keyboard
|
||||||
NEXT: Banana Keyboard
|
NEXT: Banana Keyboard
|
||||||
|
@ -29,7 +29,7 @@ radio.onDataReceived(() => {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
Compile the program and **upload the same .hex file to 2 devices!**
|
Download the program and **upload the same .hex file to 2 devices!**
|
||||||
|
|
||||||
## Step 3
|
## Step 3
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ Control of the LED screen.
|
|||||||
led.plot(0, 0);
|
led.plot(0, 0);
|
||||||
led.unplot(0, 0);
|
led.unplot(0, 0);
|
||||||
led.point(0, 0);
|
led.point(0, 0);
|
||||||
|
led.toggle(0, 0);
|
||||||
led.brightness();
|
led.brightness();
|
||||||
led.setBrightness(255);
|
led.setBrightness(255);
|
||||||
led.stopAnimation();
|
led.stopAnimation();
|
||||||
@ -14,7 +15,6 @@ led.fadeIn();
|
|||||||
led.fadeOut();
|
led.fadeOut();
|
||||||
led.plotAll();
|
led.plotAll();
|
||||||
led.screenshot();
|
led.screenshot();
|
||||||
led.toggle(0, 0);
|
|
||||||
led.toggleAll();
|
led.toggleAll();
|
||||||
led.setDisplayMode(DisplayMode.BackAndWhite);
|
led.setDisplayMode(DisplayMode.BackAndWhite);
|
||||||
```
|
```
|
||||||
|
BIN
docs/static/mb/vscode.png
vendored
Normal file
BIN
docs/static/mb/vscode.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
@ -1,21 +1,28 @@
|
|||||||
<meta name="twitter:card" content="summary" />
|
<meta name="twitter:card" content="summary" />
|
||||||
<meta name="twitter:site" content="@codethemicrobit" />
|
<meta name="twitter:site" content="@codethemicrobit" />
|
||||||
<meta name="twitter:title" content="@name@" />
|
<meta name="twitter:title" content="@name@" />
|
||||||
<meta name="twitter:description" content="@description@" />
|
<meta name="twitter:description" content="@description@" />
|
||||||
<meta name="twitter:image" content="@cardLogo@" />
|
<meta name="twitter:image" content="@cardLogo@" />
|
||||||
|
|
||||||
<meta property="og:title" content="@name@" />
|
<meta property="og:title" content="@name@" />
|
||||||
<meta property="og:site_name" content="code the micro:bit" />
|
<meta property="og:site_name" content="code the micro:bit" />
|
||||||
<meta property="og:description" content="@description@" />
|
<meta property="og:description" content="@description@" />
|
||||||
<meta property="og:image" content="@cardLogo@" />
|
<meta property="og:image" content="@cardLogo@" />
|
||||||
<!--
|
<!--
|
||||||
<meta property="og:type" content="website" />
|
<meta property="og:type" content="website" />
|
||||||
<meta property="fb:app_id" content="" />
|
<meta property="fb:app_id" content="" />
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<link rel="apple-touch-icon" href="@appLogo@">
|
<link rel="apple-touch-icon" href="@appLogo@">
|
||||||
<link rel="icon" type="image/png" 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="mask-icon" href="https://az851932.vo.msecnd.net/pub/zwxazere/safari-pinned-tab.svg" color="#000000">
|
||||||
<link rel="shortcut icon" href="@appLogo@">
|
<link rel="shortcut icon" href="@appLogo@">
|
||||||
<meta name="theme-color" content="@accentColor@">
|
<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
|
//% help=bluetooth/start-io-pin-service
|
||||||
//% blockId=bluetooth_start_io_pin_service block="bluetooth io pin service" blockGap=8
|
//% blockId=bluetooth_start_io_pin_service block="bluetooth io pin service" blockGap=8
|
||||||
|
//% parts="bluetooth"
|
||||||
void startIOPinService() {
|
void startIOPinService() {
|
||||||
new MicroBitIOPinService(*uBit.ble, uBit.io);
|
new MicroBitIOPinService(*uBit.ble, uBit.io);
|
||||||
}
|
}
|
||||||
@ -41,6 +42,7 @@ namespace bluetooth {
|
|||||||
*/
|
*/
|
||||||
//% help=bluetooth/start-led-service
|
//% help=bluetooth/start-led-service
|
||||||
//% blockId=bluetooth_start_led_service block="bluetooth led service" blockGap=8
|
//% blockId=bluetooth_start_led_service block="bluetooth led service" blockGap=8
|
||||||
|
//% parts="bluetooth"
|
||||||
void startLEDService() {
|
void startLEDService() {
|
||||||
new MicroBitLEDService(*uBit.ble, uBit.display);
|
new MicroBitLEDService(*uBit.ble, uBit.display);
|
||||||
}
|
}
|
||||||
@ -50,6 +52,7 @@ namespace bluetooth {
|
|||||||
*/
|
*/
|
||||||
//% help=bluetooth/start-temperature-service
|
//% help=bluetooth/start-temperature-service
|
||||||
//% blockId=bluetooth_start_temperature_service block="bluetooth temperature service" blockGap=8
|
//% blockId=bluetooth_start_temperature_service block="bluetooth temperature service" blockGap=8
|
||||||
|
//% parts="bluetooth"
|
||||||
void startTemperatureService() {
|
void startTemperatureService() {
|
||||||
new MicroBitTemperatureService(*uBit.ble, uBit.thermometer);
|
new MicroBitTemperatureService(*uBit.ble, uBit.thermometer);
|
||||||
}
|
}
|
||||||
@ -59,6 +62,7 @@ namespace bluetooth {
|
|||||||
*/
|
*/
|
||||||
//% help=bluetooth/start-magnetometer-service
|
//% help=bluetooth/start-magnetometer-service
|
||||||
//% blockId=bluetooth_start_magnetometer_service block="bluetooth magnetometer service" blockGap=8
|
//% blockId=bluetooth_start_magnetometer_service block="bluetooth magnetometer service" blockGap=8
|
||||||
|
//% parts="bluetooth"
|
||||||
void startMagnetometerService() {
|
void startMagnetometerService() {
|
||||||
new MicroBitMagnetometerService(*uBit.ble, uBit.compass);
|
new MicroBitMagnetometerService(*uBit.ble, uBit.compass);
|
||||||
}
|
}
|
||||||
@ -68,6 +72,7 @@ namespace bluetooth {
|
|||||||
*/
|
*/
|
||||||
//% help=bluetooth/start-accelerometer-service
|
//% help=bluetooth/start-accelerometer-service
|
||||||
//% blockId=bluetooth_start_accelerometer_service block="bluetooth accelerometer service" blockGap=8
|
//% blockId=bluetooth_start_accelerometer_service block="bluetooth accelerometer service" blockGap=8
|
||||||
|
//% parts="bluetooth"
|
||||||
void startAccelerometerService() {
|
void startAccelerometerService() {
|
||||||
new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer);
|
new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer);
|
||||||
}
|
}
|
||||||
@ -77,6 +82,7 @@ namespace bluetooth {
|
|||||||
*/
|
*/
|
||||||
//% help=bluetooth/start-button-service
|
//% help=bluetooth/start-button-service
|
||||||
//% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8
|
//% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8
|
||||||
|
//% parts="bluetooth"
|
||||||
void startButtonService() {
|
void startButtonService() {
|
||||||
new MicroBitButtonService(*uBit.ble);
|
new MicroBitButtonService(*uBit.ble);
|
||||||
}
|
}
|
||||||
@ -86,6 +92,7 @@ namespace bluetooth {
|
|||||||
*/
|
*/
|
||||||
//% help=bluetooth/start-uart-service
|
//% help=bluetooth/start-uart-service
|
||||||
//% blockId=bluetooth_start_uart_service block="bluetooth uart service" blockGap=8
|
//% blockId=bluetooth_start_uart_service block="bluetooth uart service" blockGap=8
|
||||||
|
//% parts="bluetooth"
|
||||||
void startUartService() {
|
void startUartService() {
|
||||||
if (uart) return;
|
if (uart) return;
|
||||||
// 61 octet buffer size is 3 x (MTU - 3) + 1
|
// 61 octet buffer size is 3 x (MTU - 3) + 1
|
||||||
@ -99,6 +106,7 @@ namespace bluetooth {
|
|||||||
*/
|
*/
|
||||||
//% help=bluetooth/uart-write
|
//% help=bluetooth/uart-write
|
||||||
//% blockId=bluetooth_uart_write block="bluetooth uart write %data" blockGap=8
|
//% blockId=bluetooth_uart_write block="bluetooth uart write %data" blockGap=8
|
||||||
|
//% parts="bluetooth"
|
||||||
void uartWrite(StringData *data) {
|
void uartWrite(StringData *data) {
|
||||||
startUartService();
|
startUartService();
|
||||||
uart->send(ManagedString(data));
|
uart->send(ManagedString(data));
|
||||||
@ -109,6 +117,7 @@ namespace bluetooth {
|
|||||||
*/
|
*/
|
||||||
//% help=bluetooth/uart-read
|
//% help=bluetooth/uart-read
|
||||||
//% blockId=bluetooth_uart_read block="bluetooth uart read %del=bluetooth_uart_delimiter_conv" blockGap=8
|
//% blockId=bluetooth_uart_read block="bluetooth uart read %del=bluetooth_uart_delimiter_conv" blockGap=8
|
||||||
|
//% parts="bluetooth"
|
||||||
StringData* uartRead(StringData *del) {
|
StringData* uartRead(StringData *del) {
|
||||||
startUartService();
|
startUartService();
|
||||||
return uart->readUntil(ManagedString(del)).leakData();
|
return uart->readUntil(ManagedString(del)).leakData();
|
||||||
@ -119,6 +128,7 @@ namespace bluetooth {
|
|||||||
*/
|
*/
|
||||||
//% blockId="bluetooth_uart_delimiter_conv" block="%del"
|
//% blockId="bluetooth_uart_delimiter_conv" block="%del"
|
||||||
//% weight=1
|
//% weight=1
|
||||||
|
//% parts="bluetooth"
|
||||||
StringData* delimiters(Delimiters del) {
|
StringData* delimiters(Delimiters del) {
|
||||||
ManagedString c("\n\n,$:.#"[max(0, min(6, (int)del))]);
|
ManagedString c("\n\n,$:.#"[max(0, min(6, (int)del))]);
|
||||||
return c.leakData();
|
return c.leakData();
|
||||||
@ -129,6 +139,7 @@ namespace bluetooth {
|
|||||||
*/
|
*/
|
||||||
//% help=bluetooth/on-bluetooth-connected weight=20
|
//% help=bluetooth/on-bluetooth-connected weight=20
|
||||||
//% blockId=bluetooth_on_connected block="on bluetooth connected" blockGap=8
|
//% blockId=bluetooth_on_connected block="on bluetooth connected" blockGap=8
|
||||||
|
//% parts="bluetooth"
|
||||||
void onBluetoothConnected(Action body) {
|
void onBluetoothConnected(Action body) {
|
||||||
registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, body);
|
registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, body);
|
||||||
}
|
}
|
||||||
@ -139,6 +150,7 @@ namespace bluetooth {
|
|||||||
*/
|
*/
|
||||||
//% help=bluetooth/on-bluetooth-disconnected weight=19
|
//% help=bluetooth/on-bluetooth-disconnected weight=19
|
||||||
//% blockId=bluetooth_on_disconnected block="on bluetooth disconnected"
|
//% blockId=bluetooth_on_disconnected block="on bluetooth disconnected"
|
||||||
|
//% parts="bluetooth"
|
||||||
void onBluetoothDisconnected(Action body) {
|
void onBluetoothDisconnected(Action body) {
|
||||||
registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, 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.
|
* Starts the Bluetooth IO pin service.
|
||||||
*/
|
*/
|
||||||
//% help=bluetooth/start-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;
|
function startIOPinService(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the Bluetooth LED service
|
* Starts the Bluetooth LED service
|
||||||
*/
|
*/
|
||||||
//% help=bluetooth/start-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;
|
function startLEDService(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the Bluetooth temperature service
|
* Starts the Bluetooth temperature service
|
||||||
*/
|
*/
|
||||||
//% help=bluetooth/start-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;
|
function startTemperatureService(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the Bluetooth magnetometer service
|
* Starts the Bluetooth magnetometer service
|
||||||
*/
|
*/
|
||||||
//% help=bluetooth/start-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;
|
function startMagnetometerService(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the Bluetooth accelerometer service
|
* Starts the Bluetooth accelerometer service
|
||||||
*/
|
*/
|
||||||
//% help=bluetooth/start-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;
|
function startAccelerometerService(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the Bluetooth button service
|
* Starts the Bluetooth button service
|
||||||
*/
|
*/
|
||||||
//% help=bluetooth/start-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;
|
function startButtonService(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the Bluetooth UART service
|
* Starts the Bluetooth UART service
|
||||||
*/
|
*/
|
||||||
//% help=bluetooth/start-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;
|
function startUartService(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device.
|
* Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device.
|
||||||
*/
|
*/
|
||||||
//% help=bluetooth/uart-write
|
//% 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;
|
function uartWrite(data: string): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads from the Bluetooth UART service buffer, returning its contents when the specified delimiter character is encountered.
|
* Reads from the Bluetooth UART service buffer, returning its contents when the specified delimiter character is encountered.
|
||||||
*/
|
*/
|
||||||
//% help=bluetooth/uart-read
|
//% 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;
|
function uartRead(del: string): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the delimiter corresponding string
|
* Returns the delimiter corresponding string
|
||||||
*/
|
*/
|
||||||
//% blockId="bluetooth_uart_delimiter_conv" block="%del"
|
//% blockId="bluetooth_uart_delimiter_conv" block="%del"
|
||||||
//% weight=1 shim=bluetooth::delimiters
|
//% weight=1
|
||||||
|
//% parts="bluetooth" shim=bluetooth::delimiters
|
||||||
function delimiters(del: Delimiters): string;
|
function delimiters(del: Delimiters): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,7 +92,8 @@ declare namespace bluetooth {
|
|||||||
* @param body Code to run when a Bluetooth connection is established
|
* @param body Code to run when a Bluetooth connection is established
|
||||||
*/
|
*/
|
||||||
//% help=bluetooth/on-bluetooth-connected weight=20
|
//% 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;
|
function onBluetoothConnected(body: () => void): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,7 +101,8 @@ declare namespace bluetooth {
|
|||||||
* @param body Code to run when a Bluetooth connection is lost
|
* @param body Code to run when a Bluetooth connection is lost
|
||||||
*/
|
*/
|
||||||
//% help=bluetooth/on-bluetooth-disconnected weight=19
|
//% 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;
|
function onBluetoothDisconnected(body: () => void): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ namespace basic {
|
|||||||
//% 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
|
||||||
|
//% parts="ledmatrix"
|
||||||
void showNumber(int value, int interval = 150) {
|
void showNumber(int value, int interval = 150) {
|
||||||
if (interval < 0)
|
if (interval < 0)
|
||||||
return;
|
return;
|
||||||
@ -37,6 +38,7 @@ namespace basic {
|
|||||||
//% imageLiteral=1 async
|
//% imageLiteral=1 async
|
||||||
//% blockId=device_show_leds
|
//% blockId=device_show_leds
|
||||||
//% block="show leds" icon="\uf00a"
|
//% block="show leds" icon="\uf00a"
|
||||||
|
//% parts="ledmatrix"
|
||||||
void showLeds(ImageLiteral leds, int interval = 400) {
|
void showLeds(ImageLiteral leds, int interval = 400) {
|
||||||
uBit.display.print(MicroBitImage(imageBytes(leds)), 0, 0, 0, interval);
|
uBit.display.print(MicroBitImage(imageBytes(leds)), 0, 0, 0, interval);
|
||||||
}
|
}
|
||||||
@ -51,6 +53,7 @@ namespace basic {
|
|||||||
//% block="show|string %text" icon="\uf031"
|
//% block="show|string %text" icon="\uf031"
|
||||||
//% async
|
//% async
|
||||||
//% blockId=device_print_message
|
//% blockId=device_print_message
|
||||||
|
//% parts="ledmatrix"
|
||||||
void showString(StringData *text, int interval = 150) {
|
void showString(StringData *text, int interval = 150) {
|
||||||
if (interval < 0)
|
if (interval < 0)
|
||||||
return;
|
return;
|
||||||
@ -71,6 +74,7 @@ namespace basic {
|
|||||||
*/
|
*/
|
||||||
//% help=basic/clear-screen weight=79
|
//% help=basic/clear-screen weight=79
|
||||||
//% blockId=device_clear_display block="clear screen" icon="\uf12d"
|
//% blockId=device_clear_display block="clear screen" icon="\uf12d"
|
||||||
|
//% parts="ledmatrix"
|
||||||
void clearScreen() {
|
void clearScreen() {
|
||||||
uBit.display.image.clear();
|
uBit.display.image.clear();
|
||||||
}
|
}
|
||||||
@ -81,6 +85,7 @@ namespace basic {
|
|||||||
* @param interval time in milliseconds between each redraw
|
* @param interval time in milliseconds between each redraw
|
||||||
*/
|
*/
|
||||||
//% help=basic/show-animation imageLiteral=1 async
|
//% help=basic/show-animation imageLiteral=1 async
|
||||||
|
//% parts="ledmatrix"
|
||||||
void showAnimation(ImageLiteral leds, int interval = 400) {
|
void showAnimation(ImageLiteral leds, int interval = 400) {
|
||||||
uBit.display.animate(MicroBitImage(imageBytes(leds)), interval, 5, 0);
|
uBit.display.animate(MicroBitImage(imageBytes(leds)), interval, 5, 0);
|
||||||
}
|
}
|
||||||
@ -90,6 +95,7 @@ namespace basic {
|
|||||||
* @param leds pattern of LEDs to turn on/off
|
* @param leds pattern of LEDs to turn on/off
|
||||||
*/
|
*/
|
||||||
//% help=basic/plot-leds weight=80
|
//% help=basic/plot-leds weight=80
|
||||||
|
//% parts="ledmatrix"
|
||||||
void plotLeds(ImageLiteral leds) {
|
void plotLeds(ImageLiteral leds) {
|
||||||
MicroBitImage i(imageBytes(leds));
|
MicroBitImage i(imageBytes(leds));
|
||||||
uBit.display.print(i, 0, 0, 0, 0);
|
uBit.display.print(i, 0, 0, 0, 0);
|
||||||
|
@ -196,6 +196,8 @@ namespace pxt {
|
|||||||
int programHash();
|
int programHash();
|
||||||
//%
|
//%
|
||||||
void *ptrOfLiteral(int offset);
|
void *ptrOfLiteral(int offset);
|
||||||
|
//%
|
||||||
|
int getNumGlobals();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace pxtrt {
|
namespace pxtrt {
|
||||||
@ -261,36 +263,6 @@ namespace pxtrt {
|
|||||||
r->unref();
|
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.
|
// 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)
|
RefAction *stclo(RefAction *a, int idx, uint32_t v)
|
||||||
@ -306,15 +278,38 @@ namespace pxtrt {
|
|||||||
microbit_panic(code);
|
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
|
// Debugger
|
||||||
//
|
//
|
||||||
|
|
||||||
//%
|
|
||||||
uint32_t getNumGlobals() {
|
|
||||||
return numGlobals;
|
|
||||||
}
|
|
||||||
|
|
||||||
//%
|
//%
|
||||||
void* getGlobalsPtr() {
|
void* getGlobalsPtr() {
|
||||||
return globals;
|
return globals;
|
||||||
|
@ -41,6 +41,7 @@ namespace game {
|
|||||||
*/
|
*/
|
||||||
//% weight=60
|
//% weight=60
|
||||||
//% blockId=game_create_sprite block="create sprite at|x: %x|y: %y"
|
//% blockId=game_create_sprite block="create sprite at|x: %x|y: %y"
|
||||||
|
//% parts="ledmatrix"
|
||||||
export function createSprite(x: number, y: number): LedSprite {
|
export function createSprite(x: number, y: number): LedSprite {
|
||||||
init();
|
init();
|
||||||
let p = new LedSprite(x, y);
|
let p = new LedSprite(x, y);
|
||||||
@ -64,6 +65,7 @@ namespace game {
|
|||||||
*/
|
*/
|
||||||
//% weight=10 help=game/add-score
|
//% weight=10 help=game/add-score
|
||||||
//% blockId=game_add_score block="change score by|%points" blockGap=8
|
//% blockId=game_add_score block="change score by|%points" blockGap=8
|
||||||
|
//% parts="ledmatrix"
|
||||||
export function addScore(points: number): void {
|
export function addScore(points: number): void {
|
||||||
setScore(_score + points);
|
setScore(_score + points);
|
||||||
control.inBackground(() => {
|
control.inBackground(() => {
|
||||||
@ -82,6 +84,7 @@ namespace game {
|
|||||||
*/
|
*/
|
||||||
//% weight=9 help=game/start-countdown
|
//% weight=9 help=game/start-countdown
|
||||||
//% blockId=game_start_countdown block="start countdown|(ms) %duration" blockGap=8
|
//% blockId=game_start_countdown block="start countdown|(ms) %duration" blockGap=8
|
||||||
|
//% parts="ledmatrix"
|
||||||
export function startCountdown(ms: number): void {
|
export function startCountdown(ms: number): void {
|
||||||
if (checkStart()) {
|
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
|
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
|
//% weight=8 help=game/game-over
|
||||||
//% blockId=game_game_over block="game over"
|
//% blockId=game_game_over block="game over"
|
||||||
|
//% parts="ledmatrix"
|
||||||
export function gameOver(): void {
|
export function gameOver(): void {
|
||||||
if (!_isGameOver) {
|
if (!_isGameOver) {
|
||||||
_isGameOver = true;
|
_isGameOver = true;
|
||||||
@ -194,6 +198,7 @@ namespace game {
|
|||||||
* @param life TODO
|
* @param life TODO
|
||||||
*/
|
*/
|
||||||
//% weight=10
|
//% weight=10
|
||||||
|
//% parts="ledmatrix"
|
||||||
export function removeLife(life: number): void {
|
export function removeLife(life: number): void {
|
||||||
setLife(_life - life);
|
setLife(_life - life);
|
||||||
control.inBackground(() => {
|
control.inBackground(() => {
|
||||||
@ -210,6 +215,7 @@ namespace game {
|
|||||||
* Increments the level and display a message.
|
* Increments the level and display a message.
|
||||||
*/
|
*/
|
||||||
//% weight=10
|
//% weight=10
|
||||||
|
//% parts="ledmatrix"
|
||||||
export function levelUp(): void {
|
export function levelUp(): void {
|
||||||
_level = _level + 1;
|
_level = _level + 1;
|
||||||
basic.showString("LEVEL:", 150);
|
basic.showString("LEVEL:", 150);
|
||||||
@ -246,6 +252,7 @@ namespace game {
|
|||||||
* Displays the score on the screen.
|
* Displays the score on the screen.
|
||||||
*/
|
*/
|
||||||
//% weight=60
|
//% weight=60
|
||||||
|
//% parts="ledmatrix"
|
||||||
export function showScore(): void {
|
export function showScore(): void {
|
||||||
basic.showString(" SCORE ", 100);
|
basic.showString(" SCORE ", 100);
|
||||||
basic.showNumber(_score, 150);
|
basic.showNumber(_score, 150);
|
||||||
@ -303,6 +310,7 @@ namespace game {
|
|||||||
*/
|
*/
|
||||||
//% weight=50
|
//% weight=50
|
||||||
//% blockId=game_move_sprite block="%sprite|move by %leds" blockGap=8
|
//% blockId=game_move_sprite block="%sprite|move by %leds" blockGap=8
|
||||||
|
//% parts="ledmatrix"
|
||||||
public move(leds: number): void {
|
public move(leds: number): void {
|
||||||
if (this._dir == 0) {
|
if (this._dir == 0) {
|
||||||
this._y = this._y - leds;
|
this._y = this._y - leds;
|
||||||
@ -336,6 +344,7 @@ namespace game {
|
|||||||
* @param x TODO
|
* @param x TODO
|
||||||
* @param y TODO
|
* @param y TODO
|
||||||
*/
|
*/
|
||||||
|
//% parts="ledmatrix"
|
||||||
public goTo(x: number, y: number): void {
|
public goTo(x: number, y: number): void {
|
||||||
this._x = x;
|
this._x = x;
|
||||||
this._y = y;
|
this._y = y;
|
||||||
@ -350,6 +359,7 @@ namespace game {
|
|||||||
*/
|
*/
|
||||||
//% weight=18
|
//% weight=18
|
||||||
//% blockId=game_sprite_bounce block="%sprite|if on edge, bounce"
|
//% blockId=game_sprite_bounce block="%sprite|if on edge, bounce"
|
||||||
|
//% parts="ledmatrix"
|
||||||
public ifOnEdgeBounce(): void {
|
public ifOnEdgeBounce(): void {
|
||||||
if (this._dir == 0 && this._y == 0) {
|
if (this._dir == 0 && this._y == 0) {
|
||||||
this._dir = 180;
|
this._dir = 180;
|
||||||
@ -484,6 +494,7 @@ namespace game {
|
|||||||
* @param this TODO
|
* @param this TODO
|
||||||
* @param degrees TODO
|
* @param degrees TODO
|
||||||
*/
|
*/
|
||||||
|
//% parts="ledmatrix"
|
||||||
public setDirection(degrees: number): void {
|
public setDirection(degrees: number): void {
|
||||||
this._dir = ((degrees / 45) % 8) * 45;
|
this._dir = ((degrees / 45) % 8) * 45;
|
||||||
if (this._dir <= -180) {
|
if (this._dir <= -180) {
|
||||||
@ -596,6 +607,7 @@ namespace game {
|
|||||||
* @param this TODO
|
* @param this TODO
|
||||||
* @param brightness TODO
|
* @param brightness TODO
|
||||||
*/
|
*/
|
||||||
|
//% parts="ledmatrix"
|
||||||
public setBrightness(brightness: number): void {
|
public setBrightness(brightness: number): void {
|
||||||
this._brightness = Math.clamp(0, 255, brightness);
|
this._brightness = Math.clamp(0, 255, brightness);
|
||||||
plot();
|
plot();
|
||||||
@ -664,6 +676,7 @@ namespace game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//% weight=-1
|
//% weight=-1
|
||||||
|
//% parts="ledmatrix"
|
||||||
public _plot(now: number) {
|
public _plot(now: number) {
|
||||||
let ps = this
|
let ps = this
|
||||||
if (ps._brightness > 0) {
|
if (ps._brightness > 0) {
|
||||||
@ -701,6 +714,7 @@ namespace game {
|
|||||||
/**
|
/**
|
||||||
* Plots the current sprites on the screen
|
* Plots the current sprites on the screen
|
||||||
*/
|
*/
|
||||||
|
//% parts="ledmatrix"
|
||||||
function plot(): void {
|
function plot(): void {
|
||||||
if (game.isGameOver()) {
|
if (game.isGameOver()) {
|
||||||
return;
|
return;
|
||||||
|
@ -10,6 +10,7 @@ namespace images {
|
|||||||
*/
|
*/
|
||||||
//% weight=75 help=images/create-image
|
//% weight=75 help=images/create-image
|
||||||
//% blockId=device_build_image block="create image"
|
//% blockId=device_build_image block="create image"
|
||||||
|
//% parts="ledmatrix"
|
||||||
Image createImage(ImageLiteral leds) {
|
Image createImage(ImageLiteral leds) {
|
||||||
return MicroBitImage(imageBytes(leds)).clone().leakData();
|
return MicroBitImage(imageBytes(leds)).clone().leakData();
|
||||||
}
|
}
|
||||||
@ -19,6 +20,7 @@ namespace images {
|
|||||||
*/
|
*/
|
||||||
//% weight=74 help=images/create-big-image
|
//% weight=74 help=images/create-big-image
|
||||||
//% blockId=device_build_big_image block="create big image" imageLiteral=2
|
//% blockId=device_build_big_image block="create big image" imageLiteral=2
|
||||||
|
//% parts="ledmatrix"
|
||||||
Image createBigImage(ImageLiteral leds) {
|
Image createBigImage(ImageLiteral leds) {
|
||||||
return createImage(leds);
|
return createImage(leds);
|
||||||
}
|
}
|
||||||
@ -29,6 +31,7 @@ namespace ImageMethods {
|
|||||||
* Plots the image at a given column to the screen
|
* Plots the image at a given column to the screen
|
||||||
*/
|
*/
|
||||||
//% help=images/plot-image
|
//% help=images/plot-image
|
||||||
|
//% parts="ledmatrix"
|
||||||
void plotImage(Image i, int xOffset = 0) {
|
void plotImage(Image i, int xOffset = 0) {
|
||||||
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0, 0);
|
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0, 0);
|
||||||
}
|
}
|
||||||
@ -39,6 +42,7 @@ namespace ImageMethods {
|
|||||||
*/
|
*/
|
||||||
//% help=images/show-image weight=80 blockNamespace=images
|
//% help=images/show-image weight=80 blockNamespace=images
|
||||||
//% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8
|
//% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8
|
||||||
|
//% parts="ledmatrix"
|
||||||
void showImage(Image sprite, int xOffset) {
|
void showImage(Image sprite, int xOffset) {
|
||||||
uBit.display.print(MicroBitImage(sprite), -xOffset, 0, 0);
|
uBit.display.print(MicroBitImage(sprite), -xOffset, 0, 0);
|
||||||
}
|
}
|
||||||
@ -48,6 +52,7 @@ namespace ImageMethods {
|
|||||||
* @param xOffset column index to start displaying the image
|
* @param xOffset column index to start displaying the image
|
||||||
*/
|
*/
|
||||||
//% help=images/plot-frame weight=80
|
//% help=images/plot-frame weight=80
|
||||||
|
//% parts="ledmatrix"
|
||||||
void plotFrame(Image i, int xOffset) {
|
void plotFrame(Image i, int xOffset) {
|
||||||
// TODO showImage() used in original implementation
|
// TODO showImage() used in original implementation
|
||||||
plotImage(i, xOffset * 5);
|
plotImage(i, xOffset * 5);
|
||||||
@ -60,6 +65,7 @@ namespace ImageMethods {
|
|||||||
*/
|
*/
|
||||||
//% help=images/show-image weight=79 async blockNamespace=images
|
//% 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
|
//% 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) {
|
void scrollImage(Image id, int frameOffset, int interval) {
|
||||||
MicroBitImage i(id);
|
MicroBitImage i(id);
|
||||||
if (i.getWidth() <= 5)
|
if (i.getWidth() <= 5)
|
||||||
@ -73,6 +79,7 @@ namespace ImageMethods {
|
|||||||
* Sets all pixels off.
|
* Sets all pixels off.
|
||||||
*/
|
*/
|
||||||
//% help=images/clear
|
//% help=images/clear
|
||||||
|
//% parts="ledmatrix"
|
||||||
void clear(Image i) {
|
void clear(Image i) {
|
||||||
MicroBitImage(i).clear();
|
MicroBitImage(i).clear();
|
||||||
}
|
}
|
||||||
@ -81,6 +88,7 @@ namespace ImageMethods {
|
|||||||
* Sets a specific pixel brightness at a given position
|
* Sets a specific pixel brightness at a given position
|
||||||
*/
|
*/
|
||||||
//%
|
//%
|
||||||
|
//% parts="ledmatrix"
|
||||||
void setPixelBrightness(Image i, int x, int y, int value) {
|
void setPixelBrightness(Image i, int x, int y, int value) {
|
||||||
MicroBitImage(i).setPixelValue(x, y, value);
|
MicroBitImage(i).setPixelValue(x, y, value);
|
||||||
}
|
}
|
||||||
@ -90,6 +98,7 @@ namespace ImageMethods {
|
|||||||
* Gets the pixel brightness ([0..255]) at a given position
|
* Gets the pixel brightness ([0..255]) at a given position
|
||||||
*/
|
*/
|
||||||
//%
|
//%
|
||||||
|
//% parts="ledmatrix"
|
||||||
int pixelBrightness(Image i, int x, int y) {
|
int pixelBrightness(Image i, int x, int y) {
|
||||||
int pix = MicroBitImage(i).getPixelValue(x, y);
|
int pix = MicroBitImage(i).getPixelValue(x, y);
|
||||||
if (pix < 0) return 0;
|
if (pix < 0) return 0;
|
||||||
@ -120,6 +129,7 @@ namespace ImageMethods {
|
|||||||
* @param value TODO
|
* @param value TODO
|
||||||
*/
|
*/
|
||||||
//% help=images/set-pixel
|
//% help=images/set-pixel
|
||||||
|
//% parts="ledmatrix"
|
||||||
void setPixel(Image i, int x, int y, bool value) {
|
void setPixel(Image i, int x, int y, bool value) {
|
||||||
setPixelBrightness(i, x, y, value ? 255 : 0);
|
setPixelBrightness(i, x, y, value ? 255 : 0);
|
||||||
}
|
}
|
||||||
@ -130,6 +140,7 @@ namespace ImageMethods {
|
|||||||
* @param y TODO
|
* @param y TODO
|
||||||
*/
|
*/
|
||||||
//% help=images/pixel
|
//% help=images/pixel
|
||||||
|
//% parts="ledmatrix"
|
||||||
bool pixel(Image i, int x, int y) {
|
bool pixel(Image i, int x, int y) {
|
||||||
return pixelBrightness(i, x, y) > 0;
|
return pixelBrightness(i, x, y) > 0;
|
||||||
}
|
}
|
||||||
@ -140,6 +151,7 @@ namespace ImageMethods {
|
|||||||
* @param frame TODO
|
* @param frame TODO
|
||||||
*/
|
*/
|
||||||
//% weight=70 help=images/show-frame
|
//% weight=70 help=images/show-frame
|
||||||
|
//% parts="ledmatrix"
|
||||||
void showFrame(Image i, int frame) {
|
void showFrame(Image i, int frame) {
|
||||||
showImage(i, frame * 5);
|
showImage(i, frame * 5);
|
||||||
}
|
}
|
||||||
|
@ -116,6 +116,7 @@ namespace input {
|
|||||||
*/
|
*/
|
||||||
//% help=input/on-button-pressed weight=85 blockGap=8
|
//% help=input/on-button-pressed weight=85 blockGap=8
|
||||||
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192"
|
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192"
|
||||||
|
//% parts="buttonpair"
|
||||||
void onButtonPressed(Button button, Action body) {
|
void onButtonPressed(Button button, Action body) {
|
||||||
registerWithDal((int)button, MICROBIT_BUTTON_EVT_CLICK, body);
|
registerWithDal((int)button, MICROBIT_BUTTON_EVT_CLICK, body);
|
||||||
}
|
}
|
||||||
@ -126,6 +127,7 @@ namespace input {
|
|||||||
*/
|
*/
|
||||||
//% help=input/on-gesture weight=84 blockGap=8
|
//% help=input/on-gesture weight=84 blockGap=8
|
||||||
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135"
|
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135"
|
||||||
|
//% parts="accelerometer"
|
||||||
void onGesture(Gesture gesture, Action body) {
|
void onGesture(Gesture gesture, Action body) {
|
||||||
if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
|
if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
|
||||||
uBit.accelerometer.setRange(4);
|
uBit.accelerometer.setRange(4);
|
||||||
@ -134,7 +136,7 @@ namespace input {
|
|||||||
registerWithDal(MICROBIT_ID_GESTURE, (int)gesture, body);
|
registerWithDal(MICROBIT_ID_GESTURE, (int)gesture, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do something when a pin is pressed.
|
* Do something when a pin is pressed.
|
||||||
* @param name the pin that needs to be pressed
|
* @param name the pin that needs to be pressed
|
||||||
* @param body the code to run when the pin is pressed
|
* @param body the code to run when the pin is pressed
|
||||||
@ -173,6 +175,7 @@ namespace input {
|
|||||||
//% block="button|%NAME|is pressed"
|
//% block="button|%NAME|is pressed"
|
||||||
//% blockId=device_get_button2
|
//% blockId=device_get_button2
|
||||||
//% icon="\uf192" blockGap=8
|
//% icon="\uf192" blockGap=8
|
||||||
|
//% parts="buttonpair"
|
||||||
bool buttonIsPressed(Button button) {
|
bool buttonIsPressed(Button button) {
|
||||||
if (button == Button::A)
|
if (button == Button::A)
|
||||||
return uBit.buttonA.isPressed();
|
return uBit.buttonA.isPressed();
|
||||||
@ -201,6 +204,7 @@ namespace input {
|
|||||||
//% help=input/compass-heading
|
//% help=input/compass-heading
|
||||||
//% weight=56 icon="\uf14e"
|
//% weight=56 icon="\uf14e"
|
||||||
//% blockId=device_heading block="compass heading (°)" blockGap=8
|
//% blockId=device_heading block="compass heading (°)" blockGap=8
|
||||||
|
//% parts="compass"
|
||||||
int compassHeading() {
|
int compassHeading() {
|
||||||
return uBit.compass.heading();
|
return uBit.compass.heading();
|
||||||
}
|
}
|
||||||
@ -212,6 +216,7 @@ namespace input {
|
|||||||
//% weight=55 icon="\uf06d"
|
//% weight=55 icon="\uf06d"
|
||||||
//% help=input/temperature
|
//% help=input/temperature
|
||||||
//% blockId=device_temperature block="temperature (°C)" blockGap=8
|
//% blockId=device_temperature block="temperature (°C)" blockGap=8
|
||||||
|
//% parts="thermometer"
|
||||||
int temperature() {
|
int temperature() {
|
||||||
return uBit.thermometer.getTemperature();
|
return uBit.thermometer.getTemperature();
|
||||||
}
|
}
|
||||||
@ -229,6 +234,7 @@ namespace input {
|
|||||||
*/
|
*/
|
||||||
//% help=input/acceleration weight=54 icon="\uf135"
|
//% help=input/acceleration weight=54 icon="\uf135"
|
||||||
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8
|
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8
|
||||||
|
//% parts="accelerometer"
|
||||||
int acceleration(Dimension dimension) {
|
int acceleration(Dimension dimension) {
|
||||||
switch (dimension) {
|
switch (dimension) {
|
||||||
case Dimension::X: return uBit.accelerometer.getX();
|
case Dimension::X: return uBit.accelerometer.getX();
|
||||||
@ -245,6 +251,7 @@ namespace input {
|
|||||||
*/
|
*/
|
||||||
//% help=input/light-level weight=53
|
//% help=input/light-level weight=53
|
||||||
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185"
|
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185"
|
||||||
|
//% parts="ledmatrix"
|
||||||
int lightLevel() {
|
int lightLevel() {
|
||||||
return uBit.display.readLightLevel();
|
return uBit.display.readLightLevel();
|
||||||
}
|
}
|
||||||
@ -255,6 +262,7 @@ namespace input {
|
|||||||
*/
|
*/
|
||||||
//% help=input/rotation weight=52
|
//% help=input/rotation weight=52
|
||||||
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197"
|
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197"
|
||||||
|
//% parts="accelerometer"
|
||||||
int rotation(Rotation kind) {
|
int rotation(Rotation kind) {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case Rotation::Pitch: return uBit.accelerometer.getPitch();
|
case Rotation::Pitch: return uBit.accelerometer.getPitch();
|
||||||
@ -269,6 +277,7 @@ namespace input {
|
|||||||
*/
|
*/
|
||||||
//% help=input/magnetic-force weight=51
|
//% help=input/magnetic-force weight=51
|
||||||
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076"
|
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076"
|
||||||
|
//% parts="compass"
|
||||||
int magneticForce(Dimension dimension) {
|
int magneticForce(Dimension dimension) {
|
||||||
if (!uBit.compass.isCalibrated())
|
if (!uBit.compass.isCalibrated())
|
||||||
uBit.compass.calibrate();
|
uBit.compass.calibrate();
|
||||||
@ -304,6 +313,7 @@ namespace input {
|
|||||||
//% help=input/set-accelerometer-range
|
//% help=input/set-accelerometer-range
|
||||||
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135"
|
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135"
|
||||||
//% weight=5
|
//% weight=5
|
||||||
|
//% parts="accelerometer"
|
||||||
void setAccelerometerRange(AcceleratorRange range) {
|
void setAccelerometerRange(AcceleratorRange range) {
|
||||||
uBit.accelerometer.setRange((int)range);
|
uBit.accelerometer.setRange((int)range);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ namespace led {
|
|||||||
*/
|
*/
|
||||||
//% help=led/plot weight=78
|
//% help=led/plot weight=78
|
||||||
//% blockId=device_plot block="plot|x %x|y %y" icon="\uf205" blockGap=8
|
//% blockId=device_plot block="plot|x %x|y %y" icon="\uf205" blockGap=8
|
||||||
|
//% parts="ledmatrix"
|
||||||
void plot(int x, int y) {
|
void plot(int x, int y) {
|
||||||
uBit.display.image.setPixelValue(x, y, 1);
|
uBit.display.image.setPixelValue(x, y, 1);
|
||||||
}
|
}
|
||||||
@ -29,6 +30,7 @@ namespace led {
|
|||||||
*/
|
*/
|
||||||
//% help=led/unplot weight=77
|
//% help=led/unplot weight=77
|
||||||
//% blockId=device_unplot block="unplot|x %x|y %y" icon="\uf204" blockGap=8
|
//% blockId=device_unplot block="unplot|x %x|y %y" icon="\uf204" blockGap=8
|
||||||
|
//% parts="ledmatrix"
|
||||||
void unplot(int x, int y) {
|
void unplot(int x, int y) {
|
||||||
uBit.display.image.setPixelValue(x, y, 0);
|
uBit.display.image.setPixelValue(x, y, 0);
|
||||||
}
|
}
|
||||||
@ -40,6 +42,7 @@ namespace led {
|
|||||||
*/
|
*/
|
||||||
//% help=led/point weight=76
|
//% help=led/point weight=76
|
||||||
//% blockId=device_point block="point|x %x|y %y" icon="\uf10c"
|
//% blockId=device_point block="point|x %x|y %y" icon="\uf10c"
|
||||||
|
//% parts="ledmatrix"
|
||||||
bool point(int x, int y) {
|
bool point(int x, int y) {
|
||||||
int pix = uBit.display.image.getPixelValue(x, y);
|
int pix = uBit.display.image.getPixelValue(x, y);
|
||||||
return pix > 0;
|
return pix > 0;
|
||||||
@ -50,6 +53,7 @@ namespace led {
|
|||||||
*/
|
*/
|
||||||
//% help=led/brightness weight=60
|
//% help=led/brightness weight=60
|
||||||
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8
|
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8
|
||||||
|
//% parts="ledmatrix"
|
||||||
int brightness() {
|
int brightness() {
|
||||||
return uBit.display.getBrightness();
|
return uBit.display.getBrightness();
|
||||||
}
|
}
|
||||||
@ -60,6 +64,7 @@ namespace led {
|
|||||||
*/
|
*/
|
||||||
//% help=led/set-brightness weight=59
|
//% help=led/set-brightness weight=59
|
||||||
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042"
|
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042"
|
||||||
|
//% parts="ledmatrix"
|
||||||
void setBrightness(int value) {
|
void setBrightness(int value) {
|
||||||
uBit.display.setBrightness(value);
|
uBit.display.setBrightness(value);
|
||||||
}
|
}
|
||||||
@ -69,6 +74,7 @@ namespace led {
|
|||||||
*/
|
*/
|
||||||
//% weight=50 help=led/stop-animation
|
//% weight=50 help=led/stop-animation
|
||||||
//% blockId=device_stop_animation block="stop animation" icon="\uf04d"
|
//% blockId=device_stop_animation block="stop animation" icon="\uf04d"
|
||||||
|
//% parts="ledmatrix"
|
||||||
void stopAnimation() {
|
void stopAnimation() {
|
||||||
uBit.display.stopAnimation();
|
uBit.display.stopAnimation();
|
||||||
}
|
}
|
||||||
@ -78,6 +84,7 @@ namespace led {
|
|||||||
* @param mode TODO
|
* @param mode TODO
|
||||||
*/
|
*/
|
||||||
//% weight=1 help=led/set-display-mode
|
//% weight=1 help=led/set-display-mode
|
||||||
|
//% parts="ledmatrix"
|
||||||
void setDisplayMode(DisplayMode_ mode) {
|
void setDisplayMode(DisplayMode_ mode) {
|
||||||
uBit.display.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.
|
* Takes a screenshot of the LED screen and returns an image.
|
||||||
*/
|
*/
|
||||||
//% help=led/screenshot
|
//% help=led/screenshot
|
||||||
|
//% parts="ledmatrix"
|
||||||
Image screenshot() {
|
Image screenshot() {
|
||||||
return uBit.display.screenShot().leakData();
|
return uBit.display.screenShot().leakData();
|
||||||
/*
|
/*
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
//% help=led/plot-bar-graph weight=20
|
//% 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
|
//% 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 {
|
export function plotBarGraph(value: number, high: number): void {
|
||||||
let now = input.runningTime();
|
let now = input.runningTime();
|
||||||
serial.writeString(value.toString() + "\r\n");
|
serial.writeString(value.toString() + "\r\n");
|
||||||
@ -53,6 +54,7 @@
|
|||||||
*/
|
*/
|
||||||
//% help=led/toggle weight=77
|
//% help=led/toggle weight=77
|
||||||
//% blockId=device_led_toggle block="toggle|x %x|y %y" icon="\uf204" blockGap=8
|
//% blockId=device_led_toggle block="toggle|x %x|y %y" icon="\uf204" blockGap=8
|
||||||
|
//% parts="ledmatrix"
|
||||||
export function toggle(x: number, y: number): void {
|
export function toggle(x: number, y: number): void {
|
||||||
if (led.point(x, y)) {
|
if (led.point(x, y)) {
|
||||||
led.unplot(x, y);
|
led.unplot(x, y);
|
||||||
@ -65,6 +67,7 @@
|
|||||||
* Turns all LEDS on
|
* Turns all LEDS on
|
||||||
*/
|
*/
|
||||||
//% help=led/plot-all
|
//% help=led/plot-all
|
||||||
|
//% parts="ledmatrix"
|
||||||
export function plotAll(): void {
|
export function plotAll(): void {
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
for (let j = 0; j < 5; j++) {
|
for (let j = 0; j < 5; j++) {
|
||||||
@ -77,6 +80,7 @@
|
|||||||
* Inverts the current LED display
|
* Inverts the current LED display
|
||||||
*/
|
*/
|
||||||
//% help=led/toggle-all
|
//% help=led/toggle-all
|
||||||
|
//% parts="ledmatrix"
|
||||||
export function toggleAll(): void {
|
export function toggleAll(): void {
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
for (let j = 0; j < 5; j++) {
|
for (let j = 0; j < 5; j++) {
|
||||||
@ -90,6 +94,7 @@
|
|||||||
* @param ms TODO
|
* @param ms TODO
|
||||||
*/
|
*/
|
||||||
//% help=led/fade-in
|
//% help=led/fade-in
|
||||||
|
//% parts="ledmatrix"
|
||||||
export function fadeIn(ms: number = 700): void {
|
export function fadeIn(ms: number = 700): void {
|
||||||
if (ms < 20) {
|
if (ms < 20) {
|
||||||
led.setBrightness(255);
|
led.setBrightness(255);
|
||||||
@ -112,6 +117,7 @@
|
|||||||
* @param ms TODO
|
* @param ms TODO
|
||||||
*/
|
*/
|
||||||
//% help=led/fade-out
|
//% help=led/fade-out
|
||||||
|
//% parts="ledmatrix"
|
||||||
export function fadeOut(ms: number = 700): void {
|
export function fadeOut(ms: number = 700): void {
|
||||||
if (ms < 20) {
|
if (ms < 20) {
|
||||||
led.setBrightness(0);
|
led.setBrightness(0);
|
||||||
|
@ -1,63 +1,110 @@
|
|||||||
enum Note {
|
enum Note {
|
||||||
C = 262,
|
C = 262,
|
||||||
//% block=C#
|
//% block=C#
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
CSharp = 277,
|
CSharp = 277,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
D = 294,
|
D = 294,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
Eb = 311,
|
Eb = 311,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
E = 330,
|
E = 330,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
F = 349,
|
F = 349,
|
||||||
//% block=F#
|
//% block=F#
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
FSharp = 370,
|
FSharp = 370,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
G = 392,
|
G = 392,
|
||||||
//% block=G#
|
//% block=G#
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
GSharp = 415,
|
GSharp = 415,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
A = 440,
|
A = 440,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
Bb = 466,
|
Bb = 466,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
B = 494,
|
B = 494,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
C3 = 131,
|
C3 = 131,
|
||||||
//% block=C#3
|
//% block=C#3
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
CSharp3 = 139,
|
CSharp3 = 139,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
D3 = 147,
|
D3 = 147,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
Eb3 = 156,
|
Eb3 = 156,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
E3 = 165,
|
E3 = 165,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
F3 = 175,
|
F3 = 175,
|
||||||
//% block=F#3
|
//% block=F#3
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
FSharp3 = 185,
|
FSharp3 = 185,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
G3 = 196,
|
G3 = 196,
|
||||||
//% block=G#3
|
//% block=G#3
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
GSharp3 = 208,
|
GSharp3 = 208,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
A3 = 220,
|
A3 = 220,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
Bb3 = 233,
|
Bb3 = 233,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
B3 = 247,
|
B3 = 247,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
C4 = 262,
|
C4 = 262,
|
||||||
//% block=C#4
|
//% block=C#4
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
CSharp4 = 277,
|
CSharp4 = 277,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
D4 = 294,
|
D4 = 294,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
Eb4 = 311,
|
Eb4 = 311,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
E4 = 330,
|
E4 = 330,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
F4 = 349,
|
F4 = 349,
|
||||||
//% block=F#4
|
//% block=F#4
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
FSharp4 = 370,
|
FSharp4 = 370,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
G4 = 392,
|
G4 = 392,
|
||||||
//% block=G#4
|
//% block=G#4
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
GSharp4 = 415,
|
GSharp4 = 415,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
A4 = 440,
|
A4 = 440,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
Bb4 = 466,
|
Bb4 = 466,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
B4 = 494,
|
B4 = 494,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
C5 = 523,
|
C5 = 523,
|
||||||
//% block=C#5
|
//% block=C#5
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
CSharp5 = 555,
|
CSharp5 = 555,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
D5 = 587,
|
D5 = 587,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
Eb5 = 622,
|
Eb5 = 622,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
E5 = 659,
|
E5 = 659,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
F5 = 698,
|
F5 = 698,
|
||||||
//% block=F#5
|
//% block=F#5
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
FSharp5 = 740,
|
FSharp5 = 740,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
G5 = 784,
|
G5 = 784,
|
||||||
//% block=G#5
|
//% block=G#5
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
GSharp5 = 831,
|
GSharp5 = 831,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
A5 = 880,
|
A5 = 880,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
Bb5 = 932,
|
Bb5 = 932,
|
||||||
|
//% blockIdentity=music.noteFrequency
|
||||||
B5 = 989,
|
B5 = 989,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +168,7 @@ namespace music {
|
|||||||
*/
|
*/
|
||||||
//% weight=50 help=music/note-frequency
|
//% weight=50 help=music/note-frequency
|
||||||
//% blockId=device_note block="%note"
|
//% blockId=device_note block="%note"
|
||||||
|
//% shim=TD_ID
|
||||||
export function noteFrequency(name: Note): number {
|
export function noteFrequency(name: Note): number {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
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.
|
* Creates an image that fits on the LED screen.
|
||||||
*/
|
*/
|
||||||
//% weight=75 help=images/create-image
|
//% 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;
|
function createImage(leds: string): Image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an image with 2 frames.
|
* Creates an image with 2 frames.
|
||||||
*/
|
*/
|
||||||
//% weight=74 help=images/create-big-image
|
//% 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;
|
function createBigImage(leds: string): Image;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +29,8 @@ declare interface Image {
|
|||||||
/**
|
/**
|
||||||
* Plots the image at a given column to the screen
|
* 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;
|
plotImage(xOffset?: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,14 +38,16 @@ declare interface Image {
|
|||||||
* @param xOffset column index to start displaying the image
|
* @param xOffset column index to start displaying the image
|
||||||
*/
|
*/
|
||||||
//% help=images/show-image weight=80 blockNamespace=images
|
//% 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;
|
showImage(xOffset: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws the ``index``-th frame of the image on the screen.
|
* Draws the ``index``-th frame of the image on the screen.
|
||||||
* @param xOffset column index to start displaying the image
|
* @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;
|
plotFrame(xOffset: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,25 +56,29 @@ declare interface Image {
|
|||||||
* @param interval time between each animation step in milli seconds, eg: 200
|
* @param interval time between each animation step in milli seconds, eg: 200
|
||||||
*/
|
*/
|
||||||
//% help=images/show-image weight=79 async blockNamespace=images
|
//% 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;
|
scrollImage(frameOffset: number, interval: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets all pixels off.
|
* Sets all pixels off.
|
||||||
*/
|
*/
|
||||||
//% help=images/clear shim=ImageMethods::clear
|
//% help=images/clear
|
||||||
|
//% parts="ledmatrix" shim=ImageMethods::clear
|
||||||
clear(): void;
|
clear(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a specific pixel brightness at a given position
|
* 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;
|
setPixelBrightness(x: number, y: number, value: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the pixel brightness ([0..255]) at a given position
|
* Gets the pixel brightness ([0..255]) at a given position
|
||||||
*/
|
*/
|
||||||
//% shim=ImageMethods::pixelBrightness
|
//%
|
||||||
|
//% parts="ledmatrix" shim=ImageMethods::pixelBrightness
|
||||||
pixelBrightness(x: number, y: number): number;
|
pixelBrightness(x: number, y: number): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,7 +99,8 @@ declare interface Image {
|
|||||||
* @param y TODO
|
* @param y TODO
|
||||||
* @param value 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;
|
setPixel(x: number, y: number, value: boolean): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -98,14 +108,16 @@ declare interface Image {
|
|||||||
* @param x TODO
|
* @param x TODO
|
||||||
* @param y TODO
|
* @param y TODO
|
||||||
*/
|
*/
|
||||||
//% help=images/pixel shim=ImageMethods::pixel
|
//% help=images/pixel
|
||||||
|
//% parts="ledmatrix" shim=ImageMethods::pixel
|
||||||
pixel(x: number, y: number): boolean;
|
pixel(x: number, y: number): boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows a particular frame of the image strip.
|
* Shows a particular frame of the image strip.
|
||||||
* @param frame TODO
|
* @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;
|
showFrame(frame: number): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +135,8 @@ 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 interval.defl=150 shim=basic::showNumber
|
//% async
|
||||||
|
//% parts="ledmatrix" interval.defl=150 shim=basic::showNumber
|
||||||
function showNumber(value: number, interval?: number): void;
|
function showNumber(value: number, interval?: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,7 +148,8 @@ 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" 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;
|
function showLeds(leds: string, interval?: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,14 +161,16 @@ 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 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;
|
function showString(text: string, interval?: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turn off all LEDs
|
* Turn off all LEDs
|
||||||
*/
|
*/
|
||||||
//% help=basic/clear-screen weight=79
|
//% 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;
|
function clearScreen(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -162,14 +178,16 @@ declare namespace basic {
|
|||||||
* @param leds pattern of LEDs to turn on/off
|
* @param leds pattern of LEDs to turn on/off
|
||||||
* @param interval time in milliseconds between each redraw
|
* @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;
|
function showAnimation(leds: string, interval?: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws an image on the LED screen.
|
* Draws an image on the LED screen.
|
||||||
* @param leds pattern of LEDs to turn on/off
|
* @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;
|
function plotLeds(leds: string): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -201,7 +219,8 @@ declare namespace input {
|
|||||||
* @param body TODO
|
* @param body TODO
|
||||||
*/
|
*/
|
||||||
//% help=input/on-button-pressed weight=85 blockGap=8
|
//% 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;
|
function onButtonPressed(button: Button, body: () => void): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -209,7 +228,8 @@ declare namespace input {
|
|||||||
* @param body TODO
|
* @param body TODO
|
||||||
*/
|
*/
|
||||||
//% help=input/on-gesture weight=84 blockGap=8
|
//% 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;
|
function onGesture(gesture: Gesture, body: () => void): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -236,7 +256,8 @@ declare namespace input {
|
|||||||
//% help=input/button-is-pressed weight=57
|
//% help=input/button-is-pressed weight=57
|
||||||
//% block="button|%NAME|is pressed"
|
//% block="button|%NAME|is pressed"
|
||||||
//% blockId=device_get_button2
|
//% 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;
|
function buttonIsPressed(button: Button): boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -253,7 +274,8 @@ declare namespace input {
|
|||||||
*/
|
*/
|
||||||
//% help=input/compass-heading
|
//% help=input/compass-heading
|
||||||
//% weight=56 icon="\uf14e"
|
//% 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;
|
function compassHeading(): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -261,7 +283,8 @@ declare namespace input {
|
|||||||
*/
|
*/
|
||||||
//% weight=55 icon="\uf06d"
|
//% weight=55 icon="\uf06d"
|
||||||
//% help=input/temperature
|
//% 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;
|
function temperature(): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -269,14 +292,16 @@ declare namespace input {
|
|||||||
* @param dimension TODO
|
* @param dimension TODO
|
||||||
*/
|
*/
|
||||||
//% help=input/acceleration weight=54 icon="\uf135"
|
//% 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;
|
function acceleration(dimension: Dimension): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.
|
* Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.
|
||||||
*/
|
*/
|
||||||
//% help=input/light-level weight=53
|
//% 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;
|
function lightLevel(): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -284,7 +309,8 @@ declare namespace input {
|
|||||||
* @param kind TODO
|
* @param kind TODO
|
||||||
*/
|
*/
|
||||||
//% help=input/rotation weight=52
|
//% 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;
|
function rotation(kind: Rotation): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -292,7 +318,8 @@ declare namespace input {
|
|||||||
* @param dimension TODO
|
* @param dimension TODO
|
||||||
*/
|
*/
|
||||||
//% help=input/magnetic-force weight=51
|
//% 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;
|
function magneticForce(dimension: Dimension): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -314,7 +341,8 @@ declare namespace input {
|
|||||||
*/
|
*/
|
||||||
//% help=input/set-accelerometer-range
|
//% help=input/set-accelerometer-range
|
||||||
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135"
|
//% 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;
|
function setAccelerometerRange(range: AcceleratorRange): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,7 +428,8 @@ declare namespace led {
|
|||||||
* @param y TODO
|
* @param y TODO
|
||||||
*/
|
*/
|
||||||
//% help=led/plot weight=78
|
//% 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;
|
function plot(x: number, y: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -409,7 +438,8 @@ declare namespace led {
|
|||||||
* @param y TODO
|
* @param y TODO
|
||||||
*/
|
*/
|
||||||
//% help=led/unplot weight=77
|
//% 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;
|
function unplot(x: number, y: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -418,14 +448,16 @@ declare namespace led {
|
|||||||
* @param y TODO
|
* @param y TODO
|
||||||
*/
|
*/
|
||||||
//% help=led/point weight=76
|
//% 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;
|
function point(x: number, y: number): boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the screen brightness from 0 (off) to 255 (full bright).
|
* Get the screen brightness from 0 (off) to 255 (full bright).
|
||||||
*/
|
*/
|
||||||
//% help=led/brightness weight=60
|
//% 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;
|
function brightness(): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -433,27 +465,31 @@ declare namespace led {
|
|||||||
* @param value the brightness value, eg:255, 127, 0
|
* @param value the brightness value, eg:255, 127, 0
|
||||||
*/
|
*/
|
||||||
//% help=led/set-brightness weight=59
|
//% 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;
|
function setBrightness(value: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels the current animation and clears other pending animations.
|
* Cancels the current animation and clears other pending animations.
|
||||||
*/
|
*/
|
||||||
//% weight=50 help=led/stop-animation
|
//% 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;
|
function stopAnimation(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the display mode between black and white and greyscale for rendering LEDs.
|
* Sets the display mode between black and white and greyscale for rendering LEDs.
|
||||||
* @param mode TODO
|
* @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;
|
function setDisplayMode(mode: DisplayMode): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a screenshot of the LED screen and returns an image.
|
* 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;
|
function screenshot(): Image;
|
||||||
}
|
}
|
||||||
declare namespace pins {
|
declare namespace pins {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-microbit",
|
"name": "pxt-microbit",
|
||||||
"version": "0.3.41",
|
"version": "0.3.56",
|
||||||
"description": "micro:bit target for PXT",
|
"description": "micro:bit target for PXT",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"JavaScript",
|
"JavaScript",
|
||||||
@ -29,6 +29,6 @@
|
|||||||
"typescript": "^1.8.7"
|
"typescript": "^1.8.7"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-core": "0.3.45"
|
"pxt-core": "0.3.65"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,14 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"files": [
|
"files": [
|
||||||
"main.blocks",
|
"main.blocks",
|
||||||
"main.ts"
|
"main.ts",
|
||||||
|
"README.md"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"files": {
|
"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.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": {
|
"tsprj": {
|
||||||
@ -49,11 +51,13 @@
|
|||||||
},
|
},
|
||||||
"description": "",
|
"description": "",
|
||||||
"files": [
|
"files": [
|
||||||
"main.ts"
|
"main.ts",
|
||||||
|
"README.md"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"files": {
|
"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": {
|
"compile": {
|
||||||
@ -77,7 +81,7 @@
|
|||||||
"yottaTarget": "bbc-microbit-classic-gcc",
|
"yottaTarget": "bbc-microbit-classic-gcc",
|
||||||
"yottaCorePackage": "pxt-microbit-core",
|
"yottaCorePackage": "pxt-microbit-core",
|
||||||
"githubCorePackage": "microsoft/pxt-microbit-core",
|
"githubCorePackage": "microsoft/pxt-microbit-core",
|
||||||
"gittag": "v0.3.1",
|
"gittag": "v0.4.1",
|
||||||
"serviceId": "ws"
|
"serviceId": "ws"
|
||||||
},
|
},
|
||||||
"serial": {
|
"serial": {
|
||||||
|
19
sim/state.ts
19
sim/state.ts
@ -470,7 +470,7 @@ namespace pxsim {
|
|||||||
radio: RadioBus;
|
radio: RadioBus;
|
||||||
|
|
||||||
// display
|
// display
|
||||||
image = createImage(5);
|
image = createInternalImage(5);
|
||||||
brigthness = 255;
|
brigthness = 255;
|
||||||
displayMode = DisplayMode.bw;
|
displayMode = DisplayMode.bw;
|
||||||
font: Image = createFont();
|
font: Image = createFont();
|
||||||
@ -608,14 +608,19 @@ namespace pxsim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Image {
|
export class Image extends RefObject {
|
||||||
public static height: number = 5;
|
public static height: number = 5;
|
||||||
public width: number;
|
public width: number;
|
||||||
public data: number[];
|
public data: number[];
|
||||||
constructor(width: number, data: number[]) {
|
constructor(width: number, data: number[]) {
|
||||||
|
super()
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.data = data;
|
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 {
|
public get(x: number, y: number): number {
|
||||||
if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0;
|
if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0;
|
||||||
return this.data[y * this.width + x];
|
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 {
|
export function createImage(width: number): Image {
|
||||||
return new Image(width, new Array(width * 5));
|
return new Image(width, new Array(width * 5));
|
||||||
}
|
}
|
||||||
@ -661,7 +672,7 @@ namespace pxsim {
|
|||||||
export function createImageFromString(text: string): Image {
|
export function createImageFromString(text: string): Image {
|
||||||
let font = board().font;
|
let font = board().font;
|
||||||
let w = font.width;
|
let w = font.width;
|
||||||
let sprite = createImage(6 * text.length - 1);
|
let sprite = createInternalImage(6 * text.length - 1);
|
||||||
let k = 0;
|
let k = 0;
|
||||||
for (let i = 0; i < text.length; i++) {
|
for (let i = 0; i < text.length; i++) {
|
||||||
let charCode = text.charCodeAt(i);
|
let charCode = text.charCodeAt(i);
|
||||||
@ -685,7 +696,7 @@ namespace pxsim {
|
|||||||
|
|
||||||
let nb = data.length;
|
let nb = data.length;
|
||||||
let n = nb / 5;
|
let n = nb / 5;
|
||||||
let font = createImage(nb);
|
let font = createInternalImage(nb);
|
||||||
for (let c = 0; c < n; c++) {
|
for (let c = 0; c < n; c++) {
|
||||||
for (let row = 0; row < 5; row++) {
|
for (let row = 0; row < 5; row++) {
|
||||||
let char = data[c * 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": "."
|
||||||
|
}
|
||||||
|
}
|
10
travis-tests.sh
Executable file
10
travis-tests.sh
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
set -x
|
||||||
|
export KS_FORCE_CLOUD=yes
|
||||||
|
(cd libs/lang-test0; node ../../node_modules/pxt-core/built/pxt.js run)
|
||||||
|
(cd libs/lang-test1; node ../../node_modules/pxt-core/built/pxt.js run)
|
||||||
|
(cd libs/lang-test0; node ../../node_modules/pxt-core/built/pxt.js test)
|
||||||
|
(cd libs/lang-test1; node ../../node_modules/pxt-core/built/pxt.js test)
|
||||||
|
node node_modules/pxt-core/built/pxt.js testdir tests
|
||||||
|
(cd libs/hello; node ../../node_modules/pxt-core/built/pxt.js testconv https://az851932.vo.msecnd.net/files/td-converter-tests-v0.json)
|
Reference in New Issue
Block a user