From 4039a85bc9089129126e4b805f0310e6e3d898a7 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Fri, 5 Jan 2018 16:17:33 +0000 Subject: [PATCH] Make sure the ESC button always stops the program --- libs/core/buttons.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/core/buttons.ts b/libs/core/buttons.ts index 854b395e..0de89e8c 100644 --- a/libs/core/buttons.ts +++ b/libs/core/buttons.ts @@ -163,6 +163,10 @@ namespace brick { if (sl[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 } @@ -172,8 +176,6 @@ namespace brick { if (!btnsMM) control.fail("no buttons?") buttons = [] sensors.internal.unsafePollForChanges(50, readButtons, (prev, curr) => { - if (curr & DAL.BUTTON_ID_ESCAPE) - control.reset() for (let b of buttons) b._update(!!(curr & b.mask)) })