davinci: parts: Check if motor is busy before doing any operation
Change-Id: I83e383d5f6d3d8e723259bc55945aab48e5acd6c
This commit is contained in:
parent
65c44dd66e
commit
619c58031f
@ -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,24 +152,45 @@ public class PopupCameraService extends Service implements Handler.Callback {
|
||||
}
|
||||
|
||||
private void updateMotor(String cameraState) {
|
||||
if (mMotor == null) return;
|
||||
try {
|
||||
if (cameraState.equals(Constants.OPEN_CAMERA_STATE)
|
||||
&& mMotor.getMotorStatus() == Constants.MOTOR_STATUS_TAKEBACK) {
|
||||
lightUp();
|
||||
playSoundEffect(Constants.OPEN_CAMERA_STATE);
|
||||
mMotor.popupMotor(1);
|
||||
mSensorManager.registerListener(mFreeFallListener, mFreeFallSensor,
|
||||
SensorManager.SENSOR_DELAY_NORMAL);
|
||||
} else if (cameraState.equals(Constants.CLOSE_CAMERA_STATE)
|
||||
&& mMotor.getMotorStatus() == Constants.MOTOR_STATUS_POPUP) {
|
||||
lightUp();
|
||||
playSoundEffect(Constants.CLOSE_CAMERA_STATE);
|
||||
mMotor.takebackMotor(1);
|
||||
mSensorManager.unregisterListener(mFreeFallListener, mFreeFallSensor);
|
||||
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) {
|
||||
lightUp();
|
||||
playSoundEffect(Constants.OPEN_CAMERA_STATE);
|
||||
mMotor.popupMotor(1);
|
||||
mSensorManager.registerListener(mFreeFallListener, mFreeFallSensor,
|
||||
SensorManager.SENSOR_DELAY_NORMAL);
|
||||
} else if (cameraState.equals(Constants.CLOSE_CAMERA_STATE)
|
||||
&& mMotor.getMotorStatus() == Constants.MOTOR_STATUS_POPUP) {
|
||||
lightUp();
|
||||
playSoundEffect(Constants.CLOSE_CAMERA_STATE);
|
||||
mMotor.takebackMotor(1);
|
||||
mSensorManager.unregisterListener(mFreeFallListener, mFreeFallSensor);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
// Do nothing
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user