Skip to content

Commit

Permalink
fix: set default for supported manufacturers
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobrosenberg committed Apr 8, 2022
1 parent b1e031c commit 4dcaa19
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
".git",
"env",
"venv"
]
],
"description": "Files to be ignored by Pymakr."
},
"pymakr.advancedMode": {
"type": "boolean",
Expand Down Expand Up @@ -135,17 +136,23 @@
"type": "string"
},
"default": [
".*"
"manufacturer=Pycom",
"manufacturer=Pycom Ltd.",
"manufacturer=FTDI",
"manufacturer=Microsoft",
"manufacturer=Microchip Technology, Inc.",
"manufacturer=1a86"
],
"description": "Filter devices to include in the devices list. Uses regular expression. Will not include devices that match the exclude list."

"description": "Filter devices to include in the devices list. Uses regular expression. Matches can be done against any property, eg. \"Microsoft\" or against a specific property, eg. \"manufacturer=Microsoft\r\n\r\nFor a list of available devices, run the command \"list devices\"."
},
"pymakr.devices.exclude": {
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "Filter devices to exclude from the devices list. Uses regular expression. Takes precedence over includes."
"description": "Same as Devices: Include, but for exclude. Excluded devices will not show, even if listed in the include list."
}
}
},
Expand Down Expand Up @@ -208,6 +215,10 @@
]
},
"commands": [
{
"command": "pymakr.listDevices",
"title": "List devices"
},
{
"command": "pymakr.resetDevice",
"title": "Hard reset device"
Expand Down
6 changes: 5 additions & 1 deletion src/PyMakr.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const { writable } = require("./utils/store");
const { coerceDisposable } = require("./utils/misc");
const manifest = require("../package.json");
const { createVSCodeHelpers } = require("./utils/vscodeHelpers");
const { TextDocumentProvider } = require("./providers/TextDocumentProvider");

/**
* Pymakr is the root class and scope of the extension.
Expand Down Expand Up @@ -58,6 +59,8 @@ class PyMakr {
/** Provides device access for the file explorer */
this.fileSystemProvider = new FileSystemProvider(this);

this.textDocumentProvider = new TextDocumentProvider(this)

this.registerWithIde();
this.setup();
}
Expand All @@ -74,6 +77,7 @@ class PyMakr {
vscode.workspace.registerFileSystemProvider("telnet", this.fileSystemProvider, { isCaseSensitive: true }),
vscode.window.registerTreeDataProvider("pymakr-projects-tree", this.projectsProvider),
vscode.window.registerTreeDataProvider("pymakr-devices-tree", this.devicesProvider),
vscode.workspace.registerTextDocumentContentProvider("pymakrDocument", this.textDocumentProvider),
vscode.workspace.onDidChangeConfiguration(this.onUpdatedConfig.bind(this)),
vscode.window.registerTerminalProfileProvider("pymakr.terminal-profile", {
provideTerminalProfile: () => ({
Expand All @@ -98,7 +102,7 @@ class PyMakr {
/**
* Registers usb devices and scans for projects in workspace
*/
async setup() {
async setup() {
await Promise.all([this.devicesStore.registerUSBDevices(), this.registerProjects()]);
await this.recoverProjects();
this.projectsProvider.refresh(); // tell the provider that projects were updated
Expand Down
10 changes: 8 additions & 2 deletions src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { mkdirSync, readFileSync, writeFileSync } = require("fs");
const { writeFile } = require("fs").promises;
const vscode = require("vscode");
const { msgs } = require("../utils/msgs");
const { mapEnumsToQuickPick, getRelativeFromNearestParent } = require("../utils/misc");
const { mapEnumsToQuickPick } = require("../utils/misc");
const { relative } = require("path");

/**
Expand Down Expand Up @@ -43,6 +43,12 @@ class Commands {
}

commands = {
// todo link to this command from configuration's "Devices: Include" section
listDevices: async () => {
let uri = vscode.Uri.parse("pymakrDocument:" + "Pymakr: available devices");
let doc = await vscode.workspace.openTextDocument(uri); // calls back into the provider
await vscode.window.showTextDocument(doc, { preview: false });
},
/**
* Reboot device
* @param {DeviceTreeItem} treeItem
Expand Down Expand Up @@ -320,7 +326,7 @@ class Commands {
device.disconnect();
},
/**
* Creates a new terminal. If a terminal already exists for the given device, prompt
* Creates a new terminal. If a terminal already exists for the given device, prompt
* the user if they want to to open a new shared terminal or the existing terminal
* @param {ProjectDeviceTreeItem} treeItem
*/
Expand Down
32 changes: 32 additions & 0 deletions src/providers/TextDocumentProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { SerialPort } = require("serialport");
const vscode = require("vscode");
const { serializeKeyValuePairs } = require("../utils/misc");

/**
* @implements {vscode.TextDocumentContentProvider}
*/
class TextDocumentProvider {
/**
* @param {PyMakr} pymakr
*/
constructor(pymakr) {
this.pymakr = pymakr;
}

provideTextDocumentContent(uri) {
const doc = this.paths[uri.path];
if(typeof doc === 'undefined') throw new Error('could not find pymakr document: ' + uri.toString())
return doc()
}

paths = {
'Pymakr: available devices': async () => {
const devices = await SerialPort.list();
const devicesStr = devices.map((e) => serializeKeyValuePairs(e)).join("\r\n\r\n");

return devicesStr;
},
};
}

module.exports = { TextDocumentProvider };

0 comments on commit 4dcaa19

Please sign in to comment.