Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile/upload with correct board options #1519

Merged
merged 1 commit into from
Oct 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions packages/xod-client-electron/src/app/arduinoCli.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,18 @@ const patchFqbnWithOptions = board => {
const options = board.options || [];

const defaultBoardOptions = R.compose(
R.mergeAll,
R.reject(R.isNil),
R.mergeAll,
R.map(opt => ({
[opt.optionId]: R.pathOr(null, ['values', 0, 'value'], opt),
}))
)(options);
const defaultBoardOptionKeys = R.keys(defaultBoardOptions);

// :: StrMap OptionId [OptionValue]
const boardPossibleOptionValuesById = R.compose(
R.map(R.compose(R.pluck('value'), R.prop('values'))),
R.indexBy(R.prop('optionId'))
)(options);

// Find out selected board options that equal to default board options.
//
Expand All @@ -179,10 +184,24 @@ const patchFqbnWithOptions = board => {
R.toPairs
)(selectedOptions);

// Find out board option keys that does not fit the selected board
// Find out board option keys that does not fit the selected board:
// a. no optionId for this board
// E.G. arduino:avr:mega has no options `debugLevel` and it will be ommited
// b. no optionValue for this board
// E.G. previously user uploaded on Arduino Nano with `cpu=atmega328old`,
// but now he tries to upload onto Arduino Mega, which has optionId
// `cpu`, but does not have `atmega328old` option
// :: [OptionId]
const staleBoardOptionKeys = R.compose(
R.reject(isAmong(defaultBoardOptionKeys)),
R.keys
R.reduce(
(acc, [optionId, optionValue]) =>
boardPossibleOptionValuesById[optionId] &&
R.contains(optionValue, boardPossibleOptionValuesById[optionId])
? acc
: R.append(optionId, acc),
[]
),
R.toPairs
)(selectedOptions);

const keysToOmit = R.concat(
Expand All @@ -197,8 +216,9 @@ const patchFqbnWithOptions = board => {
const oneOfDefaultOptions = R.compose(
R.pick(R.__, defaultBoardOptions),
R.of,
R.head
)(defaultBoardOptionKeys);
R.head,
R.keys
)(defaultBoardOptions);

const selectedBoardOptions = R.omit(keysToOmit, selectedOptions);

Expand Down