Skip to content

Commit f1234d7

Browse files
committed
Merge branch 'develop' of https://github.com/microsoft/vscode-arduino into pre-release-v0.3.4
2 parents a03ab8f + 03ca266 commit f1234d7

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

src/arduino/arduino.ts

+36-2
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,21 @@ export class ArduinoApp {
320320
return;
321321
}
322322
const cppConfigFile = fs.readFileSync(configFilePath, "utf8");
323-
const cppConfig = JSON.parse(cppConfigFile) as { configurations: Array<{ includePath: string[], forcedInclude: string[] }> };
323+
const cppConfig = JSON.parse(cppConfigFile) as { configurations: Array<{
324+
includePath: string[],
325+
forcedInclude: string[],
326+
defines: string[],
327+
}> };
324328
const libPaths = this.getDefaultPackageLibPaths();
325329
const defaultForcedInclude = this.getDefaultForcedIncludeFiles();
330+
const defines = this.getDefaultDefines();
326331
const configuration = cppConfig.configurations[0];
327332

328333
let cppConfigFileUpdated = false;
329-
// cpp exntension changes \\ to \\\\ in paths in JSON string, revert them first
334+
// cpp extension changes \\ to \\\\ in paths in JSON string, revert them first
330335
configuration.includePath = configuration.includePath.map((path) => path.replace(/\\\\/g, "\\"));
331336
configuration.forcedInclude = configuration.forcedInclude.map((path) => path.replace(/\\\\/g, "\\"));
337+
configuration.defines = configuration.defines.map((path) => path.replace(/\\\\/g, "\\"));
332338

333339
for (const libPath of libPaths) {
334340
if (configuration.includePath.indexOf(libPath) === -1) {
@@ -343,6 +349,12 @@ export class ArduinoApp {
343349
}
344350
}
345351

352+
for (const define of defines) {
353+
if (configuration.defines.indexOf(define) === -1) {
354+
cppConfigFileUpdated = true;
355+
configuration.defines.push(define);
356+
}
357+
}
346358
// remove all unexisting paths
347359
// concern mistake removal, comment temporary
348360
// for (let pathIndex = 0; pathIndex < configuration.includePath.length; pathIndex++) {
@@ -386,6 +398,7 @@ export class ArduinoApp {
386398
}
387399

388400
const defaultForcedInclude = this.getDefaultForcedIncludeFiles();
401+
const defaultDefines = this.getDefaultDefines();
389402

390403
if (!ArduinoWorkspace.rootPath) {
391404
return;
@@ -444,6 +457,10 @@ export class ArduinoApp {
444457
configSection.forcedInclude = defaultForcedInclude.concat(configSection.forcedInclude);
445458
}
446459

460+
if (!configSection.defines) {
461+
configSection.defines = defaultDefines;
462+
}
463+
447464
fs.writeFileSync(configFilePath, JSON.stringify(deviceContext, null, 4));
448465
}
449466

@@ -577,6 +594,16 @@ Please make sure the folder is not occupied by other procedures .`);
577594
}
578595
const toolsPath = boardDescriptor.platform.rootBoardPath;
579596
result.push(path.normalize(path.join(toolsPath, "**")));
597+
const hardwareToolPath = path.join(toolsPath, "..", "..", "tools");
598+
if (fs.existsSync(hardwareToolPath)) {
599+
result.push(path.normalize(path.join(hardwareToolPath, "**")));
600+
}
601+
602+
// Add default libraries to include path
603+
result.push(path.normalize(path.join(this._settings.defaultLibPath, "**")));
604+
605+
const userLibsPath = (path.join(this._settings.sketchbookPath, "libraries", "**"));
606+
result.push(userLibsPath);
580607
// if (util.directoryExistsSync(path.join(toolsPath, "cores"))) {
581608
// const coreLibs = fs.readdirSync(path.join(toolsPath, "cores"));
582609
// if (coreLibs && coreLibs.length > 0) {
@@ -608,6 +635,13 @@ Please make sure the folder is not occupied by other procedures .`);
608635
return result;
609636
}
610637

638+
public getDefaultDefines(): string[] {
639+
const result = [];
640+
// USBCON is required in order for Serial to be recognized by intellisense
641+
result.push("USBCON");
642+
return result;
643+
}
644+
611645
public openExample(example) {
612646
function tmpName(name) {
613647
let counter = 0;

src/serialmonitor/serialMonitor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class SerialMonitor implements vscode.Disposable {
2222
public static DEFAULT_BAUD_RATE: number = 115200;
2323

2424
public static listBaudRates(): number[] {
25-
return [300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 74880, 115200, 230400, 250000];
25+
return [300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 74880, 115200, 230400, 250000, 500000, 1000000, 2000000];
2626
}
2727

2828
public static getInstance(): SerialMonitor {

src/serialmonitor/serialportctrl.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export class SerialPortCtrl {
7979
reject(err);
8080
} else {
8181
this._outputChannel.appendLine(`[Info] Opened the serial port - ${this._currentPort}`);
82+
this._currentSerialPort.set(["dtr=true", "rts=true"], (err) => {
83+
if (err) {
84+
reject(err);
85+
}
86+
});
8287
resolve();
8388
}
8489
});
@@ -164,7 +169,13 @@ export class SerialPortCtrl {
164169
if (err) {
165170
reject(err);
166171
} else {
167-
resolve();
172+
this._currentSerialPort.set(["dtr=true", "rts=true"], (err) => {
173+
if (err) {
174+
reject(err);
175+
} else {
176+
resolve();
177+
}
178+
});
168179
}
169180
});
170181
});

0 commit comments

Comments
 (0)