Skip to content

Commit

Permalink
Remove comments that start with a semicolon ;
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Nov 8, 2017
1 parent 74700aa commit a108668
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 42 deletions.
57 changes: 31 additions & 26 deletions src/app/controllers/Grbl/GrblController.js
Expand Up @@ -128,6 +128,30 @@ class GrblController {
path: port,
baudRate: baudrate,
writeFilter: (data) => {
const line = data.trim();

if (!line) {
return data;
}

{ // Grbl settings: $0-$255
const r = line.match(/^(\$\d{1,3})=([\d\.]+)$/);
if (r) {
const name = r[1];
const value = Number(r[2]);
if ((name === '$13') && (value >= 0) && (value <= 65535)) {
const nextSettings = {
...this.controller.settings,
settings: {
...this.controller.settings.settings,
[name]: value ? '1' : '0'
}
};
this.controller.settings = nextSettings; // enforce change
}
}
}

return data;
}
});
Expand All @@ -145,16 +169,15 @@ class GrblController {
// Feeder
this.feeder = new Feeder({
dataFilter: (line, context) => {
// Remove comments that start with a semicolon `;`
line = line.replace(/\s*;.*/g, '');

context = this.populateContext(context);

const data = parser.parseLine(line, { flatten: true });
const words = ensureArray(data.words);

if (line[0] === '%') {
// Remove characters after ";"
const re = new RegExp(/\s*;.*/g);
line = line.replace(re, '');

// %wait
if (line === WAIT) {
log.debug('Wait for the planner queue to empty');
Expand Down Expand Up @@ -189,7 +212,7 @@ class GrblController {
log.debug('M6 Tool Change');
this.feeder.hold({ data: 'M6' }); // Hold reason

// [Grbl] Surround M6 with parentheses to ignore unsupported command error
// Surround M6 with parentheses to ignore unsupported command error
line = '(M6)';
}

Expand Down Expand Up @@ -228,17 +251,16 @@ class GrblController {
// Deduct the buffer size to prevent from buffer overrun
bufferSize: (128 - 8), // The default buffer size is 128 bytes
dataFilter: (line, context) => {
// Remove comments that start with a semicolon `;`
line = line.replace(/\s*;.*/g, '');

context = this.populateContext(context);

const data = parser.parseLine(line, { flatten: true });
const words = ensureArray(data.words);
const { sent, received } = this.sender.state;

if (line[0] === '%') {
// Remove characters after ";"
const re = new RegExp(/\s*;.*/g);
line = line.replace(re, '');

// %wait
if (line === WAIT) {
log.debug(`Wait for the planner queue to empty: line=${sent + 1}, sent=${sent}, received=${received}`);
Expand Down Expand Up @@ -1272,23 +1294,6 @@ class GrblController {
this.emit('serialport:write', data, context);
this.connection.write(data);
log.silly(`> ${data}`);

// Grbl settings: $0-$255
const r = cmd.match(/^(\$\d{1,3})=([\d\.]+)$/);
if (r) {
const name = r[1];
const value = Number(r[2]);
if ((name === '$13') && (value >= 0) && (value <= 65535)) {
const nextSettings = {
...this.controller.settings,
settings: {
...this.controller.settings.settings,
[name]: value ? '1' : '0'
}
};
this.controller.settings = nextSettings; // enforce change
}
}
}
writeln(data, context) {
if (_.includes(GRBL_REALTIME_COMMANDS, data)) {
Expand Down
14 changes: 6 additions & 8 deletions src/app/controllers/Smoothie/SmoothieController.js
Expand Up @@ -142,16 +142,15 @@ class SmoothieController {
// Feeder
this.feeder = new Feeder({
dataFilter: (line, context) => {
// Remove comments that start with a semicolon `;`
line = line.replace(/\s*;.*/g, '');

context = this.populateContext(context);

const data = parser.parseLine(line, { flatten: true });
const words = ensureArray(data.words);

if (line[0] === '%') {
// Remove characters after ";"
const re = new RegExp(/\s*;.*/g);
line = line.replace(re, '');

// %wait
if (line === WAIT) {
log.debug('Wait for the planner queue to empty');
Expand Down Expand Up @@ -222,17 +221,16 @@ class SmoothieController {
// Deduct the buffer size to prevent from buffer overrun
bufferSize: (128 - 8), // The default buffer size is 128 bytes
dataFilter: (line, context) => {
// Remove comments that start with a semicolon `;`
line = line.replace(/\s*;.*/g, '');

context = this.populateContext(context);

const data = parser.parseLine(line, { flatten: true });
const words = ensureArray(data.words);
const { sent, received } = this.sender.state;

if (line[0] === '%') {
// Remove characters after ";"
const re = new RegExp(/\s*;.*/g);
line = line.replace(re, '');

// %wait
if (line === WAIT) {
log.debug(`Wait for the planner queue to empty: line=${sent + 1}, sent=${sent}, received=${received}`);
Expand Down
16 changes: 8 additions & 8 deletions src/app/controllers/TinyG/TinyGController.js
Expand Up @@ -140,16 +140,16 @@ class TinyGController {
// Feeder
this.feeder = new Feeder({
dataFilter: (line, context) => {
// Remove comments that start with a semicolon `;`
// @see https://github.com/synthetos/g2/wiki/JSON-Active-Comments
line = line.replace(/\s*;.*/g, '');

context = this.populateContext(context);

const data = parser.parseLine(line, { flatten: true });
const words = ensureArray(data.words);

if (line[0] === '%') {
// Remove characters after ";"
const re = new RegExp(/\s*;.*/g);
line = line.replace(re, '');

// %wait
if (line === WAIT) {
log.debug('Wait for the planner queue to empty');
Expand Down Expand Up @@ -218,17 +218,17 @@ class TinyGController {
// Sender
this.sender = new Sender(SP_TYPE_SEND_RESPONSE, {
dataFilter: (line, context) => {
// Remove comments that start with a semicolon `;`
// @see https://github.com/synthetos/g2/wiki/JSON-Active-Comments
line = line.replace(/\s*;.*/g, '');

context = this.populateContext(context);

const data = parser.parseLine(line, { flatten: true });
const words = ensureArray(data.words);
const { sent, received } = this.sender.state;

if (line[0] === '%') {
// Remove characters after ";"
const re = new RegExp(/\s*;.*/g);
line = line.replace(re, '');

// %wait
if (line === WAIT) {
log.debug(`Wait for the planner queue to empty: line=${sent + 1}, sent=${sent}, received=${received}`);
Expand Down

0 comments on commit a108668

Please sign in to comment.