To preserve the light functionality, the light command needed to have its await statements re-organized. Issue was that light values issued to the firmware take the form of sending the character "l" and then the rgb value of the light "255,255,255" and so forth. Then the program responds with the "l" to confirm the end of the command. Because of the change within the arduino library, to treat the arduino.send() method as an async function, the program was locking up waiting for the "l" response before it could send the rgb value string.
This commit is contained in:
parent
f1ca18b4a5
commit
ce6e450b44
26
app/main.js
26
app/main.js
|
@ -371,38 +371,36 @@ light.init = function () {
|
|||
}
|
||||
light.listen = function () {
|
||||
ipcMain.on('light', async (event, arg) => {
|
||||
//return new Promise(async(resolve, reject) => {
|
||||
try {
|
||||
await light.set(arg.rgb, arg.id)
|
||||
}catch (err) {
|
||||
console.error(err)
|
||||
return reject(err)
|
||||
}
|
||||
event.returnValue = true
|
||||
// return resolve(true)
|
||||
//})
|
||||
try {
|
||||
await light.set(arg.rgb, arg.id)
|
||||
}catch (err) {
|
||||
console.error(err)
|
||||
return reject(err)
|
||||
}
|
||||
event.returnValue = true
|
||||
})
|
||||
}
|
||||
light.set = async function (rgb, id) {
|
||||
const str = rgb.join(',');
|
||||
let ms
|
||||
try {
|
||||
ms = await arduino.send('light', mcopy.cfg.arduino.cmd.light)
|
||||
ms = arduino.send('light', mcopy.cfg.arduino.cmd.light)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
console.log(ms)
|
||||
await delay(10)
|
||||
await delay(1)
|
||||
try {
|
||||
arduino.string('light', str)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
await delay(1)
|
||||
await ms
|
||||
return await light.end(rgb, id, ms)
|
||||
}
|
||||
light.end = async function (rgb, id, ms) {
|
||||
log.info('Light set to ' + rgb.join(','), 'LIGHT', true, true)
|
||||
return await mainWindow.webContents.send('light', {rgb: rgb, id : id, ms: ms})
|
||||
return await mainWindow.webContents.send('light', { rgb: rgb, id : id, ms: ms })
|
||||
}
|
||||
|
||||
proj.state = {
|
||||
|
|
Loading…
Reference in New Issue