Compare commits

..

2 Commits

Author SHA1 Message Date
Michal Moskal
1c37bea54a Make settings compile 2019-10-09 08:53:48 -07:00
Peli de Halleux
b653e54917 support for settings package 2019-10-09 08:12:22 -07:00
29 changed files with 92 additions and 348 deletions

View File

@@ -1,12 +0,0 @@
name: Compress images
on: pull_request
jobs:
build:
name: calibreapp/image-actions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: calibreapp/image-actions
uses: calibreapp/image-actions@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -73,12 +73,6 @@ Verify that the program you just created shows eyes on the Brick Display, and th
**Well done!**
## Run it Again
![EV3 Brick with Try in BrkProg_Save Folder in File Manager](/static/getting-started/try-in-file-manager.png)
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 @unplugged
Now you will learn to control the Large Motor.

View File

@@ -1,3 +1,3 @@
{
"appref": "v1.2.26"
"appref": "v1.2.22"
}

View File

@@ -388,12 +388,12 @@
}
function downloadWin64() {
// TODO: Keep this link up-to-date with the desired release version
window.open("https://makecode.com/api/release/ev3/v1.2.26/win64");
window.open("https://makecode.com/api/release/ev3/v1.2.22/win64");
tickEvent("offlineapp.download", { "target": "ev3", "platform": "win64" });
}
function downloadMac64() {
// TODO: Keep this link up-to-date with the desired release version
window.open("https://makecode.com/api/release/ev3/v1.2.26/mac64");
window.open("https://makecode.com/api/release/ev3/v1.2.22/mac64");
tickEvent("offlineapp.download", { "target": "ev3", "platform": "mac64" });
}
</script>

View File

@@ -1,18 +0,0 @@
# 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();
```

View File

@@ -1,3 +0,0 @@
{
"appref": "v1.2"
}

View File

@@ -1,6 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" id="svg4487" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.4" clip-rule="evenodd" version="1.1" width="32" height="32" viewBox="0 0 32 32">
<path id="path4485" fill="#696969" d="M16.1 2.7a13.8 13.8 0 00-4.4 27c.7 0 1-.4 1-.7v-2.4c-3.9.9-4.7-1.8-4.7-1.8-.6-1.6-1.5-2-1.5-2-1.3-1 0-.9 0-.9 1.4.1 2.2 1.4 2.2 1.4 1.2 2.1 3.2 1.5 4 1.2a3 3 0 01.9-1.9c-3.1-.3-6.3-1.5-6.3-6.8 0-1.5.5-2.7 1.4-3.7a5 5 0 01.1-3.7s1.2-.3 3.8 1.4a13.2 13.2 0 013.5-.4c1.2 0 2.4.1 3.5.4 2.6-1.7 3.8-1.4 3.8-1.4a5 5 0 01.1 3.7c.9 1 1.4 2.2 1.4 3.7 0 5.3-3.2 6.5-6.3 6.8.5.5 1 1.3 1 2.6V29c0 .4.2.8.9.6a13.8 13.8 0 00-4.4-27"/>
<g id="text4497" fill="#000" fill-opacity="1" stroke="none" stroke-width=".7" aria-label="v" font-family="consolas" font-size="26.6" font-stretch="normal" font-style="normal" font-variant="normal" font-weight="400" letter-spacing="0" style="line-height:1.25;-inkscape-font-specification:consolas" transform="rotate(14.1)" word-spacing="0">
<path id="path4499" stroke-width=".7" d="M21.4-1.7l2.9 8 3-8.3.8-1.5q.4-.4 1-.4.8 0 1.2.5.5.4.5 1v.6l-.3.5-.2.7-3.4 8.4-.4 1-.5 1-.7.5q-.4.2-1 .2-.8 0-1.2-.3-.5-.3-.7-.8l-.7-1.6-3.4-8.3q0-.4-.2-.7l-.2-.6-.1-.6.2-.7.6-.6q.4-.2.9-.2.9 0 1.2.5l.7 1.7z" font-family="Arial Rounded MT Bold" font-stretch="normal" font-style="normal" font-variant="normal" font-weight="400" style="-inkscape-font-specification:'Arial Rounded MT Bold, '"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -1,18 +1,16 @@
# Troubleshooting
## Download issues
# Troubleshooting download problems
If you're having trouble getting your code onto the EV3 Brick, try these steps to see if you can fix the problem.
### Check your **@drivename@** firmware
## Check your **@drivename@** firmware
MakeCode needs a firmware version of **1.10E** or higher installed on your brick.
#### ~hint
### ~hint
Firmware is the software that runs all the basic operations on your EV3 Brick. Your programs and the firmware work together to make the EV3 Brick do all things you want it to. Your EV3 Brick comes with firmware pre-installed, but it may need to be updated to work properly with MakeCode.
#### ~
### ~
To check the the firmware version on your EV3 Brick:
@@ -27,15 +25,15 @@ To check the the firmware version on your EV3 Brick:
If you can't find the **Brick Info** or you see that the version is less than **1.10E**, **you need to upgrade your firmware**.
### Upgrade your **@drivename@**
## Upgrade your **@drivename@**
If your a firmware version level is less than **1.10E**, you need to install an upgraded version. You can upgrade the firmware with the **EV3 Lab** or **EV3 Programming** software. Also, you can do a manual upgrade by downloading the firmware install file. See the [Firmware Update](https://education.lego.com/en-us/support/mindstorms-ev3/firmware-update) support page to learn about the upgrade process.
#### ~ hint
### ~ hint
**Recommended:** Upgrade with the **[EV3 Device Manager](https://ev3manager.education.lego.com/)**
#### ~
### ~
## Can I see the **@drivename@** drive on my computer?
@@ -47,24 +45,14 @@ On Windows, it looks like this in Explorer:
If you don't see the **@drivename@** drive, make sure your brick is powered on and check that your USB connection is good.
### The display on the EV3 Brick is blank
## The display on the EV3 Brick is blank
Make sure your EV3 Brick is charged and powered on. If your it doesn't turn on, find the charger and plug it into wall power, then connect it to your EV3 Brick. Does it turn on and start up?
### I still can't see my @drivename@ drive
## I still can't see my @drivename@ drive
Make sure that one end of your USB cable is firmly inserted into a USB port on the computer and the other end is connected to the EV3 Brick. If you still can't see the **@drivename@** drive, try a different port on the computer. If that doesn't work then maybe your cable is faulty or you need to reset the EV3 Brick.
## Why can't I delete my program (*.uf2) files from the Brick? #deletefiles
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.
We have prepared a special program that lets you delete UF2 files from the brick.
Download [these PDF instructions](/file-manager.pdf) and drop the PDF on the brick drive.
This will present you with an menu for deleting files.
For other common questions, try the FAQ page https://makecode.mindstorms.com/faq.
## How do I reset my EV3 Brick?
If you think your USB connection is good and you still can't see your **@drivename@** drive, try giving the EV3 Brick a reset. You can follow these steps to reset:

View File

@@ -1,4 +1,5 @@
const enum ColorSensorMode {
None = 0,
//% block="reflected light intensity"
ReflectedLightIntensity = 0,
//% block="ambient light intensity"
@@ -58,6 +59,7 @@ namespace sensors {
constructor(port: number) {
super(port)
this._setMode(ColorSensorMode.None);
this.thresholdDetector = new sensors.ThresholdDetector(this.id());
this.calibrating = false;
}
@@ -179,22 +181,6 @@ namespace sensors {
return this.getNumber(NumberFormat.UInt8LE, 0)
}
/**
* Checks the color is being detected
* @param color the color to detect
*/
//% help=sensors/color-sensor/is-color-detected
//% block="is **color sensor** %this|detected|%color=colorEnumPicker"
//% blockId=colorisColorDetectedDetected
//% parts="colorsensor"
//% blockNamespace=sensors
//% this.fieldEditor="ports"
//% weight=99 blockGap=8
//% group="Color Sensor"
isColorDetected(color: number) {
return this.color() == color;
}
/**
* Get the current raw rgb values as an array from the color sensor.
* @param sensor the color sensor to query the request

View File

@@ -1,30 +0,0 @@
# Is Color Detected
Checks the color is detected
```sig
let b = sensors.color1.isColorDetected(ColorSensorColor.Blue)
```
The [color](/reference/sensors/color) you choose to look for is one of the colors that the sensor can detect. If you want to use colors for tracking, it's best to use a color that is the same or very close to the ones the sensor detects.
## Parameters
* **color**: the [color](/reference/sensors/color) to watch for.
## Example
Wait for the sensor to see ``blue``. Then, show an expression on the screen.
```blocks
brick.showString("Waiting for blue", 1)
while(!sensors.color1.isColorDetected(ColorSensorColor.Blue)) {
pause(20)
}
brick.clearScreen()
brick.showImage(images.expressionsSick)
```
## See also
[on color detected](/reference/sensors/color-sensor/on-color-detected), [color](/reference/sensors/color)

View File

@@ -26,7 +26,6 @@ namespace brick {
*/
//% blockId=brickBatteryProperty block="battery %property"
//% group="Battery"
//% blockGap=8
//% help=brick/battery-property
export function batteryInfo(property: BatteryProperty): number {
const info = sensors.internal.getBatteryInfo();

View File

@@ -85,7 +85,7 @@ namespace brick {
//% blockId=buttonIsPressed
//% parts="brick"
//% blockNamespace=brick
//% weight=81
//% weight=81 blockGap=8
//% group="Buttons"
//% button.fieldEditor="brickbuttons"
isPressed() {

View File

@@ -277,25 +277,22 @@ void cUiUpdatePower(void)
const conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
let r = 0;
for (let i = 0; i < conns.length; ++i) {
r = conns[i] + (r << 6) + (r << 16) - r;
r = (r << 8 | conns[i]);
}
return r;
}
let nonActivated = 0;
function detectDevices() {
control.dmesg(`detect devices (hash ${hashDevices()})`)
//control.dmesg(`detect devices (${nonActivated} na)`)
const conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
let numChanged = 0;
const uartSensors: SensorInfo[] = [];
for (const sensorInfo of sensorInfos) {
const newConn = conns[sensorInfo.port]
if (newConn == sensorInfo.connType
&& sensorInfo.sensor
&& sensorInfo.sensor.isActive()) {
if (newConn == DAL.CONN_INPUT_UART)
uartSensors.push(sensorInfo);
if (newConn == sensorInfo.connType) {
// control.dmesg(`connection unchanged ${newConn} at ${sensorInfo.port}`)
continue;
}
numChanged++
@@ -326,8 +323,7 @@ void cUiUpdatePower(void)
for (const sensorInfo of uartSensors) {
let uinfo = readUartInfo(sensorInfo.port, 0)
sensorInfo.devType = uinfo[TypesOff.Type]
const mode = uinfo[TypesOff.Mode];
control.dmesg(`UART type ${sensorInfo.devType} mode ${mode}`)
control.dmesg(`UART type ${sensorInfo.devType}`)
}
}
@@ -462,7 +458,7 @@ void cUiUpdatePower(void)
reset() {
if (this.isActive()) uartReset(this._port);
this.realmode = -1;
this.realmode = 0;
}
}
@@ -540,6 +536,8 @@ void cUiUpdatePower(void)
function uartClearChange(port: number) {
control.dmesg(`UART clear change`);
const UART_DATA_READY = 8
const UART_PORT_CHANGED = 1
while (true) {
let status = getUartStatus(port)
if (port < 0) break
@@ -560,7 +558,7 @@ void cUiUpdatePower(void)
}
function setUartModes() {
control.dmesg(`UART set modes 0x${devcon.toHex()}`)
control.dmesg(`UART set modes`)
uartMM.ioctl(IO.UART_SET_CONN, devcon)
const ports: number[] = [];
for (let port = 0; port < DAL.NUM_INPUTS; ++port) {
@@ -572,26 +570,22 @@ void cUiUpdatePower(void)
while (ports.length) {
const port = ports.pop();
const status = waitNonZeroUartStatus(port)
control.dmesg(`UART status ${status} at ${port}`);
if (!(status & UART_DATA_READY))
setUartMode(port, devcon[DevConOff.Mode + port]);
control.dmesg(`UART set mode ${status} at ${port}`);
}
}
function updateUartMode(port: number, mode: number) {
control.dmesg(`UART update mode to ${mode} at ${port}`)
control.dmesg(`UART set mode to ${mode} at ${port}`)
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Connection + port, DAL.CONN_INPUT_UART)
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Type + port, 33)
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Mode + port, mode)
}
const UART_PORT_CHANGED = 1
const UART_DATA_READY = 8
function setUartMode(port: number, mode: number) {
const UART_PORT_CHANGED = 1
while (true) {
if (port < 0) return
updateUartMode(port, mode);
control.dmesg(`UART set mode 0x${devcon.toHex()}`)
uartMM.ioctl(IO.UART_SET_CONN, devcon)
let status = waitNonZeroUartStatus(port)
if (status & UART_PORT_CHANGED) {
@@ -599,8 +593,7 @@ void cUiUpdatePower(void)
uartClearChange(port)
} else {
control.dmesg(`UART status ${status}`);
if (status & UART_DATA_READY)
break;
break;
}
pause(10)
}

View File

@@ -1,6 +1,9 @@
#include "pxt.h"
#include "ev3const.h"
#include <sys/stat.h>
#include <sys/types.h>
namespace output {
/**
@@ -17,6 +20,7 @@ Buffer createBuffer(int size) {
namespace pxt {
void target_init() {
mkdir(SETTINGSDIR, 0777);
}
}

View File

@@ -159,7 +159,6 @@ namespace motors {
private _accelerationTime: number;
private _decelerationSteps: number;
private _decelerationTime: number;
private _inverted: boolean;
protected static output_types: number[] = [0x7, 0x7, 0x7, 0x7];
@@ -177,7 +176,6 @@ namespace motors {
this._accelerationTime = 0;
this._decelerationSteps = 0;
this._decelerationTime = 0;
this._inverted = false;
}
/**
@@ -227,11 +225,9 @@ namespace motors {
//% help=motors/motor/set-inverted
setInverted(inverted: boolean) {
this.init();
this._inverted = inverted;
}
protected invertedFactor(): number {
return this._inverted ? -1 : 1;
const b = mkCmd(this._port, DAL.opOutputPolarity, 1)
b.setNumber(NumberFormat.Int8LE, 2, inverted ? 0 : 1);
writePWM(b)
}
/**
@@ -298,9 +294,8 @@ namespace motors {
}
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 = {
speed: Math.clamp(-100, 100, speed | 0) * this.invertedFactor(),
speed: Math.clamp(-100, 100, speed >> 0),
useSteps: true,
steps: [step1 || 0, step2 || 0, step3 || 0]
}
@@ -567,7 +562,6 @@ namespace motors {
private __init() {
this.setOutputType(this._large);
this.setInverted(false);
}
/**
@@ -747,7 +741,7 @@ namespace motors {
//% help=motors/synced/steer
steer(turnRatio: number, speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
this.init();
speed = Math.clamp(-100, 100, speed >> 0) * this.invertedFactor();
speed = Math.clamp(-100, 100, speed >> 0);
if (!speed) {
this.stop();
return;

View File

@@ -120,7 +120,7 @@ void stopLMS() {
if (!pid)
continue;
char namebuf[100];
snprintf(namebuf, 100, "/proc/%d/cmdline", pid);
snprintf(namebuf, 1000, "/proc/%d/cmdline", pid);
FILE *f = fopen(namebuf, "r");
if (f) {
fread(namebuf, 1, 99, f);
@@ -195,42 +195,5 @@ void target_startup() {
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;
}
}

View File

@@ -1,3 +1,5 @@
#define PXT_GC_THREAD_LIST 1
#define PXT_IN_ISR() false
#define SETTINGSDIR "/mnt/ramdisk/settings"

View File

@@ -1,13 +0,0 @@
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();
}
}

View File

@@ -1,6 +1,6 @@
//% color="#68C3E2" weight=100 icon="\uf106"
//% groups='["Buttons", "Screen", "Power"]'
//% groups='["Buttons", "Screen", "Battery"]'
//% labelLineWidth=60
namespace brick {
}

View File

@@ -2,9 +2,8 @@
"name": "ev3",
"description": "The EV3 library",
"files": [
"README.md",
"README.md",
"ns.ts",
"brick.ts",
"startup.ts",
"images.jres",
"images.ts",
@@ -24,7 +23,8 @@
"touch-sensor": "file:../touch-sensor",
"ultrasonic-sensor": "file:../ultrasonic-sensor",
"gyro-sensor": "file:../gyro-sensor",
"infrared-sensor": "file:../infrared-sensor"
"infrared-sensor": "file:../infrared-sensor",
"settings": "file:../settings"
},
"palette": [
"#ffffff",

View File

@@ -2,5 +2,9 @@
console.addListener(function(priority: ConsolePriority, msg: string) {
control.dmesg(msg.substr(0, msg.length - 1))
})
// boot sequence
brick.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);

View File

@@ -129,8 +129,8 @@ namespace brick {
screenMode = ScreenMode.Ports;
renderPorts();
control.runInParallel(function () {
while (screenMode == ScreenMode.Ports) {
control.runInParallel(function() {
while(screenMode == ScreenMode.Ports) {
renderPorts();
pause(50);
}
@@ -140,18 +140,8 @@ namespace brick {
function renderPorts() {
const col = 44;
const lineHeight8 = image.font8.charHeight + 2;
const h = screen.height;
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) {
if (Math.abs(x) >= 5000) {
const k = Math.floor(x / 1000);
@@ -165,38 +155,27 @@ namespace brick {
const datas = motors.getAllMotorData();
for (let i = 0; i < datas.length; ++i) {
const data = datas[i];
const x = i * col + 2;
if (!data.actualSpeed && !data.count) continue;
screen.print(`${scale(data.actualSpeed)}%`, x, 3 * lineHeight8, 1, image.font8)
screen.print(`${scale(data.count)}>`, x, 4 * lineHeight8, 1, image.font8)
const x = i * col;
screen.print("ABCD"[i], x + 2, 1 * 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.font8)
}
screen.drawLine(0, 5 * lineHeight8, screen.width, 5 * lineHeight8, 1);
// sensors
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) {
const si = sis[i];
const x = (si.port() - 1) * col + 2;
const x = (si.port() - 1) * col;
const inf = si._info();
if (inf)
screen.print(inf, x, h - 2 * lineHeight8, 1, inf.length > 4 ? image.font5 : image.font8);
screen.print(si.port() + "", x, h - 4 * lineHeight8, 1, 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();
})
}
/**
* An image
* @param image the image

4
libs/settings/pxt.json Normal file
View File

@@ -0,0 +1,4 @@
{
"name": "settings",
"additionalFilePath": "../../node_modules/pxt-common-packages/libs/settings---files"
}

View File

@@ -1,6 +1,6 @@
{
"name": "pxt-ev3",
"version": "1.4.16",
"version": "1.4.2",
"description": "LEGO MINDSTORMS EV3 for Microsoft MakeCode",
"private": false,
"keywords": [
@@ -45,8 +45,8 @@
"@types/web-bluetooth": "0.0.4"
},
"dependencies": {
"pxt-common-packages": "6.16.37",
"pxt-core": "5.30.19"
"pxt-common-packages": "6.16.7",
"pxt-core": "5.25.6"
},
"scripts": {
"test": "node node_modules/pxt-core/built/pxt.js travis"

View File

@@ -18,7 +18,8 @@
"libs/screen",
"libs/ev3",
"libs/storage",
"libs/broadcast"
"libs/broadcast",
"libs/settings"
],
"simulator": {
"autoRun": true,
@@ -37,10 +38,7 @@
"publishing": true,
"importing": true,
"preferredPackages": [],
"githubPackages": true,
"cloudProviders": {
"github": {}
}
"githubPackages": true
},
"compile": {
"isNative": true,
@@ -78,6 +76,7 @@
"category": "loops"
},
"bannedCategories": [
"image"
]
},
"compileService": {
@@ -204,6 +203,5 @@
"alwaysGithubItem": true,
"enableTrace": true
},
"ignoreDocsErrors": true,
"uploadDocs": true
"ignoreDocsErrors": true
}

View File

@@ -1,97 +0,0 @@
//% 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()

View File

@@ -9,6 +9,7 @@ namespace pxsim {
private angle: number = 0;
private tacho: number = 0;
private speed: number = 0;
private polarity: number = 1; // -1, 1 or -1
private started: boolean;
private speedCmd: DAL;
@@ -30,7 +31,7 @@ namespace pxsim {
}
getSpeed() {
return Math.round(this.speed);
return Math.round(this.speed * (!this._synchedMotor && this.polarity == 0 ? -1 : 1));
}
getAngle() {
@@ -81,6 +82,16 @@ namespace pxsim {
return this.id == NodeType.LargeMotor;
}
setPolarity(polarity: number) {
// Either 1 or 255 (reverse)
/*
-1 : Motor will run backward
0 : Motor will run opposite direction
1 : Motor will run forward
*/
this.polarity = polarity;
}
reset() {
// not sure what reset does...
}

View File

@@ -119,7 +119,11 @@ namespace pxsim {
return 2;
}
case DAL.opOutputPolarity: {
console.error("opOutputPolarity not supported");
// reverse
const port = buf.data[1];
const polarity = pxsim.BufferMethods.getNumber(buf, BufferMethods.NumberFormat.Int8LE, 2);
const motors = ev3board().getMotor(port);
motors.forEach(motor => motor.setPolarity(polarity));
return 2;
}
case DAL.opOutputSetType: {

View File

@@ -27,6 +27,6 @@
"Tutorial Videos": "videos"
},
"electronManifest": {
"latest": "v1.2.26"
"latest": "v1.2.22"
}
}