From c17347a1dd961a416442b1be3e3477c0e2e4daae Mon Sep 17 00:00:00 2001
From: Tim Stadtmann <tim.stadtmann@rwth-aachen.de>
Date: Mon, 17 Oct 2016 13:35:59 +0200
Subject: [PATCH] isRunning is now also true if motor runs w/o limit

The implementation is based on a new flag, 'startedNotBusy', which
is set to true if single motor is started w/o limit.
---
 source/Motor.m | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/source/Motor.m b/source/Motor.m
index 5e24314..c960994 100755
--- a/source/Motor.m
+++ b/source/Motor.m
@@ -98,6 +98,7 @@ classdef Motor < MaskedHandle & dynamicprops
         
         connectedToBrick = false;  % Connection to physical Brick? 
         init = true;  % Indicates 'init-phase' (True as long as constructor is running)
+        startedNotBusy = false;  % Set to true if motor started w/o tacholimit and unsynced
         sendPowerOnSet = false;  % If true, OUTPUT_POWER is sent when setting power
         
         % Bitfield representing which opCodes should be sent on Motor.start() 
@@ -201,6 +202,7 @@ classdef Motor < MaskedHandle & dynamicprops
                 if motor.debug
                     fprintf('(DEBUG) Motor::start: Called outputStart on Port %s\n', port2str('Motor', motor.port));
                 end
+                motor.startedNotBusy = true;
             else
                 limit = motor.limitValue - (motor.smoothStart + motor.smoothStop);
                 if limit < 0
@@ -270,6 +272,8 @@ classdef Motor < MaskedHandle & dynamicprops
             if motor.debug
                 fprintf('(DEBUG) Motor::stop: Called outputStop on Port %s\n', port2str('Motor', motor.port));
             end
+            
+            motor.startedNotBusy = false;
         end
         
         function syncedStart(motor, syncMotor, varargin)
@@ -842,9 +846,15 @@ classdef Motor < MaskedHandle & dynamicprops
         
         function running = get.isRunning(motor)
             running = 0;
+            
             if motor.connectedToBrick
-                running = motor.getBusyFlag();
+                busyFlag = motor.getBusyFlag();
+            else
+                busyFlag = 0;
             end
+            
+            assert(~(motor.startedNotBusy && busyFlag));
+            running = motor.startedNotBusy || busyFlag;
         end
         
         function synced = get.isSynced(motor)
@@ -1053,6 +1063,7 @@ classdef Motor < MaskedHandle & dynamicprops
         end
     end
     
+    
     methods (Access = {?EV3})
         function connect(motor,commInterface)
             %connect Connects Motor-object to physical brick.
-- 
GitLab