Skip to content

Commit

Permalink
Merge branch '0.25.x' into chore-merge-0.25.x
Browse files Browse the repository at this point in the history
  • Loading branch information
brusherru committed Oct 19, 2018
2 parents af1d386 + 1a83415 commit 42e1dc4
Show file tree
Hide file tree
Showing 24 changed files with 307 additions and 118 deletions.
8 changes: 8 additions & 0 deletions packages/arduino-cli/README.md
Expand Up @@ -36,6 +36,14 @@ Wraps `arduino-cli config dump`.

- Returns `Promise<Object>`

### updateConfig(newConfig)
Replaces old config with the new one.

Accepts:
- `newConfig` `<Object>` — Plain JS object representation of `.cli-config.yml`

- Returns `<Object>` with the new config

### listConnectedBoards()
A wrapper with a custom extension over `arduino-cli board list`.

Expand Down
14 changes: 10 additions & 4 deletions packages/arduino-cli/src/config.js
Expand Up @@ -9,10 +9,8 @@ const getDefaultConfig = configDir => ({
arduino_data: resolve(configDir, 'data'),
});

export const configure = inputConfig => {
const configDir = fse.mkdtempSync(resolve(tmpdir(), 'arduino-cli'));
const configPath = resolve(configDir, '.cli-config.yml');
const config = inputConfig || getDefaultConfig(configDir);
// :: Path -> Object -> { config: Object, path: Path }
export const saveConfig = (configPath, config) => {
const yamlString = YAML.stringify(config, 2);

// Write config
Expand All @@ -28,6 +26,14 @@ export const configure = inputConfig => {
};
};

// :: Object -> { config: Object, path: Path }
export const configure = inputConfig => {
const configDir = fse.mkdtempSync(resolve(tmpdir(), 'arduino-cli'));
const configPath = resolve(configDir, '.cli-config.yml');
const config = inputConfig || getDefaultConfig(configDir);
return saveConfig(configPath, config);
};

// :: Path -> [URL] -> Promise [URL] Error
export const addPackageIndexUrls = (configPath, urls) =>
fse
Expand Down
15 changes: 13 additions & 2 deletions packages/arduino-cli/src/index.js
Expand Up @@ -5,7 +5,12 @@ import { exec, spawn } from 'child-process-promise';
import YAML from 'yamljs';
import { remove } from 'fs-extra';

import { configure, addPackageIndexUrl, addPackageIndexUrls } from './config';
import {
saveConfig,
configure,
addPackageIndexUrl,
addPackageIndexUrls,
} from './config';
import { patchBoardsWithOptions } from './optionParser';
import listAvailableBoards from './listAvailableBoards';
import parseProgressLog from './parseProgressLog';
Expand All @@ -19,7 +24,7 @@ const escapeSpacesNonWin = R.unless(() => IS_WIN, R.replace(/\s/g, '\\ '));
* @param {Object} config Plain-object representation of `.cli-config.yml`
*/
const ArduinoCli = (pathToBin, config = null) => {
const { path: configPath, config: cfg } = configure(config);
let { path: configPath, config: cfg } = configure(config);

const escapedConfigPath = escapeSpacesNonWin(configPath);
const run = args =>
Expand Down Expand Up @@ -68,6 +73,12 @@ const ArduinoCli = (pathToBin, config = null) => {

return {
dumpConfig: getConfig,
updateConfig: newConfig => {
const newCfg = saveConfig(configPath, newConfig);
configPath = newCfg.path;
cfg = newCfg.config;
return cfg;
},
listConnectedBoards: () => listBoardsWith('list', R.prop('serialBoards')),
listInstalledBoards: () => listBoardsWith('listall', R.prop('boards')),
listAvailableBoards: () => listAvailableBoards(cfg.arduino_data),
Expand Down
4 changes: 2 additions & 2 deletions packages/arduino-cli/src/optionParser.js
Expand Up @@ -45,9 +45,9 @@ export const getLines = R.compose(

const menuRegExp = /^menu\./;

const optionNameRegExp = /^menu\.([a-zA-Z0-9_]+)=([a-zA-Z0-9-_ ]+)$/;
const optionNameRegExp = /^menu\.([a-zA-Z0-9_]+)=(.+)$/;

const boardOptionRegExp = /^([a-zA-Z0-9_]+)\.menu\.([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)=([a-zA-Z0-9-_ ()]+)$/;
const boardOptionRegExp = /^([a-zA-Z0-9_]+)\.menu\.([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)=(.+)$/;

const osRegExp = /(linux|macosx|windows)/;

Expand Down
22 changes: 22 additions & 0 deletions packages/arduino-cli/test-func/index.spec.js
@@ -1,3 +1,4 @@
import * as R from 'ramda';
import { resolve } from 'path';
import * as fse from 'fs-extra';
import { assert } from 'chai';
Expand Down Expand Up @@ -42,6 +43,27 @@ describe('Arduino Cli', () => {
}));
});

describe('Update arduino-cli config', () => {
afterEach(() => fse.remove(tmpDir));
it('updates config', async () => {
const cli = arduinoCli(PATH_TO_CLI, cfg);
const curConf = await cli.dumpConfig();

assert.strictEqual(curConf.sketchbook_path, cfg.sketchbook_path);
assert.strictEqual(curConf.arduino_data, cfg.arduino_data);

const newDataDir = resolve(tmpDir, 'newData');
const newConf = R.assoc('arduino_data', newDataDir, curConf);
cli.updateConfig(newConf);
const updatedConf = await cli.dumpConfig();

assert.strictEqual(updatedConf.sketchbook_path, cfg.sketchbook_path);
assert.strictEqual(updatedConf.arduino_data, newDataDir);

return cli;
});
});

describe('Installs additional package index', () => {
afterEach(() => fse.remove(tmpDir));
const url =
Expand Down
@@ -1,15 +1,13 @@
#### JUST A PART OF BOARDS.TXT FILE FROM ESP8266 PACKAGE
#### SOME OPTIONS WAS REMOVED TO MINIFY FIXTURE
#### A PART OF BOARDS.TXT FILE FROM ESP8266 PACKAGE
#### WITH SOME CHANGES: MENU AND OPTION NAMES
#### NOW CONTAINS SPECIAL CHARACTERS AND CYRILLIC SYMBOLS
#### TO MAKE SURE IN THE UNIT TESTS IT WILL WORK FINE
#### WITH ANY PACKAGE.
####
#### ONLY FOR TESTS!

#
# Do not create pull-requests for this file only, CI will not accept them.
# You *must* edit/modify/run boards.txt.py to regenerate boards.txt.
# All modified files after running with option "--allgen" must be included in the pull-request.
#

menu.UploadSpeed=Upload Speed
menu.CpuFrequency=CPU Frequency
menu.UploadSpeed=Uplo@d Speed (Скорость загрузки)
menu.CpuFrequency=CPU Frequency 123,-_[]():@we$ome

##############################################################
generic.name=Generic ESP8266 Module
Expand All @@ -26,7 +24,7 @@ generic.build.variant=generic
generic.build.spiffs_pagesize=256
generic.build.debug_port=
generic.build.debug_level=
generic.menu.CpuFrequency.80=80 MHz
generic.menu.CpuFrequency.80=80 MHz (!@#$$%^&*()[]_-+,./)
generic.menu.CpuFrequency.80.build.f_cpu=80000000L
generic.menu.CpuFrequency.160=160 MHz
generic.menu.CpuFrequency.160.build.f_cpu=160000000L
Expand Down Expand Up @@ -64,7 +62,7 @@ wifi_slot.build.core=esp8266
wifi_slot.build.spiffs_pagesize=256
wifi_slot.build.debug_port=
wifi_slot.build.debug_level=
wifi_slot.menu.CpuFrequency.80=80 MHz
wifi_slot.menu.CpuFrequency.80=80 MHz (!@#$$%^&*()[]_-+,./)
wifi_slot.menu.CpuFrequency.80.build.f_cpu=80000000L
wifi_slot.menu.CpuFrequency.160=160 MHz
wifi_slot.menu.CpuFrequency.160.build.f_cpu=160000000L
Expand Down
12 changes: 6 additions & 6 deletions packages/arduino-cli/test/optionParser.spec.js
Expand Up @@ -22,8 +22,8 @@ const fixtureDir = path.resolve(__dirname, 'fixtures');
// =============================================================================

const espOptionNames = {
UploadSpeed: 'Upload Speed',
CpuFrequency: 'CPU Frequency',
UploadSpeed: 'Uplo@d Speed (Скорость загрузки)',
CpuFrequency: 'CPU Frequency 123,-_[]():@we$ome',
};

const espOptions = {
Expand All @@ -47,7 +47,7 @@ const espOptions = {
],
CpuFrequency: [
{
name: '80 MHz',
name: '80 MHz (!@#$$%^&*()[]_-+,./)',
value: '80',
},
{
Expand All @@ -58,7 +58,7 @@ const espOptions = {
};

const uploadSpeedOptions = {
optionName: 'Upload Speed',
optionName: 'Uplo@d Speed (Скорость загрузки)',
optionId: 'UploadSpeed',
values: [
{
Expand All @@ -80,11 +80,11 @@ const uploadSpeedOptions = {
],
};
const cpuFrequencyOptions = {
optionName: 'CPU Frequency',
optionName: 'CPU Frequency 123,-_[]():@we$ome',
optionId: 'CpuFrequency',
values: [
{
name: '80 MHz',
name: '80 MHz (!@#$$%^&*()[]_-+,./)',
value: '80',
},
{
Expand Down
16 changes: 16 additions & 0 deletions packages/xod-arduino/platform/runtime.cpp
Expand Up @@ -198,6 +198,22 @@ bool isTimedOut(const ContextT* ctx) {
return detail::isTimedOut(ctx->_node);
}

bool isValidDigitalPort(uint8_t port) {
#ifdef NUM_DIGITAL_PINS
return port < NUM_DIGITAL_PINS;
#else
return true;
#endif
}

bool isValidAnalogPort(uint8_t port) {
#ifdef NUM_ANALOG_INPUTS
return port >= A0 && port < A0 + NUM_ANALOG_INPUTS;
#else
return port >= A0;
#endif
}

} // namespace xod

//----------------------------------------------------------------------------
Expand Down

0 comments on commit 42e1dc4

Please sign in to comment.