parent
909daa39c9
commit
2c2f38deb6
@ -1,47 +1,61 @@
|
|||||||
module.exports.Upload = async function Upload (keymap, target, right = false) {
|
const Inquirer = require('inquirer');
|
||||||
await build(right);
|
|
||||||
|
const { Echo, Exec, IdentifyKeyboard } = require('./util');
|
||||||
|
|
||||||
|
async function Upload (keymap, path, right = false) {
|
||||||
|
await Build(keymap, path, right);
|
||||||
|
|
||||||
let board;
|
let board;
|
||||||
while (board == null) {
|
while (board == null) {
|
||||||
board = IdentifyKeyboard();
|
board = IdentifyKeyboard(undefined, path);
|
||||||
if (board == null) {
|
if (board == null) {
|
||||||
Echo(`Put your keyboard in flash mode`);
|
Echo(`Put your keyboard in flash mode`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (board.length > 1) {
|
||||||
|
const answer = await Inquirer.prompt({
|
||||||
|
name: 'path',
|
||||||
|
type: 'list',
|
||||||
|
message: `Select a the keyboard's ${right ? 'right' : 'left'} half`,
|
||||||
|
choices: board.map(board => ({
|
||||||
|
name: `${board.name} (${board.path})`,
|
||||||
|
value: board.path
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
board = board.find(board => board.path === answer.path);
|
||||||
|
} else if (board.length === 1) {
|
||||||
|
board = board[0];
|
||||||
|
}
|
||||||
|
|
||||||
Echo(`Building for ${board.name}`);
|
Echo(`Building for ${board.name} (${board.path})`);
|
||||||
await flash(right, board);
|
await Flash(keymap, board.path, right);
|
||||||
}
|
}
|
||||||
|
module.exports.Upload = Upload;
|
||||||
|
|
||||||
module.exports.Build = async function Build (right = false) {
|
async function Build (keymap, path, right = false) {
|
||||||
Echo(`Building ${right ? 'right' : 'left'}`);
|
Echo(`Building ${right ? 'right' : 'left'}`);
|
||||||
await Exec(`make ergodox_infinity-${KEYMAP} ${right ? 'MASTER=right' : ''}`);
|
await Exec(`make ergodox_infinity-${keymap} ${right ? 'MASTER=right' : ''}`);
|
||||||
|
await Exec(`make ergodox_infinity-${keymap}-.build/ergodox_infinity_${keymap}.bin ${right ? 'MASTER=right' : ''}`);
|
||||||
Echo(`Built ${right ? 'right' : 'left'}`, '');
|
Echo(`Built ${right ? 'right' : 'left'}`, '');
|
||||||
}
|
}
|
||||||
|
module.exports.Build = Build;
|
||||||
|
|
||||||
module.exports.Flash = function Flash (right = false, board) {
|
function Flash (keymap, path, right = false) {
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
Echo(`Flashing ${right ? 'right' : 'left'}`);
|
Echo(`Flashing ${right ? 'right' : 'left'}`);
|
||||||
try {
|
// make infinity-<keymap>-.build/ergodox_infinity_<keymap>.bin
|
||||||
await Exec(`make ergodox_infinity-${KEYMAP}-dfu-util ${right ? 'MASTER=right' : ''}`);
|
// await Exec(`make ergodox_infinity-${keymap}-dfu-util ${right ? 'MASTER=right' : ''}`);
|
||||||
} catch (err) {
|
await Exec(`dfu-util --path ${path} -D .build/ergodox_infinity_default.bin`);
|
||||||
if (err.message && err.message.includes(`More than one DFU capable USB device found`)) {
|
|
||||||
Echo(`QMK flash failed!`);
|
|
||||||
Echo(`Flashing manually with dfu-util`);
|
|
||||||
|
|
||||||
await Exec(`dfu-util --device ${board.id} -D .build/ergodox_infinity_default.bin`);
|
|
||||||
} else {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Echo(`Flashed ${right ? 'right' : 'left'}`, '');
|
Echo(`Flashed ${right ? 'right' : 'left'}`, '');
|
||||||
|
|
||||||
// while (IdentifyKeyboard()) {
|
// while (IdentifyKeyboard(board.path)) {
|
||||||
// Echo(`Unplug your keyboard!`);
|
// Echo(`Unplug your keyboard!`);
|
||||||
// }
|
// }
|
||||||
// TODO: Check to see if the script is done. If it is, then don't require an unplug
|
// TODO: Check to see if the script is done. If it is, then don't require an unplug
|
||||||
// TODO: Make this actually look for the keyboard to be unplugged
|
// TODO: Make this actually look for the keyboard to be unplugged
|
||||||
Echo(`Unplug your keyboard! (you have 15 seconds to do so)`);
|
// Echo(`Unplug your keyboard! (you have 15 seconds to do so)`);
|
||||||
setTimeout(() => resolve(), 15000);
|
// setTimeout(() => resolve(), 15000);
|
||||||
|
resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
module.exports.Flash = Flash;
|
||||||
|
@ -1,29 +1,39 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
const { execSync, exec } = require('child_process');
|
const { execSync, exec } = require('child_process');
|
||||||
|
const Commander = require('commander');
|
||||||
|
|
||||||
const { Echo, Exec, IdentifyKeyboard } = require('./util');
|
const { Echo, Exec, IdentifyKeyboard } = require('./util');
|
||||||
const { Upload } = require('./commands');
|
const { Upload } = require('./commands');
|
||||||
|
|
||||||
const KEYMAP = process.env.KEYMAP || 'default';
|
|
||||||
const LEFT_TARGET = process.env.LEFT;
|
const LEFT_TARGET = process.env.LEFT;
|
||||||
const RIGHT_TARGET = process.env.RIGHT;
|
const RIGHT_TARGET = process.env.RIGHT;
|
||||||
|
|
||||||
(async () => {
|
if (!process.cwd().endsWith('/qmk_firmware')) {
|
||||||
Echo(`Keymap: ${KEYMAP}`);
|
process.chdir(`${__dirname}/../`)
|
||||||
|
console.log(process.cwd());
|
||||||
if (process.env.LEFT || process.env.RIGHT) {
|
|
||||||
if (process.env.LEFT) {
|
|
||||||
await Upload(KEYMAP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.RIGHT) {
|
Commander
|
||||||
await Upload(KEYMAP, undefined, true);
|
.option('-m --keymap [name]', 'Keymap name', 'default')
|
||||||
}
|
.option('-p --path [path]', 'DFU device path')
|
||||||
|
.option('--half [half]', 'Which half to program (left, right)')
|
||||||
|
.parse(process.argv);
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
Echo(`Keymap: ${Commander.keymap}`);
|
||||||
|
|
||||||
|
if (Commander.half != null) {
|
||||||
|
await Upload(Commander.keymap, Commander.path, Commander.half === 'right');
|
||||||
} else {
|
} else {
|
||||||
// Build both halves
|
// Build both halves
|
||||||
await Upload(KEYMAP);
|
await Upload(Commander.keymap);
|
||||||
|
|
||||||
await Upload(KEYMAP, undefined, true);
|
await Upload(Commander.keymap, undefined, true);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
process.on('unhandledRejection', err => {
|
||||||
|
console.error(err);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
Loading…
Reference in new issue