From cf282db685ca5e27319b5bb9ef5507b0c1cab21f Mon Sep 17 00:00:00 2001 From: Arian Date: Sun, 11 Oct 2020 21:55:53 +0200 Subject: [PATCH] davinci: parts: Add a setting to calibrate the motor Change-Id: I9f76124759bf8497b5cd72293b5c36f85b4d1787 --- parts/res/drawable/ic_popup_calibration.xml | 9 ++++++++ parts/res/values/strings.xml | 4 +++- parts/res/xml/popup_settings.xml | 6 +++++ .../popupcamera/PopupCameraService.java | 15 ++++++++++--- .../PopupCameraSettingsFragment.java | 22 +++++++++++++++++-- 5 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 parts/res/drawable/ic_popup_calibration.xml diff --git a/parts/res/drawable/ic_popup_calibration.xml b/parts/res/drawable/ic_popup_calibration.xml new file mode 100644 index 0000000..f1c70fb --- /dev/null +++ b/parts/res/drawable/ic_popup_calibration.xml @@ -0,0 +1,9 @@ + + + + diff --git a/parts/res/values/strings.xml b/parts/res/values/strings.xml index 241e92c..239e8a4 100644 --- a/parts/res/values/strings.xml +++ b/parts/res/values/strings.xml @@ -16,7 +16,7 @@ --> - Front camera effects + Front camera settings Camera LED Enable LED light while the front camera appears and retracts Sound effects @@ -26,6 +26,8 @@ Mecha Gearwheel Cabin door + Calibration + Calibrate the popup camera motor Warning diff --git a/parts/res/xml/popup_settings.xml b/parts/res/xml/popup_settings.xml index 09129e4..98aa637 100644 --- a/parts/res/xml/popup_settings.xml +++ b/parts/res/xml/popup_settings.xml @@ -17,4 +17,10 @@ android:summary="%s" android:title="@string/popup_sound_title" /> + + diff --git a/parts/src/org/lineageos/settings/popupcamera/PopupCameraService.java b/parts/src/org/lineageos/settings/popupcamera/PopupCameraService.java index ee18e81..3c1afe8 100644 --- a/parts/src/org/lineageos/settings/popupcamera/PopupCameraService.java +++ b/parts/src/org/lineageos/settings/popupcamera/PopupCameraService.java @@ -166,7 +166,6 @@ public class PopupCameraService extends Service implements Handler.Callback { synchronized (mLock) { if (status == Constants.MOTOR_STATUS_CALIB_OK || status == Constants.MOTOR_STATUS_CALIB_ERROR) { - mMotorCalibrating = false; showCalibrationResult(status); } else if (status == Constants.MOTOR_STATUS_PRESSED) { updateMotor(Constants.CLOSE_CAMERA_STATE); @@ -179,16 +178,26 @@ public class PopupCameraService extends Service implements Handler.Callback { } } - private void calibrateMotor() { + protected void calibrateMotor() { synchronized (mLock) { - if (mMotorCalibrating || mMotor == null) + if (mMotorCalibrating) return; + if (mMotor == null) { + try { + mMotor = IMotor.getService(); + } catch (RemoteException e) { + // Do nothing + } + if (mMotor == null) + return; + } try { mMotorCalibrating = true; mMotor.calibration(); } catch (RemoteException e) { // Do nothing } + mHandler.postDelayed(() -> mMotorCalibrating = false, 7000); } } diff --git a/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsFragment.java b/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsFragment.java index 701c9ca..37e5fd8 100644 --- a/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsFragment.java +++ b/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsFragment.java @@ -21,16 +21,25 @@ import android.view.MenuItem; import androidx.preference.Preference; import androidx.preference.Preference.OnPreferenceChangeListener; +import androidx.preference.Preference.OnPreferenceClickListener; import androidx.preference.PreferenceFragment; import org.lineageos.settings.R; -public class PopupCameraSettingsFragment - extends PreferenceFragment implements OnPreferenceChangeListener { +public class PopupCameraSettingsFragment extends PreferenceFragment + implements OnPreferenceChangeListener, OnPreferenceClickListener { + private Preference mCalibrationPreference; + private static final String MOTOR_CALIBRATION_KEY = "motor_calibration"; + + private PopupCameraService mPopupCameraService = new PopupCameraService(); + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.popup_settings); getActivity().getActionBar().setDisplayHomeAsUpEnabled(true); + + mCalibrationPreference = (Preference) findPreference(MOTOR_CALIBRATION_KEY); + mCalibrationPreference.setOnPreferenceClickListener(this); } @Override @@ -46,4 +55,13 @@ public class PopupCameraSettingsFragment } return false; } + + @Override + public boolean onPreferenceClick(Preference preference) { + if (MOTOR_CALIBRATION_KEY.equals(preference.getKey())) { + mPopupCameraService.calibrateMotor(); + return true; + } + return false; + } }