Skip to content

Commit

Permalink
Version 2.1.4
Browse files Browse the repository at this point in the history
- Reload pins on MB change
- Look for MB rename on MB error
- Add a flag for debug logging
- More reliable thermistor list find
  • Loading branch information
thinkyhead committed Mar 12, 2020
1 parent a62122c commit a939c7f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 42 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ When installing "Auto Build Marlin" you'll also be prompted to install the [Plat

![](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/Activity_bar.png)

- Click the **Marlin Auto Build** icon ![AutoBuild Icon](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/AB_icon.png) in the Activities Bar (on the left side of *Visual Studio Code* window) to bring up the **Marlin Auto Build** options bar.
- Click the **Auto Build Marlin** icon ![AutoBuild Icon](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/AB_icon.png) in the Activities Bar (on the left side of *Visual Studio Code* window) to bring up the **Auto Build Marlin** options bar.

![](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/AB_menu.png)
![ABM Menu](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/AB_menu.png)

- Click any of the tool icons to open the Auto Build panel. If there's only one target environment for your board the selected action will be started. Otherwise you will have to specify the environment.

Icon|Action
----|------
![](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/B_small.png)|Start **Marlin Build** to test your Marlin build
![](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/U_small.png)|Start **Marlin Upload** to install Marlin on your board
![](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/T_small.png)|Start **Marlin Upload (traceback)** to install Marlin with debugging
![](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/C_small.png)|Start **Marlin Clean** to delete old build files
![](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/K_small.png)|Open the **Configuration Tool**
![Build](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/B_small.png)|Start **Marlin Build** to test your Marlin build
![Upload](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/U_small.png)|Start **Marlin Upload** to install Marlin on your board
![Traceback](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/T_small.png)|Start **Marlin Upload (traceback)** to install Marlin with debugging
![Clean](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/C_small.png)|Start **Marlin Clean** to delete old build files
![Configure](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/K_small.png)|Open the **Configuration Tool**

- The **Auto Build Marlin** panel displays information about your selected motherboard and basic machine parameters. Each board comes with one or more build environments that are used to generate the final Marlin binary. Choose the environment that best matches your MCU, bootloader, etc.

![Environments](https://github.com/MarlinFirmware/AutoBuildMarlin/raw/master/img/abm-envs.png)
88 changes: 54 additions & 34 deletions abm/abm.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const nicer = {
clean: 'clean',
};

const bugme = false; // Lots of debug output

const path = require('path'),
fs = require('fs'),
os = require('os');
Expand Down Expand Up @@ -128,7 +130,7 @@ function updateDefineList(cindex, txt) {
function _confEnabled(text, optname) {
const find = new RegExp(`^\\s*#define\\s+${optname}\\b`, 'gm'),
r = find.exec(text);
if (0) console.log(`${optname} is ${r?'ENABLED':'unset'}`);
if (bugme) console.log(`${optname} is ${r?'ENABLED':'unset'}`);
return (r !== null); // Any match means it's uncommented
}

Expand Down Expand Up @@ -189,7 +191,7 @@ function existingBuildPath(env) {

var timeouts = [];
function onConfigFileChanged(e, fname) {
if (0) console.log('File changed:', e, fname);
if (bugme) console.log('File changed:', e, fname);
if (timeouts[fname] !== undefined) clearTimeout(timeouts[fname]);
timeouts[fname] = setTimeout(() => {
timeouts[fname] = undefined;
Expand Down Expand Up @@ -234,7 +236,7 @@ function currentBuildEnv() {
//
function unwatchBuildFolder() {
if (build.watcher) {
if (0) console.log(`Stop Watching Build: ${currentBuildEnv()}.`);
if (bugme) console.log(`Stop Watching Build: ${currentBuildEnv()}.`);
build.watcher.close();
build.watcher = null;
}
Expand All @@ -253,12 +255,12 @@ function watchBuildFolder(env) {
const bp = existingBuildPath(env);
if (bp) {
build.watcher = fs.watch(bp, {}, (e,f) => { onBuildFolderChanged(e,f,env); });
if (0) console.log("Watching Build...");
if (bugme) console.log("Watching Build...");
}
else {
// Build folder doesn't exist (yet)
// Keep looking for it for several seconds
if (0) console.log("No build folder yet. Trying in 2s...");
if (bugme) console.log("No build folder yet. Trying in 2s...");
setTimeout(()=>{ watchBuildFolder(env); }, 2000);
}
}
Expand All @@ -271,7 +273,7 @@ function cancelBuildRefresh() {
}

function buildIsFinished(reason) {
if (0) console.log(`buildIsFinished (${reason}): ${currentBuildEnv()}`);
if (bugme) console.log(`buildIsFinished (${reason}): ${currentBuildEnv()}`);

// Updating now so kill timers
cancelBuildRefresh();
Expand All @@ -295,7 +297,7 @@ function onBuildFolderChanged(e, fname, env) {
if (fname == 'firmware.hex' || fname == 'firmware.bin') {
// If the firmware file changed, assume the build is done now
refresh_to = [ setTimeout(()=>{ unwatchBuildFolder(); }, 500) ];
if (0) console.log(`onBuildFolderChanged (bin/hex): ${env}`);
if (bugme) console.log(`onBuildFolderChanged (bin/hex): ${env}`);
}
else {
refresh_to = [
Expand All @@ -304,7 +306,7 @@ function onBuildFolderChanged(e, fname, env) {
// Assume nothing will pause for more than 15 seconds
setTimeout(()=>{ unwatchBuildFolder(); }, 15000)
];
if (0) console.log(`onBuildFolderChanged: ${env}`);
if (bugme) console.log(`onBuildFolderChanged: ${env}`);
}
}

Expand Down Expand Up @@ -354,7 +356,7 @@ function extractTempSensors() {
//pv.postMessage({ command:'text', text:mfiles.config.text });

// Get all the thermistors and save them into an object
const findAll = new RegExp('(\\/\\*+[\\s\\S]+\\*\\/)\\s*#define\\s+TEMP_SENSOR_0', 'g'),
const findAll = new RegExp('(\\/\\*+[\\s\\S]+\\*\\/)\\s*#define\\s+TEMP_SENSOR_', 'g'),
r = findAll.exec(mfiles.config.text);
const findEach = new RegExp('^\\s*\\*\\s*(-?\\d+)\\s*:\\s*(.+)$', 'gm');
let s;
Expand Down Expand Up @@ -438,8 +440,8 @@ function getExtruderSettings() {
// Get information from the board's pins file(s)
//
var pindef_info;
function getPinDefinitionInfo() {
if (!mfiles.pindef) {
function getPinDefinitionInfo(mb) {
if (!mfiles.pindef || board_info.mb != mb) {
const pbits = `src/pins/${board_info.pins_file}`.split('/');
mfiles.pindef = { name: pbits.pop(), path: pbits };
processMarlinFile('pindef');
Expand All @@ -466,20 +468,21 @@ function extractVersionInfo() {
}

//
// - Get pins file, archs, and envs for a board
// from the pins.h file.
// - Get the status of all environment builds.
// - Get pins file, archs, and envs for a board from pins.h.
// - If the board isn't found, look for a rename alert.
// - Get the status of environment builds.
//
var board_info;
function extractBoardInfo(board) {
var r, out = {}, sb = board.replace('BOARD_', '');
function extractBoardInfo(mb) {
var r, out = {}, sb = mb.replace('BOARD_', '');

// Get the include line matching the board
const lfind = new RegExp(`if\\s*MB\\(${sb}\\).*\n\\s*(#include.+)\n`, 'g');
if ((r = lfind.exec(mfiles.pins.text))) {

let inc_line = r[1];

out.mb = mb;
out.pins_file = inc_line.replace(/.*#include\s+"([^"]*)".*/, '$1');

out.archs = inc_line.replace(/.+\/\/\s*((\w+,?\s*)+)\s*env:.+/, '$1');
Expand All @@ -490,9 +493,13 @@ function extractBoardInfo(board) {
while ((r = efind.exec(inc_line)))
out.envs.push({ name: r[1], debug:r[1].match(/^.+_debug$/) });
}
else {
const bfind = new RegExp(`#error\\s+"(${mb} has been renamed \\w+)`, 'g');
out.error = (r = bfind.exec(mfiles.pins.text)) ? r[1] : `Unknown MOTHERBOARD ${mb}`;
}

// Get the description from the boards.h file
var cfind = new RegExp(`#define\\s+${board}\\s+\\d+\\s*//(.+)`, 'gm');
var cfind = new RegExp(`#define\\s+${mb}\\s+\\d+\\s*//(.+)`, 'gm');
r = cfind.exec(mfiles.boards.text);
out.description = r ? r[1].trim() : '';

Expand All @@ -518,15 +525,19 @@ function allFilesAreLoaded() {
const sensors = extractTempSensors();

const version_info = extractVersionInfo();
if (0) console.log("Version Info : ", version_info);
if (bugme) console.log("Version Info :", version_info);
const board_info = extractBoardInfo(mb);
if (0) console.log("Board Info : ", board_info);
if (bugme) console.log(`Board Info for ${mb} :`, board_info);
if (board_info.error) {
postError(board_info.error);
return; // abort the whole deal
}
const machine_info = getMachineSettings();
if (0) console.log("Machine Info : ", machine_info);
if (bugme) console.log("Machine Info :", machine_info);
const extruder_info = getExtruderSettings();
if (0) console.log("Extruder Info : ", extruder_info);
const pindef_info = getPinDefinitionInfo();
if (0) console.log("Pin Defs Info : ", pindef_info);
if (bugme) console.log("Extruder Info :", extruder_info);
const pindef_info = getPinDefinitionInfo(mb);
if (bugme) console.log("Pin Defs Info :", pindef_info);

// If no CUSTOM_MACHINE_NAME was set, get it from the pins file
if (!machine_info.name) {
Expand Down Expand Up @@ -567,7 +578,7 @@ function allFilesAreLoaded() {
function refreshOldData() { allFilesAreLoaded(); }

function readFileError(err, msg) {
if (0) console.log("fs.readFile err: ", err);
if (bugme) console.log("fs.readFile err: ", err);
pv.postMessage({ command:'error', error:msg, data:err });
}

Expand All @@ -579,7 +590,7 @@ function processMarlinFile(fileid) {

const mf_path = marlinFilePath(fileid);

if (0) console.log(`Processing... ${mf_path}`);
if (bugme) console.log(`Processing... ${mf_path}`);

if (info.filesToLoad) {
fs.readFile(mf_path, (err, data) => {
Expand Down Expand Up @@ -680,7 +691,8 @@ function lastBuild(env) {
// - Send the envs data to the UI for display.
//
function refreshBuildStatus(env) {
if (0) console.log(`Refreshing Build: ${currentBuildEnv()}`);
if (bugme) console.log(`Refreshing Build: ${currentBuildEnv()}`);
if (bugme) console.log(board_info)
board_info.envs.forEach((v) => {
if (!env || v.name == env) {
let b = lastBuild(v.name);
Expand All @@ -691,7 +703,7 @@ function refreshBuildStatus(env) {
}
});
let m = { command:'envs', val:board_info.envs };
if (0) console.log("Posting:", m);
if (bugme) console.log("Posting:", m);
pv.postMessage(m);
}

Expand All @@ -708,19 +720,19 @@ var ipc_watcher;
function createIPCFile() {
fs.writeFile(ipc_file, 'ipc', (err) => {
if (!err) {
if (0) console.log('IPC file created.');
if (bugme) console.log('IPC file created.');
ipc_watcher = fs.watch(ipc_file, {}, () => { onIPCFileChange(); });
}
else
if (0) console.log('IPC file existed?');
if (bugme) console.log('IPC file existed?');
});
}

function destroyIPCFile() {
ipc_watcher.close();
ipc_watcher = null;
fs.unlink(ipc_file, (err) => {
if (0) {
if (bugme) {
if (err)
console.log("IPC Delete Error:", err);
else
Expand Down Expand Up @@ -758,7 +770,7 @@ function terminal_command(ttl, cmdline) {
});
}
else
if (0) console.log("Terminal PID is " + terminal.processId);
if (bugme) console.log("Terminal PID is " + terminal.processId);

terminal.show(true);

Expand Down Expand Up @@ -803,8 +815,12 @@ function pio_command(opname, env, nosave) {
if (opname != 'clean') watchBuildFolder(env);
}

function postError(err, data) {
pv.postMessage({ command:'error', error:err, data:data });
function postWarning(msg, data) {
pv.postMessage({ command:'warning', warning:msg, data:data });
}

function postError(msg, data) {
pv.postMessage({ command:'error', error:msg, data:data });
}

function postTool(t) {
Expand All @@ -814,7 +830,7 @@ function postTool(t) {
// Post a value to the UI
function postValue(tag, val) {
var message = { command:'set', tag:tag, val:val };
if (0) console.log("Send to UI", message);
if (bugme) console.log("Send to UI", message);
pv.postMessage(message);
}

Expand Down Expand Up @@ -959,6 +975,10 @@ function handleWebViewMessage(m) {
//vw.showInformationMessage('Config Tab: ' + m.tab);
break;

case 'warning':
postWarning(m.warning); // Warning is echoed back to the view
break;

case 'error':
postError(m.error); // Error is just echoed back to the view but could also be handled here
break;
Expand Down
Binary file added img/abm-envs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "auto-build",
"displayName": "Auto Build Marlin",
"description": "Provides an interface to quickly build and upload Marlin Firmware.",
"version": "2.1.3",
"version": "2.1.4",
"publisher": "marlinfirmware",
"icon": "icon.png",
"badges": [
Expand Down

0 comments on commit a939c7f

Please sign in to comment.