Compare commits
1 Commits
users/GitH
...
upgradetsv
Author | SHA1 | Date | |
---|---|---|---|
fecfdc4c11 |
40
.github/workflows/pxt-buildmain.yml
vendored
40
.github/workflows/pxt-buildmain.yml
vendored
@ -1,40 +0,0 @@
|
|||||||
name: pxt-buildmain
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- 'master'
|
|
||||||
- 'main'
|
|
||||||
create:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [14.x]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- name: npm install
|
|
||||||
run: |
|
|
||||||
sudo apt-get install xvfb
|
|
||||||
sudo npm install -g pxt
|
|
||||||
npm install
|
|
||||||
- name: pxt ci
|
|
||||||
run: |
|
|
||||||
pxt ci
|
|
||||||
env:
|
|
||||||
CROWDIN_KEY: ${{ secrets.CROWDIN_KEY }}
|
|
||||||
PXT_ACCESS_TOKEN: ${{ secrets.PXT_ACCESS_TOKEN }}
|
|
||||||
PXT_RELEASE_REPO: ${{ secrets.PXT_RELEASE_REPO }}
|
|
||||||
NPM_ACCESS_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
|
|
||||||
CHROME_BIN: chromium-browser
|
|
||||||
DISPLAY: :99.0
|
|
||||||
CI: true
|
|
31
.github/workflows/pxt-buildpr.yml
vendored
31
.github/workflows/pxt-buildpr.yml
vendored
@ -1,31 +0,0 @@
|
|||||||
name: pxt-buildpr
|
|
||||||
|
|
||||||
on: [pull_request]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [14.x]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- name: npm install
|
|
||||||
run: |
|
|
||||||
sudo apt-get install xvfb
|
|
||||||
sudo npm install -g pxt
|
|
||||||
npm install
|
|
||||||
- name: pxt ci
|
|
||||||
run: |
|
|
||||||
pxt ci
|
|
||||||
env:
|
|
||||||
CHROME_BIN: chromium-browser
|
|
||||||
DISPLAY: :99.0
|
|
||||||
CI: true
|
|
39
.github/workflows/pxt-buildpush.yml
vendored
39
.github/workflows/pxt-buildpush.yml
vendored
@ -1,39 +0,0 @@
|
|||||||
name: pxt-buildpush
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
# main/master has its own build that includes the crowdin key
|
|
||||||
branches-ignore:
|
|
||||||
- 'main'
|
|
||||||
- 'master'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [14.x]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- name: npm install
|
|
||||||
run: |
|
|
||||||
sudo apt-get install xvfb
|
|
||||||
sudo npm install -g pxt
|
|
||||||
npm install
|
|
||||||
- name: pxt ci
|
|
||||||
run: |
|
|
||||||
pxt ci
|
|
||||||
env:
|
|
||||||
PXT_ACCESS_TOKEN: ${{ secrets.PXT_ACCESS_TOKEN }}
|
|
||||||
PXT_RELEASE_REPO: ${{ secrets.PXT_RELEASE_REPO }}
|
|
||||||
NPM_ACCESS_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
|
|
||||||
CHROME_BIN: chromium-browser
|
|
||||||
DISPLAY: :99.0
|
|
||||||
CI: true
|
|
9
.travis.yml
Normal file
9
.travis.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- "8.9.0"
|
||||||
|
script:
|
||||||
|
- "node node_modules/pxt-core/built/pxt.js travis"
|
||||||
|
sudo: false
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- node_modules
|
41
SECURITY.md
41
SECURITY.md
@ -1,41 +0,0 @@
|
|||||||
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.7 BLOCK -->
|
|
||||||
|
|
||||||
## Security
|
|
||||||
|
|
||||||
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
|
|
||||||
|
|
||||||
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.
|
|
||||||
|
|
||||||
## Reporting Security Issues
|
|
||||||
|
|
||||||
**Please do not report security vulnerabilities through public GitHub issues.**
|
|
||||||
|
|
||||||
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).
|
|
||||||
|
|
||||||
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
|
|
||||||
|
|
||||||
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
|
|
||||||
|
|
||||||
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
|
||||||
|
|
||||||
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
|
||||||
* Full paths of source file(s) related to the manifestation of the issue
|
|
||||||
* The location of the affected source code (tag/branch/commit or direct URL)
|
|
||||||
* Any special configuration required to reproduce the issue
|
|
||||||
* Step-by-step instructions to reproduce the issue
|
|
||||||
* Proof-of-concept or exploit code (if possible)
|
|
||||||
* Impact of the issue, including how an attacker might exploit the issue
|
|
||||||
|
|
||||||
This information will help us triage your report more quickly.
|
|
||||||
|
|
||||||
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.
|
|
||||||
|
|
||||||
## Preferred Languages
|
|
||||||
|
|
||||||
We prefer all communications to be in English.
|
|
||||||
|
|
||||||
## Policy
|
|
||||||
|
|
||||||
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).
|
|
||||||
|
|
||||||
<!-- END MICROSOFT SECURITY.MD BLOCK -->
|
|
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"appref": "v1.4.24"
|
"appref": "v"
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ while (true) {
|
|||||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
||||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
||||||
}
|
}
|
||||||
|
pause(1);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -42,5 +43,6 @@ while (true) {
|
|||||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
||||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
||||||
}
|
}
|
||||||
|
pause(1);
|
||||||
}
|
}
|
||||||
```
|
```
|
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"appref": "v1.2.31"
|
"appref": "v1.2.27"
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,16 @@
|
|||||||
|
|
||||||
## Example #example
|
## Example #example
|
||||||
|
|
||||||
Use a wait and the timer to generate a number.
|
Use the a wait and the timer to generate a crazy number.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
let something = 0
|
let crazy = 0
|
||||||
for (let i = 0; i < 100; i++) {
|
for (let i = 0; i < 100; i++) {
|
||||||
control.waitMicros(100)
|
control.waitMicros(100)
|
||||||
something = control.millis()
|
crazy = control.millis()
|
||||||
something += control.deviceSerialNumber()
|
crazy += control.deviceSerialNumber()
|
||||||
if (something != 0) {
|
if (crazy != 0) {
|
||||||
something = something / 1000000
|
crazy = crazy / 1000000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
@ -49,7 +49,7 @@ declare interface Serial extends EventTarget {
|
|||||||
requestPort(options: SerialPortRequestOptions): Promise<SerialPort>;
|
requestPort(options: SerialPortRequestOptions): Promise<SerialPort>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class WebSerialPackageIO implements pxt.packetio.PacketIO {
|
class WebSerialPackageIO implements pxt.HF2.PacketIO {
|
||||||
onData: (v: Uint8Array) => void;
|
onData: (v: Uint8Array) => void;
|
||||||
onError: (e: Error) => void;
|
onError: (e: Error) => void;
|
||||||
onEvent: (v: Uint8Array) => void;
|
onEvent: (v: Uint8Array) => void;
|
||||||
@ -87,7 +87,7 @@ class WebSerialPackageIO implements pxt.packetio.PacketIO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static portIos: WebSerialPackageIO[] = [];
|
static portIos: WebSerialPackageIO[] = [];
|
||||||
static async mkPacketIOAsync(): Promise<pxt.packetio.PacketIO> {
|
static async mkPacketIOAsync(): Promise<pxt.HF2.PacketIO> {
|
||||||
const serial = (<any>navigator).serial;
|
const serial = (<any>navigator).serial;
|
||||||
if (serial) {
|
if (serial) {
|
||||||
try {
|
try {
|
||||||
@ -130,7 +130,7 @@ class WebSerialPackageIO implements pxt.packetio.PacketIO {
|
|||||||
|
|
||||||
private async closeAsync() {
|
private async closeAsync() {
|
||||||
// don't close port
|
// don't close port
|
||||||
return pxt.U.delay(500);
|
return Promise.delay(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
reconnectAsync(): Promise<void> {
|
reconnectAsync(): Promise<void> {
|
||||||
@ -146,33 +146,11 @@ class WebSerialPackageIO implements pxt.packetio.PacketIO {
|
|||||||
this._writer = this.port.writable.getWriter();
|
this._writer = this.port.writable.getWriter();
|
||||||
return this._writer.write(pkt);
|
return this._writer.write(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
onDeviceConnectionChanged(connect: boolean) {
|
|
||||||
throw new Error("onDeviceConnectionChanged not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
onConnectionChanged() {
|
|
||||||
throw new Error("onConnectionChanged not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
isConnecting() {
|
|
||||||
throw new Error("isConnecting not implemented");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
isConnected() {
|
|
||||||
throw new Error("isConnected not implemented");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
disposeAsync() {
|
|
||||||
return Promise.reject("disposeAsync not implemented")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function hf2Async() {
|
function hf2Async() {
|
||||||
const pktIOAsync: Promise<pxt.packetio.PacketIO> = useWebSerial
|
const pktIOAsync: Promise<pxt.HF2.PacketIO> = useWebSerial
|
||||||
? WebSerialPackageIO.mkPacketIOAsync() : pxt.packetio.mkPacketIOAsync()
|
? WebSerialPackageIO.mkPacketIOAsync() : pxt.HF2.mkPacketIOAsync()
|
||||||
return pktIOAsync.then(h => {
|
return pktIOAsync.then(h => {
|
||||||
let w = new Ev3Wrapper(h)
|
let w = new Ev3Wrapper(h)
|
||||||
ev3 = w
|
ev3 = w
|
||||||
@ -212,19 +190,14 @@ export function enableWebSerialAsync() {
|
|||||||
else return Promise.resolve();
|
else return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cleanupAsync() {
|
function cleanupAsync() {
|
||||||
if (ev3) {
|
if (ev3) {
|
||||||
console.log('cleanup previous port')
|
console.log('cleanup previous port')
|
||||||
try {
|
return ev3.disconnectAsync()
|
||||||
await ev3.disconnectAsync()
|
.catch(e => { })
|
||||||
}
|
.finally(() => { ev3 = undefined; });
|
||||||
catch (e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
ev3 = undefined;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
let initPromise: Promise<Ev3Wrapper>
|
let initPromise: Promise<Ev3Wrapper>
|
||||||
@ -234,7 +207,7 @@ function initHidAsync() { // needs to run within a click handler
|
|||||||
if (useHID) {
|
if (useHID) {
|
||||||
initPromise = cleanupAsync()
|
initPromise = cleanupAsync()
|
||||||
.then(() => hf2Async())
|
.then(() => hf2Async())
|
||||||
.catch((err: any) => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
initPromise = null
|
initPromise = null
|
||||||
useHID = false;
|
useHID = false;
|
||||||
@ -311,7 +284,7 @@ export function deployCoreAsync(resp: pxtc.CompileResult) {
|
|||||||
.catch(e => {
|
.catch(e => {
|
||||||
// user easily forgets to stop robot
|
// user easily forgets to stop robot
|
||||||
bluetoothTryAgainAsync().then(() => w.disconnectAsync())
|
bluetoothTryAgainAsync().then(() => w.disconnectAsync())
|
||||||
.then(() => pxt.U.delay(1000))
|
.then(() => Promise.delay(1000))
|
||||||
.then(() => w.reconnectAsync());
|
.then(() => w.reconnectAsync());
|
||||||
|
|
||||||
// nothing we can do
|
// nothing we can do
|
||||||
@ -323,7 +296,7 @@ export function deployCoreAsync(resp: pxtc.CompileResult) {
|
|||||||
.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(() => pxt.U.delay(500))
|
.then(() => Promise.delay(500))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
pxt.tickEvent("webserial.success");
|
pxt.tickEvent("webserial.success");
|
||||||
return w.disconnectAsync()
|
return w.disconnectAsync()
|
||||||
|
@ -21,7 +21,7 @@ export function bluetoothTryAgainAsync(): Promise<void> {
|
|||||||
|
|
||||||
function enableWebSerialAndCompileAsync() {
|
function enableWebSerialAndCompileAsync() {
|
||||||
return enableWebSerialAsync()
|
return enableWebSerialAsync()
|
||||||
.then(() => pxt.U.delay(500))
|
.then(() => Promise.delay(500))
|
||||||
.then(() => projectView.compile());
|
.then(() => projectView.compile());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,6 +126,7 @@ export function showUploadDialogAsync(fn: string, url: string, _confirmAsync: (o
|
|||||||
pxt.tickEvent("bluetooth.enable");
|
pxt.tickEvent("bluetooth.enable");
|
||||||
explainWebSerialPairingAsync()
|
explainWebSerialPairingAsync()
|
||||||
.then(() => enableWebSerialAndCompileAsync())
|
.then(() => enableWebSerialAndCompileAsync())
|
||||||
|
.done();
|
||||||
}
|
}
|
||||||
} : undefined, downloadAgain ? {
|
} : undefined, downloadAgain ? {
|
||||||
label: fn,
|
label: fn,
|
||||||
|
@ -26,7 +26,7 @@ export class Ev3Wrapper {
|
|||||||
isStreaming = false;
|
isStreaming = false;
|
||||||
dataDump = /talkdbg=1/.test(window.location.href);
|
dataDump = /talkdbg=1/.test(window.location.href);
|
||||||
|
|
||||||
constructor(public io: pxt.packetio.PacketIO) {
|
constructor(public io: pxt.HF2.PacketIO) {
|
||||||
io.onData = buf => {
|
io.onData = buf => {
|
||||||
buf = buf.slice(0, HF2.read16(buf, 0) + 2)
|
buf = buf.slice(0, HF2.read16(buf, 0) + 2)
|
||||||
if (HF2.read16(buf, 4) == usbMagic) {
|
if (HF2.read16(buf, 4) == usbMagic) {
|
||||||
@ -81,7 +81,7 @@ export class Ev3Wrapper {
|
|||||||
log(`stopping PXT app`)
|
log(`stopping PXT app`)
|
||||||
let buf = this.allocCustom(2)
|
let buf = this.allocCustom(2)
|
||||||
return this.justSendAsync(buf)
|
return this.justSendAsync(buf)
|
||||||
.then(() => pxt.U.delay(500))
|
.then(() => Promise.delay(500))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ export class Ev3Wrapper {
|
|||||||
if (this.dataDump)
|
if (this.dataDump)
|
||||||
log("TALK: " + U.toHex(buf))
|
log("TALK: " + U.toHex(buf))
|
||||||
return this.io.sendPacketAsync(buf)
|
return this.io.sendPacketAsync(buf)
|
||||||
.then(() => this.msgs.shiftAsync(5000))
|
.then(() => this.msgs.shiftAsync(1000))
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
if (resp[2] != buf[2] || resp[3] != buf[3])
|
if (resp[2] != buf[2] || resp[3] != buf[3])
|
||||||
U.userError("msg count de-sync")
|
U.userError("msg count de-sync")
|
||||||
@ -236,7 +236,7 @@ export class Ev3Wrapper {
|
|||||||
let contFileReq = this.allocSystem(1 + 2, 0x97)
|
let contFileReq = this.allocSystem(1 + 2, 0x97)
|
||||||
HF2.write16(contFileReq, 7, 1000) // maxRead
|
HF2.write16(contFileReq, 7, 1000) // maxRead
|
||||||
contFileReq[6] = handle
|
contFileReq[6] = handle
|
||||||
return pxt.U.delay(data.length > 0 ? 0 : 500)
|
return Promise.delay(data.length > 0 ? 0 : 500)
|
||||||
.then(() => this.talkAsync(contFileReq, -1))
|
.then(() => this.talkAsync(contFileReq, -1))
|
||||||
.then(resp)
|
.then(resp)
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ export class Ev3Wrapper {
|
|||||||
let loop = (): Promise<void> =>
|
let loop = (): Promise<void> =>
|
||||||
this.lock.enqueue("file", () =>
|
this.lock.enqueue("file", () =>
|
||||||
this.streamFileOnceAsync(path, cb))
|
this.streamFileOnceAsync(path, cb))
|
||||||
.then(() => pxt.U.delay(500))
|
.then(() => Promise.delay(500))
|
||||||
.then(loop)
|
.then(loop)
|
||||||
return loop()
|
return loop()
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
||||||
|
|
||||||
import { FieldPorts } from "./field_ports";
|
import { FieldPorts } from "./field_ports";
|
||||||
|
import { FieldMotors } from "./field_motors";
|
||||||
import { FieldBrickButtons } from "./field_brickbuttons";
|
import { FieldBrickButtons } from "./field_brickbuttons";
|
||||||
import { FieldColorEnum } from "./field_color";
|
import { FieldColorEnum } from "./field_color";
|
||||||
import { FieldMusic } from "./field_music";
|
import { FieldMusic } from "./field_music";
|
||||||
@ -13,6 +14,9 @@ pxt.editor.initFieldExtensionsAsync = function (opts: pxt.editor.FieldExtensionO
|
|||||||
fieldEditors: [{
|
fieldEditors: [{
|
||||||
selector: "ports",
|
selector: "ports",
|
||||||
editor: FieldPorts
|
editor: FieldPorts
|
||||||
|
}, {
|
||||||
|
selector: "motors",
|
||||||
|
editor: FieldMotors
|
||||||
}, {
|
}, {
|
||||||
selector: "brickbuttons",
|
selector: "brickbuttons",
|
||||||
editor: FieldBrickButtons
|
editor: FieldBrickButtons
|
||||||
|
@ -64,7 +64,7 @@ export class FieldColorEnum extends pxtblockly.FieldColorNumber implements Block
|
|||||||
}
|
}
|
||||||
this.value_ = colour;
|
this.value_ = colour;
|
||||||
if (this.sourceBlock_) {
|
if (this.sourceBlock_) {
|
||||||
this.sourceBlock_.setColour(colour);
|
this.sourceBlock_.setColour(colour, colour, colour);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
583
fieldeditors/field_motors.ts
Normal file
583
fieldeditors/field_motors.ts
Normal file
File diff suppressed because one or more lines are too long
@ -27,6 +27,7 @@ export class FieldMusic extends pxtblockly.FieldImages implements Blockly.FieldC
|
|||||||
|
|
||||||
this.setText = Blockly.FieldDropdown.prototype.setText;
|
this.setText = Blockly.FieldDropdown.prototype.setText;
|
||||||
this.updateSize_ = (Blockly.Field as any).prototype.updateSize_;
|
this.updateSize_ = (Blockly.Field as any).prototype.updateSize_;
|
||||||
|
this.updateTextNode_ = Blockly.Field.prototype.updateTextNode_;
|
||||||
|
|
||||||
if (!pxt.BrowserUtils.isIE() && !soundCache) {
|
if (!pxt.BrowserUtils.isIE() && !soundCache) {
|
||||||
soundCache = JSON.parse(pxtTargetBundle.bundledpkgs['music']['sounds.jres']);
|
soundCache = JSON.parse(pxtTargetBundle.bundledpkgs['music']['sounds.jres']);
|
||||||
@ -67,8 +68,7 @@ export class FieldMusic extends pxtblockly.FieldImages implements Blockly.FieldC
|
|||||||
// Accessibility properties
|
// Accessibility properties
|
||||||
categoriesDiv.setAttribute('role', 'menu');
|
categoriesDiv.setAttribute('role', 'menu');
|
||||||
categoriesDiv.setAttribute('aria-haspopup', 'true');
|
categoriesDiv.setAttribute('aria-haspopup', 'true');
|
||||||
// FIXME: tertiary color?
|
categoriesDiv.style.backgroundColor = this.sourceBlock_.getColourTertiary();
|
||||||
categoriesDiv.style.backgroundColor = this.sourceBlock_.getColour();
|
|
||||||
categoriesDiv.className = 'blocklyMusicFieldCategories';
|
categoriesDiv.className = 'blocklyMusicFieldCategories';
|
||||||
|
|
||||||
this.refreshCategories(categoriesDiv, categories);
|
this.refreshCategories(categoriesDiv, categories);
|
||||||
@ -82,9 +82,7 @@ export class FieldMusic extends pxtblockly.FieldImages implements Blockly.FieldC
|
|||||||
dropdownDiv.appendChild(categoriesDiv);
|
dropdownDiv.appendChild(categoriesDiv);
|
||||||
dropdownDiv.appendChild(contentDiv);
|
dropdownDiv.appendChild(contentDiv);
|
||||||
|
|
||||||
Blockly.DropDownDiv.setColour(this.sourceBlock_.getColour(),
|
Blockly.DropDownDiv.setColour(this.sourceBlock_.getColour(), this.sourceBlock_.getColourTertiary());
|
||||||
// FIXME: tertiary color?
|
|
||||||
this.sourceBlock_.getColour());
|
|
||||||
|
|
||||||
// Calculate positioning based on the field position.
|
// Calculate positioning based on the field position.
|
||||||
let scale = (<Blockly.WorkspaceSvg>this.sourceBlock_.workspace).scale;
|
let scale = (<Blockly.WorkspaceSvg>this.sourceBlock_.workspace).scale;
|
||||||
@ -104,9 +102,10 @@ export class FieldMusic extends pxtblockly.FieldImages implements Blockly.FieldC
|
|||||||
// Update colour to look selected.
|
// Update colour to look selected.
|
||||||
if (this.sourceBlock_.isShadow()) {
|
if (this.sourceBlock_.isShadow()) {
|
||||||
this.savedPrimary_ = this.sourceBlock_.getColour();
|
this.savedPrimary_ = this.sourceBlock_.getColour();
|
||||||
// FIXME
|
this.sourceBlock_.setColour(this.sourceBlock_.getColourTertiary(),
|
||||||
// this.sourceBlock_.setColour(this.sourceBlock_.getColourTertiary(),
|
this.sourceBlock_.getColourSecondary(), this.sourceBlock_.getColourTertiary());
|
||||||
// this.sourceBlock_.getColourSecondary(), this.sourceBlock_.getColourTertiary());
|
} else if (this.box_) {
|
||||||
|
this.box_.setAttribute('fill', this.sourceBlock_.getColourTertiary());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,13 +186,11 @@ export class FieldMusic extends pxtblockly.FieldImages implements Blockly.FieldC
|
|||||||
let backgroundColor = this.savedPrimary_ || this.sourceBlock_.getColour();
|
let backgroundColor = this.savedPrimary_ || this.sourceBlock_.getColour();
|
||||||
if (value == this.getValue()) {
|
if (value == this.getValue()) {
|
||||||
// This icon is selected, show it in a different colour
|
// This icon is selected, show it in a different colour
|
||||||
// FIXME: tertiary color?
|
backgroundColor = this.sourceBlock_.getColourTertiary();
|
||||||
backgroundColor = this.sourceBlock_.getColour();
|
|
||||||
button.setAttribute('aria-selected', 'true');
|
button.setAttribute('aria-selected', 'true');
|
||||||
}
|
}
|
||||||
button.style.backgroundColor = backgroundColor;
|
button.style.backgroundColor = backgroundColor;
|
||||||
// FIXME: tertiary color?
|
button.style.borderColor = this.sourceBlock_.getColourTertiary();
|
||||||
button.style.borderColor = this.sourceBlock_.getColour();
|
|
||||||
Blockly.bindEvent_(button, 'click', this, this.buttonClick_);
|
Blockly.bindEvent_(button, 'click', this, this.buttonClick_);
|
||||||
Blockly.bindEvent_(button, 'mouseup', this, this.buttonClick_);
|
Blockly.bindEvent_(button, 'mouseup', this, this.buttonClick_);
|
||||||
// These are applied manually instead of using the :hover pseudoclass
|
// These are applied manually instead of using the :hover pseudoclass
|
||||||
|
@ -18,6 +18,7 @@ export class FieldPorts extends pxtblockly.FieldImages implements Blockly.FieldC
|
|||||||
|
|
||||||
this.setText = Blockly.FieldDropdown.prototype.setText;
|
this.setText = Blockly.FieldDropdown.prototype.setText;
|
||||||
this.updateSize_ = (Blockly.Field as any).prototype.updateSize_;
|
this.updateSize_ = (Blockly.Field as any).prototype.updateSize_;
|
||||||
|
this.updateTextNode_ = Blockly.Field.prototype.updateTextNode_;
|
||||||
}
|
}
|
||||||
|
|
||||||
trimOptions_() {
|
trimOptions_() {
|
||||||
|
2
libs/base/shims.d.ts
vendored
2
libs/base/shims.d.ts
vendored
@ -204,8 +204,6 @@ declare namespace control {
|
|||||||
*/
|
*/
|
||||||
//% shim=control::dmesgValue
|
//% shim=control::dmesgValue
|
||||||
function dmesgValue(v: any): void;
|
function dmesgValue(v: any): void;
|
||||||
}
|
|
||||||
declare namespace control {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force GC and dump basic information about heap.
|
* Force GC and dump basic information about heap.
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
namespace control {
|
|
||||||
let lastPause = 0;
|
|
||||||
const COOPERATION_INTERVAL = 20
|
|
||||||
export function cooperate() {
|
|
||||||
const now = control.millis()
|
|
||||||
if (now - lastPause > COOPERATION_INTERVAL) {
|
|
||||||
lastPause = now
|
|
||||||
pause(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -21,7 +21,8 @@ namespace sensors.internal {
|
|||||||
const now = control.millis();
|
const now = control.millis();
|
||||||
if (now - this.lastQuery >= this.interval * 2)
|
if (now - this.lastQuery >= this.interval * 2)
|
||||||
this.queryAndUpdate(); // sensor poller is not allowed to run
|
this.queryAndUpdate(); // sensor poller is not allowed to run
|
||||||
control.cooperate(); // allow events to trigger
|
if (now - this.lastPause >= this.interval * 5)
|
||||||
|
pause(1); // allow events to trigger
|
||||||
}
|
}
|
||||||
|
|
||||||
private queryAndUpdate() {
|
private queryAndUpdate() {
|
||||||
|
@ -124,7 +124,7 @@ namespace motors {
|
|||||||
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);
|
||||||
control.cooperate();
|
pause(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,7 +136,7 @@ namespace motors {
|
|||||||
//% help=motors/reset-all
|
//% help=motors/reset-all
|
||||||
export function resetAll() {
|
export function resetAll() {
|
||||||
reset(Output.ALL)
|
reset(Output.ALL)
|
||||||
control.cooperate();
|
pause(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MoveSchedule {
|
interface MoveSchedule {
|
||||||
@ -195,8 +195,7 @@ namespace motors {
|
|||||||
* @param brake a value indicating if the motor should break when off
|
* @param brake a value indicating if the motor should break when off
|
||||||
*/
|
*/
|
||||||
//% blockId=outputMotorSetBrakeMode block="set %motor|brake %brake=toggleOnOff"
|
//% blockId=outputMotorSetBrakeMode block="set %motor|brake %brake=toggleOnOff"
|
||||||
//% motor.fieldEditor="speed"
|
//% motor.fieldEditor="motors"
|
||||||
//% motor.fieldOptions.decompileLiterals=1
|
|
||||||
//% weight=60 blockGap=8
|
//% weight=60 blockGap=8
|
||||||
//% group="Properties"
|
//% group="Properties"
|
||||||
//% help=motors/motor/set-brake
|
//% help=motors/motor/set-brake
|
||||||
@ -210,8 +209,7 @@ namespace motors {
|
|||||||
* @param value true to pause; false to continue the program execution
|
* @param value true to pause; false to continue the program execution
|
||||||
*/
|
*/
|
||||||
//% blockId=outputMotorSetPauseMode block="set %motor|pause on run %brake=toggleOnOff"
|
//% blockId=outputMotorSetPauseMode block="set %motor|pause on run %brake=toggleOnOff"
|
||||||
//% motor.fieldEditor="speed"
|
//% motor.fieldEditor="motors"
|
||||||
//% motor.fieldOptions.decompileLiterals=1
|
|
||||||
//% weight=60 blockGap=8
|
//% weight=60 blockGap=8
|
||||||
//% group="Properties"
|
//% group="Properties"
|
||||||
setPauseOnRun(value: boolean) {
|
setPauseOnRun(value: boolean) {
|
||||||
@ -223,8 +221,7 @@ namespace motors {
|
|||||||
* Inverts the motor polarity
|
* Inverts the motor polarity
|
||||||
*/
|
*/
|
||||||
//% blockId=motorSetInverted block="set %motor|inverted %reversed=toggleOnOff"
|
//% blockId=motorSetInverted block="set %motor|inverted %reversed=toggleOnOff"
|
||||||
//% motor.fieldEditor="speed"
|
//% motor.fieldEditor="motors"
|
||||||
//% motor.fieldOptions.decompileLiterals=1
|
|
||||||
//% weight=59 blockGap=8
|
//% weight=59 blockGap=8
|
||||||
//% group="Properties"
|
//% group="Properties"
|
||||||
//% help=motors/motor/set-inverted
|
//% help=motors/motor/set-inverted
|
||||||
@ -241,8 +238,7 @@ namespace motors {
|
|||||||
* Set the settle time after braking in milliseconds (default is 10ms).
|
* Set the settle time after braking in milliseconds (default is 10ms).
|
||||||
*/
|
*/
|
||||||
//% blockId=motorSetBrakeSettleTime block="set %motor|brake settle time %millis|ms"
|
//% blockId=motorSetBrakeSettleTime block="set %motor|brake settle time %millis|ms"
|
||||||
//% motor.fieldEditor="speed"
|
//% motor.fieldEditor="motors"
|
||||||
//% motor.fieldOptions.decompileLiterals=1
|
|
||||||
//% weight=1 blockGap=8
|
//% weight=1 blockGap=8
|
||||||
//% group="Properties"
|
//% group="Properties"
|
||||||
//% millis.defl=200 millis.min=0 millis.max=500
|
//% millis.defl=200 millis.min=0 millis.max=500
|
||||||
@ -273,7 +269,7 @@ namespace motors {
|
|||||||
if (this._brake && this._brakeSettleTime > 0)
|
if (this._brake && this._brakeSettleTime > 0)
|
||||||
pause(this._brakeSettleTime);
|
pause(this._brakeSettleTime);
|
||||||
else {
|
else {
|
||||||
control.cooperate();
|
pause(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,7 +280,7 @@ namespace motors {
|
|||||||
// allow robot to settle
|
// allow robot to settle
|
||||||
this.settle();
|
this.settle();
|
||||||
} else {
|
} else {
|
||||||
control.cooperate();
|
pause(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,8 +343,7 @@ namespace motors {
|
|||||||
//% blockId=motorRun block="run %motor at %speed=motorSpeedPicker|\\%||for %value %unit"
|
//% blockId=motorRun block="run %motor at %speed=motorSpeedPicker|\\%||for %value %unit"
|
||||||
//% weight=100 blockGap=8
|
//% weight=100 blockGap=8
|
||||||
//% group="Move"
|
//% group="Move"
|
||||||
//% motor.fieldEditor="speed"
|
//% motor.fieldEditor="motors"
|
||||||
//% motor.fieldOptions.decompileLiterals=1
|
|
||||||
//% expandableArgumentMode=toggle
|
//% expandableArgumentMode=toggle
|
||||||
//% help=motors/motor/run
|
//% help=motors/motor/run
|
||||||
run(speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
|
run(speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
|
||||||
@ -362,7 +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);
|
||||||
control.cooperate();
|
pause(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,8 +392,7 @@ namespace motors {
|
|||||||
//% blockId=motorSchedule block="ramp %motor at %speed=motorSpeedPicker|\\%|for %value|%unit||accelerate %acceleration|decelerate %deceleration"
|
//% blockId=motorSchedule block="ramp %motor at %speed=motorSpeedPicker|\\%|for %value|%unit||accelerate %acceleration|decelerate %deceleration"
|
||||||
//% weight=99 blockGap=8
|
//% weight=99 blockGap=8
|
||||||
//% group="Move"
|
//% group="Move"
|
||||||
//% motor.fieldEditor="speed"
|
//% motor.fieldEditor="motors"
|
||||||
//% motor.fieldOptions.decompileLiterals=1
|
|
||||||
//% help=motors/motor/ramp
|
//% help=motors/motor/ramp
|
||||||
//% inlineInputMode=inline
|
//% inlineInputMode=inline
|
||||||
//% expandableArgumentMode=toggle
|
//% expandableArgumentMode=toggle
|
||||||
@ -427,8 +421,7 @@ namespace motors {
|
|||||||
* of run commands.
|
* of run commands.
|
||||||
*/
|
*/
|
||||||
//% blockId=outputMotorsetRunRamp block="set %motor|run %ramp to $value||$unit"
|
//% blockId=outputMotorsetRunRamp block="set %motor|run %ramp to $value||$unit"
|
||||||
//% motor.fieldEditor="speed"
|
//% motor.fieldEditor="motors"
|
||||||
//% motor.fieldOptions.decompileLiterals=1
|
|
||||||
//% weight=21 blockGap=8
|
//% weight=21 blockGap=8
|
||||||
//% group="Properties"
|
//% group="Properties"
|
||||||
//% help=motors/motor/set-run-phase
|
//% help=motors/motor/set-run-phase
|
||||||
@ -499,8 +492,7 @@ namespace motors {
|
|||||||
* @param value true for regulated motor
|
* @param value true for regulated motor
|
||||||
*/
|
*/
|
||||||
//% blockId=outputMotorSetRegulated block="set %motor|regulated %value=toggleOnOff"
|
//% blockId=outputMotorSetRegulated block="set %motor|regulated %value=toggleOnOff"
|
||||||
//% motor.fieldEditor="speed"
|
//% motor.fieldEditor="motors"
|
||||||
//% motor.fieldOptions.decompileLiterals=1
|
|
||||||
//% weight=58 blockGap=8
|
//% weight=58 blockGap=8
|
||||||
//% group="Properties"
|
//% group="Properties"
|
||||||
//% help=motors/motor/set-regulated
|
//% help=motors/motor/set-regulated
|
||||||
@ -525,8 +517,7 @@ namespace motors {
|
|||||||
* @param timeOut optional maximum pausing time in milliseconds
|
* @param timeOut optional maximum pausing time in milliseconds
|
||||||
*/
|
*/
|
||||||
//% blockId=motorPauseUntilRead block="pause until %motor|ready"
|
//% blockId=motorPauseUntilRead block="pause until %motor|ready"
|
||||||
//% motor.fieldEditor="speed"
|
//% motor.fieldEditor="motors"
|
||||||
//% motor.fieldOptions.decompileLiterals=1
|
|
||||||
//% weight=90 blockGap=8
|
//% weight=90 blockGap=8
|
||||||
//% group="Move"
|
//% group="Move"
|
||||||
pauseUntilReady(timeOut?: number) {
|
pauseUntilReady(timeOut?: number) {
|
||||||
@ -584,8 +575,7 @@ namespace motors {
|
|||||||
* @param motor the port which connects to the motor
|
* @param motor the port which connects to the motor
|
||||||
*/
|
*/
|
||||||
//% blockId=motorSpeed block="%motor|speed"
|
//% blockId=motorSpeed block="%motor|speed"
|
||||||
//% motor.fieldEditor="speed"
|
//% motor.fieldEditor="motors"
|
||||||
//% motor.fieldOptions.decompileLiterals=1
|
|
||||||
//% weight=72
|
//% weight=72
|
||||||
//% blockGap=8
|
//% blockGap=8
|
||||||
//% group="Counters"
|
//% group="Counters"
|
||||||
@ -600,23 +590,21 @@ namespace motors {
|
|||||||
* @param motor the port which connects to the motor
|
* @param motor the port which connects to the motor
|
||||||
*/
|
*/
|
||||||
//% blockId=motorAngle block="%motor|angle"
|
//% blockId=motorAngle block="%motor|angle"
|
||||||
//% motor.fieldEditor="speed"
|
//% motor.fieldEditor="motors"
|
||||||
//% motor.fieldOptions.decompileLiterals=1
|
|
||||||
//% weight=70
|
//% weight=70
|
||||||
//% blockGap=8
|
//% blockGap=8
|
||||||
//% group="Counters"
|
//% group="Counters"
|
||||||
//% help=motors/motor/angle
|
//% help=motors/motor/angle
|
||||||
angle(): number {
|
angle(): number {
|
||||||
this.init();
|
this.init();
|
||||||
return getMotorData(this._port).count * this.invertedFactor();
|
return getMotorData(this._port).count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the motor count
|
* Clears the motor count
|
||||||
*/
|
*/
|
||||||
//% blockId=motorClearCount block="clear %motor|counters"
|
//% blockId=motorClearCount block="clear %motor|counters"
|
||||||
//% motor.fieldEditor="speed"
|
//% motor.fieldEditor="motors"
|
||||||
//% motor.fieldOptions.decompileLiterals=1
|
|
||||||
//% weight=68
|
//% weight=68
|
||||||
//% blockGap=8
|
//% blockGap=8
|
||||||
//% group="Counters"
|
//% group="Counters"
|
||||||
@ -644,8 +632,7 @@ namespace motors {
|
|||||||
* Pauses the program until the motor is stalled.
|
* Pauses the program until the motor is stalled.
|
||||||
*/
|
*/
|
||||||
//% blockId=motorPauseUntilStall block="pause until %motor|stalled"
|
//% blockId=motorPauseUntilStall block="pause until %motor|stalled"
|
||||||
//% motor.fieldEditor="speed"
|
//% motor.fieldEditor="motors"
|
||||||
//% motor.fieldOptions.decompileLiterals=1
|
|
||||||
//% weight=89
|
//% weight=89
|
||||||
//% group="Move"
|
//% group="Move"
|
||||||
//% help=motors/motor/pause-until-stalled
|
//% help=motors/motor/pause-until-stalled
|
||||||
|
@ -28,8 +28,7 @@
|
|||||||
"platform.h",
|
"platform.h",
|
||||||
"platform.cpp",
|
"platform.cpp",
|
||||||
"dmesg.cpp",
|
"dmesg.cpp",
|
||||||
"integrator.ts",
|
"integrator.ts"
|
||||||
"cooperate.ts"
|
|
||||||
],
|
],
|
||||||
"testFiles": [
|
"testFiles": [
|
||||||
"test.ts"
|
"test.ts"
|
||||||
|
@ -12,5 +12,4 @@ music.setTempo(120)
|
|||||||
music.noteFrequency(Note.C)
|
music.noteFrequency(Note.C)
|
||||||
music.beat()
|
music.beat()
|
||||||
music.setVolume(50)
|
music.setVolume(50)
|
||||||
music.volume()
|
|
||||||
```
|
```
|
@ -13,22 +13,7 @@
|
|||||||
|
|
||||||
namespace music {
|
namespace music {
|
||||||
|
|
||||||
int _readSystemVolume() {
|
uint8_t currVolume = 50;
|
||||||
char ParBuf[8];
|
|
||||||
int volume;
|
|
||||||
|
|
||||||
int fd = open("../sys/settings/Volume.rtf", O_RDONLY);
|
|
||||||
read(fd, ParBuf, sizeof(ParBuf));
|
|
||||||
close(fd);
|
|
||||||
if (sscanf(ParBuf,"%d",&volume) > 0) {
|
|
||||||
if ((volume >= 0) && (volume <= 100)) {
|
|
||||||
return volume;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 50;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t currVolume = _readSystemVolume();
|
|
||||||
uint8_t *lmsSoundMMap;
|
uint8_t *lmsSoundMMap;
|
||||||
|
|
||||||
int writeDev(void *data, int size) {
|
int writeDev(void *data, int size) {
|
||||||
@ -52,18 +37,6 @@ void setVolume(int volume) {
|
|||||||
currVolume = max(0, min(100, volume));
|
currVolume = max(0, min(100, volume));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the output volume of the sound synthesizer.
|
|
||||||
*/
|
|
||||||
//% weight=96
|
|
||||||
//% blockId=synth_get_volume block="volume"
|
|
||||||
//% parts="speaker" blockGap=8
|
|
||||||
//% help=music/volume
|
|
||||||
//% weight=1
|
|
||||||
int volume() {
|
|
||||||
return currVolume;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SOUND_CMD_BREAK 0
|
#define SOUND_CMD_BREAK 0
|
||||||
#define SOUND_CMD_TONE 1
|
#define SOUND_CMD_TONE 1
|
||||||
#define SOUND_CMD_PLAY 2
|
#define SOUND_CMD_PLAY 2
|
||||||
@ -72,7 +45,7 @@ int volume() {
|
|||||||
|
|
||||||
struct ToneCmd {
|
struct ToneCmd {
|
||||||
uint8_t cmd;
|
uint8_t cmd;
|
||||||
uint8_t lvl;
|
uint8_t vol;
|
||||||
uint16_t freq;
|
uint16_t freq;
|
||||||
uint16_t duration;
|
uint16_t duration;
|
||||||
};
|
};
|
||||||
@ -82,26 +55,10 @@ static void _stopSound() {
|
|||||||
writeDev(&cmd, sizeof(cmd));
|
writeDev(&cmd, sizeof(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t _getVolumeLevel(uint8_t volume, uint8_t levels) {
|
|
||||||
uint8_t level;
|
|
||||||
uint8_t step = (uint8_t) (100 / (levels - 1));
|
|
||||||
if (volume < step) {
|
|
||||||
level = 0;
|
|
||||||
} else if (volume > step * (levels - 1)) {
|
|
||||||
level = levels;
|
|
||||||
} else {
|
|
||||||
level = (uint8_t) (volume / step);
|
|
||||||
}
|
|
||||||
return level;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _playTone(uint16_t frequency, uint16_t duration, uint8_t volume) {
|
static void _playTone(uint16_t frequency, uint16_t duration, uint8_t volume) {
|
||||||
// https://github.com/mindboards/ev3sources/blob/78ebaf5b6f8fe31cc17aa5dce0f8e4916a4fc072/lms2012/c_sound/source/c_sound.c#L471
|
|
||||||
uint8_t level = _getVolumeLevel(volume, 13);
|
|
||||||
|
|
||||||
ToneCmd cmd;
|
ToneCmd cmd;
|
||||||
cmd.cmd = SOUND_CMD_TONE;
|
cmd.cmd = SOUND_CMD_TONE;
|
||||||
cmd.lvl = level;
|
cmd.vol = volume;
|
||||||
cmd.freq = frequency;
|
cmd.freq = frequency;
|
||||||
cmd.duration = duration;
|
cmd.duration = duration;
|
||||||
// (*SoundInstance.pSound).Busy = TRUE;
|
// (*SoundInstance.pSound).Busy = TRUE;
|
||||||
@ -165,8 +122,7 @@ void playSample(Buffer buf) {
|
|||||||
stopUser();
|
stopUser();
|
||||||
pthread_mutex_lock(&pumpMutex);
|
pthread_mutex_lock(&pumpMutex);
|
||||||
*lmsSoundMMap = 1; // BUSY
|
*lmsSoundMMap = 1; // BUSY
|
||||||
// https://github.com/mindboards/ev3sources/blob/78ebaf5b6f8fe31cc17aa5dce0f8e4916a4fc072/lms2012/c_sound/source/c_sound.c#L605
|
uint8_t cmd[] = {SOUND_CMD_PLAY, (uint8_t)((currVolume / 33) + 1)};
|
||||||
uint8_t cmd[] = {SOUND_CMD_PLAY, _getVolumeLevel(currVolume, 8)};
|
|
||||||
writeDev(cmd, 2);
|
writeDev(cmd, 2);
|
||||||
decrRC(currentSample);
|
decrRC(currentSample);
|
||||||
currentSample = buf;
|
currentSample = buf;
|
||||||
|
10
libs/music/shims.d.ts
vendored
10
libs/music/shims.d.ts
vendored
@ -13,16 +13,6 @@ declare namespace music {
|
|||||||
//% weight=1 shim=music::setVolume
|
//% weight=1 shim=music::setVolume
|
||||||
function setVolume(volume: int32): void;
|
function setVolume(volume: int32): void;
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the output volume of the sound synthesizer.
|
|
||||||
*/
|
|
||||||
//% weight=96
|
|
||||||
//% blockId=synth_get_volume block="volume"
|
|
||||||
//% parts="speaker" blockGap=8
|
|
||||||
//% help=music/volume
|
|
||||||
//% weight=1 shim=music::volume
|
|
||||||
function volume(): int32;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Play a tone through the speaker for some amount of time.
|
* Play a tone through the speaker for some amount of time.
|
||||||
* @param frequency pitch of the tone to play in Hertz (Hz), eg: Note.C
|
* @param frequency pitch of the tone to play in Hertz (Hz), eg: Note.C
|
||||||
|
@ -5,4 +5,3 @@ music.playTone(1440, 500)
|
|||||||
pause(500)
|
pause(500)
|
||||||
music.playTone(2440, 500)
|
music.playTone(2440, 500)
|
||||||
pause(500)
|
pause(500)
|
||||||
music.volume()
|
|
||||||
|
23
package.json
23
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-ev3",
|
"name": "pxt-ev3",
|
||||||
"version": "1.4.25",
|
"version": "1.4.21",
|
||||||
"description": "LEGO MINDSTORMS EV3 for Microsoft MakeCode",
|
"description": "LEGO MINDSTORMS EV3 for Microsoft MakeCode",
|
||||||
"private": false,
|
"private": false,
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@ -32,20 +32,21 @@
|
|||||||
"docs/*/*/*.md"
|
"docs/*/*/*.md"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/marked": "^0.3.0",
|
"react": "16.8.3",
|
||||||
"@types/node": "^9.3.0",
|
"webfonts-generator": "^0.4.0",
|
||||||
"@types/react": "16.8.25",
|
"@types/jquery": "3.2.16",
|
||||||
|
"@types/react": "16.0.25",
|
||||||
"@types/react-dom": "16.0.3",
|
"@types/react-dom": "16.0.3",
|
||||||
"@types/web-bluetooth": "0.0.4",
|
"@types/web-bluetooth": "0.0.4",
|
||||||
"@vusion/webfonts-generator": "^0.7.1",
|
"@types/bluebird": "^2.0.33",
|
||||||
"react": "16.8.3",
|
"@types/marked": "^0.3.0",
|
||||||
"react-dom": "16.11.0",
|
"@types/node": "^9.3.0",
|
||||||
"semantic-ui-less": "2.4.1",
|
"semantic-ui-less": "2.2.14",
|
||||||
"typescript": "^4.2.3"
|
"typescript": "^3.7.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-common-packages": "9.2.7",
|
"pxt-common-packages": "8.1.3",
|
||||||
"pxt-core": "7.2.16"
|
"pxt-core": "6.2.8"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||||
|
@ -77,9 +77,8 @@
|
|||||||
"pauseUntilBlock": {
|
"pauseUntilBlock": {
|
||||||
"category": "loops"
|
"category": "loops"
|
||||||
},
|
},
|
||||||
"breakBlock": true,
|
"bannedCategories": [
|
||||||
"continueBlock": true,
|
]
|
||||||
"bannedCategories": []
|
|
||||||
},
|
},
|
||||||
"compileService": {
|
"compileService": {
|
||||||
"buildEngine": "dockermake",
|
"buildEngine": "dockermake",
|
||||||
@ -115,12 +114,12 @@
|
|||||||
"de",
|
"de",
|
||||||
"ja",
|
"ja",
|
||||||
"ru",
|
"ru",
|
||||||
"zh-CN",
|
"zh-CN"
|
||||||
"fr"
|
|
||||||
],
|
],
|
||||||
"highContrast": true,
|
"highContrast": true,
|
||||||
"lightToc": true,
|
"lightToc": true,
|
||||||
"docMenu": [{
|
"docMenu": [
|
||||||
|
{
|
||||||
"name": "Support",
|
"name": "Support",
|
||||||
"path": "https://forum.makecode.com/"
|
"path": "https://forum.makecode.com/"
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
CACHE MANIFEST
|
CACHE MANIFEST
|
||||||
|
|
||||||
CACHE:
|
CACHE:
|
||||||
|
/cdn/bluebird.min.js
|
||||||
/cdn/pxtsim.js
|
/cdn/pxtsim.js
|
||||||
/sim/common-sim.js
|
/sim/common-sim.js
|
||||||
/sim/sim.js
|
/sim/sim.js
|
||||||
|
@ -23,6 +23,7 @@ body {
|
|||||||
transition: none !important;
|
transition: none !important;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<script src="/cdn/bluebird.min.js"></script>
|
||||||
<script src="/cdn/pxtsim.js"></script>
|
<script src="/cdn/pxtsim.js"></script>
|
||||||
<script src="/sim/common-sim.js"></script>
|
<script src="/sim/common-sim.js"></script>
|
||||||
<script src="/sim/sim.js"></script>
|
<script src="/sim/sim.js"></script>
|
||||||
|
@ -37,7 +37,7 @@ namespace pxsim {
|
|||||||
return Math.round(this.angle);
|
return Math.round(this.angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the secondary motor if any
|
// returns the slave motor if any
|
||||||
getSynchedMotor() {
|
getSynchedMotor() {
|
||||||
return this._synchedMotor;
|
return this._synchedMotor;
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,6 @@ namespace pxsim.music {
|
|||||||
export function stopAllSounds() {
|
export function stopAllSounds() {
|
||||||
SoundMethods.stop()
|
SoundMethods.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
pxsim.music.setVolume = (volume: number): void => {
|
|
||||||
pxsim.getAudioState().volume = volume;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function volume() {
|
|
||||||
return pxsim.getAudioState().volume;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace pxsim.SoundMethods {
|
namespace pxsim.SoundMethods {
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"newLine": "LF",
|
"newLine": "LF",
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
"lib": ["dom", "dom.iterable", "scripthost", "es6"],
|
"lib": ["dom", "dom.iterable", "scripthost", "es6"],
|
||||||
"types": [],
|
"types": ["bluebird"],
|
||||||
"typeRoots": ["../node_modules/@types"]
|
"typeRoots": ["../node_modules/@types"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -381,7 +381,7 @@ namespace pxsim.visuals {
|
|||||||
this.screenCanvas = document.createElement("canvas");
|
this.screenCanvas = document.createElement("canvas");
|
||||||
this.screenCanvas.id = "board-screen-canvas";
|
this.screenCanvas.id = "board-screen-canvas";
|
||||||
this.screenCanvas.style.userSelect = "none";
|
this.screenCanvas.style.userSelect = "none";
|
||||||
(this.screenCanvas.style as any).msUserSelect = "none";
|
this.screenCanvas.style.msUserSelect = "none";
|
||||||
this.screenCanvas.style.webkitUserSelect = "none";
|
this.screenCanvas.style.webkitUserSelect = "none";
|
||||||
(this.screenCanvas.style as any).MozUserSelect = "none";
|
(this.screenCanvas.style as any).MozUserSelect = "none";
|
||||||
this.screenCanvas.style.position = "absolute";
|
this.screenCanvas.style.position = "absolute";
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
specify theme name below
|
specify theme name below
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@placeholder: 'default';
|
|
||||||
|
|
||||||
/* Global */
|
/* Global */
|
||||||
@site : 'pxt';
|
@site : 'pxt';
|
||||||
@reset : 'default';
|
@reset : 'default';
|
||||||
@ -89,7 +87,7 @@
|
|||||||
Import Theme
|
Import Theme
|
||||||
*******************************/
|
*******************************/
|
||||||
|
|
||||||
@import (multiple) "theme.less";
|
@import "theme.less";
|
||||||
|
|
||||||
@fontPath : 'fonts';
|
@fontPath : 'fonts';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user