Endprogram (#884)
* moving end program logic to c++ * typo * always stop on reset
This commit is contained in:
		@@ -162,7 +162,6 @@ namespace brick {
 | 
				
			|||||||
        // this needs to be done in query(), which is run without the main JS execution mutex
 | 
					        // this needs to be done in query(), which is run without the main JS execution mutex
 | 
				
			||||||
        // otherwise, while(true){} will lock the device
 | 
					        // otherwise, while(true){} will lock the device
 | 
				
			||||||
        if (ret & DAL.BUTTON_ID_ESCAPE) {
 | 
					        if (ret & DAL.BUTTON_ID_ESCAPE) {
 | 
				
			||||||
            motors.stopAll(); // ensuring that all motors are off
 | 
					 | 
				
			||||||
            control.reset()
 | 
					            control.reset()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return ret
 | 
					        return ret
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,7 @@
 | 
				
			|||||||
#include <errno.h>
 | 
					#include <errno.h>
 | 
				
			||||||
#include <fcntl.h>
 | 
					#include <fcntl.h>
 | 
				
			||||||
#include <malloc.h>
 | 
					#include <malloc.h>
 | 
				
			||||||
 | 
					#include "ev3const.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define THREAD_DBG(...)
 | 
					#define THREAD_DBG(...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -489,14 +490,22 @@ void runLMS() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void stopMotors() {
 | 
					void stopMotors() {
 | 
				
			||||||
    uint8_t cmd[2] = { 0xA3, 0x0F };
 | 
					    uint8_t cmd[3] = { opOutputStop, 0x0F, 0 };
 | 
				
			||||||
    int fd = open("/dev/lms_pwm", O_RDWR);
 | 
					    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);
 | 
					    close(fd);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" void target_reset() {
 | 
					extern "C" void target_reset() {
 | 
				
			||||||
    stopMotors();
 | 
					    stopMotors();
 | 
				
			||||||
 | 
					    stopProgram();
 | 
				
			||||||
    if (lmsPid)
 | 
					    if (lmsPid)
 | 
				
			||||||
        runLMS();
 | 
					        runLMS();
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user