Improve light color test
Change the way that queue object is handled on responses
This commit is contained in:
parent
1e7d1519cf
commit
cdf5f67714
|
@ -23,6 +23,7 @@
|
||||||
"cmd" : {
|
"cmd" : {
|
||||||
"debug" : "d",
|
"debug" : "d",
|
||||||
"connect": "i",
|
"connect": "i",
|
||||||
|
"light" : "l",
|
||||||
"camera" : "c",
|
"camera" : "c",
|
||||||
"projector" : "p",
|
"projector" : "p",
|
||||||
"black" : "b",
|
"black" : "b",
|
||||||
|
|
31
app/main.js
31
app/main.js
|
@ -18,7 +18,7 @@ var init = function () {
|
||||||
createWindow();
|
createWindow();
|
||||||
mcopy.arduino.init(function (success) {
|
mcopy.arduino.init(function (success) {
|
||||||
mcopy.arduino.connect(function () {
|
mcopy.arduino.connect(function () {
|
||||||
|
mcopy.arduino.colorTest();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -115,10 +115,12 @@ mcopy.arduino.send = function (cmd, res) {
|
||||||
};
|
};
|
||||||
//send strings, after char triggers firmware to accept
|
//send strings, after char triggers firmware to accept
|
||||||
mcopy.arduino.string = function (str) {
|
mcopy.arduino.string = function (str) {
|
||||||
mcopy.arduino.serial.write(str, function (err, results) {
|
setTimeout(function () {
|
||||||
if (err) { console.log(err); }
|
mcopy.arduino.serial.write(str, function (err, results) {
|
||||||
console.log('sent: ' + str);
|
if (err) { console.log(err); }
|
||||||
});
|
//console.log('sent: ' + str);
|
||||||
|
});
|
||||||
|
}, mcopy.cfg.arduino.serialDelay);
|
||||||
};
|
};
|
||||||
//with same over serial when done
|
//with same over serial when done
|
||||||
mcopy.arduino.end = function (data) {
|
mcopy.arduino.end = function (data) {
|
||||||
|
@ -128,9 +130,9 @@ mcopy.arduino.end = function (data) {
|
||||||
mcopy.arduino.lock = false;
|
mcopy.arduino.lock = false;
|
||||||
console.log('Command ' + data + ' took ' + ms + 'ms');
|
console.log('Command ' + data + ' took ' + ms + 'ms');
|
||||||
mcopy.arduino.queue[data](ms);
|
mcopy.arduino.queue[data](ms);
|
||||||
mcopy.arduino.queue = {};
|
delete mcopy.arduino.queue[data]; //add timestamp?
|
||||||
} else {
|
} else {
|
||||||
//console.log('Received stray "' + data + '" from ' + mcopy.arduino.path); //silent to user
|
console.log('Received stray "' + data + '" from ' + mcopy.arduino.path); //silent to user
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mcopy.arduino.connect = function (callback) {
|
mcopy.arduino.connect = function (callback) {
|
||||||
|
@ -140,8 +142,8 @@ mcopy.arduino.connect = function (callback) {
|
||||||
parser: serialport.parsers.readline("\n")
|
parser: serialport.parsers.readline("\n")
|
||||||
}, false);
|
}, false);
|
||||||
mcopy.arduino.serial.open(function (error) {
|
mcopy.arduino.serial.open(function (error) {
|
||||||
if ( error ) {
|
if (error) {
|
||||||
return console.log('failed to open: '+ error, 0);
|
return console.log('failed to open: '+ error);
|
||||||
} else {
|
} else {
|
||||||
console.log('Opened connection with ' + mcopy.arduino.path);
|
console.log('Opened connection with ' + mcopy.arduino.path);
|
||||||
mcopy.arduino.serial.on('data', function (data) {
|
mcopy.arduino.serial.on('data', function (data) {
|
||||||
|
@ -159,3 +161,14 @@ mcopy.arduino.connect = function (callback) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mcopy.arduino.colorTest = function () {
|
||||||
|
var color = '255,255,255';
|
||||||
|
mcopy.arduino.send(mcopy.cfg.arduino.cmd.light, function () {
|
||||||
|
console.log('color set to ' + color);
|
||||||
|
});
|
||||||
|
//setTimeout(function () {
|
||||||
|
mcopy.arduino.string(color);
|
||||||
|
//}, mcopy.cfg.arduino.serialDelay);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
|
@ -54,9 +54,11 @@ void loop () {
|
||||||
//c - color - followed by String
|
//c - color - followed by String
|
||||||
//
|
//
|
||||||
void cmd (char val) {
|
void cmd (char val) {
|
||||||
if (val == 'c') {
|
if (val == 'i') {
|
||||||
|
Serial.println("i");//confirm connection
|
||||||
|
} else if (val == 'l') {
|
||||||
colorString();
|
colorString();
|
||||||
Serial.println("c");//End of action
|
Serial.println("l");//confirm light change
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue