davinci: parts: Check if motor is busy before doing any operation

Change-Id: I83e383d5f6d3d8e723259bc55945aab48e5acd6c
This commit is contained in:
jhenrique09 2019-11-26 18:27:25 +00:00 committed by Arian
parent 65c44dd66e
commit 619c58031f
No known key found for this signature in database
GPG Key ID: 48029380598CE3B9

View File

@ -45,6 +45,7 @@ public class PopupCameraService extends Service implements Handler.Callback {
private static final boolean DEBUG = false;
private int[] mSounds;
private boolean mMotorBusy = false;
private long mClosedEvent;
private long mOpenEvent;
@ -151,7 +152,12 @@ public class PopupCameraService extends Service implements Handler.Callback {
}
private void updateMotor(String cameraState) {
if (mMotor == null) return;
if (mMotor == null) {
return;
}
final Runnable r = () -> {
mMotorBusy = true;
mHandler.postDelayed(() -> mMotorBusy = false, 1200);
try {
if (cameraState.equals(Constants.OPEN_CAMERA_STATE)
&& mMotor.getMotorStatus() == Constants.MOTOR_STATUS_TAKEBACK) {
@ -170,6 +176,22 @@ public class PopupCameraService extends Service implements Handler.Callback {
} catch (RemoteException e) {
// Do nothing
}
};
if (mMotorBusy) {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
if (mMotorBusy) {
mHandler.postDelayed(this, 100);
} else {
mHandler.post(r);
}
}
}, 100);
} else {
mHandler.post(r);
}
}
private void lightUp() {