Make sure the ESC button always stops the program

This commit is contained in:
Michal Moskal 2018-01-05 16:17:33 +00:00
parent 7bd6280292
commit 4039a85bc9

View File

@ -163,6 +163,10 @@ namespace brick {
if (sl[i]) if (sl[i])
ret |= 1 << i ret |= 1 << i
} }
// this needs to be done in query(), which is run without the main JS execution mutex
// otherwise, while(true){} will lock the device
if (ret & DAL.BUTTON_ID_ESCAPE)
control.reset()
return ret return ret
} }
@ -172,8 +176,6 @@ namespace brick {
if (!btnsMM) control.fail("no buttons?") if (!btnsMM) control.fail("no buttons?")
buttons = [] buttons = []
sensors.internal.unsafePollForChanges(50, readButtons, (prev, curr) => { sensors.internal.unsafePollForChanges(50, readButtons, (prev, curr) => {
if (curr & DAL.BUTTON_ID_ESCAPE)
control.reset()
for (let b of buttons) for (let b of buttons)
b._update(!!(curr & b.mask)) b._update(!!(curr & b.mask))
}) })