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:
mmcw-dev 2018-03-15 12:08:23 -04:00
parent f1ca18b4a5
commit ce6e450b44
1 changed files with 12 additions and 14 deletions

View File

@ -371,38 +371,36 @@ light.init = function () {
} }
light.listen = function () { light.listen = function () {
ipcMain.on('light', async (event, arg) => { ipcMain.on('light', async (event, arg) => {
//return new Promise(async(resolve, reject) => { try {
try { await light.set(arg.rgb, arg.id)
await light.set(arg.rgb, arg.id) }catch (err) {
}catch (err) { console.error(err)
console.error(err) return reject(err)
return reject(err) }
} event.returnValue = true
event.returnValue = true
// return resolve(true)
//})
}) })
} }
light.set = async function (rgb, id) { light.set = async function (rgb, id) {
const str = rgb.join(','); const str = rgb.join(',');
let ms let ms
try { try {
ms = await arduino.send('light', mcopy.cfg.arduino.cmd.light) ms = arduino.send('light', mcopy.cfg.arduino.cmd.light)
} catch (err) { } catch (err) {
console.error(err) console.error(err)
} }
console.log(ms) await delay(1)
await delay(10)
try { try {
arduino.string('light', str) arduino.string('light', str)
} catch (err) { } catch (err) {
console.error(err) console.error(err)
} }
await delay(1)
await ms
return await light.end(rgb, id, ms) return await light.end(rgb, id, ms)
} }
light.end = async function (rgb, id, ms) { light.end = async function (rgb, id, ms) {
log.info('Light set to ' + rgb.join(','), 'LIGHT', true, true) 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 = { proj.state = {