Improvements to flasher

pull/1932/head
Louis Orleans 7 years ago
parent 47ad8cb9a1
commit cf1feccc72

@ -1,16 +1,18 @@
const Inquirer = require('inquirer');
const Chalk = require('chalk');
const { Echo, Exec, IdentifyKeyboard } = require('./util');
const { Echo, Exec, IdentifyKeyboard, Sleep } = require('./util');
async function Upload (keymap, path, right = false) {
await Build(keymap, path, right);
async function Upload (keyboard, keymap, path, right = false) {
await Build(keyboard, keymap, path, right);
// Find a keyboard to flash
let board;
while (board == null) {
board = IdentifyKeyboard(undefined, path);
if (board == null) {
Echo(`Put your keyboard in flash mode`);
Echo(Chalk.yellow`Put your keyboard in flash mode`);
await Sleep(1000);
}
}
if (board.length > 1) {
@ -28,22 +30,22 @@ async function Upload (keymap, path, right = false) {
board = board[0];
}
Echo(`Building for ${board.name} (${board.path})`);
await Flash(keymap, board, right);
Echo(Chalk.blue(`Building for ${board.name} (${board.path})`));
await Flash(keyboard, keymap, board, right);
}
module.exports.Upload = Upload;
async function Build (keymap, path, right = false) {
Echo(`Building ${right ? 'right' : 'left'}`);
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'}`, '');
async function Build (keyboard, keymap, path, right = false) {
Echo(Chalk.blue(`Building ${right ? 'right' : 'left'}`));
await Exec(`make ${keyboard}-${keymap} ${right ? 'MASTER=right' : ''}`);
await Exec(`make ${keyboard}-${keymap}-.build/${keyboard}_${keymap}.bin ${right ? 'MASTER=right' : ''}`);
Echo(Chalk.green(`Built ${right ? 'right' : 'left'}`), '');
}
module.exports.Build = Build;
async function Flash (keymap, board, right = false) {
Echo(`Flashing ${right ? 'right' : 'left'}`);
await Exec(`dfu-util --device ${board.id} --path ${board.path} -D .build/ergodox_infinity_${keymap}.bin`);
Echo(`Flashed ${right ? 'right' : 'left'}`, '');
async function Flash (keyboard, keymap, board, right = false) {
Echo(Chalk.blue(`Flashing ${right ? 'right' : 'left'}`));
await Exec(`dfu-util --device ${board.id} --path ${board.path} -D .build/${keyboard}_${keymap}.bin`);
Echo(Chalk.green(`Flashed ${right ? 'right' : 'left'}`), '');
}
module.exports.Flash = Flash;

@ -11,21 +11,22 @@ if (!process.cwd().endsWith('/qmk_firmware')) {
}
Commander
.option('-k --keyboard [name]', 'Keyboard name', 'ergodox_infinity')
.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}`);
Echo(`${Commander.keyboard} / ${Commander.keymap}`);
if (Commander.half != null) {
await Upload(Commander.keymap, Commander.path, Commander.half === 'right');
await Upload(Commander.keyboard, Commander.keymap, Commander.path, Commander.half === 'right');
} else {
// Build both halves
await Upload(Commander.keymap);
await Upload(Commander.keymap, undefined, true);
await Upload(Commander.keyboard, Commander.keymap);
await Upload(Commander.keyboard, Commander.keymap, undefined, true);
}
})();

@ -45,3 +45,8 @@ function Echo (...logs) {
}
}
module.exports.Echo = Echo;
function Sleep (duration) {
return new Promise(resolve => setTimeout(resolve, duration));
}
module.exports.Sleep = Sleep;

Loading…
Cancel
Save