From aa40e7b16910c338bacce7003bc2b3d51f1b2468 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 28 Aug 2019 08:52:01 -0700 Subject: [PATCH] Endprogram (#884) * moving end program logic to c++ * typo * always stop on reset --- libs/core/buttons.ts | 1 - libs/core/linux.cpp | 13 +++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/core/buttons.ts b/libs/core/buttons.ts index 8faad1b4..a50464e9 100644 --- a/libs/core/buttons.ts +++ b/libs/core/buttons.ts @@ -162,7 +162,6 @@ namespace brick { // 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) { - motors.stopAll(); // ensuring that all motors are off control.reset() } return ret diff --git a/libs/core/linux.cpp b/libs/core/linux.cpp index 22ab7aa3..9f8df9f6 100644 --- a/libs/core/linux.cpp +++ b/libs/core/linux.cpp @@ -14,6 +14,7 @@ #include #include #include +#include "ev3const.h" #define THREAD_DBG(...) @@ -489,14 +490,22 @@ void runLMS() { } void stopMotors() { - uint8_t cmd[2] = { 0xA3, 0x0F }; + uint8_t cmd[3] = { opOutputStop, 0x0F, 0 }; int fd = open("/dev/lms_pwm", O_RDWR); - write(fd, cmd, 2); + write(fd, cmd, 3); + close(fd); +} + +void stopProgram() { + uint8_t cmd[1] = { opOutputProgramStop }; + int fd = open("/dev/lms_pwm", O_RDWR); + write(fd, cmd, 1); close(fd); } extern "C" void target_reset() { stopMotors(); + stopProgram(); if (lmsPid) runLMS(); else