Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add switch to GUI and implement alt hold toggle mode #67

Closed
wants to merge 2 commits into
base: dev_altholdpacket
from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+764 −358
Diff settings

Always

Just for now

Copy path View file
Binary file not shown.
Copy path View file
Binary file not shown.
Copy path View file
Binary file not shown.
Copy path View file
Binary file not shown.
Copy path View file
Binary file not shown.
Copy path View file
Binary file not shown.
Copy path View file
Binary file not shown.
Copy path View file
Binary file not shown.
Copy path View file
Binary file not shown.
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid
android:color="#FF8888"/>
<stroke
android:width="1dp"
android:color="#000000" />
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" />
</shape>
</item>
</selector>

Large diffs are not rendered by default.

Oops, something went wrong.
Copy path View file

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -52,7 +52,7 @@

<TextView
android:id="@+id/thrust"
android:layout_width="38dp"
android:layout_width="46dp"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
Copy path View file
Binary file not shown.
Copy path View file
Binary file not shown.
Copy path View file
Binary file not shown.
Copy path View file
Binary file not shown.
Copy path View file
Binary file not shown.
Copy path View file
@@ -21,6 +21,8 @@
<string name="button_ledring_contentDescription">LED ring button</string>
<string name="button_headlight_contentDescription">Headlight button</string>
<string name="button_buzzer_contentDescription">Buzzer button</string>
<string name="button_althold_contentDescription">Altitude hold button</string>
<string name="button_killswitch_contentDescription">Kill switch button</string>

<!-- Connection settings -->
<string name="preferences_radio_title">Connection settings</string>
@@ -65,6 +67,18 @@
<string name="preferences_afc_bool_summary_off">Normal mode</string>
<string name="preferences_xmode_title">X-Mode</string>
<string name="preferences_xmode_summary">Client X-mode</string>
<string name="preferences_altholdtoggle">Altitude hold toggle</string>
<string name="preferences_aht_title">Altitude hold toggle preferences</string>
<string name="preferences_aht_bool_summary_on">Altitude hold toggle mode. Use at your own risk!</string>
<string name="preferences_aht_bool_summary_off">Altitude hold normal mode</string>
<string name="preferences_aht_transition_time_title">Transition time [s]</string>
<string name="preferences_aht_transition_time_defaultValue">5</string>
<string name="preferences_aht_transition_dropspeed_title">Transition drop speed [m/s]</string>
<string name="preferences_aht_transition_dropspeed_defaultValue">-0.1</string>
<string name="preferences_aht_transition_takeover_threshold_title">Transition thrust take-over threshold [%]</string>
<string name="preferences_aht_transition_takeover_threshold_defaultValue">50</string>
<string name="preferences_reset_aht_title">Reset values</string>
<string name="preferences_reset_aht_summary">Reset to default values</string>

<!-- Controller settings -->
<string name="preferences_controller_title">Controller settings</string>
Copy path View file
@@ -142,6 +142,47 @@
android:summary="@string/preferences_reset_afc_summary"
android:title="@string/preferences_reset_afc_title" />
</PreferenceScreen>

<CheckBoxPreference
android:defaultValue="false"
android:key="pref_aht_bool"
android:summaryOff="@string/preferences_aht_bool_summary_off"
android:summaryOn="@string/preferences_aht_bool_summary_on"
android:title="@string/preferences_altholdtoggle" />

<!-- Advanced flight control settings -->
<PreferenceScreen
android:key="pref_aht_screen"
android:title="@string/preferences_aht_title"
android:dependency="pref_aht_bool" >
<se.bitcraze.crazyfliecontrol.prefs.SliderPreference
custom:upperLimit="10"
custom:wholeNumber="true"
android:defaultValue="@string/preferences_aht_transition_time_defaultValue"
android:dialogTitle="@string/preferences_aht_transition_time_title"
android:key="pref_aht_transition_time"
android:title="@string/preferences_aht_transition_time_title" />
<se.bitcraze.crazyfliecontrol.prefs.SliderPreference
custom:lowerLimit="-1"
custom:upperLimit="0"
custom:wholeNumber="false"
custom:steps="10"
android:defaultValue="@string/preferences_aht_transition_dropspeed_defaultValue"
android:dialogTitle="@string/preferences_aht_transition_dropspeed_title"
android:key="pref_aht_transition_dropspeed"
android:title="@string/preferences_aht_transition_dropspeed_title" />
<se.bitcraze.crazyfliecontrol.prefs.SliderPreference
custom:upperLimit="100"
custom:wholeNumber="true"
android:defaultValue="@string/preferences_aht_transition_takeover_threshold_defaultValue"
android:dialogTitle="@string/preferences_aht_transition_takeover_threshold_title"
android:key="pref_aht_transition_takeover_threshold"
android:title="@string/preferences_aht_transition_takeover_threshold_title" />
<Preference
android:key="pref_reset_aht"
android:summary="@string/preferences_reset_aht_summary"
android:title="@string/preferences_reset_aht_title" />
</PreferenceScreen>
</PreferenceScreen>

<!-- Controller settings -->
@@ -29,6 +29,7 @@

import se.bitcraze.crazyfliecontrol2.MainActivity;
import android.widget.Toast;
import static java.lang.Math.abs;


/**
@@ -75,8 +76,14 @@ public void updateFlightData() {
*/
public float getThrust() {
float thrust = ((mControls.getMode() == 1 || mControls.getMode() == 3) ? mControls.getRightAnalog_Y() : mControls.getLeftAnalog_Y());
if (thrust > mControls.getDeadzone()) {
return mControls.getMinThrust() + (thrust * mControls.getThrustFactor());
if (mActivity.isHoldAltitudeTouch()) {
if (abs(thrust) > mControls.getDeadzone()) {
return thrust*100;
}
} else {
if (thrust > mControls.getDeadzone()) {
return mControls.getMinThrust() + (thrust * mControls.getThrustFactor());
}
}
return 0;
}
@@ -116,4 +123,4 @@ public float getYaw() {
public boolean isHover() {
return false;
}
}
}
@@ -74,6 +74,7 @@
private int mGyroAmplification;
private String mGyroAmplificationDefaultValue;
private boolean mTouchThrustFullTravel;
private boolean mForceDisableTouchThrustFullTravel = false;

private String mModeDefaultValue;
private String mDeadzoneDefaultValue;
@@ -92,6 +93,17 @@
private String mMaxThrustDefaultValue;
private String mMinThrustDefaultValue;

// altitude hold toggle
private boolean mAltitudeHoldToggleModeEnable;
private int mAltitudeHoldToggleModeTransitionTime;
private float mAltitudeHoldToggleModeTransitionDropSpeed;
private int mAltitudeHoldToggleModeTransitionTakeOverThreshold;

// altitude hold toggle default values
private String mAltitudeHoldToggleModeTransitionTimeDefaultValue;
private String mAltitudeHoldToggleModeTransitionDropSpeedDefaultValue;
private String mAltitudeHoldToggleModeTransitionTakeOverThresholdDefaultValue;

public Controls(MainActivity activity, SharedPreferences preferences) {
this.mActivity = activity;
this.mPreferences = preferences;
@@ -115,6 +127,11 @@ public void setDefaultPreferenceValues(Resources res) {
mMaxYawAngleDefaultValue = res.getString(R.string.preferences_maxYawAngle_defaultValue);
mMaxThrustDefaultValue = res.getString(R.string.preferences_maxThrust_defaultValue);
mMinThrustDefaultValue = res.getString(R.string.preferences_minThrust_defaultValue);

// altitude hold toggle
mAltitudeHoldToggleModeTransitionTimeDefaultValue = res.getString(R.string.preferences_aht_transition_time_defaultValue);
mAltitudeHoldToggleModeTransitionDropSpeedDefaultValue = res.getString(R.string.preferences_aht_transition_dropspeed_defaultValue);
mAltitudeHoldToggleModeTransitionTakeOverThresholdDefaultValue = res.getString(R.string.preferences_aht_transition_takeover_threshold_defaultValue);
}

public void setControlConfig() {
@@ -129,7 +146,10 @@ public void setControlConfig() {
this.mUseGyro = mPreferences.getBoolean(PreferencesActivity.KEY_PREF_USE_GYRO_BOOL, false);
this.mGyroAmplification = Integer.parseInt(mPreferences.getString(PreferencesActivity.KEY_PREF_GYRO_AMP, mGyroAmplificationDefaultValue));

this.mTouchThrustFullTravel = mPreferences.getBoolean(PreferencesActivity.KEY_PREF_TOUCH_THRUST_FULL_TRAVEL, true);
if (mForceDisableTouchThrustFullTravel)
this.mTouchThrustFullTravel = false;
else
this.mTouchThrustFullTravel = mPreferences.getBoolean(PreferencesActivity.KEY_PREF_TOUCH_THRUST_FULL_TRAVEL, true);

this.mAlt1Action = mPreferences.getString(PreferencesActivity.KEY_PREF_ALT1_ACTION, mAlt1ActionDefaultValue);
this.mAlt2Action = mPreferences.getString(PreferencesActivity.KEY_PREF_ALT2_ACTION, mAlt2ActionDefaultValue);
@@ -148,6 +168,19 @@ public void setControlConfig() {
this.mMinThrust = Integer.parseInt(mMinThrustDefaultValue);
this.mXmode = false;
}

// altitude hold toggle
if (mPreferences.getBoolean(PreferencesActivity.KEY_PREF_AHT_BOOL, false)) {
this.mAltitudeHoldToggleModeEnable = true;
this.mAltitudeHoldToggleModeTransitionTime = Integer.parseInt(mPreferences.getString(PreferencesActivity.KEY_PREF_AHT_TRANSITION_TIME, mAltitudeHoldToggleModeTransitionTimeDefaultValue));
this.mAltitudeHoldToggleModeTransitionDropSpeed = Float.parseFloat(mPreferences.getString(PreferencesActivity.KEY_PREF_AHT_TRANSITION_DROPSPEED, mAltitudeHoldToggleModeTransitionDropSpeedDefaultValue));
this.mAltitudeHoldToggleModeTransitionTakeOverThreshold = Integer.parseInt(mPreferences.getString(PreferencesActivity.KEY_PREF_AHT_TRANSITION_TAKEOVER_THRESHOLD, mAltitudeHoldToggleModeTransitionDropSpeedDefaultValue));
} else {
this.mAltitudeHoldToggleModeEnable = false;
this.mAltitudeHoldToggleModeTransitionTime = Integer.parseInt(mAltitudeHoldToggleModeTransitionTimeDefaultValue);
this.mAltitudeHoldToggleModeTransitionDropSpeed = Float.parseFloat(mAltitudeHoldToggleModeTransitionDropSpeedDefaultValue);
this.mAltitudeHoldToggleModeTransitionTakeOverThreshold = Integer.parseInt(mAltitudeHoldToggleModeTransitionTakeOverThresholdDefaultValue);
}
}

public float getRollTrim() {
@@ -245,6 +278,15 @@ public boolean isTouchThrustFullTravel() {
return mTouchThrustFullTravel;
}

public void setForceDisableTouchThrustFullTravel(boolean value) {
if (value) this.mForceDisableTouchThrustFullTravel = true;
else this.mForceDisableTouchThrustFullTravel = false;
}

public boolean getForceDisableTouchThrustFullTravel() {
return mForceDisableTouchThrustFullTravel;
}

public float getRightAnalog_X() {
return mRight_analog_x;
}
@@ -299,6 +341,14 @@ public int getMinThrust() {
return mMinThrust;
}

public boolean getAltitudeHoldToggleModeEnable() { return mAltitudeHoldToggleModeEnable; }

public int getAltitudeHoldToggleModeTransitionTime() { return mAltitudeHoldToggleModeTransitionTime; }

public float getAltitudeHoldToggleModeTransitionDropSpeed() { return mAltitudeHoldToggleModeTransitionDropSpeed; }

public int getAltitudeHoldToggleModeTransitionTakeOverThreshold() { return mAltitudeHoldToggleModeTransitionTakeOverThreshold; }

// TODO: move methods to Controls?
public float getRollPitchFactor() {
return getMaxRollPitchAngle();
@@ -254,4 +254,7 @@ public float getThrustAbsolute() {
return 0;
}

public boolean areJoysticksReleased() { return false; }

public void updateAutoReturnMode() {}
}
@@ -45,4 +45,7 @@

public boolean isHover();

public boolean areJoysticksReleased();

public void updateAutoReturnMode();
}
@@ -47,14 +47,17 @@

protected DualJoystickView mDualJoystickView;

protected boolean mRightJoystickReleased = true;
protected boolean mLeftJoystickReleased = true;

public TouchController(Controls controls, MainActivity activity, DualJoystickView dualJoystickview) {
super(controls, activity);
this.mDualJoystickView = dualJoystickview;
this.mDualJoystickView.setMovementRange(mMovementRange, mMovementRange);
updateAutoReturnMode();
}

private void updateAutoReturnMode() {
public void updateAutoReturnMode() {
this.mDualJoystickView.setAutoReturnMode(
isLeftAnalogFullTravelThrust() ? JoystickView.AUTO_RETURN_BOTTOM : JoystickView.AUTO_RETURN_CENTER,
isRightAnalogFullTravelThrust() ? JoystickView.AUTO_RETURN_BOTTOM : JoystickView.AUTO_RETURN_CENTER
@@ -87,6 +90,7 @@ public String getControllerName() {

@Override
public void OnMoved(float pan, float tilt) {
mRightJoystickReleased = false;
if (isRightAnalogFullTravelThrust()) {
tilt = (tilt + 1.0f) / 2.0f;
}
@@ -99,12 +103,14 @@ public void OnMoved(float pan, float tilt) {

@Override
public void OnReleased() {
mRightJoystickReleased = true;
// Log.i("Joystick-Right", "Release");
mControls.setRightAnalogY(0);
mControls.setRightAnalogX(0);
}

public void OnReturnedToCenter() {
mRightJoystickReleased = true;
// Log.i("Joystick-Right", "Center");
mControls.setRightAnalogY(0);
mControls.setRightAnalogX(0);
@@ -115,6 +121,7 @@ public void OnReturnedToCenter() {

@Override
public void OnMoved(float pan, float tilt) {
mLeftJoystickReleased = false;
if (isLeftAnalogFullTravelThrust()) {
tilt = (tilt + 1.0f) / 2.0f;
}
@@ -127,16 +134,22 @@ public void OnMoved(float pan, float tilt) {

@Override
public void OnReleased() {
mLeftJoystickReleased = true;
mControls.setLeftAnalogY(0);
mControls.setLeftAnalogX(0);
}

public void OnReturnedToCenter() {
mLeftJoystickReleased = true;
mControls.setLeftAnalogY(0);
mControls.setLeftAnalogX(0);
}
};

public boolean areJoysticksReleased() {
return mRightJoystickReleased && mLeftJoystickReleased;
}


public boolean isThrustRightAnalog() {
return (mControls.getMode() == 1 || mControls.getMode() == 3);
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.