Compare commits
101 Commits
Author | SHA1 | Date | |
---|---|---|---|
5344717749 | |||
1bbf8a4473 | |||
f1d9075c9d | |||
cffbdb9eae | |||
cc75ae57da | |||
068300c5f5 | |||
251f198441 | |||
fe39902d10 | |||
030cd46c5f | |||
8cc2f1219f | |||
39a629cc58 | |||
df65c34f15 | |||
00fefe10d6 | |||
d442f5aa41 | |||
3311865817 | |||
2cd2950496 | |||
b0de3d8c1b | |||
acefe3ae11 | |||
cb6c83eec7 | |||
e0c8f65a65 | |||
a4e02dcd03 | |||
fb5776ec41 | |||
d852fd961b | |||
1ed8122804 | |||
c5cec3a6ba | |||
ba94322d4c | |||
225f1da6d5 | |||
a06331eef1 | |||
aa741ce8de | |||
61fe5091fe | |||
3d90e13797 | |||
469767a40a | |||
604fa764e6 | |||
25cf2a9cdb | |||
7549f865d6 | |||
a5de9d88bb | |||
0437df10de | |||
2079173dfa | |||
018a1e7528 | |||
757f95d984 | |||
8bc3fdc8ba | |||
e8a1e73cf5 | |||
e9b2b239ad | |||
5ad2288a9f | |||
92d13ef343 | |||
471ca5d915 | |||
f745079728 | |||
d179f18ef3 | |||
805fc6c787 | |||
374bbb8304 | |||
25452efc92 | |||
80b9c715b2 | |||
cb816c91ad | |||
3012068986 | |||
4c9c7d6a69 | |||
ad3652c290 | |||
d8971829e3 | |||
8ca4558fc2 | |||
d85b5c5129 | |||
95b1c6a50f | |||
4dc2872286 | |||
6c9ff804c8 | |||
7581b5af9e | |||
07504027f9 | |||
a0e133864a | |||
0285711954 | |||
91be998d7e | |||
e862869327 | |||
8047cb2612 | |||
8e2ffefd2c | |||
092e7b0522 | |||
42454ecd57 | |||
2563fd6031 | |||
e0c1f2dca0 | |||
c80574ed3f | |||
b28b5cb6b7 | |||
d1f11059db | |||
6de5c6afdf | |||
b72c7c0c4f | |||
352c1ca5ec | |||
6d940a9ec7 | |||
c070173346 | |||
6fcf68f174 | |||
02f2a85d28 | |||
f63196908e | |||
ad48ee12ca | |||
83aeb24a98 | |||
fc5ecd9f10 | |||
0b3b840ac1 | |||
60c09809e7 | |||
148067a143 | |||
6f34887c94 | |||
64a9930c2e | |||
5815e16647 | |||
c4f5e425c2 | |||
361ae7a2d2 | |||
3769402ade | |||
5c3c83eb52 | |||
0f07a89981 | |||
11d887a213 | |||
8150b2dbb0 |
1
.gitignore
vendored
@ -17,6 +17,7 @@ clients/**/bin/**
|
|||||||
clients/**/obj/**
|
clients/**/obj/**
|
||||||
clients/electron/projects
|
clients/electron/projects
|
||||||
libs/**/_locales/**
|
libs/**/_locales/**
|
||||||
|
package-lock.json
|
||||||
|
|
||||||
videos/**
|
videos/**
|
||||||
|
|
||||||
|
14
cmds/cmds.ts
@ -1,14 +0,0 @@
|
|||||||
/// <reference path="../node_modules/pxt-core/built/pxtlib.d.ts" />
|
|
||||||
|
|
||||||
import * as fs from 'fs';
|
|
||||||
|
|
||||||
const deploy = require("./editor/deploy")
|
|
||||||
|
|
||||||
export function deployCoreAsync(resp: pxtc.CompileResult) {
|
|
||||||
return deploy.deployCoreAsync(resp, process.env["PXT_SERIAL"] ? false : true)
|
|
||||||
.then(() => {
|
|
||||||
fs.writeFileSync("built/full-" + pxtc.BINARY_UF2, resp.outfiles[pxtc.BINARY_UF2], {
|
|
||||||
encoding: "base64"
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "es5",
|
|
||||||
"noImplicitAny": true,
|
|
||||||
"noImplicitReturns": true,
|
|
||||||
"declaration": true,
|
|
||||||
"outDir": "../built",
|
|
||||||
"module": "commonjs",
|
|
||||||
"rootDir": ".",
|
|
||||||
"newLine": "LF",
|
|
||||||
"sourceMap": false,
|
|
||||||
"types": ["node"]
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
* [Troubleshoot](/troubleshoot)
|
* [Troubleshoot](/troubleshoot)
|
||||||
* [EV3 Manager](https://ev3manager.education.lego.com/)
|
* [EV3 Manager](https://ev3manager.education.lego.com/)
|
||||||
|
* [Bluetooth](/bluetooth)
|
||||||
* [Forum](https://forum.makecode.com)
|
* [Forum](https://forum.makecode.com)
|
||||||
* [LEGO Support](https://www.lego.com/service/)
|
* [LEGO Support](https://www.lego.com/service/)
|
||||||
* [FIRST LEGO League](/fll)
|
* [FIRST LEGO League](/fll)
|
||||||
|
@ -28,7 +28,7 @@ program to a **.uf2** file, which you then copy to the **@drivename@** drive. Th
|
|||||||
|
|
||||||
### ~ hint
|
### ~ hint
|
||||||
|
|
||||||
Not seeing the **@drivename@** drive? Make sure to upgrade your firmware at https://ev3manager.education.lego.com/. Try these [troubleshooting](/troubleshoot) tips if you still have trouble getting the drive to appear.
|
**Experimental support** for Bluetooth download is now available. Please read the [Bluetooth](/bluetooth) page for more information.
|
||||||
|
|
||||||
### ~
|
### ~
|
||||||
|
|
||||||
|
62
docs/bluetooth.md
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
# Bluetooth
|
||||||
|
|
||||||
|
This page describes the procedure to download MakeCode program to the EV3 brick
|
||||||
|
over Bluetooth.
|
||||||
|
|
||||||
|
## ~ hint
|
||||||
|
|
||||||
|
### WARNING: EXPERIMENTAL FEATURES AHEAD!
|
||||||
|
|
||||||
|
Support for Bluetooth download relies on [Web Serial](https://wicg.github.io/serial/),
|
||||||
|
an experimental browser feature. Web Serial is a work [in progress](https://www.chromestatus.com/feature/6577673212002304);
|
||||||
|
it may change or be removed in future versions without notice.
|
||||||
|
|
||||||
|
By enabling these experimental browser features, you could lose browser data or compromise your device security
|
||||||
|
or privacy.
|
||||||
|
|
||||||
|
## ~
|
||||||
|
|
||||||
|
https://youtu.be/VIq8-6Egtqs
|
||||||
|
|
||||||
|
## Supported browsers
|
||||||
|
|
||||||
|
* Chrome desktop, version 77 and higher, Windows 10 or Mac OS.
|
||||||
|
* [Edge Insider desktop](https://www.microsoftedgeinsider.com), version 77 and higher, Windows 10 or Mac OS.
|
||||||
|
|
||||||
|
To make sure your browser is up to date, go to the '...' menu, click "Help" then "About".
|
||||||
|
|
||||||
|
Next you need to enable the experimental features (this may change in the future)
|
||||||
|
|
||||||
|
* go to **chrome://flags/#enable-experimental-web-platform-features** and **enable**
|
||||||
|
**Experimental Web Platform features**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Machine Setup
|
||||||
|
|
||||||
|
* pair your EV3 brick with your computer over Bluetooth. This is the usual pairing procedure.
|
||||||
|
|
||||||
|
## Download over Bluetooth
|
||||||
|
|
||||||
|
* go to https://makecode.mindstorms.com/
|
||||||
|
* click on **Download** to start a file download as usual
|
||||||
|
* on the download dialog, you should see a **Bluetooth** button. Click on the
|
||||||
|
**Bluetooth** button to enable the mode.
|
||||||
|
* **make sure the EV3 brick is not running a program**
|
||||||
|
* click on **Download** again to download over bluetooth.
|
||||||
|
|
||||||
|
## Choosing the correct serial port
|
||||||
|
|
||||||
|
Unfortunately, the browser dialog does not make it easy to select which serial port is the brick.
|
||||||
|
|
||||||
|
* On Windows, choose ``Standard Serial over Bluetooth``. There might be multiple of those but only one works. Try your luck! Once you know the COM port number, remember it for the next time around.
|
||||||
|
* On Mac OS, choose ``cu.BRICKNAME-SerialPort``
|
||||||
|
|
||||||
|
## Known issues
|
||||||
|
|
||||||
|
* We do not detect properly that the program is running on the brick. Make sure to stop the program before starting the download procedure.
|
||||||
|
* The list of programs on the brick screen is not updated when uploading via bluetooth.
|
||||||
|
|
||||||
|
## Feedback
|
||||||
|
|
||||||
|
Please send us your feedback through https://forum.makecode.com.
|
26
docs/fll.md
@ -19,6 +19,7 @@ If you found a bug, please try if it hasn't been fixed yet! Go to https://makeco
|
|||||||
* You will need to install the latest EV3 firmware on your brick. Instructions on how to do that are located here: https://makecode.mindstorms.com/troubleshoot.
|
* You will need to install the latest EV3 firmware on your brick. Instructions on how to do that are located here: https://makecode.mindstorms.com/troubleshoot.
|
||||||
* You will need a computer with a USB port to connect to the EV3 in order to download your programs.
|
* You will need a computer with a USB port to connect to the EV3 in order to download your programs.
|
||||||
* You will need internet access and a browser on your computer to get to https://makecode.mindstorms.com.
|
* You will need internet access and a browser on your computer to get to https://makecode.mindstorms.com.
|
||||||
|
* You can [install the app](/offline-app) to use the editor offline.
|
||||||
|
|
||||||
### I know LabView, how is MakeCode different?
|
### I know LabView, how is MakeCode different?
|
||||||
|
|
||||||
@ -28,12 +29,23 @@ We have compiled a guide for EV3 LabView users at https://makecode.mindstorms.co
|
|||||||
|
|
||||||
Go to https://makecode.mindstorms.com. The home screen is filled with videos, tutorials and examples that might be relevant for your missions.
|
Go to https://makecode.mindstorms.com. The home screen is filled with videos, tutorials and examples that might be relevant for your missions.
|
||||||
|
|
||||||
On the home page, scroll down to the **FLL / City Shaper / Crane Mission** section for specific lessons related to Mission 2.
|
On the home page, scroll down to the **FLL / City Shaper** section for specific lessons related to Mission 2.
|
||||||
|
|
||||||
### Can I load both LEGO MINDSTORMS EV3 Software and MakeCode programs onto my EV3?
|
### Can I load both LEGO MINDSTORMS EV3 Software and MakeCode programs onto my EV3?
|
||||||
|
|
||||||
Yes.
|
Yes.
|
||||||
|
|
||||||
|
### Can I run the program again on the brick?
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Use the Brick Buttons and navigate to the File Manager tab. Open the **BrkProg_SAVE** folder,
|
||||||
|
select your program and click the center button to run it again.
|
||||||
|
|
||||||
|
### Does it work without internet?
|
||||||
|
|
||||||
|
No, the editor is cached in your browser cache. However, you can also download the [offline app](/offline-app) in case you need to install it on a computer.
|
||||||
|
|
||||||
### How do I figure out what a block does?
|
### How do I figure out what a block does?
|
||||||
|
|
||||||
You can right-click on any block and select “Help” in the context menu to open the documentation page describing what that block does.
|
You can right-click on any block and select “Help” in the context menu to open the documentation page describing what that block does.
|
||||||
@ -87,6 +99,18 @@ You can share your projects by clicking on the **share** button in the top left
|
|||||||
|
|
||||||
Sharing programs is also shown in the [Tips and Tricks](https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=5c594c2373367f7870196f519f3bfc7a&source=embed&photo%5fid=35719472) video.
|
Sharing programs is also shown in the [Tips and Tricks](https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=5c594c2373367f7870196f519f3bfc7a&source=embed&photo%5fid=35719472) video.
|
||||||
|
|
||||||
|
### Can I use Bluetooth to transfer my program?
|
||||||
|
|
||||||
|
The official answer is currently no. That being said, we have **Experimental support** for Bluetooth download. Please read the [Bluetooth](/bluetooth) page for more information.
|
||||||
|
|
||||||
|
https://youtu.be/VIq8-6Egtqs
|
||||||
|
|
||||||
|
## Are there YouTube videos on MakeCode for EV3?
|
||||||
|
|
||||||
|
The MakeCode has a [FLL / City Shaper YouTube Channel](https://www.youtube.com/watch?v=IqL0Pyeu5Ng&list=PLMMBk9hE-SeqkOObethhlZtBTEK6FYx3n) with useful videos.
|
||||||
|
|
||||||
|
https://youtu.be/-AirqwC9DL4
|
||||||
|
|
||||||
### Why can't I delete my program (*.uf2) files from the Brick?
|
### Why can't I delete my program (*.uf2) files from the Brick?
|
||||||
|
|
||||||
There's a bug in the firmware which prevents you from deleting the programs (``*.uf2`` files) from your EV3 Brick. There isn't a firmware update to fix this yet.
|
There's a bug in the firmware which prevents you from deleting the programs (``*.uf2`` files) from your EV3 Brick. There isn't a firmware update to fix this yet.
|
||||||
|
@ -54,6 +54,12 @@ Verify that the program you just created shows eyes on the Brick Display, and th
|
|||||||
|
|
||||||
**Well done!**
|
**Well done!**
|
||||||
|
|
||||||
|
## Run it Again
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Use the Brick Buttons and navigate to the File Manager tab. Open the **BrkProg_SAVE** folder, select **Try** and click the center button to run it again.
|
||||||
|
|
||||||
## Connect a Large Motor
|
## Connect a Large Motor
|
||||||
|
|
||||||
Now you will learn to control the Large Motor.
|
Now you will learn to control the Large Motor.
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"appref": "v1.1.20"
|
"appref": "v1.2.22"
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,12 @@ motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations);
|
|||||||
motors.largeBC.stop();
|
motors.largeBC.stop();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### ~ hint
|
||||||
|
|
||||||
|
The **turn ratio range is -200, 200** unlike LabView who used -100,100.
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
## Tank
|
## Tank
|
||||||
|
|
||||||
The **tank** blocks control the speed of two motors. These are commonly used for a differential drive robot. The blocks can also specify the duration, angle, or number of rotations.
|
The **tank** blocks control the speed of two motors. These are commonly used for a differential drive robot. The blocks can also specify the duration, angle, or number of rotations.
|
||||||
|
@ -388,12 +388,12 @@
|
|||||||
}
|
}
|
||||||
function downloadWin64() {
|
function downloadWin64() {
|
||||||
// TODO: Keep this link up-to-date with the desired release version
|
// TODO: Keep this link up-to-date with the desired release version
|
||||||
window.open("https://makecode.com/api/release/ev3/v1.0.11/win64");
|
window.open("https://makecode.com/api/release/ev3/v1.2.22/win64");
|
||||||
tickEvent("offlineapp.download", { "target": "ev3", "platform": "win64" });
|
tickEvent("offlineapp.download", { "target": "ev3", "platform": "win64" });
|
||||||
}
|
}
|
||||||
function downloadMac64() {
|
function downloadMac64() {
|
||||||
// TODO: Keep this link up-to-date with the desired release version
|
// TODO: Keep this link up-to-date with the desired release version
|
||||||
window.open("https://makecode.com/api/release/ev3/v1.0.11/mac64");
|
window.open("https://makecode.com/api/release/ev3/v1.2.22/mac64");
|
||||||
tickEvent("offlineapp.download", { "target": "ev3", "platform": "mac64" });
|
tickEvent("offlineapp.download", { "target": "ev3", "platform": "mac64" });
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -3,9 +3,3 @@
|
|||||||
## Offline app #target-app
|
## Offline app #target-app
|
||||||
|
|
||||||
The MakeCode editor is available as app which you can install on a computer with Windows or Mac OS. Once installed, the **[MakeCode Offline App](/offline-app)** lets you create, run, and download your projects to the @boardname@. It works the same as the Web application does in your browser but it's a stand-alone application that will work when a connection to the internet is restricted or not available.
|
The MakeCode editor is available as app which you can install on a computer with Windows or Mac OS. Once installed, the **[MakeCode Offline App](/offline-app)** lets you create, run, and download your projects to the @boardname@. It works the same as the Web application does in your browser but it's a stand-alone application that will work when a connection to the internet is restricted or not available.
|
||||||
|
|
||||||
### ~ hint
|
|
||||||
|
|
||||||
The [MakeCode Offline App](/offline-app) is currently in development and is made available as a **pre-release** version.
|
|
||||||
|
|
||||||
### ~
|
|
||||||
|
@ -1,9 +1,88 @@
|
|||||||
# Projects
|
# Projects
|
||||||
|
|
||||||
Here are some cool projects that you can build with your @boardname@!
|
```codecard
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Getting Started",
|
||||||
|
"url": "/getting-started",
|
||||||
|
"imageUrl": "/static/lessons/firmware.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Brick Tutorials",
|
||||||
|
"url": "/tutorials/brick",
|
||||||
|
"imageUrl": "/static/tutorials/wake-up.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Motor Tutorials",
|
||||||
|
"url": "/tutorials/motors",
|
||||||
|
"imageUrl": "/static/tutorials/run-motors.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Touch Sensor Tutorials",
|
||||||
|
"url": "/tutorials/touch-sensor",
|
||||||
|
"imageUrl": "/static/tutorials/touch-to-run.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Color Sensor Tutorials",
|
||||||
|
"url": "/tutorials/color-sensor",
|
||||||
|
"imageUrl": "/static/tutorials/what-color.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Ultrasonic Sensor Tutorials",
|
||||||
|
"url": "/tutorials/ultrasonic-sensor",
|
||||||
|
"imageUrl": "/static/tutorials/object-near.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Gyro Tutorials",
|
||||||
|
"url": "/tutorials/gyro",
|
||||||
|
"imageUrl": "/static/tutorials/calibrate-gyro.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Infrared Sensor Tutorials",
|
||||||
|
"url": "/tutorials/infrared-sensor",
|
||||||
|
"imageUrl": "/static/tutorials/security-alert.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "FLL / City Shaper",
|
||||||
|
"url": "/tutorials/city-shaper",
|
||||||
|
"imageUrl": "/static/tutorials/city-shaper/robot1.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Design Engineering",
|
||||||
|
"url": "/design-engineering",
|
||||||
|
"imageUrl": "/static/lessons/make-it-move-without-wheels.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Coding",
|
||||||
|
"url": "/coding",
|
||||||
|
"imageUrl": "/static/lessons/autonomous-parking.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Maker",
|
||||||
|
"url": "/maker",
|
||||||
|
"imageUrl": "/static/lessons/make-a-sound-machine.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Tutorial Videos",
|
||||||
|
"url": "/videos",
|
||||||
|
"imageUrl": "https://legoeducation.videomarketingplatform.co/27288170/35719444/5d009e5f93fbf479c2e5ed2bf87a7990/thumbnail.png"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
## Basic
|
## See Also
|
||||||
|
|
||||||
Basic projects to build with your EV3 Brick.
|
[Getting Started](/getting-started),
|
||||||
|
[Brick Tutorials](/tutorials/brick),
|
||||||
|
[Motor Tutorials](/tutorials/motors),
|
||||||
|
[Touch Sensor Tutorials](/tutorials/touch-sensor),
|
||||||
|
[Color Sensor Tutorials](/tutorials/color-sensor),
|
||||||
|
[Ultrasonic Sensor Tutorials](/tutorials/ultrasonic-sensor),
|
||||||
|
[Gyro Tutorials](/tutorials/gyro),
|
||||||
|
[Infrared Sensor Tutorials](/tutorials/infrared-sensor),
|
||||||
|
[FLL / City Shaper](/tutorials/city-shaper),
|
||||||
|
[Design Engineering](/design-engineering),
|
||||||
|
[Coding](/coding),
|
||||||
|
[Maker](/maker),
|
||||||
|
[Tutorial Videos](/videos)
|
||||||
|
|
||||||
Coming soon.
|
|
69
docs/projects/SUMMARY.md
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
# Projects
|
||||||
|
|
||||||
|
* [Getting Started](/getting-started)
|
||||||
|
* [Prepare](https://makecode.mindstorms.com/troubleshoot)
|
||||||
|
* [Try](/getting-started/try)
|
||||||
|
* [Use](/getting-started/use)
|
||||||
|
* [First LEGO League](/fll)
|
||||||
|
* [Brick Tutorials](/tutorials/brick)
|
||||||
|
* [Wake Up!](/tutorials/wake-up)
|
||||||
|
* [Make an Animation](/tutorials/make-an-animation)
|
||||||
|
* [What Animal Am I?](/tutorials/what-animal-am-i)
|
||||||
|
* [Music Brick](/tutorials/music-brick)
|
||||||
|
* [Pause On Start](/tutorials/pause-on-start)
|
||||||
|
* [Motor Tutorials](/tutorials/motors)
|
||||||
|
* [Run Motors](/tutorials/run-motors)
|
||||||
|
* [Spin Turn](/tutorials/spin-turn)
|
||||||
|
* [Pivot Turn](/tutorials/pivot-turn)
|
||||||
|
* [Smooth Turn](/tutorials/smooth-turn)
|
||||||
|
* [Tank ZigZag](/tutorials/tank-zigzag)
|
||||||
|
* [Coast Or Brake](/tutorials/coast-or-brake)
|
||||||
|
* [Turtle](/tutorials/turtle)
|
||||||
|
* [Touch Sensor Tutorials](/tutorials/touch-sensor)
|
||||||
|
* [Touch to Run](/tutorials/touch-to-run)
|
||||||
|
* [Sensor Values](/tutorials/touch-sensor-values)
|
||||||
|
* [Stop At Object](/tutorials/stop-at-object)
|
||||||
|
* [Color Sensor Tutorials](/tutorials/color-sensor)
|
||||||
|
* [What Color?](/tutorials/what-color)
|
||||||
|
* [Line Following](/tutorials/line-following)
|
||||||
|
* [Red Light, Green Light](/tutorials/redlight-greenlight)
|
||||||
|
* [Move To Color](/tutorials/move-to-color)
|
||||||
|
* [Reflected Light Measure](/tutorials/reflected-light-measure)
|
||||||
|
* [Reflected Light Calibration](/tutorials/reflected-light-calibration)
|
||||||
|
* [Ultrasonic Sensor Tutorials](/tutorials/ultrasonic-sensor)
|
||||||
|
* [Object Near](/tutorials/object-near)
|
||||||
|
* [Wall Follower](/tutorials/wall-follower)
|
||||||
|
* [Gyro Tutorials](/tutorials/gyro)
|
||||||
|
* [Calibrate](/tutorials/calibrate-gyro)
|
||||||
|
* [Turn](/tutorials/turn-with-gyro)
|
||||||
|
* [Move Straight](/tutorials/move-straight-with-gyro)
|
||||||
|
* [Drifter](/tutorials/drifter)
|
||||||
|
* [Infrared Sensor Tutorials](/tutorials/infrared-sensor)
|
||||||
|
* [Security Alert](/tutorials/security-alert)
|
||||||
|
* [FLL / City Shaper](/tutorials/city-shaper)
|
||||||
|
* [Crane Mission / Robot 1](/tutorials/city-shaper/robot-1)
|
||||||
|
* [Crane Mission / Robot 2](/tutorials/city-shaper/robot-2)
|
||||||
|
* [Crane Mission / Video 1](https://youtu.be/IqL0Pyeu5Ng)
|
||||||
|
* [Bluetooth download (beta)](https://youtu.be/VIq8-6Egtqs)
|
||||||
|
* [Turn with Gyro](https://youtu.be/I7ncuXAfBwk)
|
||||||
|
* [Moving with Gyro](https://youtu.be/ufiOPvW37xc)
|
||||||
|
* [Line following with 1 color sensor](https://youtu.be/_LeduyKQVjg)
|
||||||
|
* [Proportional line following with 1 color sensor](https://youtu.be/-AirqwC9DL4)
|
||||||
|
* [Proportional line following with 2 color sensors](https://youtu.be/QWOflBuu9Oo)
|
||||||
|
* [Design Engineering](/design-engineering)
|
||||||
|
* [Make It Move Without Wheels](/design-engineering/make-it-move)
|
||||||
|
* [Make It Smarter and Faster](/design-engineering/make-it-smarter)
|
||||||
|
* [Make a System that Communicates](/design-engineering/make-it-communicate)
|
||||||
|
* [Coding](/coding)
|
||||||
|
* [Autonomous Parking](/coding/autonomous-parking)
|
||||||
|
* [Object Detection](/coding/object-detection)
|
||||||
|
* [Line Detection](/coding/line-detection)
|
||||||
|
* [Maker](/maker)
|
||||||
|
* [Make A Sound Machine](/maker/sound-machine)
|
||||||
|
* [Make A Security Gadget](/maker/security-gadget)
|
||||||
|
* [Tutorial Videos](/videos)
|
||||||
|
* [undefined](https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=5d009e5f93fbf479c2e5ed2bf87a7990&source=embed&photo%5fid=35719444)
|
||||||
|
* [undefined](https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=2008a566f1fb034d58d5ebe19ba8621f&source=embed&photo%5fid=35719467)
|
||||||
|
* [undefined](https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=629730c938e452f0fd7653fbc4708166&source=embed&photo%5fid=35719470)
|
||||||
|
* [undefined](https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=3513a83b87fe536b2dc512237465fd1b&source=embed&photo%5fid=35719471)
|
||||||
|
* [undefined](https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=5c594c2373367f7870196f519f3bfc7a&source=embed&photo%5fid=35719472)
|
18
docs/reference/brick/exit-program.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# exit Program
|
||||||
|
|
||||||
|
Stops the program and returns to the brick menu
|
||||||
|
|
||||||
|
```sig
|
||||||
|
brick.exitProgram();
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
Do a sequence of motor commands and stop the program.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
motors.largeA.run(50)
|
||||||
|
pause(500)
|
||||||
|
motors.stopAll()
|
||||||
|
brick.exitProgram();
|
||||||
|
```
|
@ -10,12 +10,12 @@ You can find out what's connected to the ports on the brick and show its status.
|
|||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
Show the status of the ports on the brick when the ``enter`` button is pressed.
|
Show the status of the ports on the brick. Resets all motors when ENTER is pressed.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
brick.showString("Press ENTER for port status", 1)
|
brick.showPorts()
|
||||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||||
brick.showPorts()
|
motors.resetAll()
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
25
docs/reference/motors/reset-all.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# reset All Motors
|
||||||
|
|
||||||
|
Reset all motors currently running on the brick.
|
||||||
|
|
||||||
|
```sig
|
||||||
|
motors.resetAll();
|
||||||
|
```
|
||||||
|
|
||||||
|
The motors counters are resetted.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
Tank the EV3 Brick forward at half speed for 5 seconds and then stop.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
motors.largeAB.tank(50, 50);
|
||||||
|
pause(5000);
|
||||||
|
motors.stopAll();
|
||||||
|
motors.resetAll();
|
||||||
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
[stop all](/reference/motors/motor/stop-all),
|
||||||
|
[reset](/reference/motors/motor/reset)
|
@ -22,4 +22,5 @@ motors.stopAll();
|
|||||||
|
|
||||||
[stop](/reference/motors/motor/stop),
|
[stop](/reference/motors/motor/stop),
|
||||||
[reset](/reference/motors/motor/reset),
|
[reset](/reference/motors/motor/reset),
|
||||||
|
[reset-all](/reference/motors/motor/reset-all),
|
||||||
[set brake](/reference/motors/motor/set-brake)
|
[set brake](/reference/motors/motor/set-brake)
|
@ -22,7 +22,7 @@ If you decide to use a **value** of rotation distance, you need to choose a type
|
|||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
* **turnRatio**: a [number](/types/number) that is the percentage of speed of the drive motor. The follower motor runs at this speed. A negative number steers to the left and a positive number steers to the right. This is a number between `-100` and `100`.
|
* **turnRatio**: a [number](/types/number) that is the percentage of speed of the drive motor. The follower motor runs at this speed. A negative number steers to the left and a positive number steers to the right. This is a number between `-200` and `200`.
|
||||||
* **speed**: a [number](/types/number) that is the percentage of full speed. A negative value runs the motors in the reverse direction. This is the speed that the drive motor runs at.
|
* **speed**: a [number](/types/number) that is the percentage of full speed. A negative value runs the motors in the reverse direction. This is the speed that the drive motor runs at.
|
||||||
* **value**: the [number](/types/number) of movement units to rotate for. A value of `0` means run the motor continuously.
|
* **value**: the [number](/types/number) of movement units to rotate for. A value of `0` means run the motor continuously.
|
||||||
* **unit**: the movement unit of rotation. This can be `milliseconds`, `seconds`, `degrees`, or `rotations`. If the number for **value** is `0`, this parameter isn't used.
|
* **unit**: the movement unit of rotation. This can be `milliseconds`, `seconds`, `degrees`, or `rotations`. If the number for **value** is `0`, this parameter isn't used.
|
||||||
|
BIN
docs/static/bluetooth/experimental.png
vendored
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
docs/static/getting-started/try-in-file-manager.png
vendored
Normal file
After Width: | Height: | Size: 89 KiB |
BIN
docs/static/tutorials/calibrate-gyro.png
vendored
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
docs/static/tutorials/city-shaper/robot1.jpg
vendored
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
docs/static/tutorials/city-shaper/robot2.jpg
vendored
Normal file
After Width: | Height: | Size: 31 KiB |
BIN
docs/static/tutorials/drifter.png
vendored
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
docs/static/tutorials/move-straight-with-gyro.png
vendored
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
docs/static/tutorials/move-to-color.png
vendored
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
docs/static/tutorials/pause-on-start.png
vendored
Normal file
After Width: | Height: | Size: 9.9 KiB |
BIN
docs/static/tutorials/turn-with-gyro.png
vendored
Normal file
After Width: | Height: | Size: 10 KiB |
@ -25,6 +25,11 @@ Step by step guides to coding your @boardname@.
|
|||||||
"description": "Use the color sensor to follow line or detect colors",
|
"description": "Use the color sensor to follow line or detect colors",
|
||||||
"url":"/tutorials/color-sensor",
|
"url":"/tutorials/color-sensor",
|
||||||
"imageUrl":"/static/tutorials/what-color.png"
|
"imageUrl":"/static/tutorials/what-color.png"
|
||||||
|
}, {
|
||||||
|
"name": "Gyro",
|
||||||
|
"description": "Drive straight or turn more precisely with the gyro",
|
||||||
|
"url":"/tutorials/gyro",
|
||||||
|
"imageUrl":"/static/tutorials/calibrate-gyro.png"
|
||||||
}, {
|
}, {
|
||||||
"name": "Ultrasonic Sensor",
|
"name": "Ultrasonic Sensor",
|
||||||
"description": "Use the ultrasonic sensor to detect obstacles",
|
"description": "Use the ultrasonic sensor to detect obstacles",
|
||||||
|
@ -27,6 +27,12 @@
|
|||||||
"cardType": "tutorial",
|
"cardType": "tutorial",
|
||||||
"url":"/tutorials/music-brick",
|
"url":"/tutorials/music-brick",
|
||||||
"imageUrl":"/static/tutorials/music-brick.png"
|
"imageUrl":"/static/tutorials/music-brick.png"
|
||||||
|
}, {
|
||||||
|
"name": "Pause On Start",
|
||||||
|
"description": "Don't start running immediately!",
|
||||||
|
"cardType": "tutorial",
|
||||||
|
"url":"/tutorials/pause-on-start",
|
||||||
|
"imageUrl":"/static/tutorials/pause-on-start.png"
|
||||||
}]
|
}]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
37
docs/tutorials/calibrate-gyro.md
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# Calibrate Gyro
|
||||||
|
|
||||||
|
## Introduction @fullscreen
|
||||||
|
|
||||||
|
The gyroscope is a very useful sensor in the EV3 system. It detects the rotation rate
|
||||||
|
which can be very useful to correct the trajectory of the robot and do precise turns.
|
||||||
|
|
||||||
|
However, the sensor can be imprecise and subject to drifting. It is recommend to
|
||||||
|
calibrate your sensor at least once after starting your brick. You don't have to
|
||||||
|
recalibrate on every run.
|
||||||
|
|
||||||
|
* [EV3 Driving Base](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf)
|
||||||
|
* [EV3 Driving Base with Gyro](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-gyro-sensor-driving-base-a521f8ebe355c281c006418395309e15.pdf)
|
||||||
|
|
||||||
|
|
||||||
|
## Step 1 Show ports
|
||||||
|
|
||||||
|
Add the ``||brick:show ports||`` to see the status of the gyroscope.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
brick.showPorts()
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Step 2 Calibration
|
||||||
|
|
||||||
|
Add a ``||sensors:calibrate gyro||`` block to calibrate the gyro. The block
|
||||||
|
detects if the sensor is present and does a full reset of the sensor if necessary.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
brick.showPorts()
|
||||||
|
sensors.gyro2.calibrate()
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 3 Download and run @fullscreen
|
||||||
|
|
||||||
|
Download this program to your brick and press the ENTER button.
|
54
docs/tutorials/city-shaper.md
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# City Shaper
|
||||||
|
|
||||||
|
## Tutorials
|
||||||
|
|
||||||
|
```codecard
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Crane Mission / Robot 1",
|
||||||
|
"description": "Learn the basics and build your first robot driving base.",
|
||||||
|
"cardType": "tutorial",
|
||||||
|
"url":"/tutorials/city-shaper/robot-1",
|
||||||
|
"imageUrl": "/static/tutorials/city-shaper/robot1.jpg"
|
||||||
|
}, {
|
||||||
|
"name": "Crane Mission / Robot 2",
|
||||||
|
"description": "Program your robot to move in different ways.",
|
||||||
|
"cardType": "tutorial",
|
||||||
|
"url":"/tutorials/city-shaper/robot-2",
|
||||||
|
"imageUrl": "/static/tutorials/city-shaper/robot2.jpg"
|
||||||
|
}, {
|
||||||
|
"name": "Crane Mission / Video 1",
|
||||||
|
"description": "A video of the Robot 1 tutorial",
|
||||||
|
"youTubeId": "IqL0Pyeu5Ng"
|
||||||
|
}, {
|
||||||
|
"name": "Bluetooth download (beta)",
|
||||||
|
"description": "EXPERIMENTAL! Learn how to download code via Bluetooth.",
|
||||||
|
"youTubeId": "VIq8-6Egtqs"
|
||||||
|
}, {
|
||||||
|
"name": "Turn with Gyro",
|
||||||
|
"description": "Use the gyro for precise turns.",
|
||||||
|
"youTubeId": "I7ncuXAfBwk"
|
||||||
|
}, {
|
||||||
|
"name": "Moving with Gyro",
|
||||||
|
"description": "Use the gyro for correct the robot trajectory.",
|
||||||
|
"youTubeId": "ufiOPvW37xc"
|
||||||
|
}, {
|
||||||
|
"name": "Line following with 1 color sensor",
|
||||||
|
"description": "Simple line following using the color sensor.",
|
||||||
|
"youTubeId": "_LeduyKQVjg"
|
||||||
|
}, {
|
||||||
|
"name": "Proportional line following with 1 color sensor",
|
||||||
|
"description": "Proportional line following using the color sensor.",
|
||||||
|
"youTubeId": "-AirqwC9DL4"
|
||||||
|
}, {
|
||||||
|
"name": "Proportional line following with 2 color sensors",
|
||||||
|
"description": "Proportional line following using two color sensor.",
|
||||||
|
"youTubeId": "QWOflBuu9Oo"
|
||||||
|
}]
|
||||||
|
```
|
||||||
|
|
||||||
|
## See Also
|
||||||
|
|
||||||
|
[Robot 1](/tutorials/city-shaper/robot-1),
|
||||||
|
[Robot 2](/tutorials/city-shaper/robot-2)
|
||||||
|
|
@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
## Step 1 - Build Your Driving Base Robot @unplugged
|
## Step 1 - Build Your Driving Base Robot @unplugged
|
||||||
|
|
||||||
Build the robot driving base:
|
Build the medium motor robot driving base:
|
||||||
|
|
||||||
[](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf)
|
* [Driving base](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf)
|
||||||
|
* [Medium motor driving base](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-medium-motor-driving-base-e66e2fc0d917485ef1aa023e8358e7a7.pdf)
|
||||||
|
|
||||||
If clicking on the image above doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
If clicking on the image above doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ At first, it's nice to know that your program is running. Plug in a ``||brick:sh
|
|||||||
into the ``||loops:on start||`` block. Change the image to something else if you want!
|
into the ``||loops:on start||`` block. Change the image to something else if you want!
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
brick.showMood(moods.neutral)
|
brick.showMood(moods.sleeping)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Step 3 - Try your code @fullscreen
|
## Step 3 - Try your code @fullscreen
|
||||||
@ -22,17 +23,29 @@ brick.showMood(moods.neutral)
|
|||||||
Look at the simulator and check that your image is showing on the screen. When you are ready, press the **DOWNLOAD** button
|
Look at the simulator and check that your image is showing on the screen. When you are ready, press the **DOWNLOAD** button
|
||||||
and follow the instructions to transfer your code on the brick.
|
and follow the instructions to transfer your code on the brick.
|
||||||
|
|
||||||
## Step 4 - Steer motors @fullscreen
|
## Step 4 - Pause on Start @fullscreen
|
||||||
|
|
||||||
|
As you may have noticed, the code starts running immediately once you download it to the brick. To prevent the robot
|
||||||
|
from rolling away, add a ``||brick:pause until enter pressed||`` button to wait for the user to press enter.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
brick.showMood(moods.sleeping)
|
||||||
|
brick.buttonEnter.pauseUntil(ButtonEvent.Pressed)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 5 - Steer motors @fullscreen
|
||||||
|
|
||||||
Drag a ``||motors:steer motors||`` block from the **MOTORS** toolbox drawer and snap it in under ``||brick:show mood||``.
|
Drag a ``||motors:steer motors||`` block from the **MOTORS** toolbox drawer and snap it in under ``||brick:show mood||``.
|
||||||
Click on the **(+)** symbol and make sure to tell your motors to turn **1** rotation.
|
Click on the **(+)** symbol and make sure to tell your motors to turn **1** rotation.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
|
brick.showMood(moods.sleeping)
|
||||||
|
brick.buttonEnter.pauseUntil(ButtonEvent.Pressed)
|
||||||
brick.showMood(moods.neutral)
|
brick.showMood(moods.neutral)
|
||||||
motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)
|
motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Step 5 - Try your code @fullscreen
|
## Step 6 - Try your code @fullscreen
|
||||||
|
|
||||||
Whenever you make a code change, the simulator will restart so you can see what your latest change will do.
|
Whenever you make a code change, the simulator will restart so you can see what your latest change will do.
|
||||||
When you are ready, click **DOWNLOAD** and follow the instructions to transfer the code into your brick.
|
When you are ready, click **DOWNLOAD** and follow the instructions to transfer the code into your brick.
|
||||||
|
@ -25,6 +25,7 @@ After downloading your code, press **UP** to move the robot.
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
brick.showMood(moods.awake)
|
||||||
motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)
|
motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)
|
||||||
})
|
})
|
||||||
brick.showMood(moods.neutral)
|
brick.showMood(moods.neutral)
|
||||||
@ -38,6 +39,7 @@ Drag a ``||motors:set brake||`` block into the ``||loops:on start||`` and set it
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
brick.showMood(moods.awake)
|
||||||
motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)
|
motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)
|
||||||
})
|
})
|
||||||
brick.showMood(moods.neutral)
|
brick.showMood(moods.neutral)
|
||||||
@ -53,9 +55,11 @@ Put a ``||motors:steer motors||`` in for that button and set the turn ratio to d
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
brick.showMood(moods.middleLeft)
|
||||||
motors.largeBC.steer(-50, 50, 1, MoveUnit.Rotations)
|
motors.largeBC.steer(-50, 50, 1, MoveUnit.Rotations)
|
||||||
})
|
})
|
||||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
brick.showMood(moods.middleRight)
|
||||||
motors.largeBC.steer(50, 50, 1, MoveUnit.Rotations)
|
motors.largeBC.steer(50, 50, 1, MoveUnit.Rotations)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
@ -67,6 +71,7 @@ Add a ``||motors:steer motors||`` to an ``||brick:on button||`` block and change
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
brick.showMood(moods.knockedOut)
|
||||||
motors.largeBC.steer(0, -50, 1, MoveUnit.Rotations)
|
motors.largeBC.steer(0, -50, 1, MoveUnit.Rotations)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
@ -85,6 +90,7 @@ Create a program that moves the Driving Base and makes it stop 6 cm from the Cub
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
brick.showMood(moods.dizzy)
|
||||||
motors.largeBC.steer(0, 50)
|
motors.largeBC.steer(0, 50)
|
||||||
pauseUntil(() => sensors.ultrasonic4.distance() < 6)
|
pauseUntil(() => sensors.ultrasonic4.distance() < 6)
|
||||||
motors.largeBC.stop()
|
motors.largeBC.stop()
|
||||||
|
@ -21,6 +21,12 @@
|
|||||||
"cardType": "tutorial",
|
"cardType": "tutorial",
|
||||||
"url":"/tutorials/redlight-greenlight",
|
"url":"/tutorials/redlight-greenlight",
|
||||||
"imageUrl":"/static/tutorials/redlight-greenlight.png"
|
"imageUrl":"/static/tutorials/redlight-greenlight.png"
|
||||||
|
}, {
|
||||||
|
"name": "Move To Color",
|
||||||
|
"description": "Move straight until a color is detected.",
|
||||||
|
"cardType": "tutorial",
|
||||||
|
"url":"/tutorials/move-to-color",
|
||||||
|
"imageUrl":"/static/tutorials/move-to-color.png"
|
||||||
}, {
|
}, {
|
||||||
"name": "Reflected Light Measure",
|
"name": "Reflected Light Measure",
|
||||||
"description": "Teach the sensor what light or dark is.",
|
"description": "Teach the sensor what light or dark is.",
|
||||||
|
34
docs/tutorials/drifter.md
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Drifter
|
||||||
|
|
||||||
|
Use this program to try out the gyro sensor and the effect of drifting.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// this loop shows the rate, angle and drift of the robot
|
||||||
|
forever(() => {
|
||||||
|
brick.showValue("rate", sensors.gyro2.rate(), 1)
|
||||||
|
brick.showValue("angle", sensors.gyro2.angle(), 2)
|
||||||
|
brick.showValue("drift", sensors.gyro2.drift(), 3)
|
||||||
|
})
|
||||||
|
// this loop shows wheter the sensor is calibrating
|
||||||
|
forever(() => {
|
||||||
|
brick.showString(sensors.gyro2.isCalibrating() ? "calibrating..." : "", 4)
|
||||||
|
})
|
||||||
|
// instructions on how to use the buttons
|
||||||
|
brick.showString("ENTER: calibrate", 7)
|
||||||
|
brick.showString(" (reset+drift)", 8)
|
||||||
|
brick.showString("LEFT: reset", 9)
|
||||||
|
brick.showString("RIGHT: compute drift", 10)
|
||||||
|
|
||||||
|
// enter -> calibrate
|
||||||
|
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
sensors.gyro2.calibrate()
|
||||||
|
})
|
||||||
|
// right -> compute drift
|
||||||
|
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
sensors.gyro2.computeDrift()
|
||||||
|
})
|
||||||
|
// left -> reset
|
||||||
|
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
sensors.gyro2.reset()
|
||||||
|
})
|
||||||
|
```
|
31
docs/tutorials/gyro.md
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Gyro tutorials
|
||||||
|
|
||||||
|
## Tutorials
|
||||||
|
|
||||||
|
```codecard
|
||||||
|
[{
|
||||||
|
"name": "Calibrate",
|
||||||
|
"description": "Make sure you gyro sensor is ready to use",
|
||||||
|
"cardType": "tutorial",
|
||||||
|
"url":"/tutorials/calibrate-gyro",
|
||||||
|
"imageUrl":"/static/tutorials/calibrate-gyro.png"
|
||||||
|
}, {
|
||||||
|
"name": "Turn",
|
||||||
|
"description": "Use the gyro to turn precisely",
|
||||||
|
"cardType": "tutorial",
|
||||||
|
"url":"/tutorials/turn-with-gyro",
|
||||||
|
"imageUrl":"/static/tutorials/turn-with-gyro.png"
|
||||||
|
}, {
|
||||||
|
"name": "Move Straight",
|
||||||
|
"description": "Use the gyro to correct the trajectory of the robot",
|
||||||
|
"cardType": "tutorial",
|
||||||
|
"url":"/tutorials/move-straight-with-gyro",
|
||||||
|
"imageUrl":"/static/tutorials/move-straight-with-gyro.png"
|
||||||
|
}, {
|
||||||
|
"name": "Drifter",
|
||||||
|
"description": "Explore how the gyro is drifting",
|
||||||
|
"cardType": "example",
|
||||||
|
"url":"/tutorials/drifter",
|
||||||
|
"imageUrl":"/static/tutorials/drifter.png"
|
||||||
|
}]
|
||||||
|
```
|
@ -42,7 +42,7 @@
|
|||||||
}, {
|
}, {
|
||||||
"name": "Turtle",
|
"name": "Turtle",
|
||||||
"description": "Encode moves and run them on a driving base",
|
"description": "Encode moves and run them on a driving base",
|
||||||
"url":"/examples/turtle",
|
"url":"/tutorials/turtle",
|
||||||
"cardType": "example"
|
"cardType": "example"
|
||||||
}]
|
}]
|
||||||
```
|
```
|
||||||
|
61
docs/tutorials/move-straight-with-gyro.md
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# Move Straight With Gyro
|
||||||
|
|
||||||
|
## Introduction @fullscreen
|
||||||
|
|
||||||
|
Rotating using a wheel is not precise. The wheel can slip or the motors
|
||||||
|
can be slightly different.
|
||||||
|
With the help of the gyro you can detect and correct deviations in your trajectory.
|
||||||
|
|
||||||
|
* [EV3 Driving Base](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf)
|
||||||
|
* [EV3 Driving Base with Gyro](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-gyro-sensor-driving-base-a521f8ebe355c281c006418395309e15.pdf)
|
||||||
|
|
||||||
|
|
||||||
|
## Step 1 Calibration
|
||||||
|
|
||||||
|
Add a ``||sensors:calibrate gyro||`` block in a ``||brick:on button enter pressed||`` block so that you can manually start a calibration process. Run the calibration
|
||||||
|
at least once after connecting the gyro.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
brick.showPorts()
|
||||||
|
sensors.gyro2.calibrate()
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 2 Compute the error
|
||||||
|
|
||||||
|
Make a new **error** variable and drag the ``||sensors:gyro rate||``
|
||||||
|
and multiply it by -1. Since the rate shows the rotation rate, we will
|
||||||
|
counter it by negating it.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let error = 0
|
||||||
|
brick.showPorts()
|
||||||
|
sensors.gyro2.calibrate()
|
||||||
|
while (true) {
|
||||||
|
error = sensors.gyro2.rate() * -1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 3 Steer with feedback
|
||||||
|
|
||||||
|
Drag a ``||motors:steer motors||`` block under the variable and pass
|
||||||
|
the **error** variable into the turn ratio section.
|
||||||
|
|
||||||
|
If the robot is turning right, the gyro will report a positive rotation rate
|
||||||
|
and the turn ratio will be negative which will the turn the robot left!
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let error = 0
|
||||||
|
brick.showPorts()
|
||||||
|
sensors.gyro2.calibrate()
|
||||||
|
while (true) {
|
||||||
|
error = sensors.gyro2.rate() * -1
|
||||||
|
motors.largeBC.steer(error, 50)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 4 Run it!
|
||||||
|
|
||||||
|
Download to your brick and test out if the robot is going straight.
|
||||||
|
|
||||||
|
This kind of technique is called a proportional controller;
|
||||||
|
it corrects the inputs (motor speed) with a feedback proportional to the output (rotation rate).
|
65
docs/tutorials/move-to-color.md
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# Move To Color
|
||||||
|
|
||||||
|
## Introduction @fullscreen
|
||||||
|
|
||||||
|
This tutorial shows how to move the EV3 driving base until the color sensor detects a color.
|
||||||
|
|
||||||
|
Here are the building instructions for the robot:
|
||||||
|
|
||||||
|
* [EV3 driving base](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf)
|
||||||
|
* [Color sensor down](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-color-sensor-down-driving-base-d30ed30610c3d6647d56e17bc64cf6e2.pdf)
|
||||||
|
|
||||||
|
|
||||||
|
## Step 1 Run code on button pressed
|
||||||
|
|
||||||
|
Drag ``||brick:on button pressed||`` block so that your code starts when the enter button is pressed (and not at the start). We are also using the ``||brick:show string||``
|
||||||
|
message easily diagnose if the program does not work.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
brick.showString("started", 1)
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 2 Turn on the motors
|
||||||
|
|
||||||
|
Drag a ``||motors:steer motors B+C||`` block under the button pressed event. This will turn on both motors.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
brick.showString("started", 1)
|
||||||
|
motors.largeBC.steer(0, 50)
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 3 Pause until color
|
||||||
|
|
||||||
|
Drag a ``||sensors:pause until color detected||`` block after the steer and select the color you want to detect. This block will stop the program until the color is detected.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
brick.showString("started", 1)
|
||||||
|
motors.largeBC.steer(0, 50)
|
||||||
|
brick.showString("looking for red", 1)
|
||||||
|
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 4 Stop the motors!
|
||||||
|
|
||||||
|
Once the color is detected, the program will continue to run blocks. Drag a ``||motors:stop B+C motor||`` so that both motors stop.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
brick.showString("started", 1)
|
||||||
|
motors.largeBC.steer(0, 50)
|
||||||
|
brick.showString("looking for red", 1)
|
||||||
|
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||||
|
brick.showString("stop", 1)
|
||||||
|
motors.largeBC.stop()
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 5
|
||||||
|
|
||||||
|
Download your program to your brick and try it out!
|
33
docs/tutorials/pause-on-start.md
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# Pause On Start
|
||||||
|
|
||||||
|
## Introduction @unplugged
|
||||||
|
|
||||||
|
Sometimes you don't want your program to run right away... you can use a button to wait before moving the motors.
|
||||||
|
|
||||||
|
## Step 1
|
||||||
|
|
||||||
|
Let's start by showing an image on the screen so the user knows that the robot is ready and waiting.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
brick.showImage(images.informationStop1)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 2
|
||||||
|
|
||||||
|
Drag the ``||brick:pause until enter pressed||`` button to wait for the user to press the Enter button.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
brick.showImage(images.informationStop1)
|
||||||
|
brick.buttonEnter.pauseUntil(ButtonEvent.Pressed)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 3
|
||||||
|
|
||||||
|
Add all the motor and sensor code you want after those blocks!
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
brick.showImage(images.informationStop1)
|
||||||
|
brick.buttonEnter.pauseUntil(ButtonEvent.Pressed)
|
||||||
|
brick.showImage(images.expressionsBigSmile)
|
||||||
|
motors.largeBC.tank(50, 50, 1, MoveUnit.Seconds)
|
||||||
|
```
|
43
docs/tutorials/turn-with-gyro.md
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# Turn With Gyro
|
||||||
|
|
||||||
|
## Introduction @fullscreen
|
||||||
|
|
||||||
|
Use the gyro to measure how much the robot is turning, regardless if your wheels are slipping.
|
||||||
|
|
||||||
|
## Step 1 Calibrate
|
||||||
|
|
||||||
|
Add the ``||sensors:calibrate gyro||`` block to make sure your gyro is ready to use.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
sensors.gyro2.calibrate()
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 2 Turn
|
||||||
|
|
||||||
|
Use motor blocks to make the robot turn. Don't go too fast!
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
sensors.gyro2.calibrate()
|
||||||
|
motors.largeBC.steer(200, 20)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 3 Pause for turn
|
||||||
|
|
||||||
|
Use the ``||sensors:pause until rotated||`` block to wait until the desired amount of rotation has occured.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
sensors.gyro2.calibrate()
|
||||||
|
motors.largeBC.steer(200, 20)
|
||||||
|
sensors.gyro2.pauseUntilRotated(90)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 4 Stop
|
||||||
|
|
||||||
|
Stop the motors!
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
sensors.gyro2.calibrate()
|
||||||
|
motors.largeBC.steer(200, 20)
|
||||||
|
sensors.gyro2.pauseUntilRotated(90)
|
||||||
|
motors.stopAll()
|
||||||
|
```
|
247
editor/deploy.ts
@ -2,72 +2,231 @@
|
|||||||
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
||||||
|
|
||||||
import UF2 = pxtc.UF2;
|
import UF2 = pxtc.UF2;
|
||||||
|
import { Ev3Wrapper } from "./wrap";
|
||||||
|
import { bluetoothTryAgainAsync } from "./dialogs";
|
||||||
|
|
||||||
export let ev3: pxt.editor.Ev3Wrapper
|
export let ev3: Ev3Wrapper;
|
||||||
|
|
||||||
export function debug() {
|
export function debug() {
|
||||||
return initAsync()
|
return initHidAsync()
|
||||||
.then(w => w.downloadFileAsync("/tmp/dmesg.txt", v => console.log(pxt.Util.uint8ArrayToString(v))))
|
.then(w => w.downloadFileAsync("/tmp/dmesg.txt", v => console.log(pxt.Util.uint8ArrayToString(v))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Web Serial API https://wicg.github.io/serial/
|
||||||
|
// chromium bug https://bugs.chromium.org/p/chromium/issues/detail?id=884928
|
||||||
|
// Under experimental features in Chrome Desktop 77+
|
||||||
|
enum ParityType {
|
||||||
|
"none",
|
||||||
|
"even",
|
||||||
|
"odd",
|
||||||
|
"mark",
|
||||||
|
"space"
|
||||||
|
}
|
||||||
|
declare interface SerialOptions {
|
||||||
|
baudrate?: number;
|
||||||
|
databits?: number;
|
||||||
|
stopbits?: number;
|
||||||
|
parity?: ParityType;
|
||||||
|
buffersize?: number;
|
||||||
|
rtscts?: boolean;
|
||||||
|
xon?: boolean;
|
||||||
|
xoff?: boolean;
|
||||||
|
xany?: boolean;
|
||||||
|
}
|
||||||
|
type SerialPortInfo = pxt.Map<string>;
|
||||||
|
type SerialPortRequestOptions = any;
|
||||||
|
declare class SerialPort {
|
||||||
|
open(options?: SerialOptions): Promise<void>;
|
||||||
|
close(): void;
|
||||||
|
readonly readable: any;
|
||||||
|
readonly writable: any;
|
||||||
|
//getInfo(): SerialPortInfo;
|
||||||
|
}
|
||||||
|
declare interface Serial extends EventTarget {
|
||||||
|
onconnect: any;
|
||||||
|
ondisconnect: any;
|
||||||
|
getPorts(): Promise<SerialPort[]>
|
||||||
|
requestPort(options: SerialPortRequestOptions): Promise<SerialPort>;
|
||||||
|
}
|
||||||
|
|
||||||
|
class WebSerialPackageIO implements pxt.HF2.PacketIO {
|
||||||
|
onData: (v: Uint8Array) => void;
|
||||||
|
onError: (e: Error) => void;
|
||||||
|
onEvent: (v: Uint8Array) => void;
|
||||||
|
onSerial: (v: Uint8Array, isErr: boolean) => void;
|
||||||
|
sendSerialAsync: (buf: Uint8Array, useStdErr: boolean) => Promise<void>;
|
||||||
|
private _reader: any;
|
||||||
|
private _writer: any;
|
||||||
|
|
||||||
|
constructor(private port: SerialPort, private options: SerialOptions) {
|
||||||
|
}
|
||||||
|
|
||||||
|
async readSerialAsync() {
|
||||||
|
this._reader = this.port.readable.getReader();
|
||||||
|
let buffer: Uint8Array;
|
||||||
|
const reader = this._reader;
|
||||||
|
while (reader === this._reader) { // will change if we recycle the connection
|
||||||
|
const { done, value } = await this._reader.read()
|
||||||
|
if (!buffer) buffer = value;
|
||||||
|
else { // concat
|
||||||
|
let tmp = new Uint8Array(buffer.length + value.byteLength)
|
||||||
|
tmp.set(buffer, 0)
|
||||||
|
tmp.set(value, buffer.length)
|
||||||
|
buffer = tmp;
|
||||||
|
}
|
||||||
|
if (buffer && buffer.length >= 6) {
|
||||||
|
this.onData(new Uint8Array(buffer));
|
||||||
|
buffer = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static isSupported(): boolean {
|
||||||
|
return !!(<any>navigator).serial;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async mkPacketIOAsync(): Promise<pxt.HF2.PacketIO> {
|
||||||
|
const serial = (<any>navigator).serial;
|
||||||
|
if (serial) {
|
||||||
|
try {
|
||||||
|
const requestOptions: SerialPortRequestOptions = {};
|
||||||
|
const port = await serial.requestPort(requestOptions);
|
||||||
|
const options: SerialOptions = {
|
||||||
|
baudrate: 460800,
|
||||||
|
buffersize: 4096
|
||||||
|
};
|
||||||
|
return new WebSerialPackageIO(port, options);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`connection error`, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error("could not open serial port");
|
||||||
|
}
|
||||||
|
|
||||||
|
error(msg: string): any {
|
||||||
|
console.error(msg);
|
||||||
|
throw new Error(lf("error on brick ({0})", msg))
|
||||||
|
}
|
||||||
|
|
||||||
|
private openAsync() {
|
||||||
|
console.log(`serial: opening port`)
|
||||||
|
if (!!this._reader) return Promise.resolve();
|
||||||
|
this._reader = undefined;
|
||||||
|
this._writer = undefined;
|
||||||
|
return this.port.open(this.options)
|
||||||
|
.then(() => {
|
||||||
|
this.readSerialAsync();
|
||||||
|
return Promise.resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private closeAsync() {
|
||||||
|
console.log(`serial: closing port`);
|
||||||
|
this.port.close();
|
||||||
|
this._reader = undefined;
|
||||||
|
this._writer = undefined;
|
||||||
|
return Promise.delay(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
reconnectAsync(): Promise<void> {
|
||||||
|
return this.openAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnectAsync(): Promise<void> {
|
||||||
|
return this.closeAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
sendPacketAsync(pkt: Uint8Array): Promise<void> {
|
||||||
|
if (!this._writer)
|
||||||
|
this._writer = this.port.writable.getWriter();
|
||||||
|
return this._writer.write(pkt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function hf2Async() {
|
function hf2Async() {
|
||||||
return pxt.HF2.mkPacketIOAsync()
|
const pktIOAsync: Promise<pxt.HF2.PacketIO> = useWebSerial
|
||||||
.then(h => {
|
? WebSerialPackageIO.mkPacketIOAsync() : pxt.HF2.mkPacketIOAsync()
|
||||||
let w = new pxt.editor.Ev3Wrapper(h)
|
return pktIOAsync.then(h => {
|
||||||
|
let w = new Ev3Wrapper(h)
|
||||||
ev3 = w
|
ev3 = w
|
||||||
return w.reconnectAsync(true)
|
return w.reconnectAsync(true)
|
||||||
.then(() => w)
|
.then(() => w)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let noHID = false
|
let useHID = false;
|
||||||
|
let useWebSerial = false;
|
||||||
let initPromise: Promise<pxt.editor.Ev3Wrapper>
|
export function initAsync(): Promise<void> {
|
||||||
export function initAsync() {
|
|
||||||
if (initPromise)
|
|
||||||
return initPromise
|
|
||||||
|
|
||||||
let canHID = false
|
|
||||||
if (pxt.U.isNodeJS) {
|
if (pxt.U.isNodeJS) {
|
||||||
// doesn't seem to work ATM
|
// doesn't seem to work ATM
|
||||||
canHID = false
|
useHID = false
|
||||||
} else {
|
} else {
|
||||||
const forceHexDownload = /forceHexDownload/i.test(window.location.href);
|
const nodehid = /nodehid/i.test(window.location.href);
|
||||||
if (pxt.Cloud.isLocalHost() && pxt.Cloud.localToken && !forceHexDownload)
|
if (pxt.BrowserUtils.isLocalHost() && pxt.Cloud.localToken && nodehid)
|
||||||
canHID = true
|
useHID = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (noHID)
|
if (WebSerialPackageIO.isSupported())
|
||||||
canHID = false
|
pxt.tickEvent("webserial.supported");
|
||||||
|
|
||||||
if (canHID) {
|
return Promise.resolve();
|
||||||
initPromise = hf2Async()
|
}
|
||||||
|
|
||||||
|
export function canUseWebSerial() {
|
||||||
|
return WebSerialPackageIO.isSupported();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function enableWebSerialAsync() {
|
||||||
|
initPromise = undefined;
|
||||||
|
useWebSerial = WebSerialPackageIO.isSupported();
|
||||||
|
useHID = useWebSerial;
|
||||||
|
if (useWebSerial)
|
||||||
|
return initHidAsync().then(() => { });
|
||||||
|
else return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanupAsync() {
|
||||||
|
if (ev3) {
|
||||||
|
console.log('cleanup previous port')
|
||||||
|
return ev3.disconnectAsync()
|
||||||
|
.catch(e => { })
|
||||||
|
.finally(() => { ev3 = undefined; });
|
||||||
|
}
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
let initPromise: Promise<Ev3Wrapper>
|
||||||
|
function initHidAsync() { // needs to run within a click handler
|
||||||
|
if (initPromise)
|
||||||
|
return initPromise
|
||||||
|
if (useHID) {
|
||||||
|
initPromise = cleanupAsync()
|
||||||
|
.then(() => hf2Async())
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
initPromise = null
|
initPromise = null
|
||||||
noHID = true
|
useHID = false;
|
||||||
return Promise.reject(err)
|
useWebSerial = false;
|
||||||
|
return Promise.reject(err);
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
noHID = true
|
useHID = false
|
||||||
|
useWebSerial = false;
|
||||||
initPromise = Promise.reject(new Error("no HID"))
|
initPromise = Promise.reject(new Error("no HID"))
|
||||||
}
|
}
|
||||||
|
return initPromise;
|
||||||
return initPromise
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this comes from aux/pxt.lms
|
// this comes from aux/pxt.lms
|
||||||
|
const fspath = "../prjs/BrkProg_SAVE/"
|
||||||
const rbfTemplate = `
|
const rbfTemplate = `
|
||||||
4c45474f580000006d000100000000001c000000000000000e000000821b038405018130813e8053
|
4c45474f580000006d000100000000001c000000000000000e000000821b038405018130813e8053
|
||||||
74617274696e672e2e2e0084006080XX00448581644886488405018130813e80427965210084000a
|
74617274696e672e2e2e0084006080XX00448581644886488405018130813e80427965210084000a
|
||||||
`
|
`
|
||||||
export function deployCoreAsync(resp: pxtc.CompileResult) {
|
export function deployCoreAsync(resp: pxtc.CompileResult) {
|
||||||
let w: pxt.editor.Ev3Wrapper
|
|
||||||
|
|
||||||
let filename = resp.downloadFileBaseName || "pxt"
|
let filename = resp.downloadFileBaseName || "pxt"
|
||||||
filename = filename.replace(/^lego-/, "")
|
filename = filename.replace(/^lego-/, "")
|
||||||
|
|
||||||
let fspath = "../prjs/BrkProg_SAVE/"
|
|
||||||
|
|
||||||
let elfPath = fspath + filename + ".elf"
|
let elfPath = fspath + filename + ".elf"
|
||||||
let rbfPath = fspath + filename + ".rbf"
|
let rbfPath = fspath + filename + ".rbf"
|
||||||
|
|
||||||
@ -107,27 +266,41 @@ export function deployCoreAsync(resp: pxtc.CompileResult) {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (noHID) return saveUF2Async()
|
if (!useHID) return saveUF2Async()
|
||||||
|
|
||||||
return initAsync()
|
pxt.tickEvent("webserial.flash");
|
||||||
|
let w: Ev3Wrapper;
|
||||||
|
return initHidAsync()
|
||||||
.then(w_ => {
|
.then(w_ => {
|
||||||
w = w_
|
w = w_
|
||||||
if (w.isStreaming)
|
if (w.isStreaming)
|
||||||
pxt.U.userError("please stop the program first")
|
pxt.U.userError("please stop the program first")
|
||||||
return w.stopAsync()
|
return w.reconnectAsync(false)
|
||||||
|
.catch(e => {
|
||||||
|
// user easily forgets to stop robot
|
||||||
|
bluetoothTryAgainAsync().then(() => w.disconnectAsync())
|
||||||
|
.then(() => Promise.delay(1000))
|
||||||
|
.then(() => w.reconnectAsync());
|
||||||
|
|
||||||
|
// nothing we can do
|
||||||
|
return Promise.reject(e);
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
.then(() => w.stopAsync())
|
||||||
.then(() => w.rmAsync(elfPath))
|
.then(() => w.rmAsync(elfPath))
|
||||||
.then(() => w.flashAsync(elfPath, UF2.readBytes(origElfUF2, 0, origElfUF2.length * 256)))
|
.then(() => w.flashAsync(elfPath, UF2.readBytes(origElfUF2, 0, origElfUF2.length * 256)))
|
||||||
.then(() => w.flashAsync(rbfPath, rbfBIN))
|
.then(() => w.flashAsync(rbfPath, rbfBIN))
|
||||||
.then(() => w.runAsync(rbfPath))
|
.then(() => w.runAsync(rbfPath))
|
||||||
|
.then(() => Promise.delay(500))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
pxt.tickEvent("webserial.success");
|
||||||
return w.disconnectAsync()
|
return w.disconnectAsync()
|
||||||
//return Promise.delay(1000).then(() => w.dmesgAsync())
|
//return Promise.delay(1000).then(() => w.dmesgAsync())
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
// if we failed to initalize, retry
|
pxt.tickEvent("webserial.fail");
|
||||||
if (noHID)
|
useHID = false;
|
||||||
return saveUF2Async()
|
useWebSerial = false;
|
||||||
else
|
// if we failed to initalize, tell the user to retry
|
||||||
return Promise.reject(e)
|
return Promise.reject(e)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
145
editor/dialogs.tsx
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { canUseWebSerial, enableWebSerialAsync } from "./deploy";
|
||||||
|
import { projectView } from "./extension";
|
||||||
|
|
||||||
|
let confirmAsync: (options: any) => Promise<number>;
|
||||||
|
|
||||||
|
export function bluetoothTryAgainAsync(): Promise<void> {
|
||||||
|
return confirmAsync({
|
||||||
|
header: lf("Bluetooth download failed..."),
|
||||||
|
jsx: <ul>
|
||||||
|
<li>{lf("Make sure to stop your program or exit portview on the EV3.")}</li>
|
||||||
|
<li>{lf("Check your battery level.")}</li>
|
||||||
|
<li>{lf("Close EV3 LabView or other MakeCode editor tabs.")}</li>
|
||||||
|
</ul>,
|
||||||
|
hasCloseIcon: false,
|
||||||
|
hideCancel: true,
|
||||||
|
hideAgree: false,
|
||||||
|
agreeLbl: lf("Try again")
|
||||||
|
}).then(r => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
function enableWebSerialAndCompileAsync() {
|
||||||
|
return enableWebSerialAsync()
|
||||||
|
.then(() => Promise.delay(500))
|
||||||
|
.then(() => projectView.compile());
|
||||||
|
}
|
||||||
|
|
||||||
|
let bluetoothDialogShown = false;
|
||||||
|
function explainWebSerialPairingAsync(): Promise<void> {
|
||||||
|
if (!confirmAsync || bluetoothDialogShown) return Promise.resolve();
|
||||||
|
|
||||||
|
bluetoothDialogShown = true;
|
||||||
|
return confirmAsync({
|
||||||
|
header: lf("Bluetooth pairing"),
|
||||||
|
hasCloseIcon: false,
|
||||||
|
hideCancel: true,
|
||||||
|
buttons: [{
|
||||||
|
label: lf("Help"),
|
||||||
|
icon: "question circle",
|
||||||
|
className: "lightgrey",
|
||||||
|
url: "/bluetooth"
|
||||||
|
}],
|
||||||
|
jsx: <p>
|
||||||
|
{lf("You will be prompted to select a serial port.")}
|
||||||
|
{pxt.BrowserUtils.isWindows()
|
||||||
|
? lf("Look for 'Standard Serial over Bluetooth link'.")
|
||||||
|
: lf("Loop for 'cu.EV3-SerialPort'.")}
|
||||||
|
{lf("If you have paired multiple EV3, you might have to try out multiple ports until you find the correct one.")}
|
||||||
|
</p>
|
||||||
|
}).then(() => { })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showUploadDialogAsync(fn: string, url: string, _confirmAsync: (options: any) => Promise<number>): Promise<void> {
|
||||||
|
confirmAsync = _confirmAsync;
|
||||||
|
// https://msdn.microsoft.com/en-us/library/cc848897.aspx
|
||||||
|
// "For security reasons, data URIs are restricted to downloaded resources.
|
||||||
|
// Data URIs cannot be used for navigation, for scripting, or to populate frame or iframe elements"
|
||||||
|
const downloadAgain = !pxt.BrowserUtils.isIE() && !pxt.BrowserUtils.isEdge();
|
||||||
|
const docUrl = pxt.appTarget.appTheme.usbDocs;
|
||||||
|
|
||||||
|
const jsx =
|
||||||
|
<div className="ui grid stackable">
|
||||||
|
<div className="column five wide" style={{ backgroundColor: "#E2E2E2" }}>
|
||||||
|
<div className="ui header">{lf("First time here?")}</div>
|
||||||
|
<strong style={{ fontSize: "small" }}>{lf("You must have version 1.10E or above of the firmware")}</strong>
|
||||||
|
<div style={{ justifyContent: "center", display: "flex", padding: "1rem" }}>
|
||||||
|
<img className="ui image" src="/static/download/firmware.png" style={{ height: "100px" }} />
|
||||||
|
</div>
|
||||||
|
<a href="/troubleshoot" target="_blank">{lf("Check your firmware version here and update if needed")}</a>
|
||||||
|
</div>
|
||||||
|
<div className="column eleven wide">
|
||||||
|
<div className="ui grid">
|
||||||
|
<div className="row">
|
||||||
|
<div className="column">
|
||||||
|
<div className="ui two column grid padded">
|
||||||
|
<div className="column">
|
||||||
|
<div className="ui">
|
||||||
|
<div className="image">
|
||||||
|
<img className="ui medium rounded image" src="/static/download/connect.svg" style={{ height: "109px", width: "261px", marginBottom: "1rem" }} />
|
||||||
|
</div>
|
||||||
|
<div className="content">
|
||||||
|
<div className="description">
|
||||||
|
<span className="ui yellow circular label">1</span>
|
||||||
|
<strong>{lf("Connect the EV3 to your computer with a USB cable")}</strong>
|
||||||
|
<br />
|
||||||
|
<span style={{ fontSize: "small" }}>{lf("Use the miniUSB port on the top of the EV3 Brick")}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="column">
|
||||||
|
<div className="ui">
|
||||||
|
<div className="image">
|
||||||
|
<img className="ui medium rounded image" src="/static/download/transfer.svg" style={{ height: "109px", width: "261px", marginBottom: "1rem" }} />
|
||||||
|
</div>
|
||||||
|
<div className="content">
|
||||||
|
<div className="description">
|
||||||
|
<span className="ui yellow circular label">2</span>
|
||||||
|
<strong>{lf("Move the .uf2 file to the EV3 Brick")}</strong>
|
||||||
|
<br />
|
||||||
|
<span style={{ fontSize: "small" }}>{lf("Locate the downloaded .uf2 file and drag it to the EV3 USB drive")}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>;
|
||||||
|
|
||||||
|
return confirmAsync({
|
||||||
|
header: lf("Download to your EV3"),
|
||||||
|
jsx,
|
||||||
|
hasCloseIcon: true,
|
||||||
|
hideCancel: true,
|
||||||
|
hideAgree: false,
|
||||||
|
agreeLbl: lf("I got it"),
|
||||||
|
className: 'downloaddialog',
|
||||||
|
buttons: [canUseWebSerial() ? {
|
||||||
|
label: lf("Bluetooth"),
|
||||||
|
icon: "bluetooth",
|
||||||
|
className: "bluetooth focused",
|
||||||
|
onclick: () => {
|
||||||
|
pxt.tickEvent("bluetooth.enable");
|
||||||
|
explainWebSerialPairingAsync()
|
||||||
|
.then(() => enableWebSerialAndCompileAsync())
|
||||||
|
.done();
|
||||||
|
}
|
||||||
|
} : undefined, downloadAgain ? {
|
||||||
|
label: fn,
|
||||||
|
icon: "download",
|
||||||
|
className: "lightgrey focused",
|
||||||
|
url,
|
||||||
|
fileName: fn
|
||||||
|
} : undefined, docUrl ? {
|
||||||
|
label: lf("Help"),
|
||||||
|
icon: "help",
|
||||||
|
className: "lightgrey",
|
||||||
|
url: docUrl
|
||||||
|
} : undefined]
|
||||||
|
//timeout: 20000
|
||||||
|
}).then(() => { });
|
||||||
|
}
|
@ -1,113 +1,26 @@
|
|||||||
|
/// <reference path="../node_modules/pxt-core/localtypings/pxtarget.d.ts" />
|
||||||
|
/// <reference path="../node_modules/pxt-core/built/pxtblocks.d.ts" />
|
||||||
|
/// <reference path="../node_modules/pxt-core/built/pxtcompiler.d.ts" />
|
||||||
|
/// <reference path="../node_modules/pxt-core/built/pxtlib.d.ts" />
|
||||||
/// <reference path="../node_modules/pxt-core/built/pxteditor.d.ts"/>
|
/// <reference path="../node_modules/pxt-core/built/pxteditor.d.ts"/>
|
||||||
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
||||||
|
|
||||||
import { deployCoreAsync, initAsync } from "./deploy";
|
import { deployCoreAsync, initAsync } from "./deploy";
|
||||||
|
import { showUploadDialogAsync } from "./dialogs";
|
||||||
|
|
||||||
|
export let projectView: pxt.editor.IProjectView;
|
||||||
|
|
||||||
pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): Promise<pxt.editor.ExtensionResult> {
|
pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): Promise<pxt.editor.ExtensionResult> {
|
||||||
pxt.debug('loading pxt-ev3 target extensions...')
|
pxt.debug('loading pxt-ev3 target extensions...')
|
||||||
|
projectView = opts.projectView;
|
||||||
|
|
||||||
const res: pxt.editor.ExtensionResult = {
|
const res: pxt.editor.ExtensionResult = {
|
||||||
deployCoreAsync,
|
deployAsync: deployCoreAsync,
|
||||||
showUploadInstructionsAsync: (fn: string, url: string, confirmAsync: (options: any) => Promise<number>) => {
|
showUploadInstructionsAsync: showUploadDialogAsync
|
||||||
let resolve: (thenableOrResult?: void | PromiseLike<void>) => void;
|
|
||||||
let reject: (error: any) => void;
|
|
||||||
const deferred = new Promise<void>((res, rej) => {
|
|
||||||
resolve = res;
|
|
||||||
reject = rej;
|
|
||||||
});
|
|
||||||
const boardName = pxt.appTarget.appTheme.boardName || "???";
|
|
||||||
const boardDriveName = pxt.appTarget.appTheme.driveDisplayName || pxt.appTarget.compile.driveName || "???";
|
|
||||||
|
|
||||||
// https://msdn.microsoft.com/en-us/library/cc848897.aspx
|
|
||||||
// "For security reasons, data URIs are restricted to downloaded resources.
|
|
||||||
// Data URIs cannot be used for navigation, for scripting, or to populate frame or iframe elements"
|
|
||||||
const downloadAgain = !pxt.BrowserUtils.isIE() && !pxt.BrowserUtils.isEdge();
|
|
||||||
const docUrl = pxt.appTarget.appTheme.usbDocs;
|
|
||||||
const saveAs = pxt.BrowserUtils.hasSaveAs();
|
|
||||||
|
|
||||||
const htmlBody = `
|
|
||||||
<div class="ui grid stackable">
|
|
||||||
<div class="column five wide" style="background-color: #E2E2E2;">
|
|
||||||
<div class="ui header">${lf("First time here?")}</div>
|
|
||||||
<strong style="font-size:small">${lf("You must have version 1.10E or above of the firmware")}</strong>
|
|
||||||
<div style="justify-content: center;display: flex;padding: 1rem;">
|
|
||||||
<img class="ui image" src="/static/download/firmware.png" style="height:100px;" />
|
|
||||||
</div>
|
|
||||||
<a href="/troubleshoot" target="_blank">${lf("Check your firmware version here and update if needed")}</a>
|
|
||||||
</div>
|
|
||||||
<div class="column eleven wide">
|
|
||||||
<div class="ui grid">
|
|
||||||
<div class="row">
|
|
||||||
<div class="column">
|
|
||||||
<div class="ui two column grid padded">
|
|
||||||
<div class="column">
|
|
||||||
<div class="ui">
|
|
||||||
<div class="image">
|
|
||||||
<img class="ui medium rounded image" src="/static/download/connect.svg" style="height:109px;width:261px;margin-bottom:1rem;" />
|
|
||||||
</div>
|
|
||||||
<div class="content">
|
|
||||||
<div class="description">
|
|
||||||
<span class="ui yellow circular label">1</span>
|
|
||||||
<strong>${lf("Connect the EV3 to your computer with a USB cable")}</strong>
|
|
||||||
<br />
|
|
||||||
<span style="font-size:small">${lf("Use the miniUSB port on the top of the EV3 Brick")}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="column">
|
|
||||||
<div class="ui">
|
|
||||||
<div class="image">
|
|
||||||
<img class="ui medium rounded image" src="/static/download/transfer.svg" style="height:109px;width:261px;margin-bottom:1rem;" />
|
|
||||||
</div>
|
|
||||||
<div class="content">
|
|
||||||
<div class="description">
|
|
||||||
<span class="ui yellow circular label">2</span>
|
|
||||||
<strong>${lf("Move the .uf2 file to the EV3 Brick")}</strong>
|
|
||||||
<br />
|
|
||||||
<span style="font-size:small">${lf("Locate the downloaded .uf2 file and drag it to the EV3 USB drive")}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
return confirmAsync({
|
|
||||||
header: lf("Download to your EV3"),
|
|
||||||
htmlBody,
|
|
||||||
hasCloseIcon: true,
|
|
||||||
hideCancel: true,
|
|
||||||
hideAgree: false,
|
|
||||||
agreeLbl: lf("I got it"),
|
|
||||||
className: 'downloaddialog',
|
|
||||||
buttons: [downloadAgain ? {
|
|
||||||
label: fn,
|
|
||||||
icon: "download",
|
|
||||||
className: "lightgrey focused",
|
|
||||||
url,
|
|
||||||
fileName: fn
|
|
||||||
} : undefined, docUrl ? {
|
|
||||||
label: lf("Help"),
|
|
||||||
icon: "help",
|
|
||||||
className: "lightgrey",
|
|
||||||
url: docUrl
|
|
||||||
} : undefined]
|
|
||||||
//timeout: 20000
|
|
||||||
}).then(() => { });
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
initAsync().catch(e => {
|
initAsync().catch(e => {
|
||||||
// probably no HID - we'll try this again upon deployment
|
// probably no HID - we'll try this again upon deployment
|
||||||
})
|
})
|
||||||
return Promise.resolve<pxt.editor.ExtensionResult>(res);
|
return Promise.resolve<pxt.editor.ExtensionResult>(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// When require()d from node, bind the global pxt namespace
|
|
||||||
// namespace pxt {
|
|
||||||
// export const dummyExport = 1;
|
|
||||||
// }
|
|
||||||
// eval("if (typeof process === 'object' && process + '' === '[object process]') pxt = global.pxt")
|
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": true,
|
||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
|
"noImplicitThis": true,
|
||||||
|
"declaration": true,
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"isolatedModules": false,
|
||||||
"outDir": "../built/editor",
|
"outDir": "../built/editor",
|
||||||
"rootDir": ".",
|
"rootDir": ".",
|
||||||
"newLine": "LF",
|
"newLine": "LF",
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
"allowSyntheticDefaultImports": true,
|
"jsx": "react"
|
||||||
"declaration": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,26 +1,30 @@
|
|||||||
namespace pxt.editor {
|
/**
|
||||||
import HF2 = pxt.HF2
|
* See https://www.lego.com/cdn/cs/set/assets/blt6879b00ae6951482/LEGO_MINDSTORMS_EV3_Communication_Developer_Kit.pdf
|
||||||
import U = pxt.U
|
* https://github.com/mindboards/ev3sources/blob/master/lms2012/lms2012/source/bytecodes.h#L146
|
||||||
|
*/
|
||||||
|
import HF2 = pxt.HF2
|
||||||
|
import U = pxt.U
|
||||||
|
|
||||||
function log(msg: string) {
|
function log(msg: string) {
|
||||||
pxt.log("EWRAP: " + msg)
|
pxt.log("serial: " + msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DirEntry {
|
export interface DirEntry {
|
||||||
name: string;
|
name: string;
|
||||||
md5?: string;
|
md5?: string;
|
||||||
size?: number;
|
size?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const runTemplate = "C00882010084XX0060640301606400"
|
const runTemplate = "C00882010084XX0060640301606400"
|
||||||
const usbMagic = 0x3d3f
|
const usbMagic = 0x3d3f
|
||||||
|
const DIRECT_COMMAND_NO_REPLY = 0x80
|
||||||
|
|
||||||
export class Ev3Wrapper {
|
export class Ev3Wrapper {
|
||||||
msgs = new U.PromiseBuffer<Uint8Array>()
|
msgs = new U.PromiseBuffer<Uint8Array>()
|
||||||
private cmdSeq = U.randomUint32() & 0xffff;
|
private cmdSeq = U.randomUint32() & 0xffff;
|
||||||
private lock = new U.PromiseQueue();
|
private lock = new U.PromiseQueue();
|
||||||
isStreaming = false;
|
isStreaming = false;
|
||||||
dataDump = false;
|
dataDump = /talkdbg=1/.test(window.location.href);
|
||||||
|
|
||||||
constructor(public io: pxt.HF2.PacketIO) {
|
constructor(public io: pxt.HF2.PacketIO) {
|
||||||
io.onData = buf => {
|
io.onData = buf => {
|
||||||
@ -30,8 +34,8 @@ namespace pxt.editor {
|
|||||||
let payload = buf.slice(8)
|
let payload = buf.slice(8)
|
||||||
if (code == 1) {
|
if (code == 1) {
|
||||||
let str = U.uint8ArrayToString(payload)
|
let str = U.uint8ArrayToString(payload)
|
||||||
if (Util.isNodeJS)
|
if (U.isNodeJS)
|
||||||
console.log("SERIAL: " + str.replace(/\n+$/, ""))
|
pxt.debug("SERIAL: " + str.replace(/\n+$/, ""))
|
||||||
else
|
else
|
||||||
window.postMessage({
|
window.postMessage({
|
||||||
type: 'serial',
|
type: 'serial',
|
||||||
@ -39,7 +43,7 @@ namespace pxt.editor {
|
|||||||
data: str
|
data: str
|
||||||
}, "*")
|
}, "*")
|
||||||
} else
|
} else
|
||||||
console.log("Magic: " + code + ": " + U.toHex(payload))
|
pxt.debug("Magic: " + code + ": " + U.toHex(payload))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.dataDump)
|
if (this.dataDump)
|
||||||
@ -90,7 +94,7 @@ namespace pxt.editor {
|
|||||||
runAsync(path: string) {
|
runAsync(path: string) {
|
||||||
let codeHex = runTemplate.replace("XX", U.toHex(U.stringToUint8Array(path)))
|
let codeHex = runTemplate.replace("XX", U.toHex(U.stringToUint8Array(path)))
|
||||||
let code = U.fromHex(codeHex)
|
let code = U.fromHex(codeHex)
|
||||||
let pkt = this.allocCore(2 + code.length, 0)
|
let pkt = this.allocCore(2 + code.length, DIRECT_COMMAND_NO_REPLY)
|
||||||
HF2.write16(pkt, 5, 0x0800)
|
HF2.write16(pkt, 5, 0x0800)
|
||||||
U.memcpy(pkt, 7, code)
|
U.memcpy(pkt, 7, code)
|
||||||
log(`run ${path}`)
|
log(`run ${path}`)
|
||||||
@ -279,7 +283,4 @@ namespace pxt.editor {
|
|||||||
log(`disconnect`);
|
log(`disconnect`);
|
||||||
return this.io.disconnectAsync()
|
return this.io.disconnectAsync()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -3,9 +3,7 @@
|
|||||||
|
|
||||||
import { FieldPorts } from "./field_ports";
|
import { FieldPorts } from "./field_ports";
|
||||||
import { FieldMotors } from "./field_motors";
|
import { FieldMotors } from "./field_motors";
|
||||||
import { FieldSpeed } from "./field_speed";
|
|
||||||
import { FieldBrickButtons } from "./field_brickbuttons";
|
import { FieldBrickButtons } from "./field_brickbuttons";
|
||||||
import { FieldTurnRatio } from "./field_turnratio";
|
|
||||||
import { FieldColorEnum } from "./field_color";
|
import { FieldColorEnum } from "./field_color";
|
||||||
import { FieldMusic } from "./field_music";
|
import { FieldMusic } from "./field_music";
|
||||||
|
|
||||||
@ -19,15 +17,9 @@ pxt.editor.initFieldExtensionsAsync = function (opts: pxt.editor.FieldExtensionO
|
|||||||
}, {
|
}, {
|
||||||
selector: "motors",
|
selector: "motors",
|
||||||
editor: FieldMotors
|
editor: FieldMotors
|
||||||
}, {
|
|
||||||
selector: "speed",
|
|
||||||
editor: FieldSpeed
|
|
||||||
}, {
|
}, {
|
||||||
selector: "brickbuttons",
|
selector: "brickbuttons",
|
||||||
editor: FieldBrickButtons
|
editor: FieldBrickButtons
|
||||||
}, {
|
|
||||||
selector: "turnratio",
|
|
||||||
editor: FieldTurnRatio
|
|
||||||
}, {
|
}, {
|
||||||
selector: "colorenum",
|
selector: "colorenum",
|
||||||
editor: FieldColorEnum
|
editor: FieldColorEnum
|
||||||
|
@ -121,17 +121,17 @@ export class FieldBrickButtons extends Blockly.FieldDropdown implements Blockly.
|
|||||||
Blockly.DropDownDiv.setColour('#ffffff', '#dddddd');
|
Blockly.DropDownDiv.setColour('#ffffff', '#dddddd');
|
||||||
|
|
||||||
// Calculate positioning based on the field position.
|
// Calculate positioning based on the field position.
|
||||||
var scale = this.sourceBlock_.workspace.scale;
|
let scale = (<Blockly.WorkspaceSvg>this.sourceBlock_.workspace).scale;
|
||||||
var bBox = { width: this.size_.width, height: this.size_.height };
|
let bBox = { width: this.size_.width, height: this.size_.height };
|
||||||
bBox.width *= scale;
|
bBox.width *= scale;
|
||||||
bBox.height *= scale;
|
bBox.height *= scale;
|
||||||
var position = this.fieldGroup_.getBoundingClientRect();
|
let position = this.fieldGroup_.getBoundingClientRect();
|
||||||
var primaryX = position.left + bBox.width / 2;
|
let primaryX = position.left + bBox.width / 2;
|
||||||
var primaryY = position.top + bBox.height;
|
let primaryY = position.top + bBox.height;
|
||||||
var secondaryX = primaryX;
|
let secondaryX = primaryX;
|
||||||
var secondaryY = position.top;
|
let secondaryY = position.top;
|
||||||
// Set bounds to workspace; show the drop-down.
|
// Set bounds to workspace; show the drop-down.
|
||||||
(Blockly.DropDownDiv as any).setBoundsElement(this.sourceBlock_.workspace.getParentSvg().parentNode);
|
(Blockly.DropDownDiv as any).setBoundsElement((<Blockly.WorkspaceSvg>this.sourceBlock_.workspace).getParentSvg().parentNode);
|
||||||
(Blockly.DropDownDiv as any).show(this, primaryX, primaryY, secondaryX, secondaryY,
|
(Blockly.DropDownDiv as any).show(this, primaryX, primaryY, secondaryX, secondaryY,
|
||||||
this.onHide_.bind(this));
|
this.onHide_.bind(this));
|
||||||
}
|
}
|
||||||
@ -152,9 +152,10 @@ export class FieldBrickButtons extends Blockly.FieldDropdown implements Blockly.
|
|||||||
* Callback for when the drop-down is hidden.
|
* Callback for when the drop-down is hidden.
|
||||||
*/
|
*/
|
||||||
private onHide_ = function () {
|
private onHide_ = function () {
|
||||||
Blockly.DropDownDiv.content_.removeAttribute('role');
|
const content = Blockly.DropDownDiv.getContentDiv();
|
||||||
Blockly.DropDownDiv.content_.removeAttribute('aria-haspopup');
|
content.removeAttribute('role');
|
||||||
Blockly.DropDownDiv.content_.removeAttribute('aria-activedescendant');
|
content.removeAttribute('aria-haspopup');
|
||||||
Blockly.DropDownDiv.getContentDiv().style.width = '';
|
content.removeAttribute('aria-activedescendant');
|
||||||
|
(content as HTMLElement).style.width = '';
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -44,7 +44,7 @@ export class FieldColorEnum extends pxtblockly.FieldColorNumber implements Block
|
|||||||
* @return {string} Current colour in '#rrggbb' format.
|
* @return {string} Current colour in '#rrggbb' format.
|
||||||
*/
|
*/
|
||||||
getValue(opt_asHex?: boolean) {
|
getValue(opt_asHex?: boolean) {
|
||||||
var colour = this.mapColour(this.colour_);
|
const colour = this.mapColour(this.value_);
|
||||||
if (!opt_asHex && colour.indexOf('#') > -1) {
|
if (!opt_asHex && colour.indexOf('#') > -1) {
|
||||||
return `0x${colour.replace(/^#/, '')}`;
|
return `0x${colour.replace(/^#/, '')}`;
|
||||||
}
|
}
|
||||||
@ -56,13 +56,13 @@ export class FieldColorEnum extends pxtblockly.FieldColorNumber implements Block
|
|||||||
* @param {string} colour The new colour in '#rrggbb' format.
|
* @param {string} colour The new colour in '#rrggbb' format.
|
||||||
*/
|
*/
|
||||||
setValue(colorStr: string) {
|
setValue(colorStr: string) {
|
||||||
var colour = this.mapEnum(colorStr);
|
let colour = this.mapEnum(colorStr);
|
||||||
if (this.sourceBlock_ && Blockly.Events.isEnabled() &&
|
if (this.sourceBlock_ && Blockly.Events.isEnabled() &&
|
||||||
this.colour_ != colour) {
|
this.value_ != colour) {
|
||||||
Blockly.Events.fire(new (Blockly as any).Events.BlockChange(
|
Blockly.Events.fire(new (Blockly as any).Events.BlockChange(
|
||||||
this.sourceBlock_, 'field', this.name, this.colour_, colour));
|
this.sourceBlock_, 'field', this.name, this.value_, colour));
|
||||||
}
|
}
|
||||||
this.colour_ = colour;
|
this.value_ = colour;
|
||||||
if (this.sourceBlock_) {
|
if (this.sourceBlock_) {
|
||||||
this.sourceBlock_.setColour(colour, colour, colour);
|
this.sourceBlock_.setColour(colour, colour, colour);
|
||||||
}
|
}
|
||||||
|
@ -46,31 +46,31 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
(this as any).arrowX_ = 0;
|
(this as any).arrowX_ = 0;
|
||||||
/** @type {Number} */
|
/** @type {Number} */
|
||||||
this.arrowY_ = 11;
|
this.arrowY_ = 11;
|
||||||
this.arrow_ = Blockly.utils.createSvgElement('image', {
|
this.arrow_ = Blockly.utils.dom.createSvgElement('image', {
|
||||||
'height': (this as any).arrowSize_ + 'px',
|
'height': (this as any).arrowSize_ + 'px',
|
||||||
'width': (this as any).arrowSize_ + 'px'
|
'width': (this as any).arrowSize_ + 'px'
|
||||||
});
|
}, null);
|
||||||
this.arrow_.setAttributeNS('http://www.w3.org/1999/xlink',
|
this.arrow_.setAttributeNS('http://www.w3.org/1999/xlink',
|
||||||
'xlink:href', (Blockly.FieldDropdown as any).DROPDOWN_SVG_DATAURI);
|
'xlink:href', (Blockly.FieldDropdown as any).DROPDOWN_SVG_DATAURI);
|
||||||
|
|
||||||
this.arrow2_ = Blockly.utils.createSvgElement('image', {
|
this.arrow2_ = <SVGImageElement>Blockly.utils.dom.createSvgElement('image', {
|
||||||
'height': (this as any).arrowSize_ + 'px',
|
'height': (this as any).arrowSize_ + 'px',
|
||||||
'width': (this as any).arrowSize_ + 'px'
|
'width': (this as any).arrowSize_ + 'px'
|
||||||
});
|
}, null);
|
||||||
this.arrow2_.setAttributeNS('http://www.w3.org/1999/xlink',
|
this.arrow2_.setAttributeNS('http://www.w3.org/1999/xlink',
|
||||||
'xlink:href', (Blockly.FieldDropdown as any).DROPDOWN_SVG_DATAURI);
|
'xlink:href', (Blockly.FieldDropdown as any).DROPDOWN_SVG_DATAURI);
|
||||||
(this as any).className_ += ' blocklyDropdownText';
|
(this as any).className_ += ' blocklyDropdownText';
|
||||||
|
|
||||||
// Build the DOM.
|
// Build the DOM.
|
||||||
this.fieldGroup_ = Blockly.utils.createSvgElement('g', {}, null);
|
this.fieldGroup_ = Blockly.utils.dom.createSvgElement('g', {}, null);
|
||||||
if (!this.visible_) {
|
if (!this.visible_) {
|
||||||
(this.fieldGroup_ as any).style.display = 'none';
|
(this.fieldGroup_ as any).style.display = 'none';
|
||||||
}
|
}
|
||||||
// Adjust X to be flipped for RTL. Position is relative to horizontal start of source block.
|
// Adjust X to be flipped for RTL. Position is relative to horizontal start of source block.
|
||||||
var size = this.getSize();
|
let size = this.getSize();
|
||||||
var fieldX = (this.sourceBlock_.RTL) ? -size.width / 2 : size.width / 2;
|
let fieldX = (this.sourceBlock_.RTL) ? -size.width / 2 : size.width / 2;
|
||||||
/** @type {!Element} */
|
/** @type {!Element} */
|
||||||
this.textElement_ = Blockly.utils.createSvgElement('text',
|
this.textElement_ = Blockly.utils.dom.createSvgElement('text',
|
||||||
{
|
{
|
||||||
'class': (this as any).className_,
|
'class': (this as any).className_,
|
||||||
'x': fieldX,
|
'x': fieldX,
|
||||||
@ -79,7 +79,7 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
},
|
},
|
||||||
this.fieldGroup_);
|
this.fieldGroup_);
|
||||||
fieldX += 10; // size of first group.
|
fieldX += 10; // size of first group.
|
||||||
this.textElement2_ = Blockly.utils.createSvgElement('text',
|
this.textElement2_ = <SVGTextElement>Blockly.utils.dom.createSvgElement('text',
|
||||||
{
|
{
|
||||||
'class': (this as any).className_,
|
'class': (this as any).className_,
|
||||||
'x': fieldX,
|
'x': fieldX,
|
||||||
@ -89,17 +89,17 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
this.fieldGroup_);
|
this.fieldGroup_);
|
||||||
|
|
||||||
this.updateEditable();
|
this.updateEditable();
|
||||||
this.sourceBlock_.getSvgRoot().appendChild(this.fieldGroup_);
|
(this.sourceBlock_ as Blockly.BlockSvg).getSvgRoot().appendChild(this.fieldGroup_);
|
||||||
// Force a render.
|
// Force a render.
|
||||||
this.render_();
|
this.render_();
|
||||||
this.size_.width = 0;
|
this.isDirty_ = true;
|
||||||
(this as any).mouseDownWrapper_ =
|
(this as any).mouseDownWrapper_ =
|
||||||
Blockly.bindEventWithChecks_((this as any).getClickTarget_(), 'mousedown', this,
|
Blockly.bindEventWithChecks_((this as any).getClickTarget_(), 'mousedown', this,
|
||||||
(this as any).onMouseDown_);
|
(this as any).onMouseDown_);
|
||||||
|
|
||||||
// Add second dropdown
|
// Add second dropdown
|
||||||
if (this.shouldShowRect_()) {
|
if (this.shouldShowRect_()) {
|
||||||
this.box_ = Blockly.utils.createSvgElement('rect', {
|
this.box_ = <SVGRectElement>Blockly.utils.dom.createSvgElement('rect', {
|
||||||
'rx': (Blockly.BlockSvg as any).CORNER_RADIUS,
|
'rx': (Blockly.BlockSvg as any).CORNER_RADIUS,
|
||||||
'ry': (Blockly.BlockSvg as any).CORNER_RADIUS,
|
'ry': (Blockly.BlockSvg as any).CORNER_RADIUS,
|
||||||
'x': 0,
|
'x': 0,
|
||||||
@ -112,7 +112,7 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
'fill-opacity': 1
|
'fill-opacity': 1
|
||||||
}, null);
|
}, null);
|
||||||
this.fieldGroup_.insertBefore(this.box_, this.textElement_);
|
this.fieldGroup_.insertBefore(this.box_, this.textElement_);
|
||||||
this.box2_ = Blockly.utils.createSvgElement('rect', {
|
this.box2_ = <SVGRectElement>Blockly.utils.dom.createSvgElement('rect', {
|
||||||
'rx': (Blockly.BlockSvg as any).CORNER_RADIUS,
|
'rx': (Blockly.BlockSvg as any).CORNER_RADIUS,
|
||||||
'ry': (Blockly.BlockSvg as any).CORNER_RADIUS,
|
'ry': (Blockly.BlockSvg as any).CORNER_RADIUS,
|
||||||
'x': 0,
|
'x': 0,
|
||||||
@ -128,7 +128,7 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Force a reset of the text to add the arrow.
|
// Force a reset of the text to add the arrow.
|
||||||
var text = this.text_;
|
let text = this.text_;
|
||||||
this.text_ = null;
|
this.text_ = null;
|
||||||
this.setText(text);
|
this.setText(text);
|
||||||
}
|
}
|
||||||
@ -149,9 +149,9 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
getFirstValueI11n(value: string) {
|
getFirstValueI11n(value: string) {
|
||||||
const firstValue = this.getFirstValue(value);
|
const firstValue = this.getFirstValue(value);
|
||||||
const motorOptions = {
|
const motorOptions = {
|
||||||
'medium motor': lf('medium motor'),
|
'medium motor': lf("medium motor"),
|
||||||
'large motor': lf('large motor'),
|
'large motor': lf("large motor"),
|
||||||
'large motors': lf('large motors')
|
'large motors': lf("large motors")
|
||||||
}
|
}
|
||||||
return motorOptions[firstValue];
|
return motorOptions[firstValue];
|
||||||
}
|
}
|
||||||
@ -179,7 +179,7 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
// Not rendered yet.
|
// Not rendered yet.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var text = this.text_;
|
let text = this.text_;
|
||||||
if (text.length > this.maxDisplayLength) {
|
if (text.length > this.maxDisplayLength) {
|
||||||
// Truncate displayed string and add an ellipsis ('...').
|
// Truncate displayed string and add an ellipsis ('...').
|
||||||
text = text.substring(0, this.maxDisplayLength - 2) + '\u2026';
|
text = text.substring(0, this.maxDisplayLength - 2) + '\u2026';
|
||||||
@ -200,11 +200,11 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
// Prevent the field from disappearing if empty.
|
// Prevent the field from disappearing if empty.
|
||||||
text = Blockly.Field.NBSP;
|
text = Blockly.Field.NBSP;
|
||||||
}
|
}
|
||||||
var textNode = document.createTextNode(text);
|
let textNode = document.createTextNode(text);
|
||||||
this.textElement2_.appendChild(textNode);
|
this.textElement2_.appendChild(textNode);
|
||||||
|
|
||||||
// Cached width is obsolete. Clear it.
|
// Cached width is obsolete. Clear it.
|
||||||
this.size_.width = 0;
|
this.isDirty_ = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
patchDualMotorText(text: string) {
|
patchDualMotorText(text: string) {
|
||||||
@ -233,8 +233,8 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
if (this.textElement2_) {
|
if (this.textElement2_) {
|
||||||
this.textElement2_.parentNode.appendChild(this.arrow2_);
|
this.textElement2_.parentNode.appendChild(this.arrow2_);
|
||||||
}
|
}
|
||||||
if (this.sourceBlock_ && this.sourceBlock_.rendered) {
|
if (this.sourceBlock_ && (<Blockly.BlockSvg>this.sourceBlock_).rendered) {
|
||||||
this.sourceBlock_.render();
|
(<Blockly.BlockSvg>this.sourceBlock_).render();
|
||||||
this.sourceBlock_.bumpNeighbours_();
|
this.sourceBlock_.bumpNeighbours_();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,7 +244,7 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var addedWidth = 0;
|
let addedWidth = 0;
|
||||||
if (this.sourceBlock_.RTL) {
|
if (this.sourceBlock_.RTL) {
|
||||||
(this as any).arrow2X_ = (this as any).arrowSize_ - (Blockly.BlockSvg as any).DROPDOWN_ARROW_PADDING;
|
(this as any).arrow2X_ = (this as any).arrowSize_ - (Blockly.BlockSvg as any).DROPDOWN_ARROW_PADDING;
|
||||||
addedWidth = (this as any).arrowSize_ + (Blockly.BlockSvg as any).DROPDOWN_ARROW_PADDING;
|
addedWidth = (this as any).arrowSize_ + (Blockly.BlockSvg as any).DROPDOWN_ARROW_PADDING;
|
||||||
@ -263,10 +263,10 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
return addedWidth;
|
return addedWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
updateWidth() {
|
updateSize_() {
|
||||||
// Calculate width of field
|
// Calculate width of field
|
||||||
var width = Blockly.Field.getCachedWidth(this.textElement_);
|
let width = Blockly.Field.getCachedWidth(this.textElement_);
|
||||||
var width2 = Blockly.Field.getCachedWidth(this.textElement2_);
|
let width2 = Blockly.Field.getCachedWidth(this.textElement2_);
|
||||||
|
|
||||||
// Add padding to left and right of text.
|
// Add padding to left and right of text.
|
||||||
if (this.EDITABLE) {
|
if (this.EDITABLE) {
|
||||||
@ -311,15 +311,15 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
|
|
||||||
// First dropdown
|
// First dropdown
|
||||||
// Use one of the following options, medium motor, large motor or large motors (translated)
|
// Use one of the following options, medium motor, large motor or large motors (translated)
|
||||||
const textNode1 = document.createTextNode(this.getFirstValueI11n(this.value_));
|
const textNode1 = document.createTextNode(this.getFirstValueI11n(<string>this.value_));
|
||||||
this.textElement_.appendChild(textNode1);
|
this.textElement_.appendChild(textNode1);
|
||||||
|
|
||||||
// Second dropdown, no need to translate. Only port numbers
|
// Second dropdown, no need to translate. Only port numbers
|
||||||
if (this.textElement2_) {
|
if (this.textElement2_) {
|
||||||
const textNode2 = document.createTextNode(this.getSecondValue(this.value_));
|
const textNode2 = document.createTextNode(this.getSecondValue(<string>this.value_));
|
||||||
this.textElement2_.appendChild(textNode2);
|
this.textElement2_.appendChild(textNode2);
|
||||||
}
|
}
|
||||||
this.updateWidth();
|
this.updateSize_();
|
||||||
|
|
||||||
// Update text centering, based on newly calculated width.
|
// Update text centering, based on newly calculated width.
|
||||||
let centerTextX = ((this as any).width1 - this.arrowWidth_) / 2;
|
let centerTextX = ((this as any).width1 - this.arrowWidth_) / 2;
|
||||||
@ -347,8 +347,8 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply new text element x position.
|
// Apply new text element x position.
|
||||||
var width = Blockly.Field.getCachedWidth(this.textElement_);
|
let width = Blockly.Field.getCachedWidth(this.textElement_);
|
||||||
var newX = centerTextX - width / 2;
|
let newX = centerTextX - width / 2;
|
||||||
this.textElement_.setAttribute('x', `${newX}`);
|
this.textElement_.setAttribute('x', `${newX}`);
|
||||||
|
|
||||||
// Update text centering, based on newly calculated width.
|
// Update text centering, based on newly calculated width.
|
||||||
@ -377,8 +377,8 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply new text element x position.
|
// Apply new text element x position.
|
||||||
var width2 = Blockly.Field.getCachedWidth(this.textElement2_);
|
let width2 = Blockly.Field.getCachedWidth(this.textElement2_);
|
||||||
var newX2 = centerTextX2 - width2 / 2;
|
let newX2 = centerTextX2 - width2 / 2;
|
||||||
this.textElement2_.setAttribute('x', `${newX2 + (this as any).width1 + Blockly.BlockSvg.BOX_FIELD_PADDING}`);
|
this.textElement2_.setAttribute('x', `${newX2 + (this as any).width1 + Blockly.BlockSvg.BOX_FIELD_PADDING}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,7 +401,7 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
if (Blockly.DropDownDiv.hideIfOwner(this)) {
|
if (Blockly.DropDownDiv.hideIfOwner(this)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.isFirst_ = e.clientX - this.getScaledBBox_().left < ((this as any).width1 * this.sourceBlock_.workspace.scale);
|
this.isFirst_ = e.clientX - this.getScaledBBox_().left < ((this as any).width1 * (<Blockly.WorkspaceSvg>this.sourceBlock_.workspace).scale);
|
||||||
// If there is an existing drop-down someone else owns, hide it immediately and clear it.
|
// If there is an existing drop-down someone else owns, hide it immediately and clear it.
|
||||||
Blockly.DropDownDiv.hideWithoutAnimation();
|
Blockly.DropDownDiv.hideWithoutAnimation();
|
||||||
Blockly.DropDownDiv.clearContent();
|
Blockly.DropDownDiv.clearContent();
|
||||||
@ -411,14 +411,14 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
// Accessibility properties
|
// Accessibility properties
|
||||||
contentDiv.setAttribute('role', 'menu');
|
contentDiv.setAttribute('role', 'menu');
|
||||||
contentDiv.setAttribute('aria-haspopup', 'true');
|
contentDiv.setAttribute('aria-haspopup', 'true');
|
||||||
let options = this.getOptions();
|
const foptions = this.getOptions(); // [img info, text]
|
||||||
|
|
||||||
let opts = {};
|
let opts = {};
|
||||||
let conts = {};
|
let conts = {};
|
||||||
let vals = {};
|
let vals = {};
|
||||||
// Go through all option values and split them into groups
|
// Go through all option values and split them into groups
|
||||||
for (let opt = 0; opt < options.length; opt++) {
|
for (let opt = 0; opt < foptions.length; opt++) {
|
||||||
const value = options[opt][1];
|
const value = foptions[opt][1];
|
||||||
const motorValue = value.substring(value.indexOf('.') + 1);
|
const motorValue = value.substring(value.indexOf('.') + 1);
|
||||||
const typeValue = motorValue.indexOf('large') == 0 ? 'large' : 'medium';
|
const typeValue = motorValue.indexOf('large') == 0 ? 'large' : 'medium';
|
||||||
const portValue = motorValue.indexOf('large') == 0 ? motorValue.substring(5) : motorValue.substring(6);
|
const portValue = motorValue.indexOf('large') == 0 ? motorValue.substring(5) : motorValue.substring(6);
|
||||||
@ -429,13 +429,14 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
if (!opts[key]) opts[key] = [];
|
if (!opts[key]) opts[key] = [];
|
||||||
opts[key].push(portValue);
|
opts[key].push(portValue);
|
||||||
|
|
||||||
conts[text] = options[opt][0];
|
conts[text] = foptions[opt][0];
|
||||||
vals[text] = value;
|
vals[text] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentFirst = this.getFirstValue(this.value_);
|
const currentFirst = this.getFirstValue(<string>this.value_);
|
||||||
const currentSecond = this.getSecondValue(this.value_);
|
//const currentSecond = this.getSecondValue(<string>this.value_);
|
||||||
|
|
||||||
|
let options: string[];
|
||||||
if (!this.isFirst_) {
|
if (!this.isFirst_) {
|
||||||
options = opts[currentFirst];
|
options = opts[currentFirst];
|
||||||
} else {
|
} else {
|
||||||
@ -526,7 +527,7 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
Blockly.DropDownDiv.setColour(this.backgroundColour_, this.borderColour_);
|
Blockly.DropDownDiv.setColour(this.backgroundColour_, this.borderColour_);
|
||||||
|
|
||||||
// Calculate positioning based on the field position.
|
// Calculate positioning based on the field position.
|
||||||
let scale = this.sourceBlock_.workspace.scale;
|
let scale = (<Blockly.WorkspaceSvg>this.sourceBlock_.workspace).scale;
|
||||||
let width = this.isFirst_ ? (this as any).width1 : (this as any).width2;
|
let width = this.isFirst_ ? (this as any).width1 : (this as any).width2;
|
||||||
let bBox = { width: this.size_.width, height: this.size_.height };
|
let bBox = { width: this.size_.width, height: this.size_.height };
|
||||||
width *= scale;
|
width *= scale;
|
||||||
@ -538,7 +539,7 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
let secondaryX = primaryX;
|
let secondaryX = primaryX;
|
||||||
let secondaryY = position.top;
|
let secondaryY = position.top;
|
||||||
// Set bounds to workspace; show the drop-down.
|
// Set bounds to workspace; show the drop-down.
|
||||||
(Blockly.DropDownDiv as any).setBoundsElement(this.sourceBlock_.workspace.getParentSvg().parentNode);
|
(Blockly.DropDownDiv as any).setBoundsElement((<Blockly.WorkspaceSvg>this.sourceBlock_.workspace).getParentSvg().parentNode);
|
||||||
(Blockly.DropDownDiv as any).show(this, primaryX, primaryY, secondaryX, secondaryY,
|
(Blockly.DropDownDiv as any).show(this, primaryX, primaryY, secondaryX, secondaryY,
|
||||||
this.onHide_.bind(this));
|
this.onHide_.bind(this));
|
||||||
|
|
||||||
@ -561,10 +562,11 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
|||||||
* Callback for when the drop-down is hidden.
|
* Callback for when the drop-down is hidden.
|
||||||
*/
|
*/
|
||||||
protected onHide_() {
|
protected onHide_() {
|
||||||
Blockly.DropDownDiv.content_.removeAttribute('role');
|
const content = Blockly.DropDownDiv.getContentDiv();
|
||||||
Blockly.DropDownDiv.content_.removeAttribute('aria-haspopup');
|
content.removeAttribute('role');
|
||||||
Blockly.DropDownDiv.content_.removeAttribute('aria-activedescendant');
|
content.removeAttribute('aria-haspopup');
|
||||||
Blockly.DropDownDiv.getContentDiv().style.width = '';
|
content.removeAttribute('aria-activedescendant');
|
||||||
|
(content as HTMLElement).style.width = '';
|
||||||
if (this.isFirst_ && this.box_) {
|
if (this.isFirst_ && this.box_) {
|
||||||
this.box_.setAttribute('fill', this.sourceBlock_.getColour());
|
this.box_.setAttribute('fill', this.sourceBlock_.getColour());
|
||||||
} else if (!this.isFirst_ && this.box2_) {
|
} else if (!this.isFirst_ && this.box2_) {
|
||||||
|
@ -26,7 +26,7 @@ export class FieldMusic extends pxtblockly.FieldImages implements Blockly.FieldC
|
|||||||
this.width_ = parseInt(options.width) || 380;
|
this.width_ = parseInt(options.width) || 380;
|
||||||
|
|
||||||
this.setText = Blockly.FieldDropdown.prototype.setText;
|
this.setText = Blockly.FieldDropdown.prototype.setText;
|
||||||
this.updateWidth = (Blockly.Field as any).prototype.updateWidth;
|
this.updateSize_ = (Blockly.Field as any).prototype.updateSize_;
|
||||||
this.updateTextNode_ = Blockly.Field.prototype.updateTextNode_;
|
this.updateTextNode_ = Blockly.Field.prototype.updateTextNode_;
|
||||||
|
|
||||||
if (!pxt.BrowserUtils.isIE() && !soundCache) {
|
if (!pxt.BrowserUtils.isIE() && !soundCache) {
|
||||||
@ -78,14 +78,14 @@ export class FieldMusic extends pxtblockly.FieldImages implements Blockly.FieldC
|
|||||||
contentDiv.style.width = (this as any).width_ + 'px';
|
contentDiv.style.width = (this as any).width_ + 'px';
|
||||||
contentDiv.style.cssFloat = 'left';
|
contentDiv.style.cssFloat = 'left';
|
||||||
|
|
||||||
dropdownDiv.style.maxHeight = `410px`;
|
(dropdownDiv as HTMLElement).style.maxHeight = `410px`;
|
||||||
dropdownDiv.appendChild(categoriesDiv);
|
dropdownDiv.appendChild(categoriesDiv);
|
||||||
dropdownDiv.appendChild(contentDiv);
|
dropdownDiv.appendChild(contentDiv);
|
||||||
|
|
||||||
Blockly.DropDownDiv.setColour(this.sourceBlock_.getColour(), this.sourceBlock_.getColourTertiary());
|
Blockly.DropDownDiv.setColour(this.sourceBlock_.getColour(), this.sourceBlock_.getColourTertiary());
|
||||||
|
|
||||||
// Calculate positioning based on the field position.
|
// Calculate positioning based on the field position.
|
||||||
let scale = this.sourceBlock_.workspace.scale;
|
let scale = (<Blockly.WorkspaceSvg>this.sourceBlock_.workspace).scale;
|
||||||
let bBox = { width: this.size_.width, height: this.size_.height };
|
let bBox = { width: this.size_.width, height: this.size_.height };
|
||||||
bBox.width *= scale;
|
bBox.width *= scale;
|
||||||
bBox.height *= scale;
|
bBox.height *= scale;
|
||||||
@ -95,7 +95,7 @@ export class FieldMusic extends pxtblockly.FieldImages implements Blockly.FieldC
|
|||||||
let secondaryX = primaryX;
|
let secondaryX = primaryX;
|
||||||
let secondaryY = position.top;
|
let secondaryY = position.top;
|
||||||
// Set bounds to workspace; show the drop-down.
|
// Set bounds to workspace; show the drop-down.
|
||||||
(Blockly.DropDownDiv as any).setBoundsElement(this.sourceBlock_.workspace.getParentSvg().parentNode);
|
(Blockly.DropDownDiv as any).setBoundsElement((<Blockly.WorkspaceSvg>this.sourceBlock_.workspace).getParentSvg().parentNode);
|
||||||
(Blockly.DropDownDiv as any).show(this, primaryX, primaryY, secondaryX, secondaryY,
|
(Blockly.DropDownDiv as any).show(this, primaryX, primaryY, secondaryX, secondaryY,
|
||||||
this.onHide_.bind(this));
|
this.onHide_.bind(this));
|
||||||
|
|
||||||
@ -236,7 +236,7 @@ export class FieldMusic extends pxtblockly.FieldImages implements Blockly.FieldC
|
|||||||
|
|
||||||
protected onHide_() {
|
protected onHide_() {
|
||||||
super.onHide_();
|
super.onHide_();
|
||||||
Blockly.DropDownDiv.getContentDiv().style.maxHeight = '';
|
(Blockly.DropDownDiv.getContentDiv() as HTMLElement).style.maxHeight = '';
|
||||||
this.stopSounds();
|
this.stopSounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ export class FieldPorts extends pxtblockly.FieldImages implements Blockly.FieldC
|
|||||||
this.width_ = parseInt(options.width) || 300;
|
this.width_ = parseInt(options.width) || 300;
|
||||||
|
|
||||||
this.setText = Blockly.FieldDropdown.prototype.setText;
|
this.setText = Blockly.FieldDropdown.prototype.setText;
|
||||||
this.updateWidth = (Blockly.Field as any).prototype.updateWidth;
|
this.updateSize_ = (Blockly.Field as any).prototype.updateSize_;
|
||||||
this.updateTextNode_ = Blockly.Field.prototype.updateTextNode_;
|
this.updateTextNode_ = Blockly.Field.prototype.updateTextNode_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,97 +0,0 @@
|
|||||||
/// <reference path="../node_modules/pxt-core/localtypings/blockly.d.ts"/>
|
|
||||||
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
|
||||||
|
|
||||||
export interface FieldSpeedOptions extends Blockly.FieldCustomOptions {
|
|
||||||
min?: string;
|
|
||||||
max?: string;
|
|
||||||
label?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class FieldSpeed extends Blockly.FieldSlider implements Blockly.FieldCustom {
|
|
||||||
public isFieldCustom_ = true;
|
|
||||||
|
|
||||||
private params: any;
|
|
||||||
|
|
||||||
private speedSVG: SVGElement;
|
|
||||||
private circleBar: SVGCircleElement;
|
|
||||||
private reporter: SVGTextElement;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class for a color wheel field.
|
|
||||||
* @param {number|string} value The initial content of the field.
|
|
||||||
* @param {Function=} opt_validator An optional function that is called
|
|
||||||
* to validate any constraints on what the user entered. Takes the new
|
|
||||||
* text as an argument and returns either the accepted text, a replacement
|
|
||||||
* text, or null to abort the change.
|
|
||||||
* @extends {Blockly.FieldNumber}
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
constructor(value_: any, params: FieldSpeedOptions, opt_validator?: Function) {
|
|
||||||
super(String(value_), '-100', '100', null, '10', 'Speed', opt_validator);
|
|
||||||
this.params = params;
|
|
||||||
if (this.params['min']) this.min_ = parseFloat(this.params.min);
|
|
||||||
if (this.params['max']) this.max_ = parseFloat(this.params.max);
|
|
||||||
if (this.params['label']) this.labelText_ = this.params.label;
|
|
||||||
|
|
||||||
(this as any).sliderColor_ = '#a8aaa8';
|
|
||||||
}
|
|
||||||
|
|
||||||
createLabelDom_(labelText: string) {
|
|
||||||
var labelContainer = document.createElement('div');
|
|
||||||
this.speedSVG = document.createElementNS("http://www.w3.org/2000/svg", "svg") as SVGGElement;
|
|
||||||
pxsim.svg.hydrate(this.speedSVG, {
|
|
||||||
viewBox: "0 0 200 100",
|
|
||||||
width: "170"
|
|
||||||
});
|
|
||||||
|
|
||||||
labelContainer.appendChild(this.speedSVG);
|
|
||||||
|
|
||||||
const outerCircle = pxsim.svg.child(this.speedSVG, "circle", {
|
|
||||||
'stroke-dasharray': '565.48', 'stroke-dashoffset': '0',
|
|
||||||
'cx': 100, 'cy': 100, 'r': '90', 'style': `fill:transparent; transition: stroke-dashoffset 0.1s linear;`,
|
|
||||||
'stroke': '#a8aaa8', 'stroke-width': '1rem'
|
|
||||||
}) as SVGCircleElement;
|
|
||||||
this.circleBar = pxsim.svg.child(this.speedSVG, "circle", {
|
|
||||||
'stroke-dasharray': '565.48', 'stroke-dashoffset': '0',
|
|
||||||
'cx': 100, 'cy': 100, 'r': '90', 'style': `fill:transparent; transition: stroke-dashoffset 0.1s linear;`,
|
|
||||||
'stroke': '#f12a21', 'stroke-width': '1rem'
|
|
||||||
}) as SVGCircleElement;
|
|
||||||
|
|
||||||
this.reporter = pxsim.svg.child(this.speedSVG, "text", {
|
|
||||||
'x': 100, 'y': 80,
|
|
||||||
'text-anchor': 'middle', 'dominant-baseline': 'middle',
|
|
||||||
'style': 'font-size: 50px',
|
|
||||||
'class': 'sim-text inverted number'
|
|
||||||
}) as SVGTextElement;
|
|
||||||
|
|
||||||
// labelContainer.setAttribute('class', 'blocklyFieldSliderLabel');
|
|
||||||
var readout = document.createElement('span');
|
|
||||||
readout.setAttribute('class', 'blocklyFieldSliderReadout');
|
|
||||||
// var label = document.createElement('span');
|
|
||||||
// label.setAttribute('class', 'blocklyFieldSliderLabelText');
|
|
||||||
// label.innerHTML = labelText;
|
|
||||||
// labelContainer.appendChild(label);
|
|
||||||
// labelContainer.appendChild(readout);
|
|
||||||
return [labelContainer, readout];
|
|
||||||
};
|
|
||||||
|
|
||||||
setReadout_(readout: Element, value: string) {
|
|
||||||
this.updateSpeed(parseFloat(value));
|
|
||||||
// Update reporter
|
|
||||||
this.reporter.textContent = `${value}%`;
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateSpeed(speed: number) {
|
|
||||||
let sign = this.sign(speed);
|
|
||||||
speed = (Math.abs(speed) / 100 * 50) + 50;
|
|
||||||
if (sign == -1) speed = 50 - speed;
|
|
||||||
let c = Math.PI * (90 * 2);
|
|
||||||
let pct = ((100 - speed) / 100) * c;
|
|
||||||
this.circleBar.setAttribute('stroke-dashoffset', `${pct}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// A re-implementation of Math.sign (since IE11 doesn't support it)
|
|
||||||
private sign(num: number) {
|
|
||||||
return num ? num < 0 ? -1 : 1 : 0;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,108 +0,0 @@
|
|||||||
/// <reference path="../node_modules/pxt-core/localtypings/blockly.d.ts"/>
|
|
||||||
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
|
||||||
|
|
||||||
export interface FieldTurnRatioOptions extends Blockly.FieldCustomOptions {
|
|
||||||
}
|
|
||||||
|
|
||||||
export class FieldTurnRatio extends Blockly.FieldSlider implements Blockly.FieldCustom {
|
|
||||||
public isFieldCustom_ = true;
|
|
||||||
|
|
||||||
private params: any;
|
|
||||||
|
|
||||||
private path_: SVGPathElement;
|
|
||||||
private reporter_: SVGTextElement;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class for a color wheel field.
|
|
||||||
* @param {number|string} value The initial content of the field.
|
|
||||||
* @param {Function=} opt_validator An optional function that is called
|
|
||||||
* to validate any constraints on what the user entered. Takes the new
|
|
||||||
* text as an argument and returns either the accepted text, a replacement
|
|
||||||
* text, or null to abort the change.
|
|
||||||
* @extends {Blockly.FieldNumber}
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
constructor(value_: any, params: FieldTurnRatioOptions, opt_validator?: Function) {
|
|
||||||
super(String(value_), '-100', '100', null, '10', 'TurnRatio', opt_validator);
|
|
||||||
this.params = params;
|
|
||||||
(this as any).sliderColor_ = '#a8aaa8';
|
|
||||||
}
|
|
||||||
|
|
||||||
static HALF = 80;
|
|
||||||
static HANDLE_RADIUS = 30;
|
|
||||||
static RADIUS = FieldTurnRatio.HALF - FieldTurnRatio.HANDLE_RADIUS - 1;
|
|
||||||
|
|
||||||
createLabelDom_(labelText: string) {
|
|
||||||
let labelContainer = document.createElement('div');
|
|
||||||
let svg = Blockly.utils.createSvgElement('svg', {
|
|
||||||
'xmlns': 'http://www.w3.org/2000/svg',
|
|
||||||
'xmlns:html': 'http://www.w3.org/1999/xhtml',
|
|
||||||
'xmlns:xlink': 'http://www.w3.org/1999/xlink',
|
|
||||||
'version': '1.1',
|
|
||||||
'height': (FieldTurnRatio.HALF + FieldTurnRatio.HANDLE_RADIUS + 10) + 'px',
|
|
||||||
'width': (FieldTurnRatio.HALF * 2) + 'px'
|
|
||||||
}, labelContainer);
|
|
||||||
let defs = Blockly.utils.createSvgElement('defs', {}, svg);
|
|
||||||
let marker = Blockly.utils.createSvgElement('marker', {
|
|
||||||
'id': 'head',
|
|
||||||
'orient': "auto",
|
|
||||||
'markerWidth': '2',
|
|
||||||
'markerHeight': '4',
|
|
||||||
'refX': '0.1', 'refY': '1.5'
|
|
||||||
}, defs);
|
|
||||||
let markerPath = Blockly.utils.createSvgElement('path', {
|
|
||||||
'd': 'M0,0 V3 L1.5,1.5 Z',
|
|
||||||
'fill': '#f12a21'
|
|
||||||
}, marker);
|
|
||||||
this.reporter_ = pxsim.svg.child(svg, "text", {
|
|
||||||
'x': FieldTurnRatio.HALF, 'y': 96,
|
|
||||||
'text-anchor': 'middle', 'dominant-baseline': 'middle',
|
|
||||||
'style': 'font-size: 50px',
|
|
||||||
'class': 'sim-text inverted number'
|
|
||||||
}) as SVGTextElement;
|
|
||||||
this.path_ = Blockly.utils.createSvgElement('path', {
|
|
||||||
'x1': FieldTurnRatio.HALF,
|
|
||||||
'y1': FieldTurnRatio.HALF,
|
|
||||||
'marker-end': 'url(#head)',
|
|
||||||
'style': 'fill: none; stroke: #f12a21; stroke-width: 10'
|
|
||||||
}, svg);
|
|
||||||
this.updateGraph_();
|
|
||||||
let readout = document.createElement('span');
|
|
||||||
readout.setAttribute('class', 'blocklyFieldSliderReadout');
|
|
||||||
return [labelContainer, readout];
|
|
||||||
};
|
|
||||||
|
|
||||||
updateGraph_() {
|
|
||||||
if (!this.path_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let v = goog.math.clamp(parseFloat(this.getText()), -100, 100);
|
|
||||||
if (isNaN(v)) {
|
|
||||||
v = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const x = goog.math.clamp(parseFloat(this.getText()), -100, 100) / 100;
|
|
||||||
const theta = x * Math.PI / 2;
|
|
||||||
const cx = FieldTurnRatio.HALF;
|
|
||||||
const cy = FieldTurnRatio.HALF - 14;
|
|
||||||
const gamma = Math.PI - 2 * theta;
|
|
||||||
const r = FieldTurnRatio.RADIUS;
|
|
||||||
const alpha = 0.2 + Math.abs(x) * 0.5;
|
|
||||||
const x1 = 0;
|
|
||||||
const y1 = r * alpha;
|
|
||||||
const y2 = r * Math.sin(Math.PI / 2 - theta);
|
|
||||||
const x2 = r * Math.cos(Math.PI / 2 - theta);
|
|
||||||
const y3 = y2 - r * alpha * Math.cos(2 * theta);
|
|
||||||
const x3 = x2 - r * alpha * Math.sin(2 * theta);
|
|
||||||
|
|
||||||
|
|
||||||
const d = `M ${cx} ${cy} C ${cx} ${cy - y1} ${cx + x3} ${cy - y3} ${cx + x2} ${cy - y2}`;
|
|
||||||
this.path_.setAttribute('d', d);
|
|
||||||
|
|
||||||
this.reporter_.textContent = `${v}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
setReadout_(readout: Element, value: string) {
|
|
||||||
this.updateGraph_();
|
|
||||||
}
|
|
||||||
}
|
|
9
libs/base/enums.d.ts
vendored
@ -22,13 +22,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
declare const enum ValType {
|
declare const enum PerfCounters {
|
||||||
Undefined = 0,
|
GC = 0,
|
||||||
Boolean = 1,
|
|
||||||
Number = 2,
|
|
||||||
String = 3,
|
|
||||||
Object = 4,
|
|
||||||
Function = 5,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-generated. Do not edit. Really.
|
// Auto-generated. Do not edit. Really.
|
||||||
|
76
libs/base/shims.d.ts
vendored
@ -4,6 +4,18 @@
|
|||||||
|
|
||||||
//% indexerGet=BufferMethods::getByte indexerSet=BufferMethods::setByte
|
//% indexerGet=BufferMethods::getByte indexerSet=BufferMethods::setByte
|
||||||
declare interface Buffer {
|
declare interface Buffer {
|
||||||
|
/**
|
||||||
|
* Reads an unsigned byte at a particular location
|
||||||
|
*/
|
||||||
|
//% shim=BufferMethods::getUint8
|
||||||
|
getUint8(off: int32): int32;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes an unsigned byte at a particular location
|
||||||
|
*/
|
||||||
|
//% shim=BufferMethods::setUint8
|
||||||
|
setUint8(off: int32, v: int32): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a number in specified format in the buffer.
|
* Write a number in specified format in the buffer.
|
||||||
*/
|
*/
|
||||||
@ -42,6 +54,12 @@ declare interface Buffer {
|
|||||||
//% start.defl=0 length.defl=-1 shim=BufferMethods::shift
|
//% start.defl=0 length.defl=-1 shim=BufferMethods::shift
|
||||||
shift(offset: int32, start?: int32, length?: int32): void;
|
shift(offset: int32, start?: int32, length?: int32): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a buffer to string assuming UTF8 encoding
|
||||||
|
*/
|
||||||
|
//% shim=BufferMethods::toString
|
||||||
|
toString(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a buffer to its hexadecimal representation.
|
* Convert a buffer to its hexadecimal representation.
|
||||||
*/
|
*/
|
||||||
@ -72,6 +90,13 @@ declare namespace control {
|
|||||||
*/
|
*/
|
||||||
//% shim=control::createBuffer
|
//% shim=control::createBuffer
|
||||||
function createBuffer(size: int32): Buffer;
|
function createBuffer(size: int32): Buffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new buffer with UTF8-encoded string
|
||||||
|
* @param str the string to put in the buffer
|
||||||
|
*/
|
||||||
|
//% shim=control::createBufferFromUTF8
|
||||||
|
function createBufferFromUTF8(str: string): Buffer;
|
||||||
}
|
}
|
||||||
declare namespace loops {
|
declare namespace loops {
|
||||||
|
|
||||||
@ -101,6 +126,12 @@ declare namespace control {
|
|||||||
//% blockId=control_running_time block="millis (ms)" shim=control::millis
|
//% blockId=control_running_time block="millis (ms)" shim=control::millis
|
||||||
function millis(): int32;
|
function millis(): int32;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets current time in microseconds. Overflows every ~18 minutes.
|
||||||
|
*/
|
||||||
|
//% shim=control::micros
|
||||||
|
function micros(): int32;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used internally
|
* Used internally
|
||||||
*/
|
*/
|
||||||
@ -143,11 +174,54 @@ declare namespace control {
|
|||||||
//% help=control/device-serial-number shim=control::deviceSerialNumber
|
//% help=control/device-serial-number shim=control::deviceSerialNumber
|
||||||
function deviceSerialNumber(): int32;
|
function deviceSerialNumber(): int32;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Derive a unique, consistent 64-bit serial number of this device from internal data.
|
||||||
|
*/
|
||||||
|
//% blockId="control_device_long_serial_number" block="device long serial number" weight=9
|
||||||
|
//% help=control/device-long-serial-number shim=control::deviceLongSerialNumber
|
||||||
|
function deviceLongSerialNumber(): Buffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
//% shim=control::__log
|
//% shim=control::__log
|
||||||
function __log(text: string): void;
|
function __log(prority: int32, text: string): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dump internal information about a value.
|
||||||
|
*/
|
||||||
|
//% shim=control::dmesgValue
|
||||||
|
function dmesgValue(v: any): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force GC and dump basic information about heap.
|
||||||
|
*/
|
||||||
|
//% shim=control::gc
|
||||||
|
function gc(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force GC and halt waiting for debugger to do a full heap dump.
|
||||||
|
*/
|
||||||
|
//% shim=control::heapDump
|
||||||
|
function heapDump(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set flags used when connecting an external debugger.
|
||||||
|
*/
|
||||||
|
//% shim=control::setDebugFlags
|
||||||
|
function setDebugFlags(flags: int32): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Record a heap snapshot to debug memory leaks.
|
||||||
|
*/
|
||||||
|
//% shim=control::heapSnapshot
|
||||||
|
function heapSnapshot(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if profiling is enabled in the current build.
|
||||||
|
*/
|
||||||
|
//% shim=control::profilingEnabled
|
||||||
|
function profilingEnabled(): boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-generated. Do not edit. Really.
|
// Auto-generated. Do not edit. Really.
|
||||||
|
66
libs/broadcast/broadcast.ts
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
* Message broadcasting
|
||||||
|
*/
|
||||||
|
//% weight=70
|
||||||
|
//% color="#58AB41"
|
||||||
|
namespace broadcast {
|
||||||
|
const broadcastEventId = control.allocateNotifyEvent();
|
||||||
|
const broadcastDoneEventId = control.allocateNotifyEvent();
|
||||||
|
|
||||||
|
function normalizeId(id: number) {
|
||||||
|
// upper ids are reserved for answer
|
||||||
|
return ((id + 1) | 0) & 0xffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An enum shim
|
||||||
|
*/
|
||||||
|
//% shim=ENUM_GET
|
||||||
|
//% blockId=msg_enum_shim
|
||||||
|
//% block="$arg"
|
||||||
|
//% enumName="Messages"
|
||||||
|
//% enumMemberName="message"
|
||||||
|
//% enumPromptHint="e.g. Move, Turn, ..."
|
||||||
|
//% enumInitialMembers="message1"
|
||||||
|
//% blockHidden=1
|
||||||
|
//% enumIsHash=1
|
||||||
|
export function __messageShim(arg: number) {
|
||||||
|
// This function should do nothing, but must take in a single
|
||||||
|
// argument of type number and return a number value.
|
||||||
|
return arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register code to run when a message is received
|
||||||
|
*/
|
||||||
|
//% block="on %id=msg_enum_shim|received"
|
||||||
|
//% blockId=broadcastonreceived draggableParameters
|
||||||
|
export function onMessageReceived(message: number, body: () => void) {
|
||||||
|
const messageid = normalizeId(message);
|
||||||
|
control.onEvent(broadcastEventId, messageid, function () {
|
||||||
|
body();
|
||||||
|
control.raiseEvent(broadcastDoneEventId, messageid);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a message to activate code
|
||||||
|
*/
|
||||||
|
//% block="send %id=msg_enum_shim"
|
||||||
|
//% blockId=broadcastsend draggableParameters
|
||||||
|
export function sendMessage(message: number) {
|
||||||
|
const messageid = normalizeId(message);
|
||||||
|
control.raiseEvent(broadcastEventId, messageid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a message and pauses until the handler to finishes.
|
||||||
|
*/
|
||||||
|
//% block="send %id=msg_enum_shim| and pause"
|
||||||
|
//% blockId=broadcastsendpause
|
||||||
|
export function sendMessageAndPause(message: number) {
|
||||||
|
const messageid = normalizeId(message);
|
||||||
|
control.raiseEvent(broadcastEventId, messageid);
|
||||||
|
control.waitForEvent(broadcastDoneEventId, messageid);
|
||||||
|
}
|
||||||
|
}
|
11
libs/broadcast/pxt.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "broadcast",
|
||||||
|
"description": "Broadcasting messages - beta",
|
||||||
|
"files": [
|
||||||
|
"broadcast.ts"
|
||||||
|
],
|
||||||
|
"public": true,
|
||||||
|
"dependencies": {
|
||||||
|
"core": "file:../core"
|
||||||
|
}
|
||||||
|
}
|
@ -59,9 +59,9 @@ namespace sensors {
|
|||||||
|
|
||||||
constructor(port: number) {
|
constructor(port: number) {
|
||||||
super(port)
|
super(port)
|
||||||
this._setMode(ColorSensorMode.None);
|
|
||||||
this.thresholdDetector = new sensors.ThresholdDetector(this.id());
|
this.thresholdDetector = new sensors.ThresholdDetector(this.id());
|
||||||
this.calibrating = false;
|
this.calibrating = false;
|
||||||
|
this.setMode(ColorSensorMode.ReflectedLightIntensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
_colorEventValue(value: number) {
|
_colorEventValue(value: number) {
|
||||||
@ -73,13 +73,7 @@ namespace sensors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setMode(m: ColorSensorMode) {
|
setMode(m: ColorSensorMode) {
|
||||||
if (m == ColorSensorMode.AmbientLightIntensity) {
|
// don't change threshold after initialization
|
||||||
this.thresholdDetector.setLowThreshold(5);
|
|
||||||
this.thresholdDetector.setHighThreshold(20);
|
|
||||||
} else {
|
|
||||||
this.thresholdDetector.setLowThreshold(20);
|
|
||||||
this.thresholdDetector.setHighThreshold(80);
|
|
||||||
}
|
|
||||||
this._setMode(m)
|
this._setMode(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +105,9 @@ namespace sensors {
|
|||||||
"red",
|
"red",
|
||||||
"white",
|
"white",
|
||||||
"brown"][this._query()];
|
"brown"][this._query()];
|
||||||
|
case ColorSensorMode.AmbientLightIntensity:
|
||||||
|
case ColorSensorMode.ReflectedLightIntensity:
|
||||||
|
return `${this._query()}%`;
|
||||||
default:
|
default:
|
||||||
return this._query().toString();
|
return this._query().toString();
|
||||||
}
|
}
|
||||||
@ -180,6 +177,7 @@ namespace sensors {
|
|||||||
//% blockGap=8
|
//% blockGap=8
|
||||||
color(): ColorSensorColor {
|
color(): ColorSensorColor {
|
||||||
this.setMode(ColorSensorMode.Color)
|
this.setMode(ColorSensorMode.Color)
|
||||||
|
this.poke();
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,6 +195,7 @@ namespace sensors {
|
|||||||
//% blockGap=8
|
//% blockGap=8
|
||||||
rgbRaw(): number[] {
|
rgbRaw(): number[] {
|
||||||
this.setMode(ColorSensorMode.RgbRaw);
|
this.setMode(ColorSensorMode.RgbRaw);
|
||||||
|
this.poke();
|
||||||
return [this.getNumber(NumberFormat.UInt16LE, 0), this.getNumber(NumberFormat.UInt16LE, 2), this.getNumber(NumberFormat.UInt16LE, 4)];
|
return [this.getNumber(NumberFormat.UInt16LE, 0), this.getNumber(NumberFormat.UInt16LE, 2), this.getNumber(NumberFormat.UInt16LE, 4)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +249,8 @@ namespace sensors {
|
|||||||
//% group="Color Sensor"
|
//% group="Color Sensor"
|
||||||
light(mode: LightIntensityMode) {
|
light(mode: LightIntensityMode) {
|
||||||
this.setMode(<ColorSensorMode><number>mode)
|
this.setMode(<ColorSensorMode><number>mode)
|
||||||
switch(mode) {
|
this.poke();
|
||||||
|
switch (mode) {
|
||||||
case LightIntensityMode.ReflectedRaw:
|
case LightIntensityMode.ReflectedRaw:
|
||||||
return this.reflectedLightRaw();
|
return this.reflectedLightRaw();
|
||||||
default:
|
default:
|
||||||
@ -280,6 +280,7 @@ namespace sensors {
|
|||||||
//%
|
//%
|
||||||
reflectedLightRaw(): number {
|
reflectedLightRaw(): number {
|
||||||
this.setMode(ColorSensorMode.RefRaw);
|
this.setMode(ColorSensorMode.RefRaw);
|
||||||
|
this.poke();
|
||||||
return this.getNumber(NumberFormat.UInt16LE, 0);
|
return this.getNumber(NumberFormat.UInt16LE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ namespace brick {
|
|||||||
*/
|
*/
|
||||||
//% blockId=brickBatteryProperty block="battery %property"
|
//% blockId=brickBatteryProperty block="battery %property"
|
||||||
//% group="Battery"
|
//% group="Battery"
|
||||||
|
//% blockGap=8
|
||||||
//% help=brick/battery-property
|
//% help=brick/battery-property
|
||||||
export function batteryInfo(property: BatteryProperty): number {
|
export function batteryInfo(property: BatteryProperty): number {
|
||||||
const info = sensors.internal.getBatteryInfo();
|
const info = sensors.internal.getBatteryInfo();
|
||||||
|
@ -55,6 +55,10 @@ namespace brick {
|
|||||||
this._wasPressed = false
|
this._wasPressed = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected poke() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//% hidden
|
//% hidden
|
||||||
_update(curr: boolean) {
|
_update(curr: boolean) {
|
||||||
if (this == null) return
|
if (this == null) return
|
||||||
@ -81,10 +85,11 @@ namespace brick {
|
|||||||
//% blockId=buttonIsPressed
|
//% blockId=buttonIsPressed
|
||||||
//% parts="brick"
|
//% parts="brick"
|
||||||
//% blockNamespace=brick
|
//% blockNamespace=brick
|
||||||
//% weight=81 blockGap=8
|
//% weight=81
|
||||||
//% group="Buttons"
|
//% group="Buttons"
|
||||||
//% button.fieldEditor="brickbuttons"
|
//% button.fieldEditor="brickbuttons"
|
||||||
isPressed() {
|
isPressed() {
|
||||||
|
this.poke();
|
||||||
return this._isPressed
|
return this._isPressed
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +107,7 @@ namespace brick {
|
|||||||
//% group="Buttons"
|
//% group="Buttons"
|
||||||
//% button.fieldEditor="brickbuttons"
|
//% button.fieldEditor="brickbuttons"
|
||||||
wasPressed() {
|
wasPressed() {
|
||||||
|
this.poke();
|
||||||
const r = this._wasPressed
|
const r = this._wasPressed
|
||||||
this._wasPressed = false
|
this._wasPressed = false
|
||||||
return r
|
return r
|
||||||
@ -144,6 +150,7 @@ namespace brick {
|
|||||||
namespace brick {
|
namespace brick {
|
||||||
let btnsMM: MMap
|
let btnsMM: MMap
|
||||||
let buttons: DevButton[]
|
let buttons: DevButton[]
|
||||||
|
let buttonPoller: sensors.internal.Poller;
|
||||||
|
|
||||||
export namespace internal {
|
export namespace internal {
|
||||||
export function getBtnsMM() {
|
export function getBtnsMM() {
|
||||||
@ -167,7 +174,7 @@ namespace brick {
|
|||||||
btnsMM = control.mmap("/dev/lms_ui", DAL.NUM_BUTTONS, 0)
|
btnsMM = control.mmap("/dev/lms_ui", DAL.NUM_BUTTONS, 0)
|
||||||
if (!btnsMM) control.fail("no buttons?")
|
if (!btnsMM) control.fail("no buttons?")
|
||||||
buttons = []
|
buttons = []
|
||||||
sensors.internal.unsafePollForChanges(50, readButtons, (prev, curr) => {
|
buttonPoller = new sensors.internal.Poller(50, readButtons, (prev, curr) => {
|
||||||
for (let b of buttons)
|
for (let b of buttons)
|
||||||
b._update(!!(curr & b.mask))
|
b._update(!!(curr & b.mask))
|
||||||
})
|
})
|
||||||
@ -182,6 +189,10 @@ namespace brick {
|
|||||||
initBtns()
|
initBtns()
|
||||||
buttons.push(this)
|
buttons.push(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected poke() {
|
||||||
|
buttonPoller.poke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initBtns() // always ON as it handles ESCAPE button
|
initBtns() // always ON as it handles ESCAPE button
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
#include "pxt.h"
|
|
||||||
|
|
||||||
namespace control {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Announce that an event happened to registered handlers.
|
|
||||||
* @param src ID of the Component that generated the event
|
|
||||||
* @param value Component specific code indicating the cause of the event.
|
|
||||||
* @param mode optional definition of how the event should be processed after construction.
|
|
||||||
*/
|
|
||||||
//% weight=21 blockGap=12 blockId="control_raise_event"
|
|
||||||
//% block="raise event|from %src|with value %value" blockExternalInputs=1
|
|
||||||
//% help=control/raise-event
|
|
||||||
void raiseEvent(int src, int value) {
|
|
||||||
pxt::raiseEvent(src, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allocates the next user notification event
|
|
||||||
*/
|
|
||||||
//% help=control/allocate-notify-event
|
|
||||||
int allocateNotifyEvent() {
|
|
||||||
return pxt::allocateNotifyEvent();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Write data to DMESG debugging buffer. */
|
|
||||||
//%
|
|
||||||
void dmesg(String s) {
|
|
||||||
DMESG("# %s", s->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace serial {
|
|
||||||
/** Send DMESG debug buffer over serial. */
|
|
||||||
//%
|
|
||||||
void writeDmesg() {
|
|
||||||
pxt::dumpDmesg();
|
|
||||||
}
|
|
||||||
}
|
|
409
libs/core/dal.d.ts
vendored
@ -1,6 +1,305 @@
|
|||||||
// Auto-generated. Do not edit.
|
// Auto-generated. Do not edit.
|
||||||
declare const enum DAL {
|
declare const enum DAL {
|
||||||
// built/dockermake/pxtapp/ev3const.h
|
// /pxtapp/configkeys.h
|
||||||
|
CFG_PIN_NAME_MSK = 65535,
|
||||||
|
CFG_PIN_CONFIG_MSK = 4294901760,
|
||||||
|
CFG_PIN_CONFIG_ACTIVE_LO = 65536,
|
||||||
|
CFG_MAGIC0 = 513675505,
|
||||||
|
CFG_MAGIC1 = 539130489,
|
||||||
|
CFG_PIN_ACCELEROMETER_INT = 1,
|
||||||
|
CFG_PIN_ACCELEROMETER_SCL = 2,
|
||||||
|
CFG_PIN_ACCELEROMETER_SDA = 3,
|
||||||
|
CFG_PIN_BTN_A = 4,
|
||||||
|
CFG_PIN_BTN_B = 5,
|
||||||
|
CFG_PIN_BTN_SLIDE = 6,
|
||||||
|
CFG_PIN_DOTSTAR_CLOCK = 7,
|
||||||
|
CFG_PIN_DOTSTAR_DATA = 8,
|
||||||
|
CFG_PIN_FLASH_CS = 9,
|
||||||
|
CFG_PIN_FLASH_MISO = 10,
|
||||||
|
CFG_PIN_FLASH_MOSI = 11,
|
||||||
|
CFG_PIN_FLASH_SCK = 12,
|
||||||
|
CFG_PIN_LED = 13,
|
||||||
|
CFG_PIN_LIGHT = 14,
|
||||||
|
CFG_PIN_MICROPHONE = 15,
|
||||||
|
CFG_PIN_MIC_CLOCK = 16,
|
||||||
|
CFG_PIN_MIC_DATA = 17,
|
||||||
|
CFG_PIN_MISO = 18,
|
||||||
|
CFG_PIN_MOSI = 19,
|
||||||
|
CFG_PIN_NEOPIXEL = 20,
|
||||||
|
CFG_PIN_RX = 21,
|
||||||
|
CFG_PIN_RXLED = 22,
|
||||||
|
CFG_PIN_SCK = 23,
|
||||||
|
CFG_PIN_SCL = 24,
|
||||||
|
CFG_PIN_SDA = 25,
|
||||||
|
CFG_PIN_SPEAKER_AMP = 26,
|
||||||
|
CFG_PIN_TEMPERATURE = 27,
|
||||||
|
CFG_PIN_TX = 28,
|
||||||
|
CFG_PIN_TXLED = 29,
|
||||||
|
CFG_PIN_IR_OUT = 30,
|
||||||
|
CFG_PIN_IR_IN = 31,
|
||||||
|
CFG_PIN_DISPLAY_SCK = 32,
|
||||||
|
CFG_PIN_DISPLAY_MISO = 33,
|
||||||
|
CFG_PIN_DISPLAY_MOSI = 34,
|
||||||
|
CFG_PIN_DISPLAY_CS = 35,
|
||||||
|
CFG_PIN_DISPLAY_DC = 36,
|
||||||
|
CFG_DISPLAY_WIDTH = 37,
|
||||||
|
CFG_DISPLAY_HEIGHT = 38,
|
||||||
|
CFG_DISPLAY_CFG0 = 39,
|
||||||
|
CFG_DISPLAY_CFG1 = 40,
|
||||||
|
CFG_DISPLAY_CFG2 = 41,
|
||||||
|
CFG_DISPLAY_CFG3 = 42,
|
||||||
|
CFG_PIN_DISPLAY_RST = 43,
|
||||||
|
CFG_PIN_DISPLAY_BL = 44,
|
||||||
|
CFG_PIN_SERVO_1 = 45,
|
||||||
|
CFG_PIN_SERVO_2 = 46,
|
||||||
|
CFG_PIN_BTN_LEFT = 47,
|
||||||
|
CFG_PIN_BTN_RIGHT = 48,
|
||||||
|
CFG_PIN_BTN_UP = 49,
|
||||||
|
CFG_PIN_BTN_DOWN = 50,
|
||||||
|
CFG_PIN_BTN_MENU = 51,
|
||||||
|
CFG_PIN_LED_R = 52,
|
||||||
|
CFG_PIN_LED_G = 53,
|
||||||
|
CFG_PIN_LED_B = 54,
|
||||||
|
CFG_PIN_LED1 = 55,
|
||||||
|
CFG_PIN_LED2 = 56,
|
||||||
|
CFG_PIN_LED3 = 57,
|
||||||
|
CFG_PIN_LED4 = 58,
|
||||||
|
CFG_SPEAKER_VOLUME = 59,
|
||||||
|
CFG_PIN_JACK_TX = 60,
|
||||||
|
CFG_PIN_JACK_SENSE = 61,
|
||||||
|
CFG_PIN_JACK_HPEN = 62,
|
||||||
|
CFG_PIN_JACK_BZEN = 63,
|
||||||
|
CFG_PIN_JACK_PWREN = 64,
|
||||||
|
CFG_PIN_JACK_SND = 65,
|
||||||
|
CFG_PIN_JACK_BUSLED = 66,
|
||||||
|
CFG_PIN_JACK_COMMLED = 67,
|
||||||
|
CFG_PIN_BTN_SOFT_RESET = 69,
|
||||||
|
CFG_ACCELEROMETER_TYPE = 70,
|
||||||
|
CFG_PIN_BTNMX_LATCH = 71,
|
||||||
|
CFG_PIN_BTNMX_CLOCK = 72,
|
||||||
|
CFG_PIN_BTNMX_DATA = 73,
|
||||||
|
CFG_PIN_BTN_MENU2 = 74,
|
||||||
|
CFG_PIN_BATTSENSE = 75,
|
||||||
|
CFG_PIN_VIBRATION = 76,
|
||||||
|
CFG_PIN_PWREN = 77,
|
||||||
|
CFG_DISPLAY_TYPE = 78,
|
||||||
|
CFG_PIN_ROTARY_ENCODER_A = 79,
|
||||||
|
CFG_PIN_ROTARY_ENCODER_B = 80,
|
||||||
|
CFG_ACCELEROMETER_SPACE = 81,
|
||||||
|
CFG_PIN_WIFI_MOSI = 82,
|
||||||
|
CFG_PIN_WIFI_MISO = 83,
|
||||||
|
CFG_PIN_WIFI_SCK = 84,
|
||||||
|
CFG_PIN_WIFI_TX = 85,
|
||||||
|
CFG_PIN_WIFI_RX = 86,
|
||||||
|
CFG_PIN_WIFI_CS = 87,
|
||||||
|
CFG_PIN_WIFI_BUSY = 88,
|
||||||
|
CFG_PIN_WIFI_RESET = 89,
|
||||||
|
CFG_PIN_WIFI_GPIO0 = 90,
|
||||||
|
CFG_PIN_WIFI_AT_TX = 91,
|
||||||
|
CFG_PIN_WIFI_AT_RX = 92,
|
||||||
|
CFG_PIN_USB_POWER = 93,
|
||||||
|
ACCELEROMETER_TYPE_LIS3DH = 50,
|
||||||
|
ACCELEROMETER_TYPE_LIS3DH_ALT = 48,
|
||||||
|
ACCELEROMETER_TYPE_MMA8453 = 56,
|
||||||
|
ACCELEROMETER_TYPE_FXOS8700 = 60,
|
||||||
|
ACCELEROMETER_TYPE_MMA8653 = 58,
|
||||||
|
ACCELEROMETER_TYPE_MSA300 = 76,
|
||||||
|
ACCELEROMETER_TYPE_MPU6050 = 104,
|
||||||
|
DISPLAY_TYPE_ST7735 = 7735,
|
||||||
|
DISPLAY_TYPE_ILI9341 = 9341,
|
||||||
|
CFG_PIN_A0 = 100,
|
||||||
|
CFG_PIN_A1 = 101,
|
||||||
|
CFG_PIN_A2 = 102,
|
||||||
|
CFG_PIN_A3 = 103,
|
||||||
|
CFG_PIN_A4 = 104,
|
||||||
|
CFG_PIN_A5 = 105,
|
||||||
|
CFG_PIN_A6 = 106,
|
||||||
|
CFG_PIN_A7 = 107,
|
||||||
|
CFG_PIN_A8 = 108,
|
||||||
|
CFG_PIN_A9 = 109,
|
||||||
|
CFG_PIN_A10 = 110,
|
||||||
|
CFG_PIN_A11 = 111,
|
||||||
|
CFG_PIN_A12 = 112,
|
||||||
|
CFG_PIN_A13 = 113,
|
||||||
|
CFG_PIN_A14 = 114,
|
||||||
|
CFG_PIN_A15 = 115,
|
||||||
|
CFG_PIN_A16 = 116,
|
||||||
|
CFG_PIN_A17 = 117,
|
||||||
|
CFG_PIN_A18 = 118,
|
||||||
|
CFG_PIN_A19 = 119,
|
||||||
|
CFG_PIN_A20 = 120,
|
||||||
|
CFG_PIN_A21 = 121,
|
||||||
|
CFG_PIN_A22 = 122,
|
||||||
|
CFG_PIN_A23 = 123,
|
||||||
|
CFG_PIN_A24 = 124,
|
||||||
|
CFG_PIN_A25 = 125,
|
||||||
|
CFG_PIN_A26 = 126,
|
||||||
|
CFG_PIN_A27 = 127,
|
||||||
|
CFG_PIN_A28 = 128,
|
||||||
|
CFG_PIN_A29 = 129,
|
||||||
|
CFG_PIN_A30 = 130,
|
||||||
|
CFG_PIN_A31 = 131,
|
||||||
|
CFG_PIN_D0 = 150,
|
||||||
|
CFG_PIN_D1 = 151,
|
||||||
|
CFG_PIN_D2 = 152,
|
||||||
|
CFG_PIN_D3 = 153,
|
||||||
|
CFG_PIN_D4 = 154,
|
||||||
|
CFG_PIN_D5 = 155,
|
||||||
|
CFG_PIN_D6 = 156,
|
||||||
|
CFG_PIN_D7 = 157,
|
||||||
|
CFG_PIN_D8 = 158,
|
||||||
|
CFG_PIN_D9 = 159,
|
||||||
|
CFG_PIN_D10 = 160,
|
||||||
|
CFG_PIN_D11 = 161,
|
||||||
|
CFG_PIN_D12 = 162,
|
||||||
|
CFG_PIN_D13 = 163,
|
||||||
|
CFG_PIN_D14 = 164,
|
||||||
|
CFG_PIN_D15 = 165,
|
||||||
|
CFG_PIN_D16 = 166,
|
||||||
|
CFG_PIN_D17 = 167,
|
||||||
|
CFG_PIN_D18 = 168,
|
||||||
|
CFG_PIN_D19 = 169,
|
||||||
|
CFG_PIN_D20 = 170,
|
||||||
|
CFG_PIN_D21 = 171,
|
||||||
|
CFG_PIN_D22 = 172,
|
||||||
|
CFG_PIN_D23 = 173,
|
||||||
|
CFG_PIN_D24 = 174,
|
||||||
|
CFG_PIN_D25 = 175,
|
||||||
|
CFG_PIN_D26 = 176,
|
||||||
|
CFG_PIN_D27 = 177,
|
||||||
|
CFG_PIN_D28 = 178,
|
||||||
|
CFG_PIN_D29 = 179,
|
||||||
|
CFG_PIN_D30 = 180,
|
||||||
|
CFG_PIN_D31 = 181,
|
||||||
|
CFG_NUM_NEOPIXELS = 200,
|
||||||
|
CFG_NUM_DOTSTARS = 201,
|
||||||
|
CFG_DEFAULT_BUTTON_MODE = 202,
|
||||||
|
CFG_SWD_ENABLED = 203,
|
||||||
|
CFG_FLASH_BYTES = 204,
|
||||||
|
CFG_RAM_BYTES = 205,
|
||||||
|
CFG_SYSTEM_HEAP_BYTES = 206,
|
||||||
|
CFG_LOW_MEM_SIMULATION_KB = 207,
|
||||||
|
CFG_BOOTLOADER_BOARD_ID = 208,
|
||||||
|
CFG_UF2_FAMILY = 209,
|
||||||
|
CFG_PINS_PORT_SIZE = 210,
|
||||||
|
CFG_BOOTLOADER_PROTECTION = 211,
|
||||||
|
CFG_POWER_DEEPSLEEP_TIMEOUT = 212,
|
||||||
|
CFG_ANALOG_BUTTON_THRESHOLD = 213,
|
||||||
|
CFG_CPU_MHZ = 214,
|
||||||
|
CFG_CONTROLLER_LIGHT_MAX_BRIGHTNESS = 215,
|
||||||
|
CFG_PIN_B0 = 300,
|
||||||
|
CFG_PIN_B1 = 301,
|
||||||
|
CFG_PIN_B2 = 302,
|
||||||
|
CFG_PIN_B3 = 303,
|
||||||
|
CFG_PIN_B4 = 304,
|
||||||
|
CFG_PIN_B5 = 305,
|
||||||
|
CFG_PIN_B6 = 306,
|
||||||
|
CFG_PIN_B7 = 307,
|
||||||
|
CFG_PIN_B8 = 308,
|
||||||
|
CFG_PIN_B9 = 309,
|
||||||
|
CFG_PIN_B10 = 310,
|
||||||
|
CFG_PIN_B11 = 311,
|
||||||
|
CFG_PIN_B12 = 312,
|
||||||
|
CFG_PIN_B13 = 313,
|
||||||
|
CFG_PIN_B14 = 314,
|
||||||
|
CFG_PIN_B15 = 315,
|
||||||
|
CFG_PIN_B16 = 316,
|
||||||
|
CFG_PIN_B17 = 317,
|
||||||
|
CFG_PIN_B18 = 318,
|
||||||
|
CFG_PIN_B19 = 319,
|
||||||
|
CFG_PIN_B20 = 320,
|
||||||
|
CFG_PIN_B21 = 321,
|
||||||
|
CFG_PIN_B22 = 322,
|
||||||
|
CFG_PIN_B23 = 323,
|
||||||
|
CFG_PIN_B24 = 324,
|
||||||
|
CFG_PIN_B25 = 325,
|
||||||
|
CFG_PIN_B26 = 326,
|
||||||
|
CFG_PIN_B27 = 327,
|
||||||
|
CFG_PIN_B28 = 328,
|
||||||
|
CFG_PIN_B29 = 329,
|
||||||
|
CFG_PIN_B30 = 330,
|
||||||
|
CFG_PIN_B31 = 331,
|
||||||
|
CFG_PIN_C0 = 350,
|
||||||
|
CFG_PIN_C1 = 351,
|
||||||
|
CFG_PIN_C2 = 352,
|
||||||
|
CFG_PIN_C3 = 353,
|
||||||
|
CFG_PIN_C4 = 354,
|
||||||
|
CFG_PIN_C5 = 355,
|
||||||
|
CFG_PIN_C6 = 356,
|
||||||
|
CFG_PIN_C7 = 357,
|
||||||
|
CFG_PIN_C8 = 358,
|
||||||
|
CFG_PIN_C9 = 359,
|
||||||
|
CFG_PIN_C10 = 360,
|
||||||
|
CFG_PIN_C11 = 361,
|
||||||
|
CFG_PIN_C12 = 362,
|
||||||
|
CFG_PIN_C13 = 363,
|
||||||
|
CFG_PIN_C14 = 364,
|
||||||
|
CFG_PIN_C15 = 365,
|
||||||
|
CFG_PIN_C16 = 366,
|
||||||
|
CFG_PIN_C17 = 367,
|
||||||
|
CFG_PIN_C18 = 368,
|
||||||
|
CFG_PIN_C19 = 369,
|
||||||
|
CFG_PIN_C20 = 370,
|
||||||
|
CFG_PIN_C21 = 371,
|
||||||
|
CFG_PIN_C22 = 372,
|
||||||
|
CFG_PIN_C23 = 373,
|
||||||
|
CFG_PIN_C24 = 374,
|
||||||
|
CFG_PIN_C25 = 375,
|
||||||
|
CFG_PIN_C26 = 376,
|
||||||
|
CFG_PIN_C27 = 377,
|
||||||
|
CFG_PIN_C28 = 378,
|
||||||
|
CFG_PIN_C29 = 379,
|
||||||
|
CFG_PIN_C30 = 380,
|
||||||
|
CFG_PIN_C31 = 381,
|
||||||
|
CFG_PIN_P0 = 400,
|
||||||
|
CFG_PIN_P1 = 401,
|
||||||
|
CFG_PIN_P2 = 402,
|
||||||
|
CFG_PIN_P3 = 403,
|
||||||
|
CFG_PIN_P4 = 404,
|
||||||
|
CFG_PIN_P5 = 405,
|
||||||
|
CFG_PIN_P6 = 406,
|
||||||
|
CFG_PIN_P7 = 407,
|
||||||
|
CFG_PIN_P8 = 408,
|
||||||
|
CFG_PIN_P9 = 409,
|
||||||
|
CFG_PIN_P10 = 410,
|
||||||
|
CFG_PIN_P11 = 411,
|
||||||
|
CFG_PIN_P12 = 412,
|
||||||
|
CFG_PIN_P13 = 413,
|
||||||
|
CFG_PIN_P14 = 414,
|
||||||
|
CFG_PIN_P15 = 415,
|
||||||
|
CFG_PIN_P16 = 416,
|
||||||
|
CFG_PIN_P17 = 417,
|
||||||
|
CFG_PIN_P18 = 418,
|
||||||
|
CFG_PIN_P19 = 419,
|
||||||
|
CFG_PIN_P20 = 420,
|
||||||
|
CFG_PIN_P21 = 421,
|
||||||
|
CFG_PIN_P22 = 422,
|
||||||
|
CFG_PIN_P23 = 423,
|
||||||
|
CFG_PIN_P24 = 424,
|
||||||
|
CFG_PIN_P25 = 425,
|
||||||
|
CFG_PIN_P26 = 426,
|
||||||
|
CFG_PIN_P27 = 427,
|
||||||
|
CFG_PIN_P28 = 428,
|
||||||
|
CFG_PIN_P29 = 429,
|
||||||
|
CFG_PIN_P30 = 430,
|
||||||
|
CFG_PIN_P31 = 431,
|
||||||
|
CFG_PIN_LORA_MISO = 1001,
|
||||||
|
CFG_PIN_LORA_MOSI = 1002,
|
||||||
|
CFG_PIN_LORA_SCK = 1003,
|
||||||
|
CFG_PIN_LORA_CS = 1004,
|
||||||
|
CFG_PIN_LORA_BOOT = 1005,
|
||||||
|
CFG_PIN_LORA_RESET = 1006,
|
||||||
|
CFG_PIN_IRRXLED = 1007,
|
||||||
|
CFG_PIN_IRTXLED = 1008,
|
||||||
|
CFG_PIN_LCD_RESET = 1009,
|
||||||
|
CFG_PIN_LCD_ENABLE = 1010,
|
||||||
|
CFG_PIN_LCD_DATALINE4 = 1011,
|
||||||
|
CFG_PIN_LCD_DATALINE5 = 1012,
|
||||||
|
CFG_PIN_LCD_DATALINE6 = 1013,
|
||||||
|
CFG_PIN_LCD_DATALINE7 = 1014,
|
||||||
|
CFG_NUM_LCD_COLUMNS = 1015,
|
||||||
|
CFG_NUM_LCD_ROWS = 1016,
|
||||||
|
// /pxtapp/ev3const.h
|
||||||
NUM_INPUTS = 4,
|
NUM_INPUTS = 4,
|
||||||
NUM_OUTPUTS = 4,
|
NUM_OUTPUTS = 4,
|
||||||
LCD_WIDTH = 178,
|
LCD_WIDTH = 178,
|
||||||
@ -10,6 +309,8 @@ declare const enum DAL {
|
|||||||
DEVICE_TYPE_NXT_LIGHT = 2,
|
DEVICE_TYPE_NXT_LIGHT = 2,
|
||||||
DEVICE_TYPE_NXT_SOUND = 3,
|
DEVICE_TYPE_NXT_SOUND = 3,
|
||||||
DEVICE_TYPE_NXT_COLOR = 4,
|
DEVICE_TYPE_NXT_COLOR = 4,
|
||||||
|
DEVICE_TYPE_NXT_ULTRASONIC = 5,
|
||||||
|
DEVICE_TYPE_NXT_TEMPERATURE = 6,
|
||||||
DEVICE_TYPE_TACHO = 7,
|
DEVICE_TYPE_TACHO = 7,
|
||||||
DEVICE_TYPE_MINITACHO = 8,
|
DEVICE_TYPE_MINITACHO = 8,
|
||||||
DEVICE_TYPE_NEWTACHO = 9,
|
DEVICE_TYPE_NEWTACHO = 9,
|
||||||
@ -46,44 +347,66 @@ declare const enum DAL {
|
|||||||
CONN_OUTPUT_TACHO = 125,
|
CONN_OUTPUT_TACHO = 125,
|
||||||
CONN_NONE = 126,
|
CONN_NONE = 126,
|
||||||
CONN_ERROR = 127,
|
CONN_ERROR = 127,
|
||||||
opProgramStart = 0x03,
|
opProgramStart = 3,
|
||||||
opOutputGetType = 0xA0,
|
opOutputGetType = 160,
|
||||||
opOutputSetType = 0xA1,
|
opOutputSetType = 161,
|
||||||
opOutputReset = 0xA2,
|
opOutputReset = 162,
|
||||||
opOutputStop = 0xA3,
|
opOutputStop = 163,
|
||||||
opOutputPower = 0xA4,
|
opOutputPower = 164,
|
||||||
opOutputSpeed = 0xA5,
|
opOutputSpeed = 165,
|
||||||
opOutputStart = 0xA6,
|
opOutputStart = 166,
|
||||||
opOutputPolarity = 0xA7,
|
opOutputPolarity = 167,
|
||||||
opOutputRead = 0xA8,
|
opOutputRead = 168,
|
||||||
opOutputTest = 0xA9,
|
opOutputTest = 169,
|
||||||
opOutputReady = 0xAA,
|
opOutputReady = 170,
|
||||||
opOutputPosition = 0xAB,
|
opOutputPosition = 171,
|
||||||
opOutputStepPower = 0xAC,
|
opOutputStepPower = 172,
|
||||||
opOutputTimePower = 0xAD,
|
opOutputTimePower = 173,
|
||||||
opOutputStepSpeed = 0xAE,
|
opOutputStepSpeed = 174,
|
||||||
opOutputTimeSpeed = 0xAF,
|
opOutputTimeSpeed = 175,
|
||||||
opOutputStepSync = 0xB0,
|
opOutputStepSync = 176,
|
||||||
opOutputTimeSync = 0xB1,
|
opOutputTimeSync = 177,
|
||||||
opOutputClearCount = 0xB2,
|
opOutputClearCount = 178,
|
||||||
opOutputGetCount = 0xB3,
|
opOutputGetCount = 179,
|
||||||
opOutputProgramStop = 0xB4,
|
opOutputProgramStop = 180,
|
||||||
BUTTON_ID_UP = 0x01,
|
BUTTON_ID_UP = 1,
|
||||||
BUTTON_ID_ENTER = 0x02,
|
BUTTON_ID_ENTER = 2,
|
||||||
BUTTON_ID_DOWN = 0x04,
|
BUTTON_ID_DOWN = 4,
|
||||||
BUTTON_ID_RIGHT = 0x08,
|
BUTTON_ID_RIGHT = 8,
|
||||||
BUTTON_ID_LEFT = 0x10,
|
BUTTON_ID_LEFT = 16,
|
||||||
BUTTON_ID_ESCAPE = 0x20,
|
BUTTON_ID_ESCAPE = 32,
|
||||||
// built/dockermake/pxtapp/pxt.h
|
// /pxtapp/platform.h
|
||||||
|
PXT_GC_THREAD_LIST = 1,
|
||||||
|
// /pxtapp/pxt.h
|
||||||
DEVICE_EVT_ANY = 0,
|
DEVICE_EVT_ANY = 0,
|
||||||
DEVICE_ID_NOTIFY = 10000,
|
DEVICE_ID_NOTIFY = 10000,
|
||||||
DEVICE_ID_NOTIFY_ONE = 10001,
|
DEVICE_ID_NOTIFY_ONE = 10001,
|
||||||
// built/dockermake/pxtapp/pxtbase.h
|
IMAGE_BITS = 1,
|
||||||
PXT_REF_TAG_STRING = 1,
|
// /pxtapp/pxtbase.h
|
||||||
PXT_REF_TAG_BUFFER = 2,
|
PXT32 = 1,
|
||||||
PXT_REF_TAG_IMAGE = 3,
|
PXT64 = 1,
|
||||||
PXT_REF_TAG_NUMBER = 32,
|
PXT_VTABLE_SHIFT = 2,
|
||||||
PXT_REF_TAG_ACTION = 33,
|
PXT_REFCNT_FLASH = 65534,
|
||||||
|
VTABLE_MAGIC = 249,
|
||||||
|
Undefined = 0,
|
||||||
|
Boolean = 1,
|
||||||
|
Number = 2,
|
||||||
|
String = 3,
|
||||||
|
Object = 4,
|
||||||
|
Function = 5,
|
||||||
|
BoxedString = 1,
|
||||||
|
BoxedNumber = 2,
|
||||||
|
BoxedBuffer = 3,
|
||||||
|
RefAction = 4,
|
||||||
|
RefImage = 5,
|
||||||
|
RefCollection = 6,
|
||||||
|
RefRefLocal = 7,
|
||||||
|
RefMap = 8,
|
||||||
|
RefMImage = 9,
|
||||||
|
MMap = 10,
|
||||||
|
User0 = 16,
|
||||||
|
PXT_IOS_HEAP_ALLOC_BITS = 20,
|
||||||
|
IMAGE_HEADER_MAGIC = 135,
|
||||||
Int8LE = 1,
|
Int8LE = 1,
|
||||||
UInt8LE = 2,
|
UInt8LE = 2,
|
||||||
Int16LE = 3,
|
Int16LE = 3,
|
||||||
@ -100,12 +423,10 @@ declare const enum DAL {
|
|||||||
Float64LE = 14,
|
Float64LE = 14,
|
||||||
Float32BE = 15,
|
Float32BE = 15,
|
||||||
Float64BE = 16,
|
Float64BE = 16,
|
||||||
Undefined = 0,
|
NUM_TRY_FRAME_REGS = 3,
|
||||||
Boolean = 1,
|
GC = 0,
|
||||||
Number = 2,
|
// /pxtapp/pxtconfig.h
|
||||||
String = 3,
|
PXT_GC = 1,
|
||||||
Object = 4,
|
// /pxtapp/pxtcore.h
|
||||||
Function = 5,
|
PXT_HARD_FLOAT = 1,
|
||||||
// built/dockermake/pxtapp/pxtconfig.h
|
|
||||||
// built/dockermake/pxtapp/pxtcore.h
|
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#define DEVICE_TYPE_NXT_LIGHT 2
|
#define DEVICE_TYPE_NXT_LIGHT 2
|
||||||
#define DEVICE_TYPE_NXT_SOUND 3
|
#define DEVICE_TYPE_NXT_SOUND 3
|
||||||
#define DEVICE_TYPE_NXT_COLOR 4
|
#define DEVICE_TYPE_NXT_COLOR 4
|
||||||
|
#define DEVICE_TYPE_NXT_ULTRASONIC 5
|
||||||
|
#define DEVICE_TYPE_NXT_TEMPERATURE 6
|
||||||
#define DEVICE_TYPE_TACHO 7
|
#define DEVICE_TYPE_TACHO 7
|
||||||
#define DEVICE_TYPE_MINITACHO 8
|
#define DEVICE_TYPE_MINITACHO 8
|
||||||
#define DEVICE_TYPE_NEWTACHO 9
|
#define DEVICE_TYPE_NEWTACHO 9
|
||||||
|
@ -1,29 +1,52 @@
|
|||||||
namespace sensors.internal {
|
namespace sensors.internal {
|
||||||
//% shim=pxt::unsafePollForChanges
|
export class Poller {
|
||||||
export function unsafePollForChanges(
|
private query: () => number;
|
||||||
periodMs: number,
|
private update: (previous: number, current: number) => void;
|
||||||
query: () => number,
|
public interval: number;
|
||||||
changeHandler: (prev: number, curr: number) => void
|
|
||||||
) {
|
|
||||||
// This is implemented in C++ without blocking the regular JS when query() is runnning
|
|
||||||
// which is generally unsafe. Query should not update globally visible state, and cannot
|
|
||||||
// call any yielding functions, like sleep().
|
|
||||||
|
|
||||||
// This is implementation for the simulator.
|
private previousValue: number;
|
||||||
|
private currentValue: number;
|
||||||
|
private lastQuery: number; // track down the last time we did a query/update cycle
|
||||||
|
private lastPause: number; // track down the last time we pause in the sensor polling loop
|
||||||
|
|
||||||
control.runInParallel(() => {
|
constructor(interval: number, query: () => number, update: (previous: number, current: number) => void) {
|
||||||
let prev = query()
|
this.interval = interval | 0;
|
||||||
changeHandler(prev, prev)
|
this.query = query;
|
||||||
while (true) {
|
this.update = update;
|
||||||
pause(periodMs)
|
|
||||||
let curr = query()
|
this.poll();
|
||||||
if (prev !== curr) {
|
|
||||||
changeHandler(prev, curr)
|
|
||||||
prev = curr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
poke(): void {
|
||||||
|
const now = control.millis();
|
||||||
|
if (now - this.lastQuery >= this.interval * 2)
|
||||||
|
this.queryAndUpdate(); // sensor poller is not allowed to run
|
||||||
|
if (now - this.lastPause >= this.interval * 5)
|
||||||
|
pause(1); // allow events to trigger
|
||||||
|
}
|
||||||
|
|
||||||
|
private queryAndUpdate() {
|
||||||
|
this.lastQuery = control.millis();
|
||||||
|
this.currentValue = this.query();
|
||||||
|
if (this.previousValue != this.currentValue) {
|
||||||
|
this.update(this.previousValue, this.currentValue);
|
||||||
|
this.previousValue = this.currentValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private poll() {
|
||||||
|
control.runInBackground(() => {
|
||||||
|
this.lastQuery = this.lastPause = control.millis();
|
||||||
|
this.previousValue = this.currentValue = this.query();
|
||||||
|
this.update(this.previousValue, this.currentValue);
|
||||||
|
while (true) {
|
||||||
|
this.lastPause = control.millis();
|
||||||
|
pause(this.interval);
|
||||||
|
this.queryAndUpdate();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function bufferToString(buf: Buffer): string {
|
export function bufferToString(buf: Buffer): string {
|
||||||
let s = ''
|
let s = ''
|
||||||
@ -38,6 +61,7 @@ namespace sensors.internal {
|
|||||||
let IICMM: MMap
|
let IICMM: MMap
|
||||||
let powerMM: MMap
|
let powerMM: MMap
|
||||||
let devcon: Buffer
|
let devcon: Buffer
|
||||||
|
let devPoller: Poller
|
||||||
let sensorInfos: SensorInfo[];
|
let sensorInfos: SensorInfo[];
|
||||||
|
|
||||||
let batteryInfo: {
|
let batteryInfo: {
|
||||||
@ -55,13 +79,28 @@ namespace sensors.internal {
|
|||||||
connType: number
|
connType: number
|
||||||
devType: number
|
devType: number
|
||||||
iicid: string
|
iicid: string
|
||||||
|
poller: Poller;
|
||||||
|
|
||||||
constructor(p: number) {
|
constructor(p: number) {
|
||||||
this.port = p
|
this.port = p; // 0-based
|
||||||
this.connType = DAL.CONN_NONE
|
this.connType = DAL.CONN_NONE
|
||||||
this.devType = DAL.DEVICE_TYPE_NONE
|
this.devType = DAL.DEVICE_TYPE_NONE
|
||||||
this.iicid = ''
|
this.iicid = ''
|
||||||
this.sensors = []
|
this.sensors = []
|
||||||
|
this.poller = new Poller(25, () => this.query(), (prev, curr) => this.update(prev, curr));
|
||||||
|
}
|
||||||
|
|
||||||
|
poke() {
|
||||||
|
this.poller.poke();
|
||||||
|
}
|
||||||
|
|
||||||
|
private query() {
|
||||||
|
if (this.sensor) return this.sensor._query();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private update(prev: number, curr: number) {
|
||||||
|
if (this.sensor) this.sensor._update(prev, curr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,19 +121,10 @@ namespace sensors.internal {
|
|||||||
|
|
||||||
powerMM = control.mmap("/dev/lms_power", 2, 0)
|
powerMM = control.mmap("/dev/lms_power", 2, 0)
|
||||||
|
|
||||||
unsafePollForChanges(500,
|
devPoller = new Poller(500, () => { return hashDevices(); },
|
||||||
() => { return hashDevices(); },
|
|
||||||
(prev, curr) => {
|
(prev, curr) => {
|
||||||
detectDevices();
|
detectDevices();
|
||||||
});
|
});
|
||||||
sensorInfos.forEach(info => {
|
|
||||||
unsafePollForChanges(50, () => {
|
|
||||||
if (info.sensor) return info.sensor._query()
|
|
||||||
return 0
|
|
||||||
}, (prev, curr) => {
|
|
||||||
if (info.sensor) info.sensor._update(prev, curr)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getActiveSensors(): Sensor[] {
|
export function getActiveSensors(): Sensor[] {
|
||||||
@ -178,12 +208,14 @@ namespace sensors.internal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBatteryInfo(): {
|
export interface BatteryInfo {
|
||||||
level: number;
|
level: number;
|
||||||
Ibatt: number,
|
Ibatt: number,
|
||||||
Vbatt: number,
|
Vbatt: number,
|
||||||
Imotor: number
|
Imotor: number
|
||||||
} {
|
}
|
||||||
|
|
||||||
|
export function getBatteryInfo(): BatteryInfo {
|
||||||
init();
|
init();
|
||||||
if (!batteryInfo) updateBatteryInfo();
|
if (!batteryInfo) updateBatteryInfo();
|
||||||
const CinCnt = batteryInfo.CinCnt;
|
const CinCnt = batteryInfo.CinCnt;
|
||||||
@ -247,42 +279,61 @@ void cUiUpdatePower(void)
|
|||||||
for (let i = 0; i < conns.length; ++i) {
|
for (let i = 0; i < conns.length; ++i) {
|
||||||
r = (r << 8 | conns[i]);
|
r = (r << 8 | conns[i]);
|
||||||
}
|
}
|
||||||
|
//control.dmesg(`devices hash: ${r}`);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
let nonActivated = 0;
|
let nonActivated = 0;
|
||||||
function detectDevices() {
|
function detectDevices() {
|
||||||
//control.dmesg(`detect devices (${nonActivated} na)`)
|
control.dmesg(`detect devices (${nonActivated} na)`)
|
||||||
const conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
|
const inDcm = analogMM.slice(AnalogOff.InDcm, DAL.NUM_INPUTS)
|
||||||
|
const inConn = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
|
||||||
let numChanged = 0;
|
let numChanged = 0;
|
||||||
const uartSensors: SensorInfo[] = [];
|
const uartSensors: SensorInfo[] = [];
|
||||||
|
|
||||||
for (const sensorInfo of sensorInfos) {
|
for (const sensorInfo of sensorInfos) {
|
||||||
const newConn = conns[sensorInfo.port]
|
const newConn = inConn[sensorInfo.port]
|
||||||
if (newConn == sensorInfo.connType) {
|
if (newConn == sensorInfo.connType) {
|
||||||
// control.dmesg(`connection unchanged ${newConn} at ${sensorInfo.port}`)
|
// control.dmesg(`connection unchanged ${newConn} at ${sensorInfo.port}`)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
numChanged++
|
numChanged++
|
||||||
sensorInfo.connType = newConn
|
sensorInfo.connType = newConn
|
||||||
sensorInfo.devType = DAL.DEVICE_TYPE_NONE
|
sensorInfo.devType = DAL.DEVICE_TYPE_NONE;
|
||||||
if (newConn == DAL.CONN_INPUT_UART) {
|
switch (newConn) {
|
||||||
|
case DAL.CONN_INPUT_UART: {
|
||||||
control.dmesg(`new UART connection at ${sensorInfo.port}`)
|
control.dmesg(`new UART connection at ${sensorInfo.port}`)
|
||||||
updateUartMode(sensorInfo.port, 0);
|
updateUartMode(sensorInfo.port, 0);
|
||||||
uartSensors.push(sensorInfo);
|
uartSensors.push(sensorInfo);
|
||||||
} else if (newConn == DAL.CONN_NXT_IIC) {
|
break;
|
||||||
control.dmesg(`new IIC connection at ${sensorInfo.port}`)
|
}
|
||||||
|
case DAL.CONN_NXT_IIC: {
|
||||||
|
control.dmesg(`new NXT IIC connection at ${sensorInfo.port}`)
|
||||||
sensorInfo.devType = DAL.DEVICE_TYPE_IIC_UNKNOWN
|
sensorInfo.devType = DAL.DEVICE_TYPE_IIC_UNKNOWN
|
||||||
sensorInfo.iicid = readIICID(sensorInfo.port)
|
sensorInfo.iicid = readIICID(sensorInfo.port)
|
||||||
control.dmesg(`IIC ID ${sensorInfo.iicid.length}`)
|
control.dmesg(`IIC ID ${sensorInfo.iicid.length}`)
|
||||||
} else if (newConn == DAL.CONN_INPUT_DUMB) {
|
break;
|
||||||
|
} case DAL.CONN_NXT_DUMB: { // analog NXT sensor
|
||||||
|
control.dmesg(`new NXT analog connection at ${sensorInfo.port}`);
|
||||||
|
sensorInfo.devType = inDcm[sensorInfo.port];
|
||||||
|
control.dmesg(`NXT analog dev type ${sensorInfo.devType}`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DAL.CONN_INPUT_DUMB: {
|
||||||
control.dmesg(`new DUMB connection at ${sensorInfo.port}`)
|
control.dmesg(`new DUMB connection at ${sensorInfo.port}`)
|
||||||
// TODO? for now assume touch
|
// TODO? for now assume touch
|
||||||
sensorInfo.devType = DAL.DEVICE_TYPE_TOUCH
|
sensorInfo.devType = DAL.DEVICE_TYPE_TOUCH
|
||||||
} else if (newConn == DAL.CONN_NONE || newConn == 0) {
|
break;
|
||||||
control.dmesg(`disconnect at port ${sensorInfo.port}`)
|
}
|
||||||
} else {
|
case DAL.CONN_NONE:
|
||||||
|
case 0: {
|
||||||
|
//control.dmesg(`disconnect at port ${sensorInfo.port}`)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
control.dmesg(`unknown connection type: ${newConn} at ${sensorInfo.port}`)
|
control.dmesg(`unknown connection type: ${newConn} at ${sensorInfo.port}`)
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +349,7 @@ void cUiUpdatePower(void)
|
|||||||
if (numChanged == 0 && nonActivated == 0)
|
if (numChanged == 0 && nonActivated == 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
control.dmesg(`updating sensor status`)
|
//control.dmesg(`updating sensor status`)
|
||||||
nonActivated = 0;
|
nonActivated = 0;
|
||||||
for (const sensorInfo of sensorInfos) {
|
for (const sensorInfo of sensorInfos) {
|
||||||
if (sensorInfo.devType == DAL.DEVICE_TYPE_IIC_UNKNOWN) {
|
if (sensorInfo.devType == DAL.DEVICE_TYPE_IIC_UNKNOWN) {
|
||||||
@ -337,6 +388,11 @@ void cUiUpdatePower(void)
|
|||||||
this.markUsed();
|
this.markUsed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
poke() {
|
||||||
|
if (this.isActive())
|
||||||
|
sensorInfos[this._port].poke();
|
||||||
|
}
|
||||||
|
|
||||||
markUsed() {
|
markUsed() {
|
||||||
sensors.__sensorUsed(this._port, this._deviceType());
|
sensors.__sensorUsed(this._port, this._deviceType());
|
||||||
}
|
}
|
||||||
@ -390,20 +446,20 @@ void cUiUpdatePower(void)
|
|||||||
constructor(port: number) {
|
constructor(port: number) {
|
||||||
super(port)
|
super(port)
|
||||||
this.mode = 0
|
this.mode = 0
|
||||||
this.realmode = 0
|
this.realmode = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_activated() {
|
_activated() {
|
||||||
this.realmode = 0
|
this.realmode = 0;
|
||||||
this._setMode(this.mode)
|
this._setMode(this.mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _setMode(m: number) {
|
protected _setMode(m: number) {
|
||||||
//control.dmesg(`_setMode p=${this.port} m: ${this.realmode} -> ${m}`)
|
|
||||||
let v = m | 0
|
let v = m | 0
|
||||||
this.mode = v
|
this.mode = v
|
||||||
if (!this.isActive()) return
|
if (!this.isActive()) return
|
||||||
if (this.realmode != this.mode) {
|
if (this.realmode != this.mode) {
|
||||||
|
control.dmesg(`_setMode p=${this._port} m: ${this.realmode} -> ${v}`)
|
||||||
this.realmode = v
|
this.realmode = v
|
||||||
setUartMode(this._port, v)
|
setUartMode(this._port, v)
|
||||||
}
|
}
|
||||||
@ -533,18 +589,19 @@ void cUiUpdatePower(void)
|
|||||||
while (ports.length) {
|
while (ports.length) {
|
||||||
const port = ports.pop();
|
const port = ports.pop();
|
||||||
const status = waitNonZeroUartStatus(port)
|
const status = waitNonZeroUartStatus(port)
|
||||||
control.dmesg(`UART set mode ${status} at ${port}`);
|
control.dmesg(`UART status ${status} at ${port}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateUartMode(port: number, mode: number) {
|
function updateUartMode(port: number, mode: number) {
|
||||||
control.dmesg(`UART set mode to ${mode} at ${port}`)
|
control.dmesg(`UART update mode to ${mode} at ${port}`)
|
||||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Connection + port, DAL.CONN_INPUT_UART)
|
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Connection + port, DAL.CONN_INPUT_UART)
|
||||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Type + port, 33)
|
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Type + port, 33)
|
||||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Mode + port, mode)
|
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Mode + port, mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUartMode(port: number, mode: number) {
|
function setUartMode(port: number, mode: number) {
|
||||||
|
control.dmesg(`UART set mode ${mode} at ${port}`);
|
||||||
const UART_PORT_CHANGED = 1
|
const UART_PORT_CHANGED = 1
|
||||||
while (true) {
|
while (true) {
|
||||||
if (port < 0) return
|
if (port < 0) return
|
||||||
@ -555,7 +612,7 @@ void cUiUpdatePower(void)
|
|||||||
control.dmesg(`UART clear changed at ${port}`)
|
control.dmesg(`UART clear changed at ${port}`)
|
||||||
uartClearChange(port)
|
uartClearChange(port)
|
||||||
} else {
|
} else {
|
||||||
control.dmesg(`UART status ${status}`);
|
control.dmesg(`UART status ${status} at ${port}`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pause(10)
|
pause(10)
|
||||||
@ -570,15 +627,16 @@ void cUiUpdatePower(void)
|
|||||||
DAL.MAX_DEVICE_DATALENGTH)
|
DAL.MAX_DEVICE_DATALENGTH)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUartNumber(fmt: NumberFormat, off: number, port: number) {
|
function getUartNumber(fmt: NumberFormat, off: number, port: number): number {
|
||||||
if (port < 0) return 0
|
if (port < 0) return 0
|
||||||
let index = uartMM.getNumber(NumberFormat.UInt16LE, UartOff.Actual + port * 2)
|
const index = uartMM.getNumber(NumberFormat.UInt16LE, UartOff.Actual + port * 2)
|
||||||
return uartMM.getNumber(fmt,
|
return uartMM.getNumber(fmt,
|
||||||
UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index + off)
|
UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index + off)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setIICMode(port: number, type: number, mode: number) {
|
export function setIICMode(port: number, type: number, mode: number) {
|
||||||
if (port < 0) return;
|
if (port < 0) return;
|
||||||
|
control.dmesg(`iic set type ${type} mode ${mode} at ${port}`)
|
||||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Connection + port, DAL.CONN_NXT_IIC)
|
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Connection + port, DAL.CONN_NXT_IIC)
|
||||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Type + port, type)
|
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Type + port, type)
|
||||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Mode + port, mode)
|
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Mode + port, mode)
|
||||||
@ -779,10 +837,10 @@ namespace sensors {
|
|||||||
|
|
||||||
export class ThresholdDetector {
|
export class ThresholdDetector {
|
||||||
public id: number;
|
public id: number;
|
||||||
public min: number;
|
private min: number;
|
||||||
public max: number;
|
private max: number;
|
||||||
public lowThreshold: number;
|
private lowThreshold: number;
|
||||||
public highThreshold: number;
|
private highThreshold: number;
|
||||||
public level: number;
|
public level: number;
|
||||||
public state: ThresholdState;
|
public state: ThresholdState;
|
||||||
|
|
||||||
|
26
libs/core/integrator.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
namespace control {
|
||||||
|
export class EulerIntegrator {
|
||||||
|
public value: number;
|
||||||
|
private t: number;
|
||||||
|
private v: number;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public integrate(derivative: number): void {
|
||||||
|
let now = control.millis();
|
||||||
|
let dt = (now -this.t) / 1000.0;
|
||||||
|
this.value += dt * (this.v + derivative) / 2;
|
||||||
|
|
||||||
|
this.t = now;
|
||||||
|
this.v = derivative;
|
||||||
|
}
|
||||||
|
|
||||||
|
public reset() {
|
||||||
|
this.value = 0;
|
||||||
|
this.v = 0;
|
||||||
|
this.t = control.millis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,593 +0,0 @@
|
|||||||
#include "pxt.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <cstdarg>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <malloc.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include "ev3const.h"
|
|
||||||
|
|
||||||
#define THREAD_DBG(...)
|
|
||||||
|
|
||||||
#define MALLOC_LIMIT (8 * 1024 * 1024)
|
|
||||||
#define MALLOC_CHECK_PERIOD (1024 * 1024)
|
|
||||||
|
|
||||||
void *xmalloc(size_t sz) {
|
|
||||||
static size_t allocBytes = 0;
|
|
||||||
allocBytes += sz;
|
|
||||||
if (allocBytes >= MALLOC_CHECK_PERIOD) {
|
|
||||||
allocBytes = 0;
|
|
||||||
auto info = mallinfo();
|
|
||||||
DMESG("malloc used: %d kb", info.uordblks / 1024);
|
|
||||||
if (info.uordblks > MALLOC_LIMIT) {
|
|
||||||
target_panic(904);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
auto r = malloc(sz);
|
|
||||||
if (r == NULL)
|
|
||||||
target_panic(905); // shouldn't happen
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *operator new(size_t size) {
|
|
||||||
return xmalloc(size);
|
|
||||||
}
|
|
||||||
void *operator new[](size_t size) {
|
|
||||||
return xmalloc(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator delete(void *p) {
|
|
||||||
free(p);
|
|
||||||
}
|
|
||||||
void operator delete[](void *p) {
|
|
||||||
free(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace pxt {
|
|
||||||
|
|
||||||
static int startTime;
|
|
||||||
static pthread_mutex_t execMutex;
|
|
||||||
static pthread_mutex_t eventMutex;
|
|
||||||
static pthread_cond_t newEventBroadcast;
|
|
||||||
|
|
||||||
struct Thread {
|
|
||||||
struct Thread *next;
|
|
||||||
Action act;
|
|
||||||
TValue arg0;
|
|
||||||
pthread_t pid;
|
|
||||||
pthread_cond_t waitCond;
|
|
||||||
int waitSource;
|
|
||||||
int waitValue;
|
|
||||||
TValue data0;
|
|
||||||
TValue data1;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct Thread *allThreads;
|
|
||||||
static struct Event *eventHead, *eventTail;
|
|
||||||
static int usbFD;
|
|
||||||
static int dmesgPtr;
|
|
||||||
static int dmesgSerialPtr;
|
|
||||||
static char dmesgBuf[4096];
|
|
||||||
|
|
||||||
struct Event {
|
|
||||||
struct Event *next;
|
|
||||||
int source;
|
|
||||||
int value;
|
|
||||||
};
|
|
||||||
|
|
||||||
Event lastEvent;
|
|
||||||
|
|
||||||
Event *mkEvent(int source, int value) {
|
|
||||||
auto res = new Event();
|
|
||||||
memset(res, 0, sizeof(Event));
|
|
||||||
res->source = source;
|
|
||||||
res->value = value;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define USB_MAGIC 0x3d3f
|
|
||||||
#define USB_SERIAL 1
|
|
||||||
#define USB_RESTART 2
|
|
||||||
#define USB_DMESG 3
|
|
||||||
|
|
||||||
struct UsbPacket {
|
|
||||||
uint16_t size;
|
|
||||||
uint16_t msgcount;
|
|
||||||
uint16_t magic;
|
|
||||||
uint16_t code;
|
|
||||||
char buf[1024 - 8];
|
|
||||||
};
|
|
||||||
|
|
||||||
void *usbThread(void *) {
|
|
||||||
UsbPacket pkt;
|
|
||||||
UsbPacket resp;
|
|
||||||
while (true) {
|
|
||||||
int len = read(usbFD, &pkt, sizeof(pkt));
|
|
||||||
if (len <= 4) {
|
|
||||||
sleep_core_us(20000);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
resp.msgcount = pkt.msgcount;
|
|
||||||
if (pkt.magic == USB_MAGIC) {
|
|
||||||
if (pkt.code == USB_RESTART) {
|
|
||||||
target_reset();
|
|
||||||
} else if (pkt.code == USB_DMESG) {
|
|
||||||
dumpDmesg();
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
resp.magic = pkt.magic;
|
|
||||||
resp.code = pkt.code;
|
|
||||||
resp.size = 8;
|
|
||||||
write(usbFD, &resp, sizeof(resp));
|
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
resp.magic = 0xffff;
|
|
||||||
resp.size = 4;
|
|
||||||
write(usbFD, &resp, sizeof(resp));
|
|
||||||
}
|
|
||||||
sleep_core_us(1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void startUsb() {
|
|
||||||
usbFD = open("/dev/lms_usbdev", O_RDWR, 0666);
|
|
||||||
pthread_t pid;
|
|
||||||
pthread_create(&pid, NULL, usbThread, NULL);
|
|
||||||
pthread_detach(pid);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *exitThread(void *) {
|
|
||||||
int fd = open("/dev/lms_ui", O_RDWR, 0666);
|
|
||||||
if (fd < 0)
|
|
||||||
return 0;
|
|
||||||
uint8_t *data =
|
|
||||||
(uint8_t *)mmap(NULL, NUM_BUTTONS, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
||||||
if (data == MAP_FAILED) {
|
|
||||||
close(fd);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
for (;;) {
|
|
||||||
if (data[5])
|
|
||||||
target_reset();
|
|
||||||
sleep_core_us(50000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void startExitThread() {
|
|
||||||
pthread_t pid;
|
|
||||||
pthread_create(&pid, NULL, exitThread, NULL);
|
|
||||||
pthread_detach(pid);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendUsb(uint16_t code, const char *data, int len) {
|
|
||||||
while (len > 0) {
|
|
||||||
int sz = len;
|
|
||||||
if (sz > 1000)
|
|
||||||
sz = 1000;
|
|
||||||
UsbPacket pkt = {(uint16_t)(6 + sz), 0, USB_MAGIC, code, {}};
|
|
||||||
memcpy(pkt.buf, data, sz);
|
|
||||||
write(usbFD, &pkt, sizeof(pkt));
|
|
||||||
len -= sz;
|
|
||||||
data += sz;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendSerial(const char *data, int len) {
|
|
||||||
sendUsb(USB_SERIAL, data, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
volatile bool paniced;
|
|
||||||
extern "C" void drawPanic(int code);
|
|
||||||
|
|
||||||
extern "C" void target_panic(int error_code) {
|
|
||||||
char buf[50];
|
|
||||||
paniced = true;
|
|
||||||
pthread_mutex_trylock(&execMutex);
|
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "\nPANIC %d\n", error_code);
|
|
||||||
|
|
||||||
drawPanic(error_code);
|
|
||||||
DMESG("PANIC %d", error_code);
|
|
||||||
|
|
||||||
for (int i = 0; i < 10; ++i) {
|
|
||||||
sendSerial(buf, strlen(buf));
|
|
||||||
sleep_core_us(500 * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
target_reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void startUser() {
|
|
||||||
pthread_mutex_lock(&execMutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void stopUser() {
|
|
||||||
pthread_mutex_unlock(&execMutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sleep_core_us(uint64_t us) {
|
|
||||||
struct timespec ts;
|
|
||||||
ts.tv_sec = us / 1000000;
|
|
||||||
ts.tv_nsec = (us % 1000000) * 1000;
|
|
||||||
while (nanosleep(&ts, &ts))
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
void sleep_ms(uint32_t ms) {
|
|
||||||
stopUser();
|
|
||||||
sleep_core_us(ms * 1000);
|
|
||||||
startUser();
|
|
||||||
}
|
|
||||||
|
|
||||||
void sleep_us(uint64_t us) {
|
|
||||||
if (us > 50000) {
|
|
||||||
sleep_ms(us / 1000);
|
|
||||||
}
|
|
||||||
sleep_core_us(us);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t currTime() {
|
|
||||||
struct timeval tv;
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
int current_time_ms() {
|
|
||||||
return currTime() - startTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
void disposeThread(Thread *t) {
|
|
||||||
if (allThreads == t) {
|
|
||||||
allThreads = t->next;
|
|
||||||
} else {
|
|
||||||
for (auto tt = allThreads; tt; tt = tt->next) {
|
|
||||||
if (tt->next == t) {
|
|
||||||
tt->next = t->next;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
decr(t->act);
|
|
||||||
decr(t->arg0);
|
|
||||||
decr(t->data0);
|
|
||||||
decr(t->data1);
|
|
||||||
pthread_cond_destroy(&t->waitCond);
|
|
||||||
delete t;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void runAct(Thread *thr) {
|
|
||||||
startUser();
|
|
||||||
pxt::runAction1(thr->act, thr->arg0);
|
|
||||||
stopUser();
|
|
||||||
disposeThread(thr);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mainThread(Thread *) {}
|
|
||||||
|
|
||||||
void setupThread(Action a, TValue arg = 0, void (*runner)(Thread *) = NULL, TValue d0 = 0,
|
|
||||||
TValue d1 = 0) {
|
|
||||||
if (runner == NULL)
|
|
||||||
runner = runAct;
|
|
||||||
auto thr = new Thread();
|
|
||||||
memset(thr, 0, sizeof(Thread));
|
|
||||||
thr->next = allThreads;
|
|
||||||
allThreads = thr;
|
|
||||||
thr->act = incr(a);
|
|
||||||
thr->arg0 = incr(arg);
|
|
||||||
thr->data0 = incr(d0);
|
|
||||||
thr->data1 = incr(d1);
|
|
||||||
pthread_cond_init(&thr->waitCond, NULL);
|
|
||||||
if (runner == mainThread) {
|
|
||||||
thr->pid = pthread_self();
|
|
||||||
} else {
|
|
||||||
pthread_create(&thr->pid, NULL, (void *(*)(void *))runner, thr);
|
|
||||||
THREAD_DBG("setup thread: %p (pid %p)", thr, thr->pid);
|
|
||||||
pthread_detach(thr->pid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void releaseFiber() {
|
|
||||||
stopUser();
|
|
||||||
pthread_exit(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void runInParallel(Action a) {
|
|
||||||
setupThread(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void runFor(Thread *t) {
|
|
||||||
startUser();
|
|
||||||
while (true) {
|
|
||||||
pxt::runAction0(t->act);
|
|
||||||
sleep_ms(20);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void runForever(Action a) {
|
|
||||||
setupThread(a, 0, runFor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void waitForEvent(int source, int value) {
|
|
||||||
THREAD_DBG("waitForEv: %d %d", source, value);
|
|
||||||
auto self = pthread_self();
|
|
||||||
for (auto t = allThreads; t; t = t->next) {
|
|
||||||
THREAD_DBG("t: %p", t);
|
|
||||||
if (t->pid == self) {
|
|
||||||
pthread_mutex_lock(&eventMutex);
|
|
||||||
t->waitSource = source;
|
|
||||||
t->waitValue = value;
|
|
||||||
stopUser();
|
|
||||||
// spourious wake ups may occur they say
|
|
||||||
while (t->waitSource) {
|
|
||||||
pthread_cond_wait(&t->waitCond, &eventMutex);
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&eventMutex);
|
|
||||||
startUser();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DMESG("current thread not registered!");
|
|
||||||
target_panic(901);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dispatchEvent(Event &e) {
|
|
||||||
lastEvent = e;
|
|
||||||
|
|
||||||
auto curr = findBinding(e.source, e.value);
|
|
||||||
if (curr)
|
|
||||||
setupThread(curr->action, fromInt(e.value));
|
|
||||||
|
|
||||||
curr = findBinding(e.source, DEVICE_EVT_ANY);
|
|
||||||
if (curr)
|
|
||||||
setupThread(curr->action, fromInt(e.value));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *evtDispatcher(void *dummy) {
|
|
||||||
pthread_mutex_lock(&eventMutex);
|
|
||||||
while (true) {
|
|
||||||
pthread_cond_wait(&newEventBroadcast, &eventMutex);
|
|
||||||
while (eventHead != NULL) {
|
|
||||||
if (paniced)
|
|
||||||
return 0;
|
|
||||||
Event *ev = eventHead;
|
|
||||||
eventHead = ev->next;
|
|
||||||
if (eventHead == NULL)
|
|
||||||
eventTail = NULL;
|
|
||||||
|
|
||||||
for (auto thr = allThreads; thr; thr = thr->next) {
|
|
||||||
if (paniced)
|
|
||||||
return 0;
|
|
||||||
if (thr->waitSource == 0)
|
|
||||||
continue;
|
|
||||||
if (thr->waitValue != ev->value && thr->waitValue != DEVICE_EVT_ANY)
|
|
||||||
continue;
|
|
||||||
if (thr->waitSource == ev->source) {
|
|
||||||
thr->waitSource = 0; // once!
|
|
||||||
pthread_cond_broadcast(&thr->waitCond);
|
|
||||||
} else if (thr->waitSource == DEVICE_ID_NOTIFY &&
|
|
||||||
ev->source == DEVICE_ID_NOTIFY_ONE) {
|
|
||||||
thr->waitSource = 0; // once!
|
|
||||||
pthread_cond_broadcast(&thr->waitCond);
|
|
||||||
break; // do not wake up any other threads
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatchEvent(*ev);
|
|
||||||
delete ev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int allocateNotifyEvent() {
|
|
||||||
static volatile int notifyId;
|
|
||||||
pthread_mutex_lock(&eventMutex);
|
|
||||||
int res = ++notifyId;
|
|
||||||
pthread_mutex_unlock(&eventMutex);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void raiseEvent(int id, int event) {
|
|
||||||
auto e = mkEvent(id, event);
|
|
||||||
pthread_mutex_lock(&eventMutex);
|
|
||||||
if (eventTail == NULL) {
|
|
||||||
if (eventHead != NULL)
|
|
||||||
target_panic(902);
|
|
||||||
eventHead = eventTail = e;
|
|
||||||
} else {
|
|
||||||
eventTail->next = e;
|
|
||||||
eventTail = e;
|
|
||||||
}
|
|
||||||
pthread_cond_broadcast(&newEventBroadcast);
|
|
||||||
pthread_mutex_unlock(&eventMutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void registerWithDal(int id, int event, Action a, int flags) {
|
|
||||||
// TODO support flags
|
|
||||||
setBinding(id, event, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void runPoller(Thread *thr) {
|
|
||||||
Action query = thr->data0;
|
|
||||||
auto us = (uint64_t)toInt(thr->data1) * 1000;
|
|
||||||
|
|
||||||
// note that this is run without the user mutex held - it should not modify any state!
|
|
||||||
TValue prev = pxt::runAction0(query);
|
|
||||||
|
|
||||||
startUser();
|
|
||||||
pxt::runAction2(thr->act, prev, prev);
|
|
||||||
stopUser();
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
sleep_core_us(us);
|
|
||||||
if (paniced)
|
|
||||||
break;
|
|
||||||
TValue curr = pxt::runAction0(query);
|
|
||||||
if (curr != prev) {
|
|
||||||
startUser();
|
|
||||||
pxt::runAction2(thr->act, prev, curr);
|
|
||||||
stopUser();
|
|
||||||
if (paniced)
|
|
||||||
break;
|
|
||||||
decr(prev);
|
|
||||||
prev = curr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// disposeThread(thr);
|
|
||||||
}
|
|
||||||
|
|
||||||
//%
|
|
||||||
void unsafePollForChanges(int ms, Action query, Action handler) {
|
|
||||||
setupThread(handler, 0, runPoller, query, fromInt(ms));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t afterProgramPage() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
void dumpDmesg() {
|
|
||||||
auto len = dmesgPtr - dmesgSerialPtr;
|
|
||||||
if (len == 0)
|
|
||||||
return;
|
|
||||||
sendSerial(dmesgBuf + dmesgSerialPtr, len);
|
|
||||||
dmesgSerialPtr = dmesgPtr;
|
|
||||||
}
|
|
||||||
|
|
||||||
int lmsPid;
|
|
||||||
void stopLMS() {
|
|
||||||
struct dirent *ent;
|
|
||||||
DIR *dir;
|
|
||||||
|
|
||||||
dir = opendir("/proc");
|
|
||||||
if (dir == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
while ((ent = readdir(dir)) != NULL) {
|
|
||||||
int pid = atoi(ent->d_name);
|
|
||||||
if (!pid)
|
|
||||||
continue;
|
|
||||||
char namebuf[100];
|
|
||||||
snprintf(namebuf, 1000, "/proc/%d/cmdline", pid);
|
|
||||||
FILE *f = fopen(namebuf, "r");
|
|
||||||
if (f) {
|
|
||||||
fread(namebuf, 1, 99, f);
|
|
||||||
if (strcmp(namebuf, "./lms2012") == 0) {
|
|
||||||
lmsPid = pid;
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
if (lmsPid)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir(dir);
|
|
||||||
|
|
||||||
lmsPid = 0; // disable SIGSTOP for now - rethink if problems with I2C (runs on a thread)
|
|
||||||
|
|
||||||
if (lmsPid) {
|
|
||||||
DMESG("SIGSTOP to lmsPID=%d", lmsPid);
|
|
||||||
if (kill(lmsPid, SIGSTOP))
|
|
||||||
DMESG("SIGSTOP failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void runLMS() {
|
|
||||||
DMESG("re-starting LMS2012");
|
|
||||||
kill(lmsPid, SIGCONT);
|
|
||||||
sleep_core_us(200000);
|
|
||||||
exit(0);
|
|
||||||
/*
|
|
||||||
chdir("/home/root/lms2012/sys");
|
|
||||||
for (int fd = 3; fd < 9999; ++fd)
|
|
||||||
close(fd);
|
|
||||||
execl("lms2012", "./lms2012");
|
|
||||||
exit(100); // should not be reached
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void stopMotors() {
|
|
||||||
uint8_t cmd[3] = {opOutputStop, 0x0F, 0};
|
|
||||||
int fd = open("/dev/lms_pwm", O_RDWR);
|
|
||||||
write(fd, cmd, 3);
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void stopProgram() {
|
|
||||||
uint8_t cmd[1] = {opOutputProgramStop};
|
|
||||||
int fd = open("/dev/lms_pwm", O_RDWR);
|
|
||||||
write(fd, cmd, 1);
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void target_reset() {
|
|
||||||
stopMotors();
|
|
||||||
stopProgram();
|
|
||||||
if (lmsPid)
|
|
||||||
runLMS();
|
|
||||||
else
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void screen_init();
|
|
||||||
void initRuntime() {
|
|
||||||
// daemon(1, 1);
|
|
||||||
startTime = currTime();
|
|
||||||
DMESG("runtime starting...");
|
|
||||||
stopLMS();
|
|
||||||
startUsb();
|
|
||||||
startExitThread();
|
|
||||||
pthread_t disp;
|
|
||||||
pthread_create(&disp, NULL, evtDispatcher, NULL);
|
|
||||||
pthread_detach(disp);
|
|
||||||
setupThread(0, 0, mainThread);
|
|
||||||
target_init();
|
|
||||||
screen_init();
|
|
||||||
startUser();
|
|
||||||
}
|
|
||||||
|
|
||||||
static FILE *dmesgFile;
|
|
||||||
|
|
||||||
void dmesgRaw(const char *buf, uint32_t len) {
|
|
||||||
if (!dmesgFile) {
|
|
||||||
dmesgFile = fopen("/tmp/dmesg.txt", "w");
|
|
||||||
if (!dmesgFile)
|
|
||||||
dmesgFile = stderr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len > sizeof(dmesgBuf) / 2)
|
|
||||||
return;
|
|
||||||
if (dmesgPtr + len > sizeof(dmesgBuf)) {
|
|
||||||
dmesgPtr = 0;
|
|
||||||
dmesgSerialPtr = 0;
|
|
||||||
}
|
|
||||||
memcpy(dmesgBuf + dmesgPtr, buf, len);
|
|
||||||
dmesgPtr += len;
|
|
||||||
fwrite(buf, 1, len, dmesgFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
void dmesg(const char *format, ...) {
|
|
||||||
char buf[500];
|
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "[%8d] ", current_time_ms());
|
|
||||||
dmesgRaw(buf, strlen(buf));
|
|
||||||
|
|
||||||
va_list arg;
|
|
||||||
va_start(arg, format);
|
|
||||||
vsnprintf(buf, sizeof(buf), format, arg);
|
|
||||||
va_end(arg);
|
|
||||||
dmesgRaw(buf, strlen(buf));
|
|
||||||
dmesgRaw("\n", 1);
|
|
||||||
|
|
||||||
fflush(dmesgFile);
|
|
||||||
fdatasync(fileno(dmesgFile));
|
|
||||||
}
|
|
||||||
} // namespace pxt
|
|
@ -25,13 +25,20 @@ PXT_VTABLE_CTOR(MMap) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MMap::print() {
|
void MMap::print() {
|
||||||
DMESG("MMap %p r=%d len=%d fd=%d data=%p", this, refcnt, length, fd, data);
|
DMESG("MMap %p len=%d fd=%d data=%p", this, length, fd, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MMap::destroy() {
|
void MMap::destroy() {
|
||||||
munmap(data, length);
|
munmap(data, length);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MMap::scan(MMap *) {}
|
||||||
|
|
||||||
|
unsigned MMap::gcsize(MMap *) {
|
||||||
|
return TOWORDS(sizeof(MMap));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace control {
|
namespace control {
|
||||||
@ -39,8 +46,8 @@ namespace control {
|
|||||||
/** Create new file mapping in memory */
|
/** Create new file mapping in memory */
|
||||||
//%
|
//%
|
||||||
MMap *mmap(String filename, int size, int offset) {
|
MMap *mmap(String filename, int size, int offset) {
|
||||||
DMESG("mmap %s len=%d off=%d", filename->data, size, offset);
|
DMESG("mmap %s len=%d off=%d", filename->getUTF8Data(), size, offset);
|
||||||
int fd = open(filename->data, O_RDWR, 0);
|
int fd = open(filename->getUTF8Data(), O_RDWR, 0);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ namespace motors {
|
|||||||
motorMM = control.mmap("/dev/lms_motor", MotorDataOff.Size * DAL.NUM_OUTPUTS, 0)
|
motorMM = control.mmap("/dev/lms_motor", MotorDataOff.Size * DAL.NUM_OUTPUTS, 0)
|
||||||
if (!motorMM) control.fail("no motor file")
|
if (!motorMM) control.fail("no motor file")
|
||||||
|
|
||||||
resetAllMotors()
|
resetAll()
|
||||||
|
|
||||||
const buf = output.createBuffer(1)
|
const buf = output.createBuffer(1)
|
||||||
buf[0] = DAL.opProgramStart
|
buf[0] = DAL.opProgramStart
|
||||||
@ -118,20 +118,25 @@ namespace motors {
|
|||||||
* Stops all motors
|
* Stops all motors
|
||||||
*/
|
*/
|
||||||
//% blockId=motorStopAll block="stop all motors"
|
//% blockId=motorStopAll block="stop all motors"
|
||||||
//% weight=1
|
//% weight=2
|
||||||
//% group="Move"
|
//% group="Move"
|
||||||
//% help=motors/stop-all
|
//% help=motors/stop-all
|
||||||
export function stopAll() {
|
export function stopAll() {
|
||||||
const b = mkCmd(Output.ALL, DAL.opOutputStop, 0)
|
const b = mkCmd(Output.ALL, DAL.opOutputStop, 0)
|
||||||
writePWM(b)
|
writePWM(b);
|
||||||
|
pause(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets all motors
|
* Resets all motors
|
||||||
*/
|
*/
|
||||||
|
//% blockId=motorResetAll block="reset all motors"
|
||||||
|
//% weight=1
|
||||||
//% group="Move"
|
//% group="Move"
|
||||||
export function resetAllMotors() {
|
//% help=motors/reset-all
|
||||||
|
export function resetAll() {
|
||||||
reset(Output.ALL)
|
reset(Output.ALL)
|
||||||
|
pause(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MoveSchedule {
|
interface MoveSchedule {
|
||||||
@ -154,6 +159,7 @@ namespace motors {
|
|||||||
private _accelerationTime: number;
|
private _accelerationTime: number;
|
||||||
private _decelerationSteps: number;
|
private _decelerationSteps: number;
|
||||||
private _decelerationTime: number;
|
private _decelerationTime: number;
|
||||||
|
private _inverted: boolean;
|
||||||
|
|
||||||
protected static output_types: number[] = [0x7, 0x7, 0x7, 0x7];
|
protected static output_types: number[] = [0x7, 0x7, 0x7, 0x7];
|
||||||
|
|
||||||
@ -171,6 +177,7 @@ namespace motors {
|
|||||||
this._accelerationTime = 0;
|
this._accelerationTime = 0;
|
||||||
this._decelerationSteps = 0;
|
this._decelerationSteps = 0;
|
||||||
this._decelerationTime = 0;
|
this._decelerationTime = 0;
|
||||||
|
this._inverted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -220,9 +227,11 @@ namespace motors {
|
|||||||
//% help=motors/motor/set-inverted
|
//% help=motors/motor/set-inverted
|
||||||
setInverted(inverted: boolean) {
|
setInverted(inverted: boolean) {
|
||||||
this.init();
|
this.init();
|
||||||
const b = mkCmd(this._port, DAL.opOutputPolarity, 1)
|
this._inverted = inverted;
|
||||||
b.setNumber(NumberFormat.Int8LE, 2, inverted ? 0 : 1);
|
}
|
||||||
writePWM(b)
|
|
||||||
|
protected invertedFactor(): number {
|
||||||
|
return this._inverted ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -259,6 +268,9 @@ namespace motors {
|
|||||||
// allow 500ms for robot to settle
|
// allow 500ms for robot to settle
|
||||||
if (this._brake && this._brakeSettleTime > 0)
|
if (this._brake && this._brakeSettleTime > 0)
|
||||||
pause(this._brakeSettleTime);
|
pause(this._brakeSettleTime);
|
||||||
|
else {
|
||||||
|
pause(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected pauseOnRun(stepsOrTime: number) {
|
protected pauseOnRun(stepsOrTime: number) {
|
||||||
@ -267,6 +279,8 @@ namespace motors {
|
|||||||
this.pauseUntilReady();
|
this.pauseUntilReady();
|
||||||
// allow robot to settle
|
// allow robot to settle
|
||||||
this.settle();
|
this.settle();
|
||||||
|
} else {
|
||||||
|
pause(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,8 +298,9 @@ namespace motors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private normalizeSchedule(speed: number, step1: number, step2: number, step3: number, unit: MoveUnit): MoveSchedule {
|
private normalizeSchedule(speed: number, step1: number, step2: number, step3: number, unit: MoveUnit): MoveSchedule {
|
||||||
|
// motor polarity is not supported at the firmware level for sync motor operations
|
||||||
const r: MoveSchedule = {
|
const r: MoveSchedule = {
|
||||||
speed: Math.clamp(-100, 100, speed >> 0),
|
speed: Math.clamp(-100, 100, speed | 0) * this.invertedFactor(),
|
||||||
useSteps: true,
|
useSteps: true,
|
||||||
steps: [step1 || 0, step2 || 0, step3 || 0]
|
steps: [step1 || 0, step2 || 0, step3 || 0]
|
||||||
}
|
}
|
||||||
@ -294,9 +309,17 @@ namespace motors {
|
|||||||
case MoveUnit.Rotations:
|
case MoveUnit.Rotations:
|
||||||
scale = 360;
|
scale = 360;
|
||||||
r.useSteps = true;
|
r.useSteps = true;
|
||||||
|
if (r.steps[1] < 0) {
|
||||||
|
r.speed = -r.speed;
|
||||||
|
r.steps[1] = -r.steps[1];
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MoveUnit.Degrees:
|
case MoveUnit.Degrees:
|
||||||
r.useSteps = true;
|
r.useSteps = true;
|
||||||
|
if (r.steps[1] < 0) {
|
||||||
|
r.speed = -r.speed;
|
||||||
|
r.steps[1] = -r.steps[1];
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MoveUnit.Seconds:
|
case MoveUnit.Seconds:
|
||||||
scale = 1000;
|
scale = 1000;
|
||||||
@ -334,6 +357,7 @@ namespace motors {
|
|||||||
// special: 0 is infinity
|
// special: 0 is infinity
|
||||||
if (schedule.steps[0] + schedule.steps[1] + schedule.steps[2] == 0) {
|
if (schedule.steps[0] + schedule.steps[1] + schedule.steps[2] == 0) {
|
||||||
this._run(schedule.speed);
|
this._run(schedule.speed);
|
||||||
|
pause(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,7 +518,7 @@ namespace motors {
|
|||||||
*/
|
*/
|
||||||
//% blockId=motorPauseUntilRead block="pause until %motor|ready"
|
//% blockId=motorPauseUntilRead block="pause until %motor|ready"
|
||||||
//% motor.fieldEditor="motors"
|
//% motor.fieldEditor="motors"
|
||||||
//% weight=90
|
//% weight=90 blockGap=8
|
||||||
//% group="Move"
|
//% group="Move"
|
||||||
pauseUntilReady(timeOut?: number) {
|
pauseUntilReady(timeOut?: number) {
|
||||||
pauseUntil(() => this.isReady(), timeOut);
|
pauseUntil(() => this.isReady(), timeOut);
|
||||||
@ -543,6 +567,7 @@ namespace motors {
|
|||||||
|
|
||||||
private __init() {
|
private __init() {
|
||||||
this.setOutputType(this._large);
|
this.setOutputType(this._large);
|
||||||
|
this.setInverted(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -602,6 +627,33 @@ namespace motors {
|
|||||||
toString(): string {
|
toString(): string {
|
||||||
return `${this._large ? "" : "M"}${this._portName} ${this.speed()}% ${this.angle()}>`;
|
return `${this._large ? "" : "M"}${this._portName} ${this.speed()}% ${this.angle()}>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pauses the program until the motor is stalled.
|
||||||
|
*/
|
||||||
|
//% blockId=motorPauseUntilStall block="pause until %motor|stalled"
|
||||||
|
//% motor.fieldEditor="motors"
|
||||||
|
//% weight=89
|
||||||
|
//% group="Move"
|
||||||
|
//% help=motors/motor/pause-until-stalled
|
||||||
|
pauseUntilStalled(timeOut?: number): void {
|
||||||
|
// let it start
|
||||||
|
pause(50);
|
||||||
|
let previous = this.angle();
|
||||||
|
let stall = 0;
|
||||||
|
pauseUntil(() => {
|
||||||
|
let current = this.angle();
|
||||||
|
if (Math.abs(current - previous) < 1) {
|
||||||
|
if (stall++ > 2) {
|
||||||
|
return true; // not moving
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stall = 0;
|
||||||
|
previous = current;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}, timeOut)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//% whenUsed fixedInstance block="large motor A" jres=icons.portA
|
//% whenUsed fixedInstance block="large motor A" jres=icons.portA
|
||||||
@ -695,9 +747,9 @@ namespace motors {
|
|||||||
//% help=motors/synced/steer
|
//% help=motors/synced/steer
|
||||||
steer(turnRatio: number, speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
|
steer(turnRatio: number, speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
|
||||||
this.init();
|
this.init();
|
||||||
speed = Math.clamp(-100, 100, speed >> 0);
|
speed = Math.clamp(-100, 100, speed >> 0) * this.invertedFactor();
|
||||||
if (!speed) {
|
if (!speed) {
|
||||||
stop(this._port, this._brake);
|
this.stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -706,10 +758,18 @@ namespace motors {
|
|||||||
let stepsOrTime: number;
|
let stepsOrTime: number;
|
||||||
switch (unit) {
|
switch (unit) {
|
||||||
case MoveUnit.Rotations:
|
case MoveUnit.Rotations:
|
||||||
|
if (value < 0) {
|
||||||
|
value = -value;
|
||||||
|
speed = -speed;
|
||||||
|
}
|
||||||
stepsOrTime = (value * 360) >> 0;
|
stepsOrTime = (value * 360) >> 0;
|
||||||
useSteps = true;
|
useSteps = true;
|
||||||
break;
|
break;
|
||||||
case MoveUnit.Degrees:
|
case MoveUnit.Degrees:
|
||||||
|
if (value < 0) {
|
||||||
|
value = -value;
|
||||||
|
speed = -speed;
|
||||||
|
}
|
||||||
stepsOrTime = value >> 0;
|
stepsOrTime = value >> 0;
|
||||||
useSteps = true;
|
useSteps = true;
|
||||||
break;
|
break;
|
||||||
@ -864,9 +924,3 @@ namespace motors {
|
|||||||
writePWM(b)
|
writePWM(b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface Buffer {
|
|
||||||
[index: number]: number;
|
|
||||||
// rest defined in buffer.cpp
|
|
||||||
}
|
|
236
libs/core/platform.cpp
Normal file
@ -0,0 +1,236 @@
|
|||||||
|
#include "pxt.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include "ev3const.h"
|
||||||
|
|
||||||
|
namespace pxt {
|
||||||
|
|
||||||
|
static int usbFD;
|
||||||
|
|
||||||
|
#define USB_MAGIC 0x3d3f
|
||||||
|
#define USB_SERIAL 1
|
||||||
|
#define USB_RESTART 2
|
||||||
|
#define USB_DMESG 3
|
||||||
|
|
||||||
|
struct UsbPacket {
|
||||||
|
uint16_t size;
|
||||||
|
uint16_t msgcount;
|
||||||
|
uint16_t magic;
|
||||||
|
uint16_t code;
|
||||||
|
char buf[1024 - 8];
|
||||||
|
};
|
||||||
|
|
||||||
|
void *usbThread(void *) {
|
||||||
|
UsbPacket pkt;
|
||||||
|
UsbPacket resp;
|
||||||
|
while (true) {
|
||||||
|
int len = read(usbFD, &pkt, sizeof(pkt));
|
||||||
|
if (len <= 4) {
|
||||||
|
sleep_core_us(20000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
resp.msgcount = pkt.msgcount;
|
||||||
|
if (pkt.magic == USB_MAGIC) {
|
||||||
|
if (pkt.code == USB_RESTART) {
|
||||||
|
target_reset();
|
||||||
|
} else if (pkt.code == USB_DMESG) {
|
||||||
|
dumpDmesg();
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
resp.magic = pkt.magic;
|
||||||
|
resp.code = pkt.code;
|
||||||
|
resp.size = 8;
|
||||||
|
write(usbFD, &resp, sizeof(resp));
|
||||||
|
*/
|
||||||
|
} else {
|
||||||
|
resp.magic = 0xffff;
|
||||||
|
resp.size = 4;
|
||||||
|
write(usbFD, &resp, sizeof(resp));
|
||||||
|
}
|
||||||
|
sleep_core_us(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void startUsb() {
|
||||||
|
usbFD = open("/dev/lms_usbdev", O_RDWR, 0666);
|
||||||
|
pthread_t pid;
|
||||||
|
pthread_create(&pid, NULL, usbThread, NULL);
|
||||||
|
pthread_detach(pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *exitThread(void *) {
|
||||||
|
int fd = open("/dev/lms_ui", O_RDWR, 0666);
|
||||||
|
if (fd < 0)
|
||||||
|
return 0;
|
||||||
|
uint8_t *data =
|
||||||
|
(uint8_t *)mmap(NULL, NUM_BUTTONS, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
|
if (data == MAP_FAILED) {
|
||||||
|
close(fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
for (;;) {
|
||||||
|
if (data[5])
|
||||||
|
target_reset();
|
||||||
|
sleep_core_us(50000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void startExitThread() {
|
||||||
|
pthread_t pid;
|
||||||
|
pthread_create(&pid, NULL, exitThread, NULL);
|
||||||
|
pthread_detach(pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendUsb(uint16_t code, const char *data, int len) {
|
||||||
|
while (len > 0) {
|
||||||
|
int sz = len;
|
||||||
|
if (sz > 1000)
|
||||||
|
sz = 1000;
|
||||||
|
UsbPacket pkt = {(uint16_t)(6 + sz), 0, USB_MAGIC, code, {}};
|
||||||
|
memcpy(pkt.buf, data, sz);
|
||||||
|
write(usbFD, &pkt, sizeof(pkt));
|
||||||
|
len -= sz;
|
||||||
|
data += sz;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendSerial(const char *data, int len) {
|
||||||
|
sendUsb(USB_SERIAL, data, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lmsPid;
|
||||||
|
void stopLMS() {
|
||||||
|
struct dirent *ent;
|
||||||
|
DIR *dir;
|
||||||
|
|
||||||
|
dir = opendir("/proc");
|
||||||
|
if (dir == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while ((ent = readdir(dir)) != NULL) {
|
||||||
|
int pid = atoi(ent->d_name);
|
||||||
|
if (!pid)
|
||||||
|
continue;
|
||||||
|
char namebuf[100];
|
||||||
|
snprintf(namebuf, 100, "/proc/%d/cmdline", pid);
|
||||||
|
FILE *f = fopen(namebuf, "r");
|
||||||
|
if (f) {
|
||||||
|
fread(namebuf, 1, 99, f);
|
||||||
|
if (strcmp(namebuf, "./lms2012") == 0) {
|
||||||
|
lmsPid = pid;
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
if (lmsPid)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
|
||||||
|
lmsPid = 0; // disable SIGSTOP for now - rethink if problems with I2C (runs on a thread)
|
||||||
|
|
||||||
|
if (lmsPid) {
|
||||||
|
DMESG("SIGSTOP to lmsPID=%d", lmsPid);
|
||||||
|
if (kill(lmsPid, SIGSTOP))
|
||||||
|
DMESG("SIGSTOP failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void runLMS() {
|
||||||
|
DMESG("re-starting LMS2012");
|
||||||
|
kill(lmsPid, SIGCONT);
|
||||||
|
sleep_core_us(200000);
|
||||||
|
exit(0);
|
||||||
|
/*
|
||||||
|
chdir("/home/root/lms2012/sys");
|
||||||
|
for (int fd = 3; fd < 9999; ++fd)
|
||||||
|
close(fd);
|
||||||
|
execl("lms2012", "./lms2012");
|
||||||
|
exit(100); // should not be reached
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopMotors() {
|
||||||
|
uint8_t cmd[3] = {opOutputStop, 0x0F, 0};
|
||||||
|
int fd = open("/dev/lms_pwm", O_RDWR);
|
||||||
|
write(fd, cmd, 3);
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopProgram() {
|
||||||
|
uint8_t cmd[1] = {opOutputProgramStop};
|
||||||
|
int fd = open("/dev/lms_pwm", O_RDWR);
|
||||||
|
write(fd, cmd, 1);
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void target_reset() {
|
||||||
|
tryLockUser();
|
||||||
|
stopMotors();
|
||||||
|
stopProgram();
|
||||||
|
if (lmsPid)
|
||||||
|
runLMS();
|
||||||
|
else
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void target_exit() {
|
||||||
|
target_reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void target_startup() {
|
||||||
|
stopLMS();
|
||||||
|
startUsb();
|
||||||
|
startExitThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
void initKeys() {}
|
||||||
|
|
||||||
|
static const char *progPath = "/mnt/ramdisk/prjs/BrkProg_SAVE";
|
||||||
|
|
||||||
|
// These are disabled except when building File_manager.pdf
|
||||||
|
// %
|
||||||
|
void deletePrjFile(String filename) {
|
||||||
|
const char *d = filename->getUTF8Data();
|
||||||
|
if (strlen(d) > 500 || strchr(d, '/'))
|
||||||
|
return;
|
||||||
|
char buf[1024];
|
||||||
|
snprintf(buf, sizeof(buf), "%s/%s", progPath, d);
|
||||||
|
unlink(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
// %
|
||||||
|
RefCollection *listPrjFiles() {
|
||||||
|
auto res = Array_::mk();
|
||||||
|
registerGCObj(res);
|
||||||
|
|
||||||
|
auto dp = opendir(progPath);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
dirent *ep = dp ? readdir(dp) : NULL;
|
||||||
|
if (!ep)
|
||||||
|
break;
|
||||||
|
if (ep->d_name[0] == '.')
|
||||||
|
continue;
|
||||||
|
auto str = mkString(ep->d_name, -1);
|
||||||
|
registerGCObj(str);
|
||||||
|
res->head.push((TValue)str);
|
||||||
|
unregisterGCObj(str);
|
||||||
|
}
|
||||||
|
if (dp)
|
||||||
|
closedir(dp);
|
||||||
|
unregisterGCObj(res);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1 +1,3 @@
|
|||||||
// leave empty
|
#define PXT_GC_THREAD_LIST 1
|
||||||
|
|
||||||
|
#define PXT_IN_ISR() false
|
||||||
|
@ -11,6 +11,7 @@ int allocateNotifyEvent();
|
|||||||
void sleep_core_us(uint64_t us);
|
void sleep_core_us(uint64_t us);
|
||||||
void startUser();
|
void startUser();
|
||||||
void stopUser();
|
void stopUser();
|
||||||
|
int tryLockUser();
|
||||||
|
|
||||||
class Button;
|
class Button;
|
||||||
typedef Button *Button_;
|
typedef Button *Button_;
|
||||||
@ -27,9 +28,13 @@ class MMap : public RefObject {
|
|||||||
MMap();
|
MMap();
|
||||||
void destroy();
|
void destroy();
|
||||||
void print();
|
void print();
|
||||||
|
|
||||||
|
static void scan(MMap *);
|
||||||
|
static unsigned gcsize(MMap *);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern volatile bool paniced;
|
extern volatile bool paniced;
|
||||||
|
void target_exit();
|
||||||
|
|
||||||
// Buffer, Sound, and Image share representation.
|
// Buffer, Sound, and Image share representation.
|
||||||
typedef Buffer Sound;
|
typedef Buffer Sound;
|
||||||
|
@ -25,11 +25,20 @@
|
|||||||
"dal.d.ts",
|
"dal.d.ts",
|
||||||
"icons.jres",
|
"icons.jres",
|
||||||
"ns.ts",
|
"ns.ts",
|
||||||
"platform.h"
|
"platform.h",
|
||||||
|
"platform.cpp",
|
||||||
|
"dmesg.cpp",
|
||||||
|
"integrator.ts"
|
||||||
],
|
],
|
||||||
"testFiles": [
|
"testFiles": [
|
||||||
"test.ts"
|
"test.ts"
|
||||||
],
|
],
|
||||||
|
"dalDTS": {
|
||||||
|
"includeDirs": [
|
||||||
|
"pxtapp"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"additionalFilePath": "../../node_modules/pxt-common-packages/libs/core---linux",
|
||||||
"npmDependencies": {},
|
"npmDependencies": {},
|
||||||
"public": true,
|
"public": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
#ifndef __PXTCORE_H
|
|
||||||
#define __PXTCORE_H
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
namespace pxt {
|
|
||||||
void dmesg(const char *fmt, ...);
|
|
||||||
#define DMESG pxt::dmesg
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void itoa(int v, char *dst) {
|
|
||||||
|
|
||||||
snprintf(dst, 30, "%d", v);
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -85,10 +85,9 @@ void updateScreen(Image_ img) {
|
|||||||
lastImg = img;
|
lastImg = img;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastImg && lastImg->isDirty() && mappedFrameBuffer != MAP_FAILED) {
|
if (lastImg && mappedFrameBuffer != MAP_FAILED) {
|
||||||
if (lastImg->bpp() != 1 || lastImg->width() != LCD_WIDTH || lastImg->height() != LCD_HEIGHT)
|
if (lastImg->bpp() != 1 || lastImg->width() != LCD_WIDTH || lastImg->height() != LCD_HEIGHT)
|
||||||
target_panic(906);
|
target_panic(906);
|
||||||
lastImg->clearDirty();
|
|
||||||
bitBufferToFrameBufferSwap(lastImg->pix(), mappedFrameBuffer);
|
bitBufferToFrameBufferSwap(lastImg->pix(), mappedFrameBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ struct hci_dev_list_req {
|
|||||||
hci_dev_req dev_req[2];
|
hci_dev_req dev_req[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint32_t bt_addr() {
|
static uint64_t bt_addr() {
|
||||||
uint32_t res = -1;
|
uint64_t res = -1;
|
||||||
|
|
||||||
int fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
|
int fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
@ -50,11 +50,8 @@ static uint32_t bt_addr() {
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&res, di.bdaddr, 4);
|
res = 0;
|
||||||
res *= 0x1000193;
|
memcpy(&res, di.bdaddr, 6);
|
||||||
res += di.bdaddr[4];
|
|
||||||
res *= 0x1000193;
|
|
||||||
res += di.bdaddr[5];
|
|
||||||
|
|
||||||
done:
|
done:
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -63,14 +60,10 @@ done:
|
|||||||
|
|
||||||
namespace pxt {
|
namespace pxt {
|
||||||
|
|
||||||
int getSerialNumber() {
|
uint64_t getLongSerialNumber() {
|
||||||
static int serial;
|
static uint64_t serial;
|
||||||
|
if (serial == 0)
|
||||||
if (serial != 0)
|
serial = bt_addr();
|
||||||
return serial;
|
|
||||||
|
|
||||||
serial = bt_addr() & 0x7fffffff;
|
|
||||||
|
|
||||||
return serial;
|
return serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
libs/core/shims.d.ts
vendored
@ -68,6 +68,12 @@ declare namespace control {
|
|||||||
/** Write data to DMESG debugging buffer. */
|
/** Write data to DMESG debugging buffer. */
|
||||||
//% shim=control::dmesg
|
//% shim=control::dmesg
|
||||||
function dmesg(s: string): void;
|
function dmesg(s: string): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the USB has been enumerated.
|
||||||
|
*/
|
||||||
|
//% shim=control::isUSBInitialized
|
||||||
|
function isUSBInitialized(): boolean;
|
||||||
}
|
}
|
||||||
declare namespace serial {
|
declare namespace serial {
|
||||||
|
|
||||||
|
13
libs/ev3/brick.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
namespace brick {
|
||||||
|
/**
|
||||||
|
* Exits the program to the main menu. (in the simulator restarts it)
|
||||||
|
*/
|
||||||
|
//% blockId=loopstop block="exit program"
|
||||||
|
//% help=reference/brick/exit-program
|
||||||
|
//% weight=10
|
||||||
|
//% blockGap=8
|
||||||
|
//% group="Buttons"
|
||||||
|
export function exitProgram() {
|
||||||
|
control.reset();
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@ namespace console._screen {
|
|||||||
console.addListener(log);
|
console.addListener(log);
|
||||||
brick.buttonUp.onEvent(ButtonEvent.Bumped, () => scroll(-3))
|
brick.buttonUp.onEvent(ButtonEvent.Bumped, () => scroll(-3))
|
||||||
brick.buttonDown.onEvent(ButtonEvent.Bumped, () => scroll(3))
|
brick.buttonDown.onEvent(ButtonEvent.Bumped, () => scroll(3))
|
||||||
|
brick.showConsole();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ namespace console._screen {
|
|||||||
printLog();
|
printLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
function log(msg: string): void {
|
function log(priority: ConsolePriority, msg: string): void {
|
||||||
lines.push(msg);
|
lines.push(msg);
|
||||||
if (lines.length + 5 > maxLines) {
|
if (lines.length + 5 > maxLines) {
|
||||||
lines.splice(0, maxLines - lines.length);
|
lines.splice(0, maxLines - lines.length);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
//% color="#68C3E2" weight=100 icon="\uf106"
|
//% color="#68C3E2" weight=100 icon="\uf106"
|
||||||
//% groups='["Buttons", "Screen", "Battery"]'
|
//% groups='["Buttons", "Screen", "Power"]'
|
||||||
//% labelLineWidth=60
|
//% labelLineWidth=60
|
||||||
namespace brick {
|
namespace brick {
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
"files": [
|
"files": [
|
||||||
"README.md",
|
"README.md",
|
||||||
"ns.ts",
|
"ns.ts",
|
||||||
|
"brick.ts",
|
||||||
"startup.ts",
|
"startup.ts",
|
||||||
"images.jres",
|
"images.jres",
|
||||||
"images.ts",
|
"images.ts",
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
// This is the last thing executed before user code
|
// This is the last thing executed before user code
|
||||||
console.addListener(function(msg: string) {
|
console.addListener(function(priority: ConsolePriority, msg: string) {
|
||||||
control.dmesg(msg.substr(0, msg.length - 1))
|
control.dmesg(msg.substr(0, msg.length - 1))
|
||||||
})
|
})
|
||||||
// pulse green, play startup sound, turn off light
|
// boot sequence
|
||||||
brick.setStatusLight(StatusLight.GreenPulse);
|
brick.showBoot();
|
||||||
// We pause for 100ms to give time to read sensor values, so they work in on_start block
|
|
||||||
pause(400)
|
|
||||||
// and we're ready
|
|
||||||
brick.setStatusLight(StatusLight.Off);
|
|
@ -1,6 +1,6 @@
|
|||||||
# calibrate
|
# calibrate
|
||||||
|
|
||||||
Reset the zero reference for the gyro to current position of the brick.
|
Detects if the gyro is drifting and performs a full reset if needed.
|
||||||
|
|
||||||
```sig
|
```sig
|
||||||
sensors.gyro2.calibrate()
|
sensors.gyro2.calibrate()
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
# compute Drift
|
||||||
|
|
||||||
|
Called when the sensor is completely still, computes the current rate drift
|
||||||
|
```sig
|
||||||
|
sensors.gyro2.computeDrift()
|
||||||
|
```
|
||||||
|
|
||||||
|
The gyroscope sensor is subject to rate drifting. This means that the measurement reported by the sensor is off by a few degrees per second over time: it is drifting.
|
||||||
|
|
||||||
|
To counter the effect of drifting, call the ``||sensors:compute drift||`` block when the sensor is still to compute the current drift. The rate meansurements will automatically be corrected based on that drift.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
This example uses a gyro sensor to
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let error = 0
|
||||||
|
sensors.gyro2.computeDrift()
|
||||||
|
while (sensors.color3.color() != ColorSensorColor.White) {
|
||||||
|
error = sensors.gyro2.rate() * -1
|
||||||
|
motors.largeBC.steer(error, 50)
|
||||||
|
}
|
||||||
|
motors.stopAll()
|
||||||
|
pause(1000)
|
||||||
|
sensors.gyro2.computeDrift()
|
||||||
|
while (sensors.color3.color() != ColorSensorColor.Blue) {
|
||||||
|
error = sensors.gyro2.rate() * -1
|
||||||
|
motors.largeBC.steer(error, 50)
|
||||||
|
}
|
||||||
|
motors.stopAll()
|
||||||
|
```
|
||||||
|
|
||||||
|
## See Also
|
||||||
|
|
||||||
|
[rate](/reference/sensors/gyro/rate),
|
||||||
|
[compute drift](/reference/sensors/gyro/compute-drift)
|
||||||
|
|
39
libs/gyro-sensor/docs/reference/sensors/gyro/drift.md
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# drift
|
||||||
|
|
||||||
|
Get the computed rate drift
|
||||||
|
|
||||||
|
```sig
|
||||||
|
sensors.gyro2.drift()
|
||||||
|
```
|
||||||
|
|
||||||
|
The gyroscope sensor is subject to rate drifting. This means that the measurement reported by the sensor is off by a few degrees per second over time: it is drifting.
|
||||||
|
|
||||||
|
To counter the effect of drifting, call the ``||sensors:compute drift||`` block when the sensor is still to compute the current drift. The rate meansurements will automatically be corrected based on that drift.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
This example uses a gyro sensor to drive straight until while color is detected.
|
||||||
|
The robot is stopped, the drift is computed and another movement is done.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let error = 0
|
||||||
|
sensors.gyro2.computeDrift()
|
||||||
|
while (sensors.color3.color() != ColorSensorColor.White) {
|
||||||
|
error = sensors.gyro2.rate() * -1
|
||||||
|
motors.largeBC.steer(error, 50)
|
||||||
|
}
|
||||||
|
motors.stopAll()
|
||||||
|
pause(1000)
|
||||||
|
sensors.gyro2.computeDrift()
|
||||||
|
while (sensors.color3.color() != ColorSensorColor.Blue) {
|
||||||
|
error = sensors.gyro2.rate() * -1
|
||||||
|
motors.largeBC.steer(error, 50)
|
||||||
|
}
|
||||||
|
motors.stopAll()
|
||||||
|
```
|
||||||
|
|
||||||
|
## See Also
|
||||||
|
|
||||||
|
[rate](/reference/sensors/gyro/rate),
|
||||||
|
[compute drift](/reference/sensors/gyro/compute-drift)
|
||||||
|
|
@ -0,0 +1,21 @@
|
|||||||
|
# Pause Until Rotated
|
||||||
|
|
||||||
|
Pauses the program until the gyro sensors detect that the desired amount of rotation
|
||||||
|
has been acheived.
|
||||||
|
|
||||||
|
```
|
||||||
|
sensors.gyro2.pauseUntilRotated(90)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
This program performs a square turn left, then right.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
sensors.gyro2.calibrate()
|
||||||
|
motors.largeBC.steer(200, 10)
|
||||||
|
sensors.gyro2.pauseUntilRotated(90)
|
||||||
|
motors.largeBC.steer(-200, 10)
|
||||||
|
sensors.gyro2.pauseUntilRotated(-90)
|
||||||
|
motors.largeBC.stop()
|
||||||
|
```
|
@ -7,14 +7,15 @@ const enum GyroSensorMode {
|
|||||||
namespace sensors {
|
namespace sensors {
|
||||||
//% fixedInstances
|
//% fixedInstances
|
||||||
export class GyroSensor extends internal.UartSensor {
|
export class GyroSensor extends internal.UartSensor {
|
||||||
private calibrating: boolean;
|
private _calibrating: boolean;
|
||||||
private _drift: number;
|
private _drift: number;
|
||||||
private _driftCorrection: boolean;
|
private _angle: control.EulerIntegrator;
|
||||||
constructor(port: number) {
|
constructor(port: number) {
|
||||||
super(port)
|
super(port)
|
||||||
this.calibrating = false;
|
this._calibrating = false;
|
||||||
this._drift = 0;
|
this._drift = 0;
|
||||||
this._driftCorrection = false;
|
this._angle = new control.EulerIntegrator();
|
||||||
|
this._setMode(GyroSensorMode.Rate);
|
||||||
this.setMode(GyroSensorMode.Rate);
|
this.setMode(GyroSensorMode.Rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,13 +24,17 @@ namespace sensors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_query(): number {
|
_query(): number {
|
||||||
return this.getNumber(NumberFormat.Int16LE, 0);
|
const v = this.getNumber(NumberFormat.Int16LE, 0);
|
||||||
|
this._angle.integrate(v - this._drift);
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
setMode(m: GyroSensorMode) {
|
setMode(m: GyroSensorMode) {
|
||||||
if (m == GyroSensorMode.Rate && this.mode != m)
|
// decrecated
|
||||||
this._drift = 0;
|
}
|
||||||
this._setMode(m)
|
|
||||||
|
isCalibrating(): boolean {
|
||||||
|
return this._calibrating;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,11 +50,11 @@ namespace sensors {
|
|||||||
//% weight=64 blockGap=8
|
//% weight=64 blockGap=8
|
||||||
//% group="Gyro Sensor"
|
//% group="Gyro Sensor"
|
||||||
angle(): number {
|
angle(): number {
|
||||||
if (this.calibrating)
|
this.poke();
|
||||||
pauseUntil(() => !this.calibrating, 2000);
|
if (this._calibrating)
|
||||||
|
pauseUntil(() => !this._calibrating, 2000);
|
||||||
|
|
||||||
this.setMode(GyroSensorMode.Angle);
|
return Math.round(this._angle.value);
|
||||||
return this._query();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,21 +70,14 @@ namespace sensors {
|
|||||||
//% weight=65 blockGap=8
|
//% weight=65 blockGap=8
|
||||||
//% group="Gyro Sensor"
|
//% group="Gyro Sensor"
|
||||||
rate(): number {
|
rate(): number {
|
||||||
if (this.calibrating)
|
this.poke();
|
||||||
pauseUntil(() => !this.calibrating, 2000);
|
if (this._calibrating)
|
||||||
|
pauseUntil(() => !this._calibrating, 2000);
|
||||||
this.setMode(GyroSensorMode.Rate);
|
return this._query() - this._drift;
|
||||||
let curr = this._query();
|
|
||||||
if (Math.abs(curr) < 4 && this._driftCorrection) {
|
|
||||||
const p = 0.01;
|
|
||||||
this._drift = (1 - p) * this._drift + p * curr;
|
|
||||||
curr = Math.round(curr - this._drift);
|
|
||||||
}
|
|
||||||
return curr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forces a calibration of the with light progress indicators.
|
* Detects if calibration is necessary and performs a full reset, drift computation.
|
||||||
* Must be called when the sensor is completely still.
|
* Must be called when the sensor is completely still.
|
||||||
*/
|
*/
|
||||||
//% help=sensors/gyro/calibrate
|
//% help=sensors/gyro/calibrate
|
||||||
@ -91,16 +89,30 @@ namespace sensors {
|
|||||||
//% weight=51 blockGap=8
|
//% weight=51 blockGap=8
|
||||||
//% group="Gyro Sensor"
|
//% group="Gyro Sensor"
|
||||||
calibrate(): void {
|
calibrate(): void {
|
||||||
if (this.calibrating) return; // already in calibration mode
|
if (this._calibrating) return; // already in calibration mode
|
||||||
|
|
||||||
const statusLight = brick.statusLight(); // save current status light
|
const statusLight = brick.statusLight(); // save current status light
|
||||||
brick.setStatusLight(StatusLight.Orange);
|
brick.setStatusLight(StatusLight.Orange);
|
||||||
|
|
||||||
this.calibrating = true;
|
this._calibrating = true;
|
||||||
// may be triggered by a button click,
|
// may be triggered by a button click,
|
||||||
// give time for robot to settle
|
// give time for robot to settle
|
||||||
pause(700);
|
pause(700);
|
||||||
|
|
||||||
|
// compute drift
|
||||||
|
this.computeDriftNoCalibration();
|
||||||
|
if (Math.abs(this.drift()) < 0.1) {
|
||||||
|
// no drift, skipping calibration
|
||||||
|
brick.setStatusLight(StatusLight.Green); // success
|
||||||
|
pause(1000);
|
||||||
|
brick.setStatusLight(statusLight); // resture previous light
|
||||||
|
|
||||||
|
// and we're done
|
||||||
|
this._angle.reset();
|
||||||
|
this._calibrating = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// calibrating
|
// calibrating
|
||||||
brick.setStatusLight(StatusLight.OrangePulse);
|
brick.setStatusLight(StatusLight.OrangePulse);
|
||||||
|
|
||||||
@ -109,37 +121,31 @@ namespace sensors {
|
|||||||
// wait till sensor is live
|
// wait till sensor is live
|
||||||
pauseUntil(() => this.isActive(), 7000);
|
pauseUntil(() => this.isActive(), 7000);
|
||||||
// mode toggling
|
// mode toggling
|
||||||
this.setMode(GyroSensorMode.Rate);
|
this._setMode(GyroSensorMode.Rate);
|
||||||
this.setMode(GyroSensorMode.Angle);
|
this._setMode(GyroSensorMode.Angle);
|
||||||
// switch back to the desired mode
|
this._setMode(GyroSensorMode.Rate);
|
||||||
this.setMode(this.mode);
|
|
||||||
|
|
||||||
// check sensor is ready
|
// check sensor is ready
|
||||||
if (!this.isActive()) {
|
if (!this.isActive()) {
|
||||||
brick.setStatusLight(StatusLight.RedFlash); // didn't work
|
brick.setStatusLight(StatusLight.RedFlash); // didn't work
|
||||||
pause(2000);
|
pause(2000);
|
||||||
brick.setStatusLight(statusLight); // restore previous light
|
brick.setStatusLight(statusLight); // restore previous light
|
||||||
this.calibrating = false;
|
this._angle.reset();
|
||||||
|
this._calibrating = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute drift
|
// switch to rate mode
|
||||||
this._drift = 0;
|
this.computeDriftNoCalibration();
|
||||||
if (this._driftCorrection && this.mode == GyroSensorMode.Rate) {
|
|
||||||
const n = 100;
|
|
||||||
for (let i = 0; i < n; ++i) {
|
|
||||||
this._drift += this._query();
|
|
||||||
pause(4);
|
|
||||||
}
|
|
||||||
this._drift /= n;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// and done
|
||||||
brick.setStatusLight(StatusLight.Green); // success
|
brick.setStatusLight(StatusLight.Green); // success
|
||||||
pause(1000);
|
pause(1000);
|
||||||
brick.setStatusLight(statusLight); // resture previous light
|
brick.setStatusLight(statusLight); // resture previous light
|
||||||
|
|
||||||
// and we're done
|
// and we're done
|
||||||
this.calibrating = false;
|
this._angle.reset();
|
||||||
|
this._calibrating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -151,34 +157,117 @@ namespace sensors {
|
|||||||
//% parts="gyroscope"
|
//% parts="gyroscope"
|
||||||
//% blockNamespace=sensors
|
//% blockNamespace=sensors
|
||||||
//% this.fieldEditor="ports"
|
//% this.fieldEditor="ports"
|
||||||
//% weight=50
|
//% weight=50 blockGap=8
|
||||||
//% group="Gyro Sensor"
|
//% group="Gyro Sensor"
|
||||||
reset(): void {
|
reset(): void {
|
||||||
if (this.calibrating) return; // already in calibration mode
|
if (this._calibrating) return; // already in calibration mode
|
||||||
|
|
||||||
|
this._calibrating = true;
|
||||||
|
const statusLight = brick.statusLight(); // save current status light
|
||||||
|
brick.setStatusLight(StatusLight.Orange);
|
||||||
|
|
||||||
this.calibrating = true;
|
|
||||||
// send a reset command
|
// send a reset command
|
||||||
super.reset();
|
super.reset();
|
||||||
|
this._drift = 0;
|
||||||
|
this._angle.reset();
|
||||||
|
pauseUntil(() => this.isActive(), 7000);
|
||||||
|
|
||||||
|
// check sensor is ready
|
||||||
|
if (!this.isActive()) {
|
||||||
|
brick.setStatusLight(StatusLight.RedFlash); // didn't work
|
||||||
|
pause(2000);
|
||||||
|
brick.setStatusLight(statusLight); // restore previous light
|
||||||
|
this._angle.reset();
|
||||||
|
this._calibrating = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._setMode(GyroSensorMode.Rate);
|
||||||
|
|
||||||
// and done
|
// and done
|
||||||
this.calibrating = false;
|
brick.setStatusLight(StatusLight.Green); // success
|
||||||
|
pause(1000);
|
||||||
|
brick.setStatusLight(statusLight); // resture previous light
|
||||||
|
// and done
|
||||||
|
this._angle.reset();
|
||||||
|
this._calibrating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the computed rate drift
|
* Gets the computed rate drift
|
||||||
*/
|
*/
|
||||||
//%
|
//% help=sensors/gyro/drift
|
||||||
|
//% block="**gyro** %this|drift"
|
||||||
|
//% blockId=gyroDrift
|
||||||
|
//% parts="gyroscope"
|
||||||
|
//% blockNamespace=sensors
|
||||||
|
//% this.fieldEditor="ports"
|
||||||
|
//% weight=9 blockGap=8
|
||||||
|
//% group="Gyro Sensor"
|
||||||
drift(): number {
|
drift(): number {
|
||||||
return this._drift;
|
return this._drift;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disable drift correction
|
* Computes the current sensor drift when using rate measurements.
|
||||||
* @param enabled
|
|
||||||
*/
|
*/
|
||||||
//%
|
//% help=sensors/gyro/compute-drift
|
||||||
setDriftCorrection(enabled: boolean) {
|
//% block="compute **gyro** %this|drift"
|
||||||
this._driftCorrection = enabled;
|
//% blockId=gyroComputeDrift
|
||||||
|
//% parts="gyroscope"
|
||||||
|
//% blockNamespace=sensors
|
||||||
|
//% this.fieldEditor="ports"
|
||||||
|
//% weight=10 blockGap=8
|
||||||
|
//% group="Gyro Sensor"
|
||||||
|
computeDrift() {
|
||||||
|
if (this._calibrating)
|
||||||
|
pauseUntil(() => !this._calibrating, 2000);
|
||||||
|
pause(1000); // let the robot settle
|
||||||
|
this.computeDriftNoCalibration();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pauses the program until the gyro detected
|
||||||
|
* that the angle changed by the desired amount of degrees.
|
||||||
|
* @param degrees the degrees to turn
|
||||||
|
*/
|
||||||
|
//% help=sensors/gyro/pause-until-rotated
|
||||||
|
//% block="pause until **gyro** %this|rotated %degrees=rotationPicker|degrees"
|
||||||
|
//% blockId=gyroPauseUntilRotated
|
||||||
|
//% parts="gyroscope"
|
||||||
|
//% blockNamespace=sensors
|
||||||
|
//% this.fieldEditor="ports"
|
||||||
|
//% degrees.defl=90
|
||||||
|
//% weight=63
|
||||||
|
//% group="Gyro Sensor"
|
||||||
|
pauseUntilRotated(degrees: number, timeOut?: number): void {
|
||||||
|
let a = this.angle();
|
||||||
|
const end = a + degrees;
|
||||||
|
const direction = (end - a) > 0 ? 1 : -1;
|
||||||
|
pauseUntil(() => (end - this.angle()) * direction <= 0, timeOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
private computeDriftNoCalibration() {
|
||||||
|
// clear drift
|
||||||
this._drift = 0;
|
this._drift = 0;
|
||||||
|
const n = 10;
|
||||||
|
let d = 0;
|
||||||
|
for (let i = 0; i < n; ++i) {
|
||||||
|
d += this._query();
|
||||||
|
pause(20);
|
||||||
|
}
|
||||||
|
this._drift = d / n;
|
||||||
|
this._angle.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
_info(): string {
|
||||||
|
if (this._calibrating)
|
||||||
|
return "cal...";
|
||||||
|
|
||||||
|
let r = `${this._query()}r`;
|
||||||
|
if (this._drift != 0)
|
||||||
|
r += `-${this._drift | 0}`;
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,4 +282,17 @@ namespace sensors {
|
|||||||
|
|
||||||
//% fixedInstance whenUsed block="4" jres=icons.port4
|
//% fixedInstance whenUsed block="4" jres=icons.port4
|
||||||
export const gyro4: GyroSensor = new GyroSensor(4)
|
export const gyro4: GyroSensor = new GyroSensor(4)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the rotation angle field editor
|
||||||
|
* @param degrees angle in degrees, eg: 90
|
||||||
|
*/
|
||||||
|
//% blockId=rotationPicker block="%degrees"
|
||||||
|
//% blockHidden=true shim=TD_ID
|
||||||
|
//% colorSecondary="#FFFFFF"
|
||||||
|
//% degrees.fieldEditor="numberdropdown" degrees.fieldOptions.decompileLiterals=true
|
||||||
|
//% degrees.fieldOptions.data='[["30", 30], ["45", 45], ["60", 60], ["90", 90], ["180", 180], ["-30", -30], ["-45", -45], ["-60", -60], ["-90", -90], ["-180", -180]]'
|
||||||
|
export function __rotationPicker(degrees: number): number {
|
||||||
|
return degrees;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,6 +235,7 @@ namespace sensors {
|
|||||||
//% group="Infrared Sensor"
|
//% group="Infrared Sensor"
|
||||||
//% this.fieldEditor="ports"
|
//% this.fieldEditor="ports"
|
||||||
proximity(): number {
|
proximity(): number {
|
||||||
|
this.poke();
|
||||||
this._setMode(InfraredSensorMode.Proximity)
|
this._setMode(InfraredSensorMode.Proximity)
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
}
|
}
|
||||||
@ -284,6 +285,7 @@ namespace sensors {
|
|||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
private getDirectionAndDistance() {
|
private getDirectionAndDistance() {
|
||||||
|
this.poke();
|
||||||
this._setMode(InfraredSensorMode.Seek)
|
this._setMode(InfraredSensorMode.Seek)
|
||||||
return this.getNumber(NumberFormat.UInt16LE, this._channel * 2)
|
return this.getNumber(NumberFormat.UInt16LE, this._channel * 2)
|
||||||
}
|
}
|
||||||
|
10
libs/screen/screenimage.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
namespace image {
|
||||||
|
/**
|
||||||
|
* Get the screen image
|
||||||
|
*/
|
||||||
|
//%
|
||||||
|
export function screenImage(): Image {
|
||||||
|
return screen;
|
||||||
|
}
|
||||||
|
}
|
14
libs/screen/shims.d.ts
vendored
@ -15,7 +15,7 @@ declare interface Image {
|
|||||||
height: int32;
|
height: int32;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True iff the image is monochromatic (black and white)
|
* True if the image is monochromatic (black and white)
|
||||||
*/
|
*/
|
||||||
//% property shim=ImageMethods::isMono
|
//% property shim=ImageMethods::isMono
|
||||||
isMono: boolean;
|
isMono: boolean;
|
||||||
@ -45,6 +45,18 @@ declare interface Image {
|
|||||||
//% shim=ImageMethods::fill
|
//% shim=ImageMethods::fill
|
||||||
fill(c: int32): void;
|
fill(c: int32): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy row(s) of pixel from image to buffer (8 bit per pixel).
|
||||||
|
*/
|
||||||
|
//% shim=ImageMethods::getRows
|
||||||
|
getRows(x: int32, dst: Buffer): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy row(s) of pixel from buffer to image.
|
||||||
|
*/
|
||||||
|
//% shim=ImageMethods::setRows
|
||||||
|
setRows(x: int32, src: Buffer): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a copy of the current image
|
* Return a copy of the current image
|
||||||
*/
|
*/
|
||||||
|
@ -26,6 +26,8 @@ namespace brick {
|
|||||||
None,
|
None,
|
||||||
ShowLines,
|
ShowLines,
|
||||||
Image,
|
Image,
|
||||||
|
Ports,
|
||||||
|
Console,
|
||||||
Custom
|
Custom
|
||||||
}
|
}
|
||||||
let screenMode = ScreenMode.None;
|
let screenMode = ScreenMode.None;
|
||||||
@ -124,42 +126,84 @@ namespace brick {
|
|||||||
//% help=brick/show-ports blockGap=8
|
//% help=brick/show-ports blockGap=8
|
||||||
//% weight=10 group="Screen"
|
//% weight=10 group="Screen"
|
||||||
export function showPorts() {
|
export function showPorts() {
|
||||||
screenMode = ScreenMode.Custom;
|
if (screenMode == ScreenMode.Ports) return;
|
||||||
|
|
||||||
|
screenMode = ScreenMode.Ports;
|
||||||
|
renderPorts();
|
||||||
|
control.runInParallel(function () {
|
||||||
|
while (screenMode == ScreenMode.Ports) {
|
||||||
|
renderPorts();
|
||||||
|
pause(50);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderPorts() {
|
||||||
const col = 44;
|
const col = 44;
|
||||||
const lineHeight8 = image.font8.charHeight + 2;
|
const lineHeight8 = image.font8.charHeight + 2;
|
||||||
|
const h = screen.height;
|
||||||
|
|
||||||
clearScreen();
|
clearScreen();
|
||||||
|
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
const x = i * col + 2;
|
||||||
|
screen.print("ABCD"[i], x, 1 * lineHeight8, 1, image.font8)
|
||||||
|
screen.print((i + 1).toString(), x, h - lineHeight8, 1, image.font8)
|
||||||
|
}
|
||||||
|
screen.drawLine(0, 5 * lineHeight8, screen.width, 5 * lineHeight8, 1);
|
||||||
|
screen.drawLine(0, h - 5 * lineHeight8, screen.width, h - 5 * lineHeight8, 1)
|
||||||
|
|
||||||
function scale(x: number) {
|
function scale(x: number) {
|
||||||
if (Math.abs(x) > 1000) return Math.round(x / 100) / 10 + "k";
|
if (Math.abs(x) >= 5000) {
|
||||||
return ("" + (x >> 0));
|
const k = Math.floor(x / 1000);
|
||||||
|
const r = Math.round((x - 1000 * k) / 100);
|
||||||
|
return `${k}.${r}k`
|
||||||
|
}
|
||||||
|
return ("" + (x || 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// motors
|
// motors
|
||||||
const datas = motors.getAllMotorData();
|
const datas = motors.getAllMotorData();
|
||||||
for (let i = 0; i < datas.length; ++i) {
|
for (let i = 0; i < datas.length; ++i) {
|
||||||
const data = datas[i];
|
const data = datas[i];
|
||||||
|
const x = i * col + 2;
|
||||||
if (!data.actualSpeed && !data.count) continue;
|
if (!data.actualSpeed && !data.count) continue;
|
||||||
const x = i * col;
|
screen.print(`${scale(data.actualSpeed)}%`, x, 3 * lineHeight8, 1, image.font8)
|
||||||
screen.print("ABCD"[i], x + 2, 1 * lineHeight8, 1, image.font8)
|
screen.print(`${scale(data.count)}>`, x, 4 * lineHeight8, 1, image.font8)
|
||||||
screen.print(`${scale(data.actualSpeed)}%`, x + 2, 3 * lineHeight8, 1, image.font8)
|
|
||||||
screen.print(`${scale(data.count)}>`, x + 2, 4 * lineHeight8, 1, image.font5)
|
|
||||||
}
|
}
|
||||||
screen.drawLine(0, 5 * lineHeight8, screen.width, 5 * lineHeight8, 1);
|
|
||||||
|
|
||||||
// sensors
|
// sensors
|
||||||
const sis = sensors.internal.getActiveSensors();
|
const sis = sensors.internal.getActiveSensors();
|
||||||
const h = screen.height;
|
|
||||||
screen.drawLine(0, h - 5 * lineHeight8, screen.width, h - 5 * lineHeight8, 1)
|
|
||||||
for (let i = 0; i < sis.length; ++i) {
|
for (let i = 0; i < sis.length; ++i) {
|
||||||
const si = sis[i];
|
const si = sis[i];
|
||||||
const x = (si.port() - 1) * col;
|
const x = (si.port() - 1) * col + 2;
|
||||||
const inf = si._info();
|
const inf = si._info();
|
||||||
screen.print(si.port() + "", x, h - 4 * lineHeight8, 1, image.font8)
|
if (inf)
|
||||||
screen.print(inf, x, h - 2 * lineHeight8, 1, inf.length > 4 ? image.font5 : image.font8);
|
screen.print(inf, x, h - 2 * lineHeight8, 1, inf.length > 4 ? image.font5 : image.font8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function showBoot() {
|
||||||
|
// pulse green, play startup sound, turn off light
|
||||||
|
brick.setStatusLight(StatusLight.GreenPulse);
|
||||||
|
// We pause for 100ms to give time to read sensor values, so they work in on_start block
|
||||||
|
pause(400)
|
||||||
|
// and we're ready
|
||||||
|
brick.setStatusLight(StatusLight.Off);
|
||||||
|
// always show port by default if no UI is set
|
||||||
|
control.runInParallel(function () {
|
||||||
|
// show ports if nothing is has been shown
|
||||||
|
if (screenMode != ScreenMode.None) return;
|
||||||
|
showPorts();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showConsole() {
|
||||||
|
console.sendToScreen();
|
||||||
|
screenMode = ScreenMode.Console;
|
||||||
|
clearScreen();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An image
|
* An image
|
||||||
* @param image the image
|
* @param image the image
|
||||||
|
@ -4,9 +4,9 @@ tests.onEvent(TestEvent.RunSetUp, function() {
|
|||||||
})
|
})
|
||||||
tests.onEvent(TestEvent.TestSetUp, function() {
|
tests.onEvent(TestEvent.TestSetUp, function() {
|
||||||
motors.stopAll();
|
motors.stopAll();
|
||||||
motors.resetAllMotors();
|
motors.resetAll();
|
||||||
})
|
})
|
||||||
tests.onEvent(TestEvent.TestTearDown, function() {
|
tests.onEvent(TestEvent.TestTearDown, function() {
|
||||||
motors.stopAll();
|
motors.stopAll();
|
||||||
motors.resetAllMotors();
|
motors.resetAll();
|
||||||
})
|
})
|
||||||
|
@ -73,6 +73,7 @@ namespace sensors {
|
|||||||
//% weight=81 blockGap=8
|
//% weight=81 blockGap=8
|
||||||
//% group="Touch Sensor"
|
//% group="Touch Sensor"
|
||||||
isPressed() {
|
isPressed() {
|
||||||
|
this.poke();
|
||||||
return this.button.isPressed();
|
return this.button.isPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +91,7 @@ namespace sensors {
|
|||||||
//% weight=81
|
//% weight=81
|
||||||
//% group="Touch Sensor"
|
//% group="Touch Sensor"
|
||||||
wasPressed() {
|
wasPressed() {
|
||||||
|
this.poke();
|
||||||
return this.button.wasPressed();
|
return this.button.wasPressed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,7 @@ namespace sensors {
|
|||||||
//% weight=65
|
//% weight=65
|
||||||
//% group="Ultrasonic Sensor"
|
//% group="Ultrasonic Sensor"
|
||||||
distance(): number {
|
distance(): number {
|
||||||
|
this.poke();
|
||||||
// it supposedly also has an inch mode, but we stick to cm
|
// it supposedly also has an inch mode, but we stick to cm
|
||||||
this._setMode(0)
|
this._setMode(0)
|
||||||
return this._query();
|
return this._query();
|
||||||
|
16
package.json
@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-ev3",
|
"name": "pxt-ev3",
|
||||||
"version": "1.2.1",
|
"version": "1.4.7",
|
||||||
"description": "LEGO MINDSTORMS EV3 for Microsoft MakeCode",
|
"description": "LEGO MINDSTORMS EV3 for Microsoft MakeCode",
|
||||||
"private": false,
|
"private": false,
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"JavaScript",
|
"JavaScript",
|
||||||
"education",
|
"education",
|
||||||
"lego",
|
"LEGO",
|
||||||
|
"EV3",
|
||||||
"pxt",
|
"pxt",
|
||||||
"MakeCode",
|
"MakeCode",
|
||||||
"Microsoft"
|
"Microsoft"
|
||||||
@ -32,15 +33,20 @@
|
|||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "2.6.1",
|
"typescript": "2.6.1",
|
||||||
|
"react": "16.8.3",
|
||||||
"semantic-ui-less": "2.2.14",
|
"semantic-ui-less": "2.2.14",
|
||||||
"@types/bluebird": "2.0.33",
|
"@types/bluebird": "2.0.33",
|
||||||
"@types/marked": "0.3.0",
|
"@types/marked": "0.3.0",
|
||||||
"@types/node": "8.0.53",
|
"@types/node": "8.0.53",
|
||||||
"webfonts-generator": "^0.4.0"
|
"webfonts-generator": "^0.4.0",
|
||||||
|
"@types/jquery": "3.2.16",
|
||||||
|
"@types/react": "16.0.25",
|
||||||
|
"@types/react-dom": "16.0.3",
|
||||||
|
"@types/web-bluetooth": "0.0.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-common-packages": "0.23.61",
|
"pxt-common-packages": "6.16.10",
|
||||||
"pxt-core": "4.0.9"
|
"pxt-core": "5.25.13"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||||
|
@ -17,11 +17,12 @@
|
|||||||
"libs/gyro-sensor",
|
"libs/gyro-sensor",
|
||||||
"libs/screen",
|
"libs/screen",
|
||||||
"libs/ev3",
|
"libs/ev3",
|
||||||
"libs/storage"
|
"libs/storage",
|
||||||
|
"libs/broadcast"
|
||||||
],
|
],
|
||||||
"simulator": {
|
"simulator": {
|
||||||
"autoRun": true,
|
"autoRun": true,
|
||||||
"streams": true,
|
"autoRunLight": false,
|
||||||
"aspectRatio": 0.5,
|
"aspectRatio": 0.5,
|
||||||
"parts": false,
|
"parts": false,
|
||||||
"enableTrace": true,
|
"enableTrace": true,
|
||||||
@ -49,7 +50,8 @@
|
|||||||
"flashCodeAlign": 256,
|
"flashCodeAlign": 256,
|
||||||
"floatingPoint": true,
|
"floatingPoint": true,
|
||||||
"taggedInts": true,
|
"taggedInts": true,
|
||||||
"stackAlign": 2
|
"stackAlign": 2,
|
||||||
|
"gc": true
|
||||||
},
|
},
|
||||||
"serial": {
|
"serial": {
|
||||||
"vendorId": "0x0694",
|
"vendorId": "0x0694",
|
||||||
@ -71,7 +73,9 @@
|
|||||||
"onStartColor": "#58AB41",
|
"onStartColor": "#58AB41",
|
||||||
"pauseUntilBlock": {
|
"pauseUntilBlock": {
|
||||||
"category": "loops"
|
"category": "loops"
|
||||||
}
|
},
|
||||||
|
"bannedCategories": [
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"compileService": {
|
"compileService": {
|
||||||
"buildEngine": "dockermake",
|
"buildEngine": "dockermake",
|
||||||
@ -150,6 +154,12 @@
|
|||||||
"usbHelp": [],
|
"usbHelp": [],
|
||||||
"extendEditor": true,
|
"extendEditor": true,
|
||||||
"extendFieldEditors": true,
|
"extendFieldEditors": true,
|
||||||
|
"scriptManager": true,
|
||||||
|
"importExtensionFiles": true,
|
||||||
|
"experiments": [
|
||||||
|
"python",
|
||||||
|
"alwaysGithubItemBlocks"
|
||||||
|
],
|
||||||
"disableBlockIcons": true,
|
"disableBlockIcons": true,
|
||||||
"blocklyOptions": {
|
"blocklyOptions": {
|
||||||
"grid": {
|
"grid": {
|
||||||
@ -185,6 +195,10 @@
|
|||||||
"editor.background": "#f9f9f9"
|
"editor.background": "#f9f9f9"
|
||||||
},
|
},
|
||||||
"fileNameExclusiveFilter": "[^a-zA-Z0-9]",
|
"fileNameExclusiveFilter": "[^a-zA-Z0-9]",
|
||||||
|
"qrCode": true,
|
||||||
|
"shareFinishedTutorials": true,
|
||||||
|
"nameProjectFirst": true,
|
||||||
|
"alwaysGithubItem": true,
|
||||||
"enableTrace": true
|
"enableTrace": true
|
||||||
},
|
},
|
||||||
"ignoreDocsErrors": true
|
"ignoreDocsErrors": true
|
||||||
|
97
scripts/file_manager.ts
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
//% shim=pxt::listPrjFiles
|
||||||
|
function getPrjs() {
|
||||||
|
let programs = [
|
||||||
|
"pxt",
|
||||||
|
"my amazing robot",
|
||||||
|
]
|
||||||
|
for (let i = 1; i < 6; ++i)
|
||||||
|
programs.push("Untitled-" + i)
|
||||||
|
return programs
|
||||||
|
}
|
||||||
|
|
||||||
|
//% shim=pxt::deletePrjFile
|
||||||
|
function delPrj(fn: string) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const programs = getPrjs()
|
||||||
|
.filter(s => s.substr(s.length - 4, 4) == ".rbf")
|
||||||
|
.map(s => s.substr(0, s.length - 4))
|
||||||
|
.filter(s => s != "File_manager")
|
||||||
|
|
||||||
|
programs.push("")
|
||||||
|
programs.push("Cancel")
|
||||||
|
programs.push("Delete 0 files")
|
||||||
|
|
||||||
|
let todel: boolean[] = []
|
||||||
|
let scrollTop = 0
|
||||||
|
let cursor = 0
|
||||||
|
let confirm = false
|
||||||
|
function showMenu() {
|
||||||
|
if (cursor < scrollTop + 2)
|
||||||
|
scrollTop = cursor - 2
|
||||||
|
else if (cursor > scrollTop + 11)
|
||||||
|
scrollTop = cursor - 11
|
||||||
|
if (scrollTop < 0)
|
||||||
|
scrollTop = 0
|
||||||
|
let num = 0
|
||||||
|
for (let i = 0; i < todel.length; ++i)
|
||||||
|
if (todel[i]) num++
|
||||||
|
programs[programs.length - 1] =
|
||||||
|
confirm ? "Enter to confirm" : "Delete " + num + " file(s)"
|
||||||
|
|
||||||
|
brick.clearScreen()
|
||||||
|
|
||||||
|
const h = brick.lineHeight()
|
||||||
|
for (let i = 0; i < 13; ++i) {
|
||||||
|
const y = i * h
|
||||||
|
const idx = scrollTop + i
|
||||||
|
const fg = idx == cursor ? 0 : 1
|
||||||
|
const bg = idx == cursor ? 1 : 0
|
||||||
|
// screen.fillRect(0, y, screen.width, h, bg);
|
||||||
|
let text = (idx == cursor ? ">" : " ")
|
||||||
|
+ (todel[idx] ? "*" : " ")
|
||||||
|
+ " "
|
||||||
|
+ (programs[scrollTop + i] || "")
|
||||||
|
screen.print(text, 0, y, fg, brick.font);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function move(d: number) {
|
||||||
|
confirm = false
|
||||||
|
const nc = cursor + d
|
||||||
|
if (0 <= nc && nc < programs.length)
|
||||||
|
cursor = nc
|
||||||
|
showMenu()
|
||||||
|
}
|
||||||
|
brick.buttonDown.onEvent(ButtonEvent.Pressed, () => move(1))
|
||||||
|
brick.buttonUp.onEvent(ButtonEvent.Pressed, () => move(-1))
|
||||||
|
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
if (cursor < programs.length - 3) {
|
||||||
|
todel[cursor] = !todel[cursor]
|
||||||
|
move(1)
|
||||||
|
} else if (cursor == programs.length - 3) {
|
||||||
|
// nothing
|
||||||
|
} else if (cursor == programs.length - 2) {
|
||||||
|
control.reset()
|
||||||
|
} else if (cursor == programs.length - 1) {
|
||||||
|
if (todel.every(x => !x))
|
||||||
|
return
|
||||||
|
if (confirm) {
|
||||||
|
brick.clearScreen()
|
||||||
|
brick.showString("deleting...", 6)
|
||||||
|
for (let i = 0; i < todel.length; ++i) {
|
||||||
|
if (todel[i]) {
|
||||||
|
delPrj(programs[i] + ".elf")
|
||||||
|
delPrj(programs[i] + ".rbf")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pause(1000)
|
||||||
|
control.reset()
|
||||||
|
} else {
|
||||||
|
confirm = true
|
||||||
|
showMenu()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
showMenu()
|
||||||
|
|
@ -5,6 +5,7 @@
|
|||||||
namespace pxsim {
|
namespace pxsim {
|
||||||
|
|
||||||
export class EV3Board extends CoreBoard {
|
export class EV3Board extends CoreBoard {
|
||||||
|
viewHost: visuals.BoardHost;
|
||||||
view: SVGSVGElement;
|
view: SVGSVGElement;
|
||||||
|
|
||||||
outputState: EV3OutputState;
|
outputState: EV3OutputState;
|
||||||
@ -83,7 +84,8 @@ namespace pxsim {
|
|||||||
highContrast: msg.highContrast,
|
highContrast: msg.highContrast,
|
||||||
light: msg.light
|
light: msg.light
|
||||||
};
|
};
|
||||||
const viewHost = new visuals.BoardHost(pxsim.visuals.mkBoardView({
|
this.viewHost = new visuals.BoardHost(pxsim.visuals.mkBoardView({
|
||||||
|
boardDef,
|
||||||
visual: boardDef.visual,
|
visual: boardDef.visual,
|
||||||
highContrast: msg.highContrast,
|
highContrast: msg.highContrast,
|
||||||
light: msg.light
|
light: msg.light
|
||||||
@ -91,7 +93,7 @@ namespace pxsim {
|
|||||||
|
|
||||||
document.body.innerHTML = ""; // clear children
|
document.body.innerHTML = ""; // clear children
|
||||||
document.body.className = msg.light ? "light" : "";
|
document.body.className = msg.light ? "light" : "";
|
||||||
document.body.appendChild(this.view = viewHost.getView() as SVGSVGElement);
|
document.body.appendChild(this.view = this.viewHost.getView() as SVGSVGElement);
|
||||||
|
|
||||||
this.inputNodes = [];
|
this.inputNodes = [];
|
||||||
this.outputNodes = [];
|
this.outputNodes = [];
|
||||||
@ -102,8 +104,8 @@ namespace pxsim {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
screenshot(): string {
|
screenshotAsync(width?: number): Promise<ImageData> {
|
||||||
return svg.toDataUri(new XMLSerializer().serializeToString(this.view));
|
return this.viewHost.screenshotAsync(width);
|
||||||
}
|
}
|
||||||
|
|
||||||
getBrickNode() {
|
getBrickNode() {
|
||||||
|